Package com.github.neuralnetworks.calculation.memory

Examples of com.github.neuralnetworks.calculation.memory.ValuesProvider


  connections.add(c1);

  NeuralNetworkImpl nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));

  ValuesProvider vp = TensorFactory.tensorProvider(nn, 2, true);

  Matrix i1 = vp.get(nn.getInputLayer());
  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);

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, ol);

  // most simple case
  Matrix o = vp.get(nn.getOutputLayer());
  assertEquals(14, o.get(0, 0), 0);
  assertEquals(32, o.get(0, 1), 0);
  assertEquals(32, o.get(1, 0), 0);
  assertEquals(77, o.get(1, 1), 0);

  // with bias
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(bc);

  nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));
  vp = TensorFactory.tensorProvider(nn, 2, true);

  i1 = vp.get(nn.getInputLayer());
  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);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, ol);

  o = vp.get(nn.getOutputLayer());
  assertEquals(14.1, o.get(0, 0), 0.01);
  assertEquals(32.1, o.get(0, 1), 0.01);
  assertEquals(32.2, o.get(1, 0), 0.01);
  assertEquals(77.2, o.get(1, 1), 0.01);

  // combined layers
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(c2);
  connections.add(bc);
  nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));
  vp = TensorFactory.tensorProvider(nn, 2, true);

  i1 = vp.get(il1);
  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 = vp.get(il2);
  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);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, ol);

  o = vp.get(nn.getOutputLayer());
  assertEquals(28.1, o.get(0, 0), 0.01);
  assertEquals(64.1, o.get(0, 1), 0.01);
  assertEquals(64.2, o.get(1, 0), 0.01);
  assertEquals(154.2, o.get(1, 1), 0.01);
    }
View Full Code Here


  List<Connections> connections = new ArrayList<>();
  connections.add(c1);
  NeuralNetworkImpl nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));
  ValuesProvider vp = TensorFactory.tensorProvider(nn, 2, true);

  Matrix i1 = vp.get(il1);
  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);

  aws.calculate(connections, vp, ol);

  // most simple case
  Matrix o = vp.get(ol);
  assertEquals(14, o.get(0, 0), 0);
  assertEquals(32, o.get(0, 1), 0);
  assertEquals(32, o.get(1, 0), 0);
  assertEquals(77, o.get(1, 1), 0);

  // with bias
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(bc);
  nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));
  vp = TensorFactory.tensorProvider(nn, 2, true);
  i1 = vp.get(il1);
  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);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, ol);

  o = vp.get(ol);
  assertEquals(14.1, o.get(0, 0), 0.01);
  assertEquals(32.1, o.get(0, 1), 0.01);
  assertEquals(32.2, o.get(1, 0), 0.01);
  assertEquals(77.2, o.get(1, 1), 0.01);

  // combined layers
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(c2);
  connections.add(bc);
  nn = new NeuralNetworkImpl();
  nn.addConnections(connections.toArray(new Connections[connections.size()]));
  vp = TensorFactory.tensorProvider(nn, 2, true);

  i1 = vp.get(il1);
  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 = vp.get(il2);
  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);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, ol);

  o = vp.get(ol);
  assertEquals(28.1, o.get(0, 0), 0.01);
  assertEquals(64.1, o.get(0, 1), 0.01);
  assertEquals(64.2, o.get(1, 0), 0.01);
  assertEquals(154.2, o.get(1, 1), 0.01);
    }
View Full Code Here

  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());
  in.set(8, 0, 0);
  in.set(2, 1, 0);
  in.set(1, 0, 1);
  in.set(7, 1, 1);

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

  Matrix out = results.get(nn.getOutputLayer());
  assertEquals(1.1f, out.get(0, 0), 0f);
  assertEquals(1.2f, out.get(1, 0), 0f);
  assertEquals(3.6f, out.get(0, 1), 0f);
  assertEquals(3.7f, out.get(1, 1), 0f);
View Full Code Here

  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());
  in.set(8, 0, 0);
  in.set(2, 1, 0);
  in.set(1, 0, 1);
  in.set(7, 1, 1);
View Full Code Here

      ip.reset();

      triggerEvent(new TestingStartedEvent(this));

      Set<Layer> calculatedLayers = new UniqueList<>();
      ValuesProvider results = TensorFactory.tensorProvider(n, getTestBatchSize(), Environment.getInstance().getUseDataSharedMemory());

      OutputError oe = getOutputError();
      if (oe != null) {
    oe.reset();
    results.add(oe, results.get(n.getOutputLayer()).getDimensions());
      }

      TrainingInputData input = new TrainingInputDataImpl(results.get(n.getInputLayer()), results.get(oe));
      for (int i = 0; i < ip.getInputSize(); i += getTestBatchSize()) {
    ip.populateNext(input);
    calculatedLayers.clear();
    calculatedLayers.add(n.getInputLayer());
    n.getLayerCalculator().calculate(n, n.getOutputLayer(), calculatedLayers, results);
   
    if (oe != null) {
        oe.addItem(results.get(n.getOutputLayer()), input.getTarget());
    }
   
    triggerEvent(new MiniBatchFinishedEvent(this, input, results, null));
      }
     
View Full Code Here

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

  Set<Layer> calculated = new HashSet<>();
  calculated.add(mlp.getInputLayer());

  ValuesProvider results = TensorFactory.tensorProvider(mlp, 1, true);
  results.get(mlp.getInputLayer()).set(2, 0, 0);
  results.get(mlp.getInputLayer()).set(2, 1, 0);

  mlp.getLayerCalculator().calculate(mlp, output, calculated, results);

  assertEquals(1.32, results.get(output).get(0, 0), 0.000001);
    }
View Full Code Here

    if (n.getLayerCalculator() != null) {
        OutputError outputError = t.getOutputError();
        outputError.reset();
        inputProvider.reset();

        ValuesProvider vp = mbe.getResults();
        if (vp == null) {
      vp = TensorFactory.tensorProvider(n, 1, Environment.getInstance().getUseDataSharedMemory());
        }
        if (vp.get(outputError) == null) {
      vp.add(outputError, vp.get(n.getOutputLayer()).getDimensions());
        }
        TrainingInputData input = new TrainingInputDataImpl(vp.get(n.getInputLayer()), vp.get(outputError));

        Set<Layer> calculatedLayers = new UniqueList<>();
        for (int i = 0; i < inputProvider.getInputSize(); i++) {
      inputProvider.populateNext(input);
      calculatedLayers.clear();
      calculatedLayers.add(n.getInputLayer());

      n.getLayerCalculator().calculate(n, n.getOutputLayer(), calculatedLayers, vp);

      outputError.addItem(vp.get(n.getOutputLayer()), input.getTarget());
        }

        float e = outputError.getTotalNetworkError();
        if (e <= acceptanceError) {
      System.out.println("Stopping at error " + e + " (" + (e * 100) + "%) for " + mbe.getBatchCount() + " minibatches");
View Full Code Here

  t.forEach(i -> e6[i] = 0.5f);

  Set<Layer> calculatedLayers = new HashSet<>();
  calculatedLayers.add(dbn.getInputLayer());

  ValuesProvider results = TensorFactory.tensorProvider(dbn, 1, true);
  results.get(dbn.getInputLayer()).set(1, 0, 0);
  results.get(dbn.getInputLayer()).set(0, 1, 0);
  results.get(dbn.getInputLayer()).set(1, 2, 0);
  dbn.getLayerCalculator().calculate(dbn, dbn.getOutputLayer(), calculatedLayers, results);

  assertEquals(1.06, results.get(dbn.getOutputLayer()).get(0, 0), 0.00001);
  assertEquals(1.06, results.get(dbn.getOutputLayer()).get(1, 0), 0.00001);
    }
View Full Code Here

  t.forEach(i -> e8[i] = 0.9f);

  Set<Layer> calculatedLayers = new HashSet<>();
  calculatedLayers.add(sae.getInputLayer());

  ValuesProvider results = TensorFactory.tensorProvider(sae, 1, true);
  results.get(sae.getInputLayer()).set(1, 0, 0);
  results.get(sae.getInputLayer()).set(0, 1, 0);
  results.get(sae.getInputLayer()).set(1, 2, 0);

  sae.getLayerCalculator().calculate(sae, sae.getOutputLayer(), calculatedLayers, results);

  assertEquals(1.06, results.get(sae.getOutputLayer()).get(0, 0), 0.00001);
  assertEquals(1.06, results.get(sae.getOutputLayer()).get(1, 0), 0.00001);
    }
View Full Code Here

public class GeneralTest {

    @Test
    public void testTensorProvider() {
  ValuesProvider tp = new ValuesProvider(true);
  String s1 = "1";
  tp.add(s1, 2, 3);
  String s2 = "2";
  tp.add(s2, 2, 3);

  assertTrue(tp.get(s1).getElements() == tp.get(s2).getElements());
  assertEquals(12, tp.get(s1).getElements().length, 0);
  assertEquals(0, tp.get(s1).getStartIndex(), 0);
  assertEquals(12, tp.get(s2).getElements().length, 0);
  assertEquals(6, tp.get(s2).getStartIndex(), 0);

  ValuesProvider tp2 = new ValuesProvider(tp);
  tp2.add(s1, 2, 3);
  tp2.add(s2, 2, 3);

  assertTrue(tp2.get(s1).getElements() == tp.get(s2).getElements());
  assertEquals(24, tp2.get(s1).getElements().length, 0);
  assertEquals(12, tp2.get(s1).getStartIndex(), 0);
  assertEquals(18, tp2.get(s2).getStartIndex(), 0);
    }
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.calculation.memory.ValuesProvider

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.