Package com.neuralnetwork.shared.neurons

Examples of com.neuralnetwork.shared.neurons.SOMNeuron


    latticeRadius = Math.max(latticeWidth, latticeHeight) / 2;
    timeConstant = numIterations / Math.log(latticeRadius);
   
    int iteration = 0;
    double nbhRadius;
    SOMNeuron bmu = null, temp = null;
    SOMLayer curInput = null;
    double learningRate = initialLearningRate;
   
    while (iteration < numIterations && running) {

          LOGGER.debug("Training, iteration: " + iteration);
      nbhRadius = getNeighborhoodRadius(iteration);
      // For each of the input vectors, look for the best matching
      // unit, then adjust the weights for the BMU's neighborhood
      for (int i = 0; i < inputs.size(); i++) {
        curInput = (SOMLayer) inputs.elementAt(i);
        bmu = lattice.getBMU(curInput);
        // We have the BMU for this input now, so adjust everything in
        // it's neighborhood
       
        // Optimization:  Only go through the X/Y values that
        // fall within
        // the radius
        xstart = (int) (bmu.getX() - nbhRadius - 1);
        ystart = (int) (bmu.getY() - nbhRadius - 1);
        xend = (int) (xstart + (nbhRadius * 2) + 1);
        yend = (int) (ystart + (nbhRadius * 2) + 1);
        if (xend > latticeWidth) {
                    xend = latticeWidth;
                }
        if (xstart < 0) {
                    xstart = 0;
                }
        if (yend > latticeHeight) {
                    yend = latticeHeight;
                }
        if (ystart < 0) {
                    ystart = 0;
                }
       
        for (int x = xstart; x < xend; x++) {
          for (int y = ystart; y < yend; y++) {
            temp = lattice.getNeuron(x, y);
              dist = bmu.distanceTo(temp);
              if (dist <= (nbhRadius * nbhRadius)) {
                dFalloff = getDistanceFalloff(dist, nbhRadius);
                temp.updateWeights(curInput,
                                   learningRate, dFalloff);
              }
View Full Code Here


   * .shared.neurons.SOMNeuron
   * #SOMNeuron(int)}.
   */
  @Test
  public final void testSOMNeuronInt() {
    SOMNeuron s = new SOMNeuron(1);
    assertEquals(s.getWeights().size(), 1);
  }
View Full Code Here

   * .shared.neurons.SOMNeuron
   * #SOMNeuron(int, int, int)}.
   */
  @Test
  public final void testSOMNeuronIntIntInt() {
    SOMNeuron s = new SOMNeuron(1, 2, 2);
    assertEquals(s.getWeights().size(), 1);
    assertEquals(s.getX(), 2);
    assertEquals(s.getY(), 2);
  }
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#setX(int)}.
   */
  @Test
  public final void testSetX() {
    SOMNeuron s = new SOMNeuron(1);
    assertEquals(s.getWeights().size(), 1);
    s.setX(2);
    assertEquals(s.getX(), 2);
  }
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#setY(int)}.
   */
  @Test
  public final void testSetY() {
    SOMNeuron s = new SOMNeuron(1);
    assertEquals(s.getWeights().size(), 1);
    s.setY(2);
    assertEquals(s.getY(), 2);
  }
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#getX()}.
   */
  @Test
  public final void testGetX() {
    SOMNeuron s = new SOMNeuron(1, 2, 2);
    assertEquals(s.getWeights().size(), 1);
    assertEquals(s.getX(), 2);
  }
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#getY()}.
   */
  @Test
  public final void testGetY() {
    SOMNeuron s = new SOMNeuron(1, 2, 2);
    assertEquals(s.getWeights().size(), 1);
    assertEquals(s.getY(), 2);
  }
View Full Code Here

   * .shared.neurons.SOMNeuron#distanceTo(
   * com.neuralnetwork.shared.neurons.SOMNeuron)}.
   */
  @Test
  public final void testDistanceTo() {
    SOMNeuron s = new SOMNeuron(Constants.THREE,
                                Constants.FIVE, Constants.TWO);
    SOMNeuron s1 = new SOMNeuron(Constants.THREE,
        Constants.TWO, Constants.TWO);
   
    assertEquals(DISTANCE_EXPECTED, s.distanceTo(s1),
        Constants.TEN * Math.ulp(DISTANCE_EXPECTED));
  }
 
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#setWeight(int, double)}.
   */
  @Test
  public final void testSetWeight() {
      SOMNeuron s = new SOMNeuron(Constants.THREE,
                                  Constants.FIVE, Constants.TWO);
      double w1 = 1.0 / Constants.TEN_D;
      double w2 = 2.0 / Constants.TEN_D;
      double w3 = Constants.THREE_D / Constants.TEN_D;
    s.setWeight(0, w1);
    s.setWeight(1, w2);
    s.setWeight(2, w3);
   
    assertEquals(w1, s.getWeight(0), Constants.TEN * Math.ulp(w1));
    assertEquals(w2, s.getWeight(1), Constants.TEN * Math.ulp(w2));
    assertEquals(w3, s.getWeight(2), Constants.TEN * Math.ulp(w3));
   
    try {
      s.setWeight(Constants.FOUR, 0.0);
    } catch (IndexOutOfBoundsException e) {
      assertEquals(e.getMessage(),
          "Weight index was out of bounds.");
    }
  }
View Full Code Here

   * Test method for {@link com.neuralnetwork
   * .shared.neurons.SOMNeuron#getWeight(int)}.
   */
  @Test
  public final void testGetWeight() {
      SOMNeuron s = new SOMNeuron(Constants.THREE,
                                  Constants.FIVE, Constants.TWO);
     
      double w1 = 1.0 / Constants.TEN_D;
      double w2 = 2.0 / Constants.TEN_D;
      double w3 = Constants.THREE_D / Constants.TEN_D;
     
    s.setWeight(0, w1);
    s.setWeight(1, w2);
    s.setWeight(2, w3);
   
    assertEquals(s.getWeight(0), w1, Constants.TEN * Math.ulp(w1));
    assertEquals(s.getWeight(1), w2, Constants.TEN * Math.ulp(w2));
    assertEquals(s.getWeight(2), w3, Constants.TEN * Math.ulp(w3));
    assertEquals(s.getWeight(Constants.THREE), w1,
        Constants.TEN * Math.ulp(w1));
  }
 
View Full Code Here

TOP

Related Classes of com.neuralnetwork.shared.neurons.SOMNeuron

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.