Package com.github.neuralnetworks.calculation

Examples of com.github.neuralnetworks.calculation.ValuesProvider


  super();
  this.inputProvider = inputProvider;
  this.dnn = dnn;
  this.currentNN = currentNN;
  this.calculatedLayers = new HashSet<>();
  this.layerResults = new ValuesProvider();
    }
View Full Code Here


        inputProvider.reset();

        while ((input = inputProvider.getNextInput()) != null) {
      calculatedLayers.clear();
      calculatedLayers.add(n.getInputLayer());
      ValuesProvider vp = mbe.getResults();
      if (vp == null) {
          vp = new ValuesProvider();
      }

      vp.addValues(n.getInputLayer(), input.getInput());
      n.getLayerCalculator().calculate(n, n.getOutputLayer(), calculatedLayers, vp);

      outputError.addItem(vp.getValues(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

public class GeneralTest {

    @Test
    public void testValuesProvider() {
  ValuesProvider vp = new ValuesProvider();

  NeuralNetworkImpl nn = new NeuralNetworkImpl();
  Layer i = new Layer();
  Layer h = new Layer();
  Layer o = new Layer();

  nn.addLayer(i);

  NNFactory.addFullyConnectedLayer(nn, h, 2, 3, true);
  NNFactory.addFullyConnectedLayer(nn, o, 4, 1, true);

  Matrix im = new Matrix(2, 2);
  vp.addValues(i, im);
  Matrix hm1 = vp.getValues(h, 3);
  Matrix hm2 = new Matrix(4, 2);
  vp.addValues(h, hm2);

  Matrix om = vp.getValues(o);

  assertTrue(im == vp.getValues(i, 2));
  assertTrue(im == vp.getValues(i));
  assertTrue(hm1 == vp.getValues(h, 3));
  assertTrue(hm2 == vp.getValues(h, 4));
  assertTrue(hm1 == vp.getValues(h, nn.getConnection(i, h)));
  assertTrue(hm2 == vp.getValues(h, nn.getConnection(h, o)));
  assertTrue(om == vp.getValues(o, 1));
  assertTrue(om == vp.getValues(o));
  assertTrue(2 == vp.getColumns());
    }
View Full Code Here

      ip.reset();

      triggerEvent(new TestingStartedEvent(this));

      Set<Layer> calculatedLayers = new UniqueList<>();
      ValuesProvider results = new ValuesProvider();
      TrainingInputData input = null;

      if (getOutputError() != null) {
    getOutputError().reset();
      }

      while ((input = ip.getNextInput()) != null) {
    calculatedLayers.clear();
    calculatedLayers.add(n.getInputLayer());
    results.addValues(n.getInputLayer(), input.getInput());
    n.getLayerCalculator().calculate(n, n.getOutputLayer(), calculatedLayers, results);

    if (getOutputError() != null) {
        getOutputError().addItem(results.getValues(n.getOutputLayer()), input.getTarget());
    }

    triggerEvent(new MiniBatchFinishedEvent(this, input, results, null));
      }
     
View Full Code Here

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();

  List<Connections> connections = new ArrayList<>();
  connections.add(c1);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c1.getInputLayer(), i1);
  vp.addValues(ol, o);

  aws.calculate(connections, vp, ol);

  // most simple case
  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);
  Util.fillArray(o.getElements(), 0);

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

  vp = new ValuesProvider();
  vp.addValues(c1.getInputLayer(), i1);
  vp.addValues(ol, o);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, 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);
  Util.fillArray(o.getElements(), 0);

  // combined layers
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(c2);
  connections.add(bc);

  vp = new ValuesProvider();
  vp.addValues(c1.getInputLayer(), i1);
  vp.addValues(c2.getInputLayer(), i2);
  vp.addValues(ol, o);

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

  assertEquals(28.1, o.get(0, 0), 0.01);
View Full Code Here

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();

  List<Connections> connections = new ArrayList<>();
  connections.add(c1);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c1.getOutputLayer(), i1);
  vp.addValues(ol, o);

  aws.calculate(connections, vp, ol);

  // most simple case
  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);
  Util.fillArray(o.getElements(), 0);

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

  vp = new ValuesProvider();
  vp.addValues(c1.getOutputLayer(), i1);
  vp.addValues(ol, o);

  aws = new AparapiWeightedSumConnectionCalculator();
  aws.calculate(connections, vp, 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);
  Util.fillArray(o.getElements(), 0);

  // combined layers
  connections = new ArrayList<>();
  connections.add(c1);
  connections.add(c2);
  connections.add(bc);

  vp = new ValuesProvider();
  vp.addValues(c1.getOutputLayer(), i1);
  vp.addValues(c2.getOutputLayer(), i2);
  vp.addValues(ol, o);

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

  assertEquals(28.1, o.get(0, 0), 0.01);
View Full Code Here

  Matrix i = new Matrix(new float [] {2, 2}, 1);
  Set<Layer> calculated = new HashSet<>();
  calculated.add(mlp.getInputLayer());

  ValuesProvider results = new ValuesProvider();
  results.addValues(input, i);

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

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

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

  c.getWeights()[14] = 3;
  c.getWeights()[15] = 4;

  Matrix i1 = new Matrix(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }, 1);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(nn.getInputLayer(), i1);

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

  Matrix o = vp.getValues(nn.getOutputLayer());

  assertEquals(244, o.get(0, 0), 0);
  assertEquals(244, o.get(1, 0), 0);
    }
View Full Code Here

  connections.add(c);

  ConnectionCalculator calc = new AparapiMaxPooling2D();
  Matrix o = new Matrix(8, 2);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c.getInputLayer(), i1);
  vp.addValues(c.getOutputLayer(), o);

  calc.calculate(connections, vp, c.getOutputLayer());

  assertEquals(3, o.get(0, 0), 0);
  assertEquals(4, o.get(1, 0), 0);
View Full Code Here

  connections.add(c);

  AparapiAveragePooling2D calc = new AparapiAveragePooling2D();
  Matrix o = new Matrix(8, 2);

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c.getInputLayer(), i1);
  vp.addValues(c.getOutputLayer(), o);

  calc.calculate(connections, vp, c.getOutputLayer());

  assertEquals(1.75, o.get(0, 0), 0);
  assertEquals(2.75, o.get(1, 0), 0);
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.calculation.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.