Carcigenicate

NodeAddWeightedInputs

Jul 13th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.76 KB | None | 0 0
  1. public class Node {
  2.  
  3.     private List<Double> weights;
  4.     private double activation = 0;
  5.  
  6.     public void addWeightedInputs(List<Double> inputs) {
  7.         if (inputs.size() != weights.size()) throw new IllegalArgumentException(
  8.             "Input size (" + inputs.size() +
  9.                 ") doesn't match weight's size (" + weights.size() + ").\nThis: " + this );
  10.  
  11.         double sum = 0;
  12.  
  13.         for (int i = 0; i < inputs.size(); i++) {
  14.             sum += weights.get(i) * inputs.get(i);
  15.         }
  16.  
  17.         activation = sigmoidFunction(sum);
  18.         System.out.println("Act: " + activation + ", Sum: " + sum);
  19.     }
  20.  
  21.     private static double sigmoidFunction(double activation) {
  22.         return 1.0 / (1 + Math.pow(Math.E, -activation));
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment