Examples of FullyConnected


Examples of com.github.neuralnetworks.architecture.FullyConnected

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

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

  Matrix cg = c1.getWeights();
  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.getWeights();
  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 bcg = bc.getWeights();
  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

    public void testSigmoidBP() {
  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 2, 2, 1 }, false);

  FullyConnected c1 = (FullyConnected) mlp.getInputLayer().getConnections().iterator().next();
  Matrix cg1 = c1.getWeights();
  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.getWeights();
  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 } }), new SimpleInputProvider(new float[][] { { 0.35f, 0.9f } }, new float[][] { { 0.5f } }), null, null, 1f, 0f, 0f, 0f, 0f, 1, 1, 1);
  bpt.train();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  //Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 3, 2, 1 }, true);

  List<Connections> c = mlp.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getWeights();
  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.getWeights();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

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

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

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

Examples of com.github.neuralnetworks.architecture.FullyConnected

  //Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 3, 2, 1 }, true);

  List<Connections> c = mlp.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getWeights();
  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.getWeights();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

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

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

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

Examples of com.github.neuralnetworks.architecture.FullyConnected

  //Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl nn = NNFactory.maxout(new int[] { 2, 2 }, true, null);

  List<Connections> c = nn.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getWeights();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.5f, 0, 1);
  cg1.set(0.1f, 1, 0);
  cg1.set(0.5f, 1, 1);

  FullyConnected cb1 = (FullyConnected) c.get(1);
  Matrix cgb1 = cb1.getWeights();
  cgb1.set(0.1f, 0, 0);
  cgb1.set(0.2f, 1, 0);

  ValuesProvider results = TensorFactory.tensorProvider(nn, 2, true);
  Matrix in = results.get(nn.getInputLayer());
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl nn = NNFactory.maxout(new int[] { 2, 2 }, true, null);

  List<Connections> c = nn.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getWeights();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.5f, 0, 1);
  cg1.set(0.1f, 1, 0);
  cg1.set(0.5f, 1, 1);

  FullyConnected cb1 = (FullyConnected) c.get(1);
  Matrix cgb1 = cb1.getWeights();
  cgb1.set(0.1f, 0, 0);
  cgb1.set(0.2f, 1, 0);

  ValuesProvider results = TensorFactory.tensorProvider(nn, 2, true);
  Matrix in = results.get(nn.getInputLayer());
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

  Environment.getInstance().setUseWeightsSharedMemory(true);

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

  List<Connections> c = mlp.getConnections();
  FullyConnected c1 = (FullyConnected) c.get(0);
  Matrix cg1 = c1.getWeights();
  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.getWeights();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

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

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

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

Examples of com.github.neuralnetworks.architecture.FullyConnected

  Layer leaf2 = new Layer();
  Layer output = new Layer();

  mlp.addLayer(input);

  FullyConnected fc1 = cf.fullyConnected(input, leaf1, 2, 3);
  fc1.getWeights().forEach(i -> fc1.getWeights().getElements()[i] = 0.1f);
  mlp.addConnections(fc1);

  FullyConnected fc2 = cf.fullyConnected(input, leaf2, 2, 3);
  fc2.getWeights().forEach(i -> fc2.getWeights().getElements()[i] = 0.2f);
  mlp.addConnections(fc2);

  FullyConnected fc3 = cf.fullyConnected(leaf1, output, 3, 1);
  fc3.getWeights().forEach(i -> fc3.getWeights().getElements()[i] = 0.3f);
  mlp.addConnections(fc3);
  FullyConnected fc4 = cf.fullyConnected(leaf2, output, 3, 1);
  fc4.getWeights().forEach(i -> fc4.getWeights().getElements()[i] = 0.4f);
  mlp.addConnections(fc4);

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

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

Examples of com.github.neuralnetworks.architecture.FullyConnected

    protected void init(Layer visibleLayer, Layer hiddenLayer, int visibleUnitCount, int hiddenUnitCount, boolean addVisibleBias, boolean addHiddenBias) {
  addLayer(visibleLayer);
  addLayer(hiddenLayer);

  mainConnections = new FullyConnected(visibleLayer, hiddenLayer, visibleUnitCount, hiddenUnitCount);

  if (addVisibleBias) {
      Layer visibleBiasLayer = new Layer();
      addLayer(visibleBiasLayer);
      visibleBiasConnections = new FullyConnected(visibleBiasLayer, visibleLayer, 1, visibleUnitCount);
  }

  if (addHiddenBias) {
      Layer hiddenBiasLayer = new Layer();
      addLayer(hiddenBiasLayer);
      hiddenBiasConnections = new FullyConnected(hiddenBiasLayer, hiddenLayer, 1, hiddenUnitCount);
  }
    }
View Full Code Here

Examples of com.github.neuralnetworks.architecture.FullyConnected

//        [8.59142, 3.1430812] - bias l2
//        [12.749131, -12.848652] - l2-l3
//        [-6.1552725] - bias l3

  // weights
  FullyConnected fc1 = (FullyConnected) mlp.getInputLayer().getConnections().get(0);
  fc1.getWeights().set(-5.744886f, 0, 0);
  fc1.getWeights().set(-5.7570715f, 0, 1);
  fc1.getWeights().set(-7.329507f, 1, 0);
  fc1.getWeights().set(-7.33055f, 1, 1);

  FullyConnected b1 = (FullyConnected) fc1.getOutputLayer().getConnections().get(1);
  b1.getWeights().set(8.59142f, 0, 0);
  b1.getWeights().set(3.1430812f, 1, 0);

  FullyConnected fc2 = (FullyConnected) mlp.getOutputLayer().getConnections().get(0);
  fc2.getWeights().set(12.749131f, 0, 0);
  fc2.getWeights().set(-12.848652f, 0, 1);

  FullyConnected b2 = (FullyConnected) fc2.getOutputLayer().getConnections().get(1);
  b2.getWeights().set(-6.1552725f, 0, 0);

  // create training and testing input providers
  SimpleInputProvider input = new SimpleInputProvider(new float[][] { {0, 0}, {0, 1}, {1, 0}, {1, 1} }, new float[][] { {0}, {1}, {1}, {0} });

  // create backpropagation trainer for the network
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.