Package com.github.neuralnetworks.architecture

Examples of com.github.neuralnetworks.architecture.Conv2DConnection


    @Test
    public void testCNNConstruction3() {
  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 6, 6, 1 }, { 3, 3, 2, 2 }, { 2, 2 } }, true);
  assertEquals(4, nn.getLayers().size(), 0);

  Conv2DConnection cc = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  Layer l = nn.getInputLayer().getConnections().get(0).getOutputLayer();
  assertEquals(2, cc.getOutputFeatureMapRows(), 0);
  assertEquals(2, cc.getOutputFeatureMapColumns(), 0);
  assertEquals(2, cc.getOutputFilters(), 0);

  Subsampling2DConnection sc = (Subsampling2DConnection) l.getConnections().get(2);
  l = l.getConnections().get(2).getOutputLayer();
  assertEquals(1, sc.getOutputFeatureMapRows(), 0);
  assertEquals(1, sc.getOutputFeatureMapColumns(), 0);
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;
  c.getWeights()[4] = 1;
  c.getWeights()[5] = 2;
  c.getWeights()[6] = 3;
  c.getWeights()[7] = 4;

  Matrix i1 = new Matrix(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }, 1);

  Matrix o = new Matrix(4, 1);
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;
  c.getWeights()[5] = 2;
  c.getWeights()[6] = 3;
  c.getWeights()[7] = 4;
  c.getWeights()[8] = 1;
  c.getWeights()[9] = 2;
  c.getWeights()[10] = 3;
  c.getWeights()[11] = 4;
  c.getWeights()[12] = 1;
  c.getWeights()[13] = 2;
  c.getWeights()[14] = 3;
  c.getWeights()[15] = 4;

  Matrix i1 = new Matrix(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }, 1);

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

    public void testSimpleCNN() {
  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] {{3, 3, 2}, {2, 2, 2, 1}, {2, 2}}, false);
  nn.setLayerCalculator(NNFactory.lcWeightedSum(nn, null));
  NNFactory.lcMaxPooling(nn);

  Conv2DConnection c = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  c.getWeights()[0] = 1;
  c.getWeights()[1] = 2;
  c.getWeights()[2] = 3;
  c.getWeights()[3] = 4;
  c.getWeights()[4] = 1;
  c.getWeights()[5] = 2;
  c.getWeights()[6] = 3;
  c.getWeights()[7] = 4;
  c.getWeights()[8] = 1;
  c.getWeights()[9] = 2;
  c.getWeights()[10] = 3;
  c.getWeights()[11] = 4;
  c.getWeights()[12] = 1;
  c.getWeights()[13] = 2;
  c.getWeights()[14] = 3;
  c.getWeights()[15] = 4;

  Matrix i1 = new Matrix(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }, 1);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(nn.getInputLayer(), i1);
View Full Code Here

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 3, 3, 2 }, { 2, 2, 1, 1 } }, true);
  nn.setLayerCalculator(NNFactory.lcSigmoid(nn, null));

  Conv2DConnection c = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  c.setWeights(new float [] {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f});

  Conv2DConnection b = (Conv2DConnection) nn.getOutputLayer().getConnections().get(1);
  b.setWeights(new float [] {-3f});
 
  SimpleInputProvider ts = new SimpleInputProvider(new float[][] { { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f } }, new float[][] { { 1, 1, 1, 1 } }, 1, 1);
  BackPropagationTrainer<?> t = TrainerFactory.backPropagation(nn, ts, null, null, null, 0.5f, 0f, 0f, 0f);
  t.train();

  assertEquals(0.11756, c.getWeights()[0], 0.00001);
  assertEquals(0.22640, c.getWeights()[1], 0.00001);
  assertEquals(0.34408, c.getWeights()[2], 0.00001);
  assertEquals(0.45292, c.getWeights()[3], 0.00001);
  assertEquals(0.59712, c.getWeights()[4], 0.00001);
  assertEquals(0.70596, c.getWeights()[5], 0.00001);
  assertEquals(0.82364, c.getWeights()[6], 0.00001);
  assertEquals(0.93248, c.getWeights()[7], 0.00001);
  assertEquals(-2.911599, b.getWeights()[0], 0.00001);
    }
View Full Code Here

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 5, 5, 1 }, { 2, 2, 1, 2 } }, false);
  nn.setLayerCalculator(NNFactory.lcWeightedSum(nn, null));

  Conv2DConnection cc = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  Util.fillArray(cc.getWeights(), 1);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(nn.getInputLayer(), new Matrix(new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}, 1));

  Set<Layer> calculatedLayers = new HashSet<>();
View Full Code Here

  super(properties);
    }

    @Override
    protected void addBackpropFunction(SortedMap<Connections, Integer> inputConnections, Map<Connections, BackPropagationConnectionCalculator> connectionCalculators, Layer targetLayer) {
  Conv2DConnection con = null;
  for (Connections c : inputConnections.keySet()) {
      if (c instanceof Conv2DConnection && !Util.isBias(c.getInputLayer())) {
    con = (Conv2DConnection) c;
    break;
      }
View Full Code Here

  this.weightUpdatesMomentum = new float[c.getWeights().length];
    }

    @Override
    public void calculate(List<Connections> connections, ValuesProvider valuesProvider, Layer targetLayer) {
  Conv2DConnection c = null;

  for (Connections con : connections) {
      if (con instanceof Conv2DConnection) {
    c = (Conv2DConnection) con;
      }
  }

  if (c != null) {
      // currently works only as a feedforward (including bp)
      if (targetLayer == c.getOutputLayer()) {
    super.calculate(c, valuesProvider.getValues(Util.getOppositeLayer(c, targetLayer), c), valuesProvider.getValues(targetLayer, c));
      } else {
    super.calculate(c, valuesProvider.getValues(targetLayer, c), valuesProvider.getValues(Util.getOppositeLayer(c, targetLayer), c));
      }
View Full Code Here

  super(properties);
    }

    @Override
    protected void addBackpropFunction(SortedMap<Connections, Integer> inputConnections, Map<Connections, BackPropagationConnectionCalculator> connectionCalculators, Layer targetLayer) {
  Conv2DConnection con = null;
  for (Connections c : inputConnections.keySet()) {
      if (c instanceof Conv2DConnection) {
    con = (Conv2DConnection) c;
    break;
      }
View Full Code Here

  super(properties);
    }

    @Override
    protected void addBackpropFunction(SortedMap<Connections, Integer> inputConnections, Map<Connections, BackPropagationConnectionCalculator> connectionCalculators, Layer targetLayer) {
  Conv2DConnection con = null;
  for (Connections c : inputConnections.keySet()) {
      if (c instanceof Conv2DConnection && !Util.isBias(c.getInputLayer())) {
    con = (Conv2DConnection) c;
    break;
      }
View Full Code Here

TOP

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

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.