-
Notifications
You must be signed in to change notification settings - Fork 0
Abstract class #2
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
Open
graceemetz
wants to merge
3
commits into
main
Choose a base branch
from
abstract-class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
doc/04-component-abstract-class/04-component-abstract-class.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
|
|
||
| /** | ||
| * 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. | ||
| * | ||
| * @return whether the neuron has fired. | ||
| */ | ||
| boolean activate(); | ||
|
|
||
| /** | ||
| * Set an object's weight and ensure they are usable by the neuron. | ||
| * | ||
| * @param value | ||
| * the weight being entered | ||
| */ | ||
| void setWeight(double value); | ||
|
|
||
| /** | ||
| * Sum the weights. | ||
| * | ||
| * @return the sum of the weights. | ||
| */ | ||
| double sum(); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import components.queue.Queue; | ||
| import components.queue.Queue1L; | ||
| 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> { | ||
|
|
||
| /** | ||
| * Queue of Strings to represent the values of each input. | ||
| */ | ||
| Queue<String> inputs = new Queue1L<>(); | ||
|
|
||
| /** | ||
| * Queue of values to represent the weights of each input. | ||
| */ | ||
| Queue<Double> weights = new Queue1L<>(); | ||
|
|
||
| /** | ||
| * Retrieve the weight assigned to the inputs within this node. | ||
| * | ||
| * @return the queue of weight values | ||
| */ | ||
| Queue<Double> weights(); | ||
|
|
||
| /** | ||
| * Return the inputs entered into the neuron. | ||
| * | ||
| * @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 | ||
| */ | ||
| void setInput(String value); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * Layered implementations of secondary methods for {@code Neuron}. | ||
| */ | ||
| public abstract class NeuronSecondary implements Neuron { | ||
|
|
||
| /** | ||
| * Using the sigmoid activation function: an output >= 0.5 means a yes, or | ||
| * the neuron has fired. | ||
| * | ||
| * @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; | ||
| } | ||
|
|
||
| /** | ||
| * Enter a weight to be used by the neuron. | ||
| * | ||
| * @param value | ||
| * the weight being entered | ||
| */ | ||
| @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); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Take a peek at how this is implemented in the common methods slides.