title: java simple neural network setup
body: <p>I have decided to play around with some simple concepts involving neural networks in Java, and in adapting somewhat useless code I found on a forum, I have been able to create a very simple model for the typical beginner's XOR simulation:</p>
  
  <pre><code>
  public class MainApp {
      public static void main (String [] args) {
          Neuron xor = new Neuron(0.5f);
          Neuron left = new Neuron(1.5f);
          Neuron right = new Neuron(0.5f);
          left.setWeight(-1.0f);
          right.setWeight(1.0f);
          xor.connect(left, right);
  
          for (String val : args) {
              Neuron op = new Neuron(0.0f);
              op.setWeight(Boolean.parseBoolean(val));
              left.connect(op);
              right.connect(op);
          }
  
          xor.fire();
  
          System.out.println("Result: " + xor.isFired());
  
      }
  }
  </code></pre>
  
  <pre><code>
  public class Neuron {
      private ArrayList inputs;
      private float weight;
      private float threshhold;
      private boolean fired;
  
      public Neuron (float t) {
          threshhold = t;
          fired = false;
          inputs = new ArrayList();
      }
  
      public void connect (Neuron ... ns) {
          for (Neuron n : ns) inputs.add(n);
      }
  
      public void setWeight (float newWeight) {
          weight = newWeight;
      }
  
      public void setWeight (boolean newWeight) {
          weight = newWeight ? 1.0f : 0.0f;
      }
  
      public float getWeight () {
          return weight;
      }
  
      public float fire () {
          if (inputs.size() > 0) {
              float totalWeight = 0.0f;
              for (Neuron n : inputs) {
                  n.fire();
                  totalWeight += (n.isFired()) ? n.getWeight() : 0.0f;
              }
              fired = totalWeight > threshhold;
              return totalWeight;
          }
          else if (weight != 0.0f) {
              fired = weight > threshhold;
              return weight;
          }
          else {
              return 0.0f;
          }
      }
  
      public boolean isFired () {
          return fired;
      }
  }
  </code></pre>
  
  <p>In my main class, I've created the simple simulation in modeling Jeff Heaton's diagram:
  <img src="https://i.stack.imgur.com/LcUt6.jpg" alt="XOR diagram"></p>
  
  <p>However, I wanted to ensure my implementation for the Neuron class is correct..I've already tested all possible inputs ( [true true], [true false], [false true], [false false]), and they all passed my manual verification. Additionally, since this program accepts the inputs as arguments, it also seems to pass manual verification for inputs such as [true false false], [true true false], etc..</p>
  
  <p>But conceptually speaking, would this implementation be correct? Or how can I improve upon it before I start further development and research into this topic?</p>
  
  <p>Thank you!</p>