Examples of RBM


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

     * Contrastive Divergence testing
     */
    @Test
    public void testContrastiveDivergence() {
  // RBM with 6 visible, 2 hidden units and a bias
  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

     * Persistent Contrastive Divergence testing
     */
    @Test
    public void testPersistentContrastiveDivergence() {
  // RBM with 6 visible, 2 hidden units and bias
  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

  assertEquals(0, t.getOutputError().getTotalNetworkError(), 0);
    }

    @Test
    public void testRBMLayerCalculator1() {
  RBM rbm = NNFactory.rbm(2, 2, false);
  rbm.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));

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

  RBMLayerCalculator lc = (RBMLayerCalculator) rbm.getLayerCalculator();

  Matrix visible = new Matrix(new float[] { 0.35f, 0.9f }, 1);
  Matrix hidden = new Matrix(2, 1);
  lc.calculateHiddenLayer(rbm, visible, hidden);
View Full Code Here

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

  assertEquals(0.6637, hidden.get(1, 0), 0.01);
    }

    @Test
    public void testRBMLayerCalculator2() {
  RBM rbm = NNFactory.rbm(2, 2, false);
  rbm.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));

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

  RBMLayerCalculator lc = (RBMLayerCalculator) rbm.getLayerCalculator();

  Matrix visible = new Matrix(2, 1);
  Matrix hidden = new Matrix(new float[] { 0.35f, 0.9f }, 1);

  lc.calculateVisibleLayer(rbm, visible, hidden);
View Full Code Here

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

  assertEquals(0.6637, visible.get(1, 0), 0.01);
    }

    @Test
    public void testRBMLayerCalculator3() {
  RBM rbm = NNFactory.rbm(3, 2, true);
  rbm.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));

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

  RBMLayerCalculator lc = (RBMLayerCalculator) rbm.getLayerCalculator();
  Matrix visible = new Matrix(new float[] { 1f, 0f, 1f }, 1);
  Matrix hidden = new Matrix(2, 1);
  lc.calculateHiddenLayer(rbm, visible, hidden);

  assertEquals(0.332, hidden.get(0, 0), 0.001);
View Full Code Here

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

  assertEquals(0.525, hidden.get(1, 0), 0.001);
    }

    @Test
    public void testRBMLayerCalculator4() {
  RBM rbm = NNFactory.rbm(2, 3, true);
  rbm.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));

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

  RBMLayerCalculator lc = (RBMLayerCalculator) rbm.getLayerCalculator();
  Matrix hidden = new Matrix(new float[] { 1f, 0f, 1f }, 1);
  Matrix visible = new Matrix(2, 1);
  lc.calculateVisibleLayer(rbm, visible, hidden);

  assertEquals(0.332, visible.get(0, 0), 0.001);
View Full Code Here

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

  assertEquals(0.525, visible.get(1, 0), 0.001);
    }

    @Test
    public void testOneStepContrastiveDivergence() {
  RBM rbm = NNFactory.rbm(3, 2, true);

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

  Matrix cgb2 = rbm.getHiddenBiasConnections().getConnectionGraph();
  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, 1, 1), null, null, null, 1f, 0f, 0f, 0f, 1, true);
  t.setLayerCalculator(NNFactory.rbmSigmoidSigmoid(rbm));
View Full Code Here

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

     * Contrastive Divergence testing
     */
    @Test
    public void testRBMCDSigmoidBP() {
  // RBM with 4 visible and 3 hidden units
  RBM rbm = NNFactory.rbm(4, 3, true);

  // training and testing input providers
  TrainingInputProvider trainInputProvider = new IrisInputProvider(1, 150000, new IrisTargetMultiNeuronOutputConverter(), false, true, false);
  TrainingInputProvider testInputProvider = new IrisInputProvider(1, 150, new IrisTargetMultiNeuronOutputConverter(), false, true, false);
  MultipleNeuronsOutputError error = new MultipleNeuronsOutputError();
View Full Code Here

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

  super(properties);
    }

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

  posPhaseVisible = data.getInput();
  if (negPhaseVisible == null || negPhaseVisible.getColumns() != posPhaseVisible.getColumns()) {
      negPhaseVisible = new Matrix(posPhaseVisible.getRows(), posPhaseVisible.getColumns());
      posPhaseHidden = new Matrix(nn.getMainConnections().getConnectionGraph().getRows(), posPhaseVisible.getColumns());
      negPhaseHidden = new Matrix(nn.getMainConnections().getConnectionGraph().getRows(), posPhaseVisible.getColumns());
  }

  getLayerCalculator().gibbsSampling(nn, posPhaseVisible, posPhaseHidden, negPhaseVisible, negPhaseHidden, getGibbsSamplingCount(), batch == 0 ? true : getResetRBM(), true);

  // update weights
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().getConnectionGraph().getElements().length == next.getMainConnections().getConnectionGraph().getElements().length) {
        System.arraycopy(current.getMainConnections().getConnectionGraph().getElements(), 0, next.getMainConnections().getConnectionGraph().getElements(), 0, next.getMainConnections().getConnectionGraph().getElements().length);
    }

    if (current.getVisibleBiasConnections() != null && next.getVisibleBiasConnections() != null && current.getVisibleBiasConnections().getConnectionGraph().getElements().length == next.getVisibleBiasConnections().getConnectionGraph().getElements().length) {
        System.arraycopy(current.getVisibleBiasConnections().getConnectionGraph().getElements(), 0, next.getVisibleBiasConnections().getConnectionGraph().getElements(), 0, next.getVisibleBiasConnections().getConnectionGraph().getElements().length);
    }
   
    if (current.getHiddenBiasConnections() != null && next.getHiddenBiasConnections() != null && current.getHiddenBiasConnections().getConnectionGraph().getElements().length == next.getHiddenBiasConnections().getConnectionGraph().getElements().length) {
        System.arraycopy(current.getHiddenBiasConnections().getConnectionGraph().getElements(), 0, next.getHiddenBiasConnections().getConnectionGraph().getElements(), 0, next.getHiddenBiasConnections().getConnectionGraph().getElements().length);
    }
      }
  }
    }
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.