-
-
Save busti/515bbf8c320537bb4ddc9275df4d5078 to your computer and use it in GitHub Desktop.
Dumb assignment is dumb
This file contains 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
public void train(List<Data> data) { | |
//Initialize the weight array with random values. | |
for (int i = 0; i < weights.length; i++) { | |
weights[i] = rand.nextFloat(); | |
} | |
//Create an Iterator for the training data | |
Iterator<Data> iter = data.iterator(); | |
//Train as often as there are numbers in epochen... | |
for (int j = 0; j < epochen; j++) { | |
//Create a boolean list that are determined by a fail or success. | |
List<Boolean> correct = new ArrayList<Boolean>(); | |
//Iterate through the training data and adjust the weights accordingly | |
while (iter.hasNext()) { | |
Data d = iter.next(); | |
//calculate the error value | |
float error = d.getOut() - output(d.getIn()); | |
//Adjust the weight values | |
for (int i = 0; i < weights.length; i++) { | |
weights[i] += learningrate * error * d.getIn()[i]; | |
} | |
//Determine wether the output is correct or failed to calculate the percentage later on. | |
correct.add(output(d.getIn()) == d.getOut()); | |
} | |
if (checkPercentage(correct)) { | |
System.out.println("Stopped training after " + j + "Epochen"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment