Examples of RBM


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

    public void testContrastiveDivergence() {
  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

  // RBM with 6 visible, 2 hidden units and a bias
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(6, 2, true);

  // We'll use a simple dataset of symptoms of a flu illness. There are 6
  // input features and the first three are symptoms of the illness - for
  // example 1 0 0 0 0 0 means that a patient has high temperature, 0 1
  // 0 0 0 0 - coughing, 1 1 0 0 0 0 - coughing and high temperature
View Full Code Here

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

    public void testPersistentContrastiveDivergence() {
  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

  // RBM with 6 visible, 2 hidden units and bias
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(6, 2, true);
 
  // We'll use a simple dataset of symptoms of a flu illness. There are 6
  // input features and the first three are symptoms of the illness - for
  // example 1 0 0 0 0 0 means that a patient has high temperature, 0 1
  // 0 0 0 0 - coughing, 1 1 0 0 0 0 - coughing and high temperature
View Full Code Here

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

    }

    @Test
    public void testRBMLayerCalculator1() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(2, 2, false);
  rbm.setLayerCalculator(NNFactory.lcSigmoid(rbm, null));

  Matrix cg1 = rbm.getMainConnections().getWeights();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.8f, 0, 1);
  cg1.set(0.4f, 1, 0);
  cg1.set(0.6f, 1, 1);


  ValuesProvider vp = TensorFactory.tensorProvider(rbm, 1, true);
  Matrix visible = vp.get(rbm.getVisibleLayer());
  visible.set(0.35f, 0, 0);
  visible.set(0.9f, 1, 0);

  Set<Layer> calculated = new HashSet<Layer>();
  calculated.add(rbm.getVisibleLayer());
  rbm.getLayerCalculator().calculate(rbm, rbm.getHiddenLayer(), calculated, vp);

  Matrix hidden = vp.get(rbm.getHiddenLayer());
  assertEquals(0.68, hidden.get(0, 0), 0.01);
  assertEquals(0.6637, hidden.get(1, 0), 0.01);
    }
View Full Code Here

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

    }
   
    @Test
    public void testRBMLayerCalculator2() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(2, 2, false);
  rbm.setLayerCalculator(NNFactory.lcSigmoid(rbm, null));
 
  Matrix cg1 = rbm.getMainConnections().getWeights();
  cg1.set(0.1f, 0, 0);
  cg1.set(0.8f, 1, 0);
  cg1.set(0.4f, 0, 1);
  cg1.set(0.6f, 1, 1);
 
  ValuesProvider vp = TensorFactory.tensorProvider(rbm, 1, true);
  Matrix hidden = vp.get(rbm.getHiddenLayer());
  hidden.set(0.35f, 0, 0);
  hidden.set(0.9f, 1, 0);
 
  Set<Layer> calculated = new HashSet<Layer>();
  calculated.add(rbm.getHiddenLayer());
  rbm.getLayerCalculator().calculate(rbm, rbm.getVisibleLayer(), calculated, vp);
 
  Matrix visible = vp.get(rbm.getVisibleLayer());
  assertEquals(0.68, visible.get(0, 0), 0.01);
  assertEquals(0.6637, visible.get(1, 0), 0.01);
    }
View Full Code Here

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

    }

    @Test
    public void testRBMLayerCalculator3() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(3, 2, true);
  rbm.setLayerCalculator(NNFactory.lcSigmoid(rbm, null));

  Matrix cg1 = rbm.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 = rbm.getHiddenBiasConnections().getWeights();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

  ValuesProvider vp = TensorFactory.tensorProvider(rbm, 1, true);
  Matrix visible = vp.get(rbm.getVisibleLayer());
  visible.set(1f, 0, 0);
  visible.set(0f, 1, 0);
  visible.set(1f, 2, 0);

  Set<Layer> calculated = new HashSet<Layer>();
  calculated.add(rbm.getVisibleLayer());
  rbm.getLayerCalculator().calculate(rbm, rbm.getHiddenLayer(), calculated, vp);

  Matrix hidden = vp.get(rbm.getHiddenLayer());
  assertEquals(0.332, hidden.get(0, 0), 0.001);
  assertEquals(0.525, hidden.get(1, 0), 0.001);
    }
View Full Code Here

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

    }

    @Test
    public void testRBMLayerCalculator4() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(2, 3, true);
  rbm.setLayerCalculator(NNFactory.lcSigmoid(rbm, null));

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

  Matrix cgb1 = rbm.getVisibleBiasConnections().getWeights();
  cgb1.set(-0.4f, 0, 0);
  cgb1.set(0.2f, 1, 0);

  ValuesProvider vp = TensorFactory.tensorProvider(rbm, 1, true);
  Matrix hidden = vp.get(rbm.getHiddenLayer());
  hidden.set(1f, 0, 0);
  hidden.set(0f, 1, 0);
  hidden.set(1f, 2, 0);

  Set<Layer> calculated = new HashSet<Layer>();
  calculated.add(rbm.getHiddenLayer());
  rbm.getLayerCalculator().calculate(rbm, rbm.getVisibleLayer(), calculated, vp);

  Matrix visible = vp.get(rbm.getVisibleLayer());
  assertEquals(0.332, visible.get(0, 0), 0.001);
  assertEquals(0.525, visible.get(1, 0), 0.001);
    }
View Full Code Here

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

    @Test
    public void testOneStepContrastiveDivergence() {
  //Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

  Environment.getInstance().setUseWeightsSharedMemory(true);
  RBM rbm = NNFactory.rbm(3, 2, true);

  Matrix cg1 = rbm.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 = rbm.getVisibleBiasConnections().getWeights();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);

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

  AparapiCDTrainer t = TrainerFactory.cdSigmoidTrainer(rbm, new SimpleInputProvider(new float[][] { { 1, 0, 1 } }, null), null, null, null, 1f, 0f, 0f, 0f, 1, 1, 1, true);
View Full Code Here

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

    @Test
    public void testTwoStepContrastiveDivergence() {
  //Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Environment.getInstance().setUseWeightsSharedMemory(true);
  Environment.getInstance().setUseDataSharedMemory(true);
  RBM rbm = NNFactory.rbm(3, 2, true);

  Matrix cg1 = rbm.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 = rbm.getVisibleBiasConnections().getWeights();
  cgb1.set(0f, 0, 0);
  cgb1.set(0f, 1, 0);
  cgb1.set(0f, 2, 0);

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

  AparapiCDTrainer t = TrainerFactory.cdSigmoidTrainer(rbm, new SimpleInputProvider(new float[][] { { 1, 0, 1 }, { 1, 1, 0 } }, null), null, null, null, 1f, 0f, 0f, 0f, 1, 1, 1, false);
View Full Code Here

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

    public void handleEvent(TrainingEvent event) {
  // transfer of learned weights from lower to the higher RBM
  if (event instanceof LayerTrainingFinished) {
      LayerTrainingFinished e = (LayerTrainingFinished) event;
      CDTrainerBase t = (CDTrainerBase) e.currentTrainer;
      RBM current = t.getNeuralNetwork();
      List<? extends NeuralNetwork> list = getNeuralNetwork().getNeuralNetworks();

      if (list.indexOf(current) < list.size() - 1) {
    RBM next = (RBM) list.get(list.indexOf(current) + 1);
    if (current.getMainConnections().getWeights().getSize() == next.getMainConnections().getWeights().getSize()) {
        TensorFactory.copy(current.getMainConnections().getWeights(), next.getMainConnections().getWeights());
    }

    if (current.getVisibleBiasConnections() != null && next.getVisibleBiasConnections() != null && current.getVisibleBiasConnections().getWeights().getSize() == next.getVisibleBiasConnections().getWeights().getSize()) {
        TensorFactory.copy(current.getVisibleBiasConnections().getWeights(), next.getVisibleBiasConnections().getWeights());
    }
   
    if (current.getHiddenBiasConnections() != null && next.getHiddenBiasConnections() != null && current.getHiddenBiasConnections().getWeights().getSize() == next.getHiddenBiasConnections().getWeights().getSize()) {
        TensorFactory.copy(current.getHiddenBiasConnections().getWeights(), next.getHiddenBiasConnections().getWeights());
    }
      }
  }
    }
View Full Code Here

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() {
  RBM rbm = getNeuralNetwork();

  RBMLayerCalculator lc = getLayerCalculator();
  int mbs = lc.getPositivePhaseVisible().getDimensions()[lc.getPositivePhaseVisible().getDimensions().length - 1];

  if (weightUpdatesKernel == null || weightUpdatesKernel.getMiniBatchSize() != mbs) {
      weightUpdatesKernel = new CDWeightUpdatesKernel(lc.getPositivePhaseVisible(), lc.getPositivePhaseHidden(), lc.getNegativePhaseVisible(), lc.getNegativePhaseHidden(), rbm.getMainConnections().getWeights(), getLearningRate(), getMomentum(), getl1weightDecay(), getl2weightDecay());
  }
  Environment.getInstance().getExecutionStrategy().execute(weightUpdatesKernel, rbm.getMainConnections().getWeights().getRows());

  // update visible bias
  if (rbm.getVisibleBiasConnections() != null) {
      if (visibleBiasUpdatesKernel == null || visibleBiasUpdatesKernel.getMiniBatchSize() != mbs) {
    visibleBiasUpdatesKernel = new CDBiasUpdatesKernel(rbm.getVisibleBiasConnections().getWeights(), lc.getPositivePhaseVisible(), lc.getNegativePhaseVisible(), getLearningRate(), getMomentum());
      }

      Environment.getInstance().getExecutionStrategy().execute(visibleBiasUpdatesKernel, rbm.getVisibleBiasConnections().getWeights().getSize());
  }

  // update hidden bias
  if (rbm.getHiddenBiasConnections() != null) {
      if (hiddenBiasUpdatesKernel == null || hiddenBiasUpdatesKernel.getMiniBatchSize() != mbs) {
    hiddenBiasUpdatesKernel = new CDBiasUpdatesKernel(rbm.getHiddenBiasConnections().getWeights(), lc.getPositivePhaseHidden(), lc.getNegativePhaseHidden(), getLearningRate(), getMomentum());
      }

      Environment.getInstance().getExecutionStrategy().execute(hiddenBiasUpdatesKernel, rbm.getHiddenBiasConnections().getWeights().getSize());
  }
    }
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.