Package com.github.neuralnetworks.calculation

Examples of com.github.neuralnetworks.calculation.ConnectionCalculator


    chunk.add(c.connection);

    if (i == connections.size() - 1 || connections.get(i + 1).target != c.target) {
        current = c.target;

        ConnectionCalculator result = null;
        ConnectionCalculator ffcc = null;
        if (Util.isBias(current)) {
      ffcc = lc.getConnectionCalculator(current.getConnections().get(0).getOutputLayer());
        } else if (Util.isConvolutional(current) || Util.isSubsampling(current)) {
      if (chunk.size() != 1) {
          throw new IllegalArgumentException("Convolutional layer with more than one connection");
View Full Code Here


  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix i1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);
  List<Connections> connections = new ArrayList<Connections>();
  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);
  assertEquals(7, o.get(2, 0), 0);
  assertEquals(8, o.get(3, 0), 0);
View Full Code Here

  // max pooling
  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c.getInputLayer(), a1);
  vp.addValues(c.getOutputLayer(), o);

  ConnectionCalculator calc = new AparapiMaxPooling2D();
  calc.calculate(connections, vp, c.getOutputLayer());

  ValuesProvider activations = new ValuesProvider();
  activations.addValues(c.getInputLayer(), a1);

  Matrix bpo = new Matrix(32, 2);
View Full Code Here

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  Matrix a1 = new Matrix(new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 }, 2);

  // max pooling
  ConnectionCalculator calc = new AparapiAveragePooling2D();

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

  ValuesProvider vp = new ValuesProvider();
  vp.addValues(c.getInputLayer(), a1);
  Matrix o = new Matrix(8, 2);
  vp.addValues(c.getOutputLayer(), o);

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

  ValuesProvider activations = new ValuesProvider();
  activations.addValues(c.getInputLayer(), a1);

  BackpropagationAveragePooling2D bp = new BackpropagationAveragePooling2D();
View Full Code Here

  calculate(results, connections, nn);
    }

    @Override
    public ConnectionCalculator getConnectionCalculator(Layer layer) {
  ConnectionCalculator cc = super.getConnectionCalculator(layer);
  if (cc instanceof BackPropagationConnectionCalculator) {
      ((BackPropagationConnectionCalculator) cc).setActivations(activations);
  }

  return cc;
View Full Code Here

    chunk.add(c.connection);

    if (i == connections.size() - 1 || connections.get(i + 1).target != c.target) {
        current = c.target;

        ConnectionCalculator result = null;
        ConnectionCalculator ffcc = null;
        if (Util.isBias(current)) {
      ffcc = lc.getConnectionCalculator(current.getConnections().get(0).getOutputLayer());
        } else if (Util.isConvolutional(current) || Util.isSubsampling(current)) {
      if (chunk.size() != 1) {
          throw new IllegalArgumentException("Convolutional layer with more than one connection");
View Full Code Here

    public void testMaxPooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  ConnectionCalculator calc = new AparapiMaxPooling2D();

  ValuesProvider vp = TensorFactory.tensorProvider(c, 2, true);
  float[] src = new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 };
  System.arraycopy(src, 0, vp.get(c.getInputLayer()).getElements(), vp.get(c.getInputLayer()).getStartIndex(), src.length);

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

  Tensor o = vp.get(c.getOutputLayer());

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

  // max pooling
  ValuesProvider activations = TensorFactory.tensorProvider(c, 2, true);
  float[] src = new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 };
  System.arraycopy(src, 0, activations.get(c.getInputLayer()).getElements(), activations.get(c.getInputLayer()).getStartIndex(), src.length);

  ConnectionCalculator calc = new AparapiMaxPooling2D();
  calc.calculate(connections, activations, c.getOutputLayer());

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

  BackpropagationMaxPooling2D bp = new BackpropagationMaxPooling2D();
View Full Code Here

    @Test
    public void testAveragePoolingBackpropagation() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);

  // average pooling
  ConnectionCalculator calc = new AparapiAveragePooling2D();

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

  ValuesProvider activations = TensorFactory.tensorProvider(c, 2, true);
  float[] src = new float[] { 0.5f, 1, 1, 2, 1.5f, 3, 2, 4, 2.5f, 5, 3, 6, 3.5f, 7, 4f, 8, 4.5f, 9, 5f, 10, 5.5f, 11, 6f, 12, 6.5f, 13, 7f, 14, 8f, 16, 7.5f, 15, 8.5f, 17, 9f, 18, 9.5f, 19, 10f, 20, 10.5f, 21, 11f, 22, 11.5f, 23, 12f, 24, 12.5f, 25, 13f, 26, 13.5f, 27, 14f, 28, 14.5f, 29, 15f, 30, 16f, 32, 15.5f, 31 };
  System.arraycopy(src, 0, activations.get(c.getInputLayer()).getElements(), activations.get(c.getInputLayer()).getStartIndex(), src.length);

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

  BackpropagationAveragePooling2D bp = new BackpropagationAveragePooling2D();
  bp.setActivations(activations);

  ValuesProvider vp = TensorFactory.tensorProvider(c, 2, true);
View Full Code Here

  Tensor t = TensorFactory.tensor(targetLayer, inputConnections, valuesProvider);
  return new AparapiNoise(t, t.getSize(), dropoutRate, 0);
    }

    private ConnectionCalculator getConnectionCalculator(List<Connections> connections, ValuesProvider valuesProvider, Layer targetLayer) {
  ConnectionCalculator result = inputFunctions.stream().filter(c -> {
      return !(c instanceof AparapiFullyConnected) || ((AparapiFullyConnected) c).accept(connections, valuesProvider, targetLayer);
  }).findFirst().orElse(createInputFunction(connections, valuesProvider, targetLayer));
  inputFunctions.add(result);

  return result;
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.calculation.ConnectionCalculator

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.