Examples of FullyConnected


Examples of com.github.neuralnetworks.architecture.FullyConnected

  Matrix o = new Matrix(2, 2);

  Layer il1 = new Layer();
  Layer ol = new Layer();
  Layer il2 = new Layer();
  FullyConnected c1 = new FullyConnected(il1, ol, 3, 2);
  FullyConnected c2 = new FullyConnected(il2, ol, 3, 2);
  FullyConnected bc = new FullyConnected(new Layer(), ol, 1, 2);

  Matrix cg = c1.getConnectionGraph();
  cg.set(1, 0, 0);
  cg.set(2, 0, 1);
  cg.set(3, 0, 2);
  cg.set(4, 1, 0);
  cg.set(5, 1, 1);
  cg.set(6, 1, 2);

  cg = c2.getConnectionGraph();
  cg.set(1, 0, 0);
  cg.set(2, 0, 1);
  cg.set(3, 0, 2);
  cg.set(4, 1, 0);
  cg.set(5, 1, 1);
  cg.set(6, 1, 2);

  Matrix i1 = new Matrix(3, 2);
  i1.set(1, 0, 0);
  i1.set(2, 1, 0);
  i1.set(3, 2, 0);
  i1.set(4, 0, 1);
  i1.set(5, 1, 1);
  i1.set(6, 2, 1);

  Matrix i2 = new Matrix(3, 2);
  i2.set(1, 0, 0);
  i2.set(2, 1, 0);
  i2.set(3, 2, 0);
  i2.set(4, 0, 1);
  i2.set(5, 1, 1);
  i2.set(6, 2, 1);

  Matrix bcg = bc.getConnectionGraph();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  Matrix o = new Matrix(2, 2);

  Layer il1 = new Layer();
  Layer ol = new Layer();
  Layer il2 = new Layer();
  FullyConnected c1 = new FullyConnected(ol, il1, 2, 3);
  FullyConnected c2 = new FullyConnected(ol, il2, 2, 3);
  FullyConnected bc = new FullyConnected(new Layer(), ol, 1, 2);

  Matrix cg = c1.getConnectionGraph();
  cg.set(1, 0, 0);
  cg.set(2, 1, 0);
  cg.set(3, 2, 0);
  cg.set(4, 0, 1);
  cg.set(5, 1, 1);
  cg.set(6, 2, 1);

  cg = c2.getConnectionGraph();
  cg.set(1, 0, 0);
  cg.set(2, 1, 0);
  cg.set(3, 2, 0);
  cg.set(4, 0, 1);
  cg.set(5, 1, 1);
  cg.set(6, 2, 1);

  Matrix i1 = new Matrix(3, 2);
  i1.set(1, 0, 0);
  i1.set(2, 1, 0);
  i1.set(3, 2, 0);
  i1.set(4, 0, 1);
  i1.set(5, 1, 1);
  i1.set(6, 2, 1);

  Matrix i2 = new Matrix(3, 2);
  i2.set(1, 0, 0);
  i2.set(2, 1, 0);
  i2.set(3, 2, 0);
  i2.set(4, 0, 1);
  i2.set(5, 1, 1);
  i2.set(6, 2, 1);

  Matrix bcg = bc.getConnectionGraph();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

     */
    @Test
    public void testSigmoidBP() {
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 2, 2, 1 }, false);

  FullyConnected c1 = (FullyConnected) mlp.getInputLayer().getConnections().iterator().next();
  Matrix cg1 = c1.getConnectionGraph();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.8f, 0, 1);
  cg1.set(0.4f, 1, 0);
  cg1.set(0.6f, 1, 1);

  FullyConnected c2 = (FullyConnected) mlp.getOutputLayer().getConnections().iterator().next();
  Matrix cg2 = c2.getConnectionGraph();
  cg2.set(0.3f, 0, 0);
  cg2.set(0.9f, 0, 1);

  BackPropagationTrainer<?> bpt = TrainerFactory.backPropagation(mlp, new SimpleInputProvider(new float[][] { { 0.35f, 0.9f } }, new float[][] { { 0.5f } }, 1, 1), new SimpleInputProvider(new float[][] { { 0.35f, 0.9f } }, new float[][] { { 0.5f } }, 1, 1), null, null, 1f, 0f, 0f, 0f);
  bpt.train();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

    @Test
    public void testSigmoidBP2() {
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 3, 2, 1 }, true);

  List<Connections> c = mlp.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getConnectionGraph();
  cg1.set(0.2f, 0, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(-0.5f, 0, 2);
  cg1.set(-0.3f, 1, 0);
  cg1.set(0.1f, 1, 1);
  cg1.set(0.2f, 1, 2);

  FullyConnected cb1 = (FullyConnected) c.get(1);
  Matrix cgb1 = cb1.getConnectionGraph();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

  FullyConnected c2 = (FullyConnected) c.get(2);
  Matrix cg2 = c2.getConnectionGraph();
  cg2.set(-0.3f, 0, 0);
  cg2.set(-0.2f, 0, 1);

  FullyConnected cb2 = (FullyConnected) c.get(3);
  Matrix cgb2 = cb2.getConnectionGraph();
  cgb2.set(0.1f, 0, 0);

  BackPropagationTrainer<?> bpt = TrainerFactory.backPropagation(mlp, new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, new float[][] { { 1 } }, 1, 1), new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, new float[][] { { 1 } }, 1, 1), null, null, 0.9f, 0f, 0f, 0f);
  bpt.train();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  NeuralNetworkImpl mlp = new NeuralNetworkImpl();
  Layer input = new Layer();
  mlp.addLayer(input);

  Layer leaf1 = new Layer();
  FullyConnected fc1 = new FullyConnected(input, leaf1, 2, 3);
  Util.fillArray(fc1.getConnectionGraph().getElements(), 0.1f);
  mlp.addConnection(fc1);

  Layer leaf2 = new Layer();
  FullyConnected fc2 = new FullyConnected(input, leaf2, 2, 3);
  Util.fillArray(fc2.getConnectionGraph().getElements(), 0.2f);
  mlp.addConnection(fc2);

  Layer output = new Layer();
  FullyConnected fc3 = new FullyConnected(leaf1, output, 3, 1);
  Util.fillArray(fc3.getConnectionGraph().getElements(), 0.3f);
  mlp.addConnection(fc3);
  FullyConnected fc4 = new FullyConnected(leaf2, output, 3, 1);
  Util.fillArray(fc4.getConnectionGraph().getElements(), 0.4f);
  mlp.addConnection(fc4);

  mlp.setLayerCalculator(NNFactory.lcWeightedSum(mlp, null));

  Matrix i = new Matrix(new float [] {2, 2}, 1);
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

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

  FullyConnected c1 = (FullyConnected) nn.getInputLayer().getConnections().get(0).getOutputLayer().getConnections().get(1).getOutputLayer().getConnections().get(1);
  Matrix cg1 = c1.getConnectionGraph();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.8f, 0, 1);
  cg1.set(0.4f, 1, 0);
  cg1.set(0.6f, 1, 1);

  FullyConnected c2 = (FullyConnected) nn.getOutputLayer().getConnections().iterator().next();
  Matrix cg2 = c2.getConnectionGraph();
  cg2.set(0.3f, 0, 0);
  cg2.set(0.9f, 0, 1);

  BackPropagationTrainer<?> bpt = TrainerFactory.backPropagation(nn, new SimpleInputProvider(new float[][] { { 0.35f, 0.9f } }, new float[][] { { 0.5f } }, 1, 1), new SimpleInputProvider(new float[][] { { 0.35f, 0.9f } }, new float[][] { { 0.5f } }, 1, 1), null, null, 1f, 0f, 0f, 0f);
  bpt.train();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  for (int i = 1; i < layers.length; i++) {
      int[] l = layers[i];
      Layer newLayer = null;
      Layer biasLayer = null;
      if (l.length == 1) {
    new FullyConnected(prev, newLayer = new Layer(), prevUnitCount, l[0]);
    if (addBias) {
        new FullyConnected(biasLayer = new Layer(), newLayer, 1, l[0]);
    }

    prevUnitCount = l[0];
      } else if (l.length == 4 || l.length == 2) {
    Integer inputFMRows = null;
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

     * @param nn
     * @param layer
     * @param addBias
     */
    public static FullyConnected addFullyConnectedLayer(NeuralNetworkImpl nn, Layer layer, int inputUnitCount, int outputUnitCount, boolean addBias) {
  FullyConnected result = null;
  if (nn.addLayer(layer) && nn.getOutputLayer() != layer) {
      result = new FullyConnected(nn.getOutputLayer(), layer, inputUnitCount, outputUnitCount);
  }

  if (addBias && nn.getInputLayer() != layer) {
      Layer biasLayer = new Layer();
      nn.addLayer(biasLayer);
      return new FullyConnected(biasLayer, layer, 1, outputUnitCount);
  }

  return result;
    }
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

      if (c.getInputLayer() == layer) {
    if (c instanceof Conv2DConnection) {
        Conv2DConnection cc = (Conv2DConnection) c;
        return cc.getInputFilters() == 1 && cc.getInputFeatureMapRows() == cc.getOutputFeatureMapRows() && cc.getInputFeatureMapColumns() == cc.getOutputFeatureMapColumns();
    } else if (c instanceof FullyConnected) {
        FullyConnected cg = (FullyConnected) c;
        return cg.getWeights().getColumns() == 1;
    }
      }
  }

  return false;
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  Layer ol = new Layer();
  Layer il2 = new Layer();

  Tensor weights = TensorFactory.tensor(2, 2, 3);

  FullyConnected c1 = new FullyConnected(il1, ol, TensorFactory.tensor(weights, new int[][]{{0, 0, 0}, {0, 1, 2}}));
  FullyConnected c2 = new FullyConnected(il2, ol, TensorFactory.tensor(weights, new int[][]{{1, 0, 0}, {1, 1, 2}}));
  FullyConnected bc = new FullyConnected(new Layer(), ol, 1, 2);

  Matrix cg = c1.getWeights();
  cg.set(1, 0, 0);
  cg.set(2, 0, 1);
  cg.set(3, 0, 2);
  cg.set(4, 1, 0);
  cg.set(5, 1, 1);
  cg.set(6, 1, 2);

  cg = c2.getWeights();
  cg.set(1, 0, 0);
  cg.set(2, 0, 1);
  cg.set(3, 0, 2);
  cg.set(4, 1, 0);
  cg.set(5, 1, 1);
  cg.set(6, 1, 2);

  Matrix bcg = bc.getWeights();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  List<Connections> connections = new ArrayList<>();
  connections.add(c1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.