-
Notifications
You must be signed in to change notification settings - Fork 0
Create proof of concept for component #1
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
1
commit into
main
Choose a base branch
from
proof-of-concept
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Very simple implementation of the methods in the Artificial Neuron component. | ||
| * | ||
| * @author Grace Metz | ||
| * | ||
| */ | ||
| public final class Proof { | ||
|
|
||
| /** | ||
| * To prevent instantiation. | ||
| */ | ||
| private Proof() { | ||
| } | ||
|
|
||
| /** | ||
| * Ensure that inputs are valid and usable by the neuron. | ||
| * | ||
| * @param inputs | ||
| * the list of inputs | ||
| * @param input | ||
| * the String being entered | ||
| */ | ||
| public static void setInput(ArrayList<String> inputs, String input) { | ||
| if (!input.equals(" ") && !input.isEmpty() && input.length() > 1) { | ||
| inputs.add(input); | ||
| } else { | ||
| System.out.println("Input must be a word."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set all weights and ensure they are usable by the neuron. | ||
| * | ||
| * @param weights | ||
| * the list of weights | ||
| * @param weight | ||
| * the weight being entered | ||
| */ | ||
| public static void setWeight(ArrayList<Double> weights, double weight) { | ||
| if (weight >= -1 && weight <= 1) { | ||
| weights.add(weight); | ||
| } else { | ||
| System.out.println("Weight must be between -1 and 1."); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Sum the weights. | ||
| * | ||
| * @param weights | ||
| * the list of weights | ||
| * | ||
| * @return the sum of the weights | ||
| */ | ||
| public static double sum(ArrayList<Double> weights) { | ||
| double sum = 0; | ||
|
|
||
| for (int i = 0; i < weights.size(); i++) { | ||
| sum = sum + weights.get(i); | ||
| } | ||
|
|
||
| return sum; | ||
| } | ||
|
|
||
| /** | ||
| * Using the sigmoid activation function: an output >= 0.5 means a yes, or | ||
| * the neuron has fired. | ||
| * | ||
| * @param sum | ||
| * the sum of the weights | ||
| * | ||
| * @return whether the neuron has fired. | ||
| */ | ||
| public static boolean activate(double sum) { | ||
| double s = 1.0 / (1.0 + Math.exp(-sum)); | ||
| boolean fired = false; | ||
|
|
||
| if (s >= 0.5) { | ||
| fired = true; | ||
| } | ||
|
|
||
| return fired; | ||
| } | ||
|
|
||
| /** | ||
| * Main. | ||
| * | ||
| * @param args | ||
| */ | ||
| public static void main(String[] args) { | ||
| // Decide whether today is a good day to go windsurfing | ||
| // (conditions should be sunny and windy) | ||
| // Using methods setWeight, setInput, activate, and sum | ||
|
|
||
| Scanner in = new Scanner(System.in); | ||
|
|
||
| ArrayList<String> words = new ArrayList<>(); | ||
| ArrayList<Double> importance = new ArrayList<>(); | ||
|
|
||
| System.out.println( | ||
| "Please enter a word that describes today's weather: "); | ||
| String word = in.nextLine(); | ||
| setInput(words, word); | ||
| System.out.println( | ||
| "Please enter how good that condition is for windsurfing (-1 to 1): "); | ||
| setWeight(importance, Double.parseDouble(in.nextLine())); | ||
| System.out.println("Enter another word? (y/n): "); | ||
| String loop = in.nextLine(); | ||
|
|
||
| while (loop.equals("Y")) { | ||
| System.out.println( | ||
| "Please enter a word that describes today's weather: "); | ||
| word = in.nextLine(); | ||
| setInput(words, word); | ||
| System.out.println( | ||
| "Please enter how good that condition is for windsurfing (-1 to 1): "); | ||
| setWeight(importance, Double.parseDouble(in.nextLine())); | ||
| System.out.println("Enter another word? (y/n): "); | ||
| loop = in.nextLine(); | ||
| } | ||
|
|
||
| double total = sum(importance); | ||
|
|
||
| System.out.println("Today is a good day for windsurfing: "); | ||
| System.out.println(activate(total)); | ||
|
|
||
| in.close(); | ||
| } | ||
| } | ||
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.
For a proof of concept, I would like to see instance methods. That way, we can see the actual data being stored and used.