Examples of RBM


Examples of com.github.neuralnetworks.architecture.types.RBM

     * @see com.github.neuralnetworks.training.rbm.CDTrainerBase#updateWeights(com.github.neuralnetworks.architecture.Matrix, com.github.neuralnetworks.architecture.Matrix, com.github.neuralnetworks.architecture.Matrix, com.github.neuralnetworks.architecture.Matrix)
     * before each update the kernel update parameters are refreshed
     */
    @Override
    protected void updateWeights(Matrix posPhaseVisible, Matrix posPhaseHidden, Matrix negPhaseVisible, Matrix negPhaseHidden) {
  RBM rbm = getNeuralNetwork();

  int mbs = posPhaseHidden.getColumns();

  if (weightUpdatesKernel == null || weightUpdatesKernel.getMiniBatchSize() != mbs) {
      weightUpdatesKernel = new CDWeightUpdatesKernel(posPhaseVisible, posPhaseHidden, negPhaseVisible, negPhaseHidden, rbm.getMainConnections().getConnectionGraph(), getLearningRate(), getMomentum(), getl1weightDecay(), getl2weightDecay());
  }
  Environment.getInstance().getExecutionStrategy().execute(weightUpdatesKernel, rbm.getMainConnections().getConnectionGraph().getRows());

  // update visible bias
  if (rbm.getVisibleBiasConnections() != null) {
      if (visibleBiasUpdatesKernel == null || visibleBiasUpdatesKernel.getMiniBatchSize() != mbs) {
    visibleBiasUpdatesKernel = new CDBiasUpdatesKernel(rbm.getVisibleBiasConnections().getConnectionGraph().getElements(), posPhaseVisible, negPhaseVisible, getLearningRate(), getMomentum());
      }

      Environment.getInstance().getExecutionStrategy().execute(visibleBiasUpdatesKernel, rbm.getVisibleBiasConnections().getConnectionGraph().getElements().length);
  }

  // update hidden bias
  if (rbm.getHiddenBiasConnections() != null) {
      if (hiddenBiasUpdatesKernel == null || hiddenBiasUpdatesKernel.getMiniBatchSize() != mbs) {
    hiddenBiasUpdatesKernel = new CDBiasUpdatesKernel(rbm.getHiddenBiasConnections().getConnectionGraph().getElements(), posPhaseHidden, negPhaseHidden, getLearningRate(), getMomentum());
      }

      Environment.getInstance().getExecutionStrategy().execute(hiddenBiasUpdatesKernel, rbm.getHiddenBiasConnections().getConnectionGraph().getElements().length);
  }
    }
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

  Environment.getInstance().setExecutionMode(EXECUTION_MODE.CPU);
  Environment.getInstance().setUseDataSharedMemory(true);
  Environment.getInstance().setUseWeightsSharedMemory(true);

  // RBM with 4 visible and 3 hidden units
  RBM rbm = NNFactory.rbm(4, 3, true);

  // training and testing input providers
  IrisInputProvider trainInputProvider = new IrisInputProvider(new IrisTargetMultiNeuronOutputConverter(), false);
  trainInputProvider.addInputModifier(new ScalingInputFunction(trainInputProvider));
  IrisInputProvider testInputProvider = new IrisInputProvider(new IrisTargetMultiNeuronOutputConverter(), false);
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

  assertEquals(0, bpt.getOutputError().getTotalNetworkError(), 0.1);
    }

    @Test
    public void testRBM() {
  RBM rbm = NNFactory.rbm(784, 10, false);
  MnistInputProvider trainInputProvider = new MnistInputProvider("train-images.idx3-ubyte", "train-labels.idx1-ubyte", 1, 1, new MnistTargetMultiNeuronOutputConverter());
  trainInputProvider.addInputModifier(new ScalingInputFunction(255));
  MnistInputProvider testInputProvider = new MnistInputProvider("t10k-images.idx3-ubyte", "t10k-labels.idx1-ubyte", 1000, 1, new MnistTargetMultiNeuronOutputConverter());
  testInputProvider.addInputModifier(new ScalingInputFunction(255));
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    @Test
    public void testDBNCalculation() {
  DBN dbn = NNFactory.dbn(new int [] {3, 2, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcWeightedSum(dbn, null));

  RBM firstRBM = dbn.getFirstNeuralNetwork();
  Util.fillArray(firstRBM.getMainConnections().getConnectionGraph().getElements(), 0.2f);
  Util.fillArray(firstRBM.getVisibleBiasConnections().getConnectionGraph().getElements(), 0.1f);
  Util.fillArray(firstRBM.getHiddenBiasConnections().getConnectionGraph().getElements(), 0.3f);

  RBM secondRBM = dbn.getLastNeuralNetwork();
  Util.fillArray(secondRBM.getMainConnections().getConnectionGraph().getElements(), 0.4f);
  Util.fillArray(secondRBM.getVisibleBiasConnections().getConnectionGraph().getElements(), 0.8f);
  Util.fillArray(secondRBM.getHiddenBiasConnections().getConnectionGraph().getElements(), 0.5f);

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

  ValuesProvider results = new ValuesProvider();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    @Test
    public void testDNNLayerTrainer() {
  DBN dbn = NNFactory.dbn(new int [] {3, 2, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcSigmoid(dbn, null));

  RBM firstRBM = dbn.getFirstNeuralNetwork();

  Matrix cg1 = firstRBM.getMainConnections().getConnectionGraph();
  cg1.set(0.2f, 0, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(-0.5f, 0, 2);
  cg1.set(-0.3f, 1, 0);
  cg1.set(0.1f, 1, 1);
  cg1.set(0.2f, 1, 2);

  Matrix cgb1 = firstRBM.getVisibleBiasConnections().getConnectionGraph();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);

  Matrix cgb2 = firstRBM.getHiddenBiasConnections().getConnectionGraph();
  cgb2.set(-0.4f, 0, 0);
  cgb2.set(0.2f, 1, 0);

  SimpleInputProvider inputProvider = new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, null, 1, 1);

  AparapiCDTrainer firstTrainer = TrainerFactory.cdSigmoidTrainer(firstRBM, null, null, null, null, 1f, 0f, 0f, 0f, 1, true);
  firstTrainer.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(firstRBM));

  RBM secondRBM = dbn.getLastNeuralNetwork();

  AparapiCDTrainer secondTrainer = TrainerFactory.cdSigmoidTrainer(secondRBM, null, null, null, null, 1f, 0f, 0f, 0f, 1, true);
  secondTrainer.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(secondRBM));

  Map<NeuralNetwork, OneStepTrainer<?>> layerTrainers = new HashMap<>();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    public void testDNNLayerTrainer2() {
  DBN dbn = NNFactory.dbn(new int [] {3, 3, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcSigmoid(dbn, null));

  LayerCalculatorImpl lc = (LayerCalculatorImpl) dbn.getLayerCalculator();
  RBM firstRBM = dbn.getFirstNeuralNetwork();
  lc.addConnectionCalculator(firstRBM.getHiddenLayer(), new AparapiWeightedSumConnectionCalculator());

  Matrix m1 = firstRBM.getMainConnections().getConnectionGraph();
  m1.set(1, 0, 0);
  m1.set(0, 0, 1);
  m1.set(0, 0, 2);
  m1.set(0, 1, 0);
  m1.set(1, 1, 1);
  m1.set(0, 1, 2);
  m1.set(0, 2, 0);
  m1.set(0, 2, 1);
  m1.set(1, 2, 2);

  RBM secondRBM = dbn.getLastNeuralNetwork();
 
  Matrix cg1 = secondRBM.getMainConnections().getConnectionGraph();
  cg1.set(0.2f, 0, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(-0.5f, 0, 2);
  cg1.set(-0.3f, 1, 0);
  cg1.set(0.1f, 1, 1);
  cg1.set(0.2f, 1, 2);
 
  Matrix cgb1 = secondRBM.getVisibleBiasConnections().getConnectionGraph();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);
 
  Matrix cgb2 = secondRBM.getHiddenBiasConnections().getConnectionGraph();
  cgb2.set(-0.4f, 0, 0);
  cgb2.set(0.2f, 1, 0);
 
  SimpleInputProvider inputProvider = new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, null, 1, 1);
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

  return input;
    }

    @Override
    protected void learnInput(int batch) {
  RBM nn = getNeuralNetwork();

  getLayerCalculator().gibbsSampling(nn, getGibbsSamplingCount(), batch == 0 ? true : !getIsPersistent());

  // update weights
  updateWeights();
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    public void testDBNCalculation() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  DBN dbn = NNFactory.dbn(new int [] {3, 2, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcWeightedSum(dbn, null));

  RBM firstRBM = dbn.getFirstNeuralNetwork();

  Tensor t = firstRBM.getMainConnections().getWeights();
  float[] e1 = t.getElements();
  t.forEach(i -> e1[i] = 0.2f);
 
  t = firstRBM.getVisibleBiasConnections().getWeights();
  float[] e2 = t.getElements();
  t.forEach(i -> e2[i] = 0.1f);

  t = firstRBM.getHiddenBiasConnections().getWeights();
  float[] e3 = t.getElements();
  t.forEach(i -> e3[i] = 0.3f);

  RBM secondRBM = dbn.getLastNeuralNetwork();

  t = secondRBM.getMainConnections().getWeights();
  float[] e4 = t.getElements();
  t.forEach(i -> e4[i] = 0.4f);

  t = secondRBM.getVisibleBiasConnections().getWeights();
  float[] e5 = t.getElements();
  t.forEach(i -> e5[i] = 0.8f);

  t = secondRBM.getHiddenBiasConnections().getWeights();
  float[] e6 = t.getElements();
  t.forEach(i -> e6[i] = 0.5f);

  Set<Layer> calculatedLayers = new HashSet<>();
  calculatedLayers.add(dbn.getInputLayer());
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    public void testDNNLayerTrainer() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  DBN dbn = NNFactory.dbn(new int [] {3, 2, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcSigmoid(dbn, null));

  RBM firstRBM = dbn.getFirstNeuralNetwork();

  Matrix cg1 = firstRBM.getMainConnections().getWeights();
  cg1.set(0.2f, 0, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(-0.5f, 0, 2);
  cg1.set(-0.3f, 1, 0);
  cg1.set(0.1f, 1, 1);
  cg1.set(0.2f, 1, 2);

  Matrix cgb1 = firstRBM.getVisibleBiasConnections().getWeights();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);

  Matrix cgb2 = firstRBM.getHiddenBiasConnections().getWeights();
  cgb2.set(-0.4f, 0, 0);
  cgb2.set(0.2f, 1, 0);

  SimpleInputProvider inputProvider = new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, null);

  AparapiCDTrainer firstTrainer = TrainerFactory.cdSigmoidTrainer(firstRBM, null, null, null, null, 1f, 0f, 0f, 0f, 1, 1, 1, true);

  RBM secondRBM = dbn.getLastNeuralNetwork();

  AparapiCDTrainer secondTrainer = TrainerFactory.cdSigmoidTrainer(secondRBM, null, null, null, null, 1f, 0f, 0f, 0f, 1, 1, 1, true);

  Map<NeuralNetwork, OneStepTrainer<?>> layerTrainers = new HashMap<>();
  layerTrainers.put(firstRBM, firstTrainer);
View Full Code Here

Examples of com.github.neuralnetworks.architecture.types.RBM

    public void testDNNLayerTrainer2() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  DBN dbn = NNFactory.dbn(new int [] {3, 3, 2}, true);
  dbn.setLayerCalculator(NNFactory.lcSigmoid(dbn, null));

  RBM firstRBM = dbn.getFirstNeuralNetwork();

  LayerCalculatorImpl lc = (LayerCalculatorImpl) dbn.getLayerCalculator();
  lc.addConnectionCalculator(firstRBM.getHiddenLayer(), new AparapiWeightedSumConnectionCalculator());

  Matrix m1 = firstRBM.getMainConnections().getWeights();
  m1.set(1, 0, 0);
  m1.set(0, 0, 1);
  m1.set(0, 0, 2);
  m1.set(0, 1, 0);
  m1.set(1, 1, 1);
  m1.set(0, 1, 2);
  m1.set(0, 2, 0);
  m1.set(0, 2, 1);
  m1.set(1, 2, 2);

  RBM secondRBM = dbn.getLastNeuralNetwork();
 
  Matrix cg1 = secondRBM.getMainConnections().getWeights();
  cg1.set(0.2f, 0, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(-0.5f, 0, 2);
  cg1.set(-0.3f, 1, 0);
  cg1.set(0.1f, 1, 1);
  cg1.set(0.2f, 1, 2);
 
  Matrix cgb1 = secondRBM.getVisibleBiasConnections().getWeights();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);
 
  Matrix cgb2 = secondRBM.getHiddenBiasConnections().getWeights();
  cgb2.set(-0.4f, 0, 0);
  cgb2.set(0.2f, 1, 0);

  SimpleInputProvider inputProvider = new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, null);
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.