Package com.github.neuralnetworks.architecture

Examples of com.github.neuralnetworks.architecture.Layer


 
  Set<Layer> calculated = new HashSet<Layer>();
  calculated.add(mlp.getInputLayer());
  List<ConnectionCandidate> ccc = new TargetLayerOrderStrategy(mlp, mlp.getOutputLayer(), calculated).order();
  assertEquals(4, ccc.size(), 0);
  Layer l = mlp.getInputLayer();
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  l = l.getConnections().get(0).getOutputLayer();
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));
  assertTrue(ccc.get(2).connection == l.getConnections().get(2));
  l = l.getConnections().get(2).getOutputLayer();
  assertTrue(ccc.get(3).connection == l.getConnections().get(1));

  ccc = new BreadthFirstOrderStrategy(mlp, mlp.getOutputLayer()).order();
  assertEquals(4, ccc.size(), 0);
  l = mlp.getOutputLayer();
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));

  l = l.getConnections().get(0).getInputLayer();
  assertTrue(ccc.get(2).connection == l.getConnections().get(0));
  assertTrue(ccc.get(3).connection == l.getConnections().get(1));

  // Simple MLP
  mlp = NNFactory.mlp(new int[] {3, 4}, true);

  calculated = new HashSet<Layer>();
  calculated.add(mlp.getInputLayer());
  ccc = new TargetLayerOrderStrategy(mlp, mlp.getOutputLayer(), calculated).order();
  assertEquals(2, ccc.size(), 0);
  l = mlp.getOutputLayer();
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));

  ccc = new BreadthFirstOrderStrategy(mlp, mlp.getOutputLayer()).order();
  assertEquals(2, ccc.size(), 0);
  l = mlp.getOutputLayer();
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));

  // CNN
  NeuralNetworkImpl cnn = NNFactory.convNN(new int[][] { { 3, 3, 2 }, { 2, 2, 1, 1 } }, true);

  calculated = new HashSet<Layer>();
  calculated.add(cnn.getInputLayer());
  ccc = new TargetLayerOrderStrategy(cnn, cnn.getOutputLayer(), calculated).order();
  l = cnn.getOutputLayer();
  assertEquals(2, ccc.size(), 0);
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));

  ccc = new BreadthFirstOrderStrategy(cnn, cnn.getOutputLayer()).order();
  l = cnn.getOutputLayer();
  assertEquals(2, ccc.size(), 0);
  assertTrue(ccc.get(0).connection == l.getConnections().get(0));
  assertTrue(ccc.get(1).connection == l.getConnections().get(1));
    }
View Full Code Here


    }

    @Test
    public void testConvolutions() {
  NeuralNetworkImpl nn = new NeuralNetworkImpl();
  Conv2DConnection c = new Conv2DConnection(new Layer(), new Layer(), 3, 3, 2, 2, 2, 1, 1);
  nn.addConnection(c);
  c.getWeights()[0] = 1;
  c.getWeights()[1] = 2;
  c.getWeights()[2] = 3;
  c.getWeights()[3] = 4;
View Full Code Here

  Util.fillArray(o.getElements(), 0);
    }

    @Test
    public void testConvolutions2() {
  Conv2DConnection c = new Conv2DConnection(new Layer(), new Layer(), 3, 3, 2, 2, 2, 2, 1);
  c.getWeights()[0] = 1;
  c.getWeights()[1] = 2;
  c.getWeights()[2] = 3;
  c.getWeights()[3] = 4;
  c.getWeights()[4] = 1;
View Full Code Here

  assertEquals(244, o.get(1, 0), 0);
    }

    @Test
    public void testMaxPooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix i1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  ConnectionCalculator calc = new AparapiMaxPooling2D();
View Full Code Here

  assertEquals(32, o.get(7, 1), 0);
    }

    @Test
    public void testAveragePooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix i1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  AparapiAveragePooling2D calc = new AparapiAveragePooling2D();
View Full Code Here

  assertEquals(29.5, o.get(7, 1), 0);
    }

    @Test
    public void testStochasticPooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 3, 3, 3, 3, 1);
  Matrix i1 = new Matrix(new float[] { 1.6f, 1.6f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.4f, 2.4f }, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  Matrix o = new Matrix(1, 2);
View Full Code Here

  assertEquals(2.08, o.get(0, 1), 0.01);
    }

    @Test
    public void testMaxPoolingBackpropagation() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix a1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);
  Matrix o = new Matrix(8, 2);

  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);
View Full Code Here

    }

    @Test
    public void testAveragePoolingBackpropagation() {
  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix a1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);

  // max pooling
  ConnectionCalculator calc = new AparapiAveragePooling2D();
View Full Code Here

  List<Connections> chunkCalc = new ArrayList<>();
  for (BackPropagationConnectionCalculator bc : calculators) {
      chunkCalc.clear();

      Layer target = targetLayer;
      for (Connections c : connections) {
    if (connectionCalculators.get(c) == bc) {
        chunkCalc.add(c);
        if (Util.isBias(c.getInputLayer()) && c.getInputLayer() != targetLayer) {
      target = c.getInputLayer();
View Full Code Here

    /**
     * This method creates new Autoencoder with input layer - the hidden layer of the previous topmost autoencoder.
     */
    public StackedAutoencoder addLevel(Layer layer, int inputUnitCount, int hiddenUnitCount, boolean addBias) {
  Layer currentOutputLayer = getOutputLayer();
  if (currentOutputLayer != null) {
      addNeuralNetwork(new Autoencoder(currentOutputLayer, layer, new Layer(), inputUnitCount, hiddenUnitCount, addBias));
  } else {
      addLayer(layer);
  }

  return this;
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.architecture.Layer

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.