-
Notifications
You must be signed in to change notification settings - Fork 0
Interfaces #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Interfaces #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what's going on in the lib folder. You should be able to drop the JAR in there as-is. Seems like you might have unzipped it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Manifest-Version: 1.0 | ||
| Ant-Version: Apache Ant 1.10.12 | ||
| Created-By: 19.0.1+10-21 (Oracle Corporation) | ||
| Built-By: Paolo Bucci | ||
| Sealed: false | ||
| Built-On: 2023-01-01 10:30:08 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
|
|
||
| /** | ||
| * Interface for additional methods within the Artificial Neuron component. | ||
| * | ||
| * @author Grace Metz | ||
| * | ||
| */ | ||
| public interface Neuron extends NeuronKernel { | ||
|
|
||
| /** | ||
| * Using the sigmoid activation function: an output >= 0.5 means a yes, or | ||
| * the neuron has fired. | ||
| * | ||
| * @requires {@code |this.weights| >= 0 && |this.inputs| >= 0} | ||
| * @ensures {@code <activate> = true || false} | ||
| * @return whether the neuron has fired. | ||
| */ | ||
| boolean activate(); | ||
|
|
||
| /** | ||
| * Set an object's weight and ensure that it is usable by the neuron. | ||
| * | ||
| * @param value | ||
| * the weight being entered | ||
| * @requires {@code -1 <= value <= 1} | ||
| * @ensures {@code this.weights = #this.weights * #value} | ||
| */ | ||
| void setWeight(double value); | ||
|
|
||
| /** | ||
| * Sum the weights. | ||
| * | ||
| * @requires {@code |this.weights| >= 0} | ||
| * @ensures {@code sum = this.weights[0] + ... + this.weights[|this.weights|]} | ||
| * @return the sum of the weights. | ||
| */ | ||
| double sum(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import components.queue.Queue; | ||
| import components.queue.Queue1L; | ||
|
|
||
| /** | ||
| * {@code Neuron} represented as multiple {@link Queue}s with implementations of | ||
| * primary methods. | ||
| * | ||
| * @convention [$this.inputs is a queue of String inputs] and [$this.weights is | ||
| * a queue of double weights] | ||
| * @correspondence this = ($this.inputs, $this.weights) | ||
| */ | ||
| public class Neuron1 extends NeuronSecondary { | ||
|
|
||
| /** | ||
| * Queue of Strings to represent the values of each input. | ||
| */ | ||
| private Queue<String> inputs = new Queue1L<>(); | ||
|
|
||
| /** | ||
| * Queue of values to represent the weights of each input. | ||
| */ | ||
| private Queue<Double> weights = new Queue1L<>(); | ||
|
|
||
| /** | ||
| * Creator of initial representation. | ||
| */ | ||
| private void createNewRep() { | ||
| this.inputs = new Queue1L<>(); | ||
| this.weights = new Queue1L<>(); | ||
| } | ||
|
|
||
| /** | ||
| * No-argument constructor. | ||
| */ | ||
| public Neuron1() { | ||
| this.createNewRep(); | ||
| } | ||
|
|
||
| @Override | ||
| public final Queue<Double> weights() { | ||
| return this.weights; | ||
| } | ||
|
|
||
| @Override | ||
| public final Queue<String> inputs() { | ||
| return this.inputs; | ||
| } | ||
|
|
||
| @Override | ||
| public final void setInput(String value) { | ||
| this.inputs.enqueue(value); | ||
| } | ||
|
|
||
| @Override | ||
| public final void clear() { | ||
| this.inputs = this.inputs.newInstance(); | ||
| this.weights = this.weights.newInstance(); | ||
| } | ||
|
|
||
| @Override | ||
| public final Neuron newInstance() { | ||
| Neuron newIn = new Neuron1(); | ||
| return newIn; | ||
| } | ||
|
|
||
| @Override | ||
| public final void transferFrom(Neuron arg0) { | ||
| // TODO finish this for part 6 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import components.queue.Queue; | ||
| import components.standard.Standard; | ||
|
|
||
| /** | ||
| * Interface for the essential methods and values within the Artificial Neuron | ||
| * component. | ||
| * | ||
| * @author Grace Metz | ||
| * | ||
| */ | ||
| public interface NeuronKernel extends Standard<Neuron> { | ||
|
|
||
| /** | ||
| * Retrieve the weight assigned to the inputs within this node. | ||
| * | ||
| * @requires {@code |weights| >= 0} | ||
| * @ensures {@code <weights> = weights} | ||
| * @return the queue of weight values | ||
| */ | ||
| Queue<Double> weights(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs look good |
||
|
|
||
| /** | ||
| * Return the inputs entered into the neuron. | ||
| * | ||
| * @requires {@code |inputs| >= 0} | ||
| * @ensures {@code <inputs> = inputs} | ||
| * @return the queue of input Strings | ||
| */ | ||
| Queue<String> inputs(); | ||
|
|
||
| /** | ||
| * Ensure that inputs are valid and usable by the neuron. | ||
| * | ||
| * @param value | ||
| * the String value being entered | ||
| * @requires {@code <value> != null} | ||
| * @ensures {@code <inputs> = #inputs * #value} | ||
| */ | ||
| void setInput(String value); | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import components.queue.Queue; | ||
|
|
||
| /** | ||
| * Interface for additional methods within the Artificial Neuron component. | ||
| * | ||
| * @author Grace Metz | ||
| * | ||
| */ | ||
| public abstract class NeuronSecondary implements Neuron { | ||
|
|
||
| /** | ||
| * Queue of Strings to represent the values of each input. | ||
| */ | ||
| private Queue<String> inputs; | ||
|
|
||
| /** | ||
| * Queue of values to represent the weights of each input. | ||
| */ | ||
| private Queue<Double> weights; | ||
|
|
||
| /** | ||
| * Using the sigmoid activation function: an output >= 0.5 means a yes, or | ||
| * the neuron has fired. | ||
| * | ||
| * @requires {@code |this.weights| >= 0 && |this.inputs| >= 0} | ||
| * @ensures {@code <activate> = true || false} | ||
| * @return whether the neuron has fired. | ||
| */ | ||
| @Override | ||
| public boolean activate() { | ||
| double s = 1.0 / (1.0 + Math.exp(this.sum())); | ||
| boolean fired = false; | ||
|
|
||
| if (s >= 0.5) { | ||
| fired = true; | ||
| } | ||
|
|
||
| return fired; | ||
| } | ||
|
|
||
| /** | ||
| * Set an object's weight and ensure they are usable by the neuron. | ||
| * | ||
| * @param value | ||
| * the weight being entered | ||
| * @requires {@code -1 <= value <= 1} | ||
| * @ensures {@code this.weights = #this.weights * #value} | ||
| */ | ||
| @Override | ||
| public void setWeight(double value) { | ||
| this.weights.enqueue(value); | ||
| } | ||
|
|
||
| /** | ||
| * Sum the weights. | ||
| * | ||
| * @return the sum of the weights. | ||
| */ | ||
| @Override | ||
| public double sum() { | ||
| double sum = 0; | ||
| double weight = 0; | ||
| if (this.weights.length() > 0) { | ||
| weight = this.weights.dequeue(); | ||
| sum = this.sum() + weight; | ||
| } | ||
| this.weights.enqueue(weight); | ||
|
|
||
| return sum; | ||
| } | ||
|
|
||
| /** | ||
| * Return the data in the Neuron component as a string. | ||
| * | ||
| * @return the String representing the Neuron. | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| StringBuilder result = new StringBuilder(); | ||
| result.append("Neuron [weights="); | ||
| result.append(this.weights.toString()); | ||
| result.append("]"); | ||
| result.append("[inputs="); | ||
| result.append(this.inputs.toString()); | ||
| result.append("]"); | ||
| return result.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Return whether or not this equals an object. | ||
| * | ||
| * @return whether this equals an object. | ||
| */ | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| Neuron object = this.newInstance(); | ||
|
|
||
| if (!(o == null || this.getClass() != o.getClass())) { | ||
| object = (Neuron) o; | ||
| } | ||
|
|
||
| return this.weights.equals(object.weights()) | ||
| && this.inputs.equals(object.inputs()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe PDFs can be embedded in markdown, but I was able to view the file.