Package com.github.neuralnetworks.tensor

Examples of com.github.neuralnetworks.tensor.Tensor


  BackpropagationMaxPooling2D bp = new BackpropagationMaxPooling2D();
  bp.setActivations(activations);
  bp.calculate(connections, vp, c.getInputLayer());

  Tensor a = activations.get(c.getInputLayer());
  Tensor bpo = vp.get(c.getInputLayer());

  assertEquals(true, bpo.get(0, 1, 1, 0) == a.get(0, 1, 1, 0));
  assertEquals(true, bpo.get(0, 1, 3, 0) == a.get(0, 1, 3, 0));
  assertEquals(true, bpo.get(0, 3, 1, 0) == a.get(0, 3, 1, 0));
  assertEquals(true, bpo.get(0, 3, 2, 0) == a.get(0, 3, 2, 0));
  assertEquals(true, bpo.get(0, 1, 1, 1) == a.get(0, 1, 1, 1));
  assertEquals(true, bpo.get(0, 1, 3, 1) == a.get(0, 1, 3, 1));
  assertEquals(true, bpo.get(0, 3, 1, 1) == a.get(0, 3, 1, 1));
  assertEquals(true, bpo.get(0, 3, 2, 1) == a.get(0, 3, 2, 1));
  assertEquals(true, bpo.get(1, 1, 1, 0) == a.get(1, 1, 1, 0));
  assertEquals(true, bpo.get(1, 1, 3, 0) == a.get(1, 1, 3, 0));
  assertEquals(true, bpo.get(1, 3, 1, 0) == a.get(1, 3, 1, 0));
  assertEquals(true, bpo.get(1, 3, 2, 0) == a.get(1, 3, 2, 0));
  assertEquals(true, bpo.get(1, 1, 1, 1) == a.get(1, 1, 1, 1));
  assertEquals(true, bpo.get(1, 1, 3, 1) == a.get(1, 1, 3, 1));
  assertEquals(true, bpo.get(1, 3, 1, 1) == a.get(1, 3, 1, 1));
  assertEquals(true, bpo.get(1, 3, 2, 1) == a.get(1, 3, 2, 1));
    }
View Full Code Here


  ValuesProvider vp = TensorFactory.tensorProvider(c, 2, true);
  TensorFactory.copy(activations.get(c.getOutputLayer()), vp.get(c.getOutputLayer()));

  bp.calculate(connections, vp, c.getInputLayer());

  Tensor o = activations.get(c.getOutputLayer());
  Tensor bpo = vp.get(c.getInputLayer());
  assertEquals(true, bpo.get(0, 0, 0, 0) == o.get(0, 0, 0, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 0, 2, 0) == o.get(0, 0, 1, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 2, 0, 0) == o.get(0, 1, 0, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 2, 2, 0) == o.get(0, 1, 1, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 0, 0, 0) == o.get(1, 0, 0, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 0, 2, 0) == o.get(1, 0, 1, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 2, 0, 0) == o.get(1, 1, 0, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 2, 2, 0) == o.get(1, 1, 1, 0) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 0, 0, 1) == o.get(0, 0, 0, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 0, 2, 1) == o.get(0, 0, 1, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 2, 0, 1) == o.get(0, 1, 0, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(0, 2, 2, 1) == o.get(0, 1, 1, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 0, 0, 1) == o.get(1, 0, 0, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 0, 2, 1) == o.get(1, 0, 1, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 2, 0, 1) == o.get(1, 1, 0, 1) / c.getSubsamplingRegionLength());
  assertEquals(true, bpo.get(1, 2, 2, 1) == o.get(1, 1, 1, 1) / c.getSubsamplingRegionLength());
    }
View Full Code Here

  Set<Layer> calculatedLayers = new HashSet<>();
  calculatedLayers.add(nn.getInputLayer());
  nn.getLayerCalculator().calculate(nn, nn.getOutputLayer(), calculatedLayers, vp);

  Tensor o = vp.get(nn.getOutputLayer());
  assertEquals(16, o.get(0, 0, 0, 0), 0.00001);
  assertEquals(24, o.get(0, 0, 1, 0), 0.00001);
  assertEquals(56, o.get(0, 1, 0, 0), 0.00001);
  assertEquals(64, o.get(0, 1, 1, 0), 0.00001);
    }
View Full Code Here

  NNFactory.lcMaxPooling(cnn);
  FullyConnected cnnfc = (FullyConnected) cnn.getOutputLayer().getConnections().get(0);
  cnnfc.getWeights().set(0.05f, 0, 0);
  cnnfc.getWeights().set(0.08f, 0, 1);
  ValuesProvider cnnvp = TensorFactory.tensorProvider(cnn, 1, Environment.getInstance().getUseDataSharedMemory());
  Tensor cnnin = cnnvp.get(cnn.getInputLayer());
  cnnin.set(0.2f, 0, 0, 0, 0);
  cnnin.set(0.6f, 0, 1, 0, 0);

  // MLP
  NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[] { 2, 1 }, false);
  FullyConnected mlpfc = (FullyConnected) mlp.getOutputLayer().getConnections().get(0);
  mlpfc.getWeights().set(0.05f, 0, 0);
  mlpfc.getWeights().set(0.08f, 0, 1);
  ValuesProvider mlpvp = TensorFactory.tensorProvider(mlp, 1, Environment.getInstance().getUseDataSharedMemory());
  Tensor mlpin = mlpvp.get(mlp.getInputLayer());
  mlpin.set(0.2f, 0, 0);
  mlpin.set(0.6f, 1, 0);

  // compare ff
  Set<Layer> calculated = new HashSet<>();
  calculated.add(cnn.getInputLayer());
  cnn.getLayerCalculator().calculate(cnn, cnn.getOutputLayer(), calculated, cnnvp);
View Full Code Here

        this.dropoutRate = dropoutRate;
    }

    protected void calculateBias(Connections bias, ValuesProvider valuesProvider) {
  if (bias != null) {
      Tensor biasValue = TensorFactory.tensor(bias.getInputLayer(), bias, valuesProvider);
      if (biasValue.get(new int[biasValue.getDimensions().length]) == 0) {
    biasValue.forEach(i -> biasValue.getElements()[i] = 1);
      }

      Matrix weights = ((FullyConnected) bias).getWeights();
      Matrix output = TensorFactory.tensor(bias.getOutputLayer(), bias, valuesProvider);
View Full Code Here

    protected ConnectionCalculator createInputFunction(List<Connections> inputConnections, ValuesProvider valuesProvider, Layer targetLayer) {
  return new AparapiWeightedSum(inputConnections, valuesProvider, targetLayer);
    }

    protected TensorFunction createDropoutFunction(List<Connections> inputConnections, ValuesProvider valuesProvider, Layer targetLayer) {
  Tensor t = TensorFactory.tensor(targetLayer, inputConnections, valuesProvider);
  return new AparapiNoise(t, t.getSize(), dropoutRate, 0);
    }
View Full Code Here

  assertEquals(2, m.get(1, 0), 0);
  assertEquals(6, m.get(5, 0), 0);

  // submatrix
  Tensor t = TensorFactory.tensor(5, 5, 5);
  float[] elements = t.getElements();

  for (int i = 0; i < elements.length; i++) {
      elements[i] = i + 1;
  }
View Full Code Here

  // input
  input = TensorFactory.tensor(Util.getOppositeLayer(inputConnections.get(0), targetLayer), inputConnections.get(0), valuesProvider).getElements();
  weights = ((FullyConnected) inputConnections.get(0)).getWeights().getElements();
  inputConnections.forEach(c -> {
      Tensor t = TensorFactory.tensor(Util.getOppositeLayer(c, targetLayer), c, valuesProvider);
      if (!(c instanceof FullyConnected)) {
    throw new IllegalArgumentException("Only FullyConnected connections are supported");
      }

      if (!(t instanceof Matrix)) {
    throw new IllegalArgumentException("Only matrices are supported as input");
      }

      if (input != t.getElements()) {
    throw new IllegalArgumentException("Only one input array is allowed");
      }

      if (weights != ((FullyConnected) c).getWeights().getElements()) {
    throw new IllegalArgumentException("Only one weight array is allowed");
View Full Code Here

  Layer il1 = new Layer();
  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);
View Full Code Here

  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();
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.tensor.Tensor

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.