Examples of Tensor


Examples of com.github.neuralnetworks.tensor.Tensor

  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

Examples of com.github.neuralnetworks.tensor.Tensor

  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

Examples of com.github.neuralnetworks.tensor.Tensor

        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

Examples of com.github.neuralnetworks.tensor.Tensor

    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

Examples of com.github.neuralnetworks.tensor.Tensor

  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

Examples of com.github.neuralnetworks.tensor.Tensor

  // 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

Examples of com.github.neuralnetworks.tensor.Tensor

  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

Examples of com.github.neuralnetworks.tensor.Tensor

  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

Examples of com.github.neuralnetworks.util.Tensor

  }
    }

    @Test
    public void testSoftMax() {
  Tensor t = new Tensor(5, 4, 2);
  IntStream.range(0, t.getElements().length).forEach(i -> t.getElements()[i] = i + 1);
  Matrix m = new Matrix(t, new int[] { 1, 1, 1 }, new int[] { 3, 2, 1 });
  m.set(1, 0, 0);
  m.set(2, 1, 0);
  m.set(3, 2, 0);
  m.set(4, 0, 1);
View Full Code Here

Examples of com.github.neuralnetworks.util.Tensor

  assertEquals(6 / 15f, m.get(2, 1), 0);
    }

    @Test
    public void testTensor() {
  Tensor t = new Tensor(2, 2, 2);
  float[] elements = t.getElements();

  assertEquals(8, elements.length, 0);

  t.set(1, 0, 0, 0);
  t.set(2, 0, 0, 1);
  t.set(3, 0, 1, 0);
  t.set(4, 0, 1, 1);
  t.set(5, 1, 0, 0);
  t.set(6, 1, 0, 1);
  t.set(7, 1, 1, 0);
  t.set(8, 1, 1, 1);

  for (int i = 0; i < elements.length; i++) {
      assertEquals(i + 1, elements[i], 0);
  }

  t = new Tensor(5, 5, 5);
  assertEquals(25, t.getDimensionElementsDistance(0), 0);
  assertEquals(5, t.getDimensionElementsDistance(1), 0);
  assertEquals(1, t.getDimensionElementsDistance(2), 0);

  elements = t.getElements();

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

  Tensor t2 = new Tensor(t, new int[] { 3, 0, 0 }, new int[] { 4, 4, 4 });
  assertEquals(75, t2.getStartIndex(), 0);
  assertEquals(124, t2.getEndIndex(), 0);
  assertEquals(25, t2.getDimensionElementsDistance(0), 0);
  assertEquals(5, t2.getDimensionElementsDistance(1), 0);
  assertEquals(1, t2.getDimensionElementsDistance(2), 0);
  assertEquals(50, t2.getSize(), 0);
  assertEquals(76, t2.get(0, 0, 0), 0);
  assertEquals(77, t2.get(0, 0, 1), 0);
  assertEquals(81, t2.get(0, 1, 0), 0);
  assertEquals(101, t2.get(1, 0, 0), 0);
  assertEquals(106, t2.get(1, 1, 0), 0);
  assertEquals(112, t2.get(1, 2, 1), 0);
    }
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.