Package com.github.neuralnetworks.calculation.neuronfunctions

Examples of com.github.neuralnetworks.calculation.neuronfunctions.ConnectionCalculatorFullyConnected


    public static AparapiCDTrainer cdSoftReLUTrainer(RBM rbm, TrainingInputProvider trainingSet, TrainingInputProvider testingSet, OutputError error, NNRandomInitializer rand, float learningRate, float momentum, float l1weightDecay, float l2weightDecay, int gibbsSampling, boolean isPersistentCD) {
  rbm.setLayerCalculator(NNFactory.rbmSoftReluSoftRelu(rbm));

  RBMLayerCalculator lc = NNFactory.rbmSigmoidSigmoid(rbm);
  ConnectionCalculatorFullyConnected cc = (ConnectionCalculatorFullyConnected) lc.getConnectionCalculator(rbm.getInputLayer());
  cc.addPreTransferFunction(new BernoulliDistribution());

  return new AparapiCDTrainer(rbmProperties(rbm, lc, trainingSet, testingSet, error, rand, learningRate, momentum, l1weightDecay, l2weightDecay, gibbsSampling, isPersistentCD));
    }
View Full Code Here


    public static AparapiCDTrainer cdSigmoidTrainer(RBM rbm, TrainingInputProvider trainingSet, TrainingInputProvider testingSet, OutputError error, NNRandomInitializer rand, float learningRate, float momentum, float l1weightDecay, float l2weightDecay, int gibbsSampling, boolean isPersistentCD) {
  rbm.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));

  RBMLayerCalculator lc = NNFactory.rbmSigmoidSigmoid(rbm);
  ConnectionCalculatorFullyConnected cc = (ConnectionCalculatorFullyConnected) lc.getConnectionCalculator(rbm.getInputLayer());
  cc.addPreTransferFunction(new BernoulliDistribution());

  return new AparapiCDTrainer(rbmProperties(rbm, lc, trainingSet, testingSet, error, rand, learningRate, momentum, l1weightDecay, l2weightDecay, gibbsSampling, isPersistentCD));
    }
View Full Code Here

  Matrix bcg = bc.getConnectionGraph();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  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);
  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

  Matrix bcg = bc.getConnectionGraph();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  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);
  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

  // train
  bpt.train();

  // add softmax function
  LayerCalculatorImpl lc = (LayerCalculatorImpl) mlp.getLayerCalculator();
  ConnectionCalculatorFullyConnected cc = (ConnectionCalculatorFullyConnected) lc.getConnectionCalculator(mlp.getOutputLayer());
  cc.addActivationFunction(new SoftmaxFunction());

  // test
  bpt.test();

  assertEquals(0, bpt.getOutputError().getTotalNetworkError(), 0.1);
View Full Code Here

    if (outputCC != null && nn.getOutputLayer() == l) {
        lc.addConnectionCalculator(l, outputCC);
    } else if (Util.isConvolutional(l)) {
        lc.addConnectionCalculator(l, new ConnectionCalculatorConv());
    } else {
        lc.addConnectionCalculator(l, new ConnectionCalculatorFullyConnected());
    }
      } else {
    lc.addConnectionCalculator(l, new ConstantConnectionCalculator());
      }
  }
View Full Code Here

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

  Matrix bcg = bc.getWeights();
  bcg.set(0.1f, 0, 0);
  bcg.set(0.2f, 1, 0);

  ConnectionCalculatorFullyConnected aws = new AparapiWeightedSumConnectionCalculator();

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

  float dropoutRate = properties.getParameter(Constants.DROPOUT_RATE);

  if (dropoutRate > 0) {
      LayerCalculatorImpl lc = (LayerCalculatorImpl) nn.getLayerCalculator();
      nn.getConnections().stream().filter(c -> c instanceof FullyConnected && c.getInputLayer() != nn.getInputLayer() && !Util.isBias(c.getInputLayer())).forEach(c -> {
    ConnectionCalculatorFullyConnected cc = (ConnectionCalculatorFullyConnected) lc.getConnectionCalculator(c.getOutputLayer());
    cc.setDropoutRate(dropoutRate);
      });

      addEventListener(this);
  }
    }
View Full Code Here

      if (dropoutRate > 0) {
    NeuralNetwork nn = getNeuralNetwork();

    LayerCalculatorImpl lc = (LayerCalculatorImpl) nn.getLayerCalculator();
    nn.getConnections().stream().filter(c -> c instanceof FullyConnected && c.getInputLayer() != nn.getInputLayer() && !Util.isBias(c.getInputLayer())).forEach(c -> {
        ConnectionCalculatorFullyConnected cc = (ConnectionCalculatorFullyConnected) lc.getConnectionCalculator(c.getOutputLayer());
        cc.setDropoutRate(0);
        FullyConnected fc = (FullyConnected) c;
        fc.getWeights().forEach(i -> fc.getWeights().getElements()[i] = fc.getWeights().getElements()[i] * (1 - dropoutRate));
    });
      }
  }
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.calculation.neuronfunctions.ConnectionCalculatorFullyConnected

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.