Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public class PerceptronTrainingImpl implements PerceptronTraining {
  2.  
  3. public static final Random RANDOM = new Random();
  4.  
  5. @Override
  6. public Perceptron train(final double trainingSpeed, final Iterable<TrainingData> trainingDataSet) {
  7. List<Double> weight = new ArrayList<>();
  8. for (int i = 0; i < trainingDataSet.iterator().next().getInput().size(); i++) {
  9. weight.add(RANDOM.nextDouble());
  10. }
  11. Perceptron perceptron = new ru.ifmo.enf.panina.t13.Perceptron(weight);
  12. boolean weightChanged = true;
  13. while (weightChanged) {
  14. weightChanged = false;
  15. for (TrainingData trainingData : trainingDataSet) {
  16. double o = perceptron.getOutput(trainingData.getInput());
  17. if (o != trainingData.retResult()) {
  18. weight = new ArrayList<>();
  19. weightChanged = true;
  20. for (int i = 0; i < trainingDataSet.iterator().next().getInput().size(); i++) {
  21. weight.add(perceptron.getWeights().get(i) + trainingSpeed * (trainingData.retResult() - o) * trainingData.getInput().get(i));
  22. }
  23. perceptron = new ru.ifmo.enf.panina.t13.Perceptron(weight);
  24. }
  25. }
  26. }
  27. return perceptron;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement