int nIns = 2,nOuts = 2;
int[] hiddenLayerSizes = new int[] {2,2};
double fineTuneLr = 0.001;
int fineTuneEpochs = 100;
DeepBeliefNetwork dbn_A = new DeepBeliefNetwork(nIns, hiddenLayerSizes, nOuts, hiddenLayerSizes.length, rng, x_xor_Matrix, y_xor_Matrix );
// setup layer 0
dbn_A.preTrainingLayers[ 0 ].getConnectionWeights().set(0, 0, 1.0);
dbn_A.preTrainingLayers[ 0 ].getConnectionWeights().set(0, 1, 1.0);
dbn_A.preTrainingLayers[ 0 ].getConnectionWeights().set(1, 0, 1.0);
dbn_A.preTrainingLayers[ 0 ].getConnectionWeights().set(1, 1, 1.0);
// Layer 0: hidden bias
dbn_A.preTrainingLayers[ 0 ].getHiddenBias().set( 0, 0, 15.0 );
dbn_A.preTrainingLayers[ 0 ].getHiddenBias().set( 0, 1, 16.0 );
// Layer 0: visible bias
dbn_A.preTrainingLayers[ 0 ].getVisibleBias().set( 0, 0, 25.0 );
dbn_A.preTrainingLayers[ 0 ].getVisibleBias().set( 0, 1, 26.0 );
// setup layer 1
dbn_A.preTrainingLayers[ 1 ].getConnectionWeights().set(0, 0, 1.0);
dbn_A.preTrainingLayers[ 1 ].getConnectionWeights().set(0, 1, 1.0);
dbn_A.preTrainingLayers[ 1 ].getConnectionWeights().set(1, 0, 1.0);
dbn_A.preTrainingLayers[ 1 ].getConnectionWeights().set(1, 1, 1.0);
// setup log layer
dbn_A.logisticRegressionLayer.connectionWeights.set(0, 0, 1.0);
dbn_A.logisticRegressionLayer.connectionWeights.set(0, 1, 1.0);
dbn_A.logisticRegressionLayer.connectionWeights.set(1, 0, 1.0);
dbn_A.logisticRegressionLayer.connectionWeights.set(1, 1, 1.0);
MatrixUtils.debug_print( dbn_A.logisticRegressionLayer.biasTerms );
// set up bias terms
dbn_A.logisticRegressionLayer.biasTerms.set( 0, 0, 35.0 );
dbn_A.logisticRegressionLayer.biasTerms.set( 0, 1, 36.0 );
DeepBeliefNetwork dbn_B = new DeepBeliefNetwork(nIns, hiddenLayerSizes, nOuts, hiddenLayerSizes.length, rng, x_xor_Matrix, y_xor_Matrix );
dbn_B.preTrainingLayers[ 0 ].getConnectionWeights().set(0, 0, 2.0);
dbn_B.preTrainingLayers[ 0 ].getConnectionWeights().set(0, 1, 1.0);
dbn_B.preTrainingLayers[ 0 ].getConnectionWeights().set(1, 0, 3.0);
dbn_B.preTrainingLayers[ 0 ].getConnectionWeights().set(1, 1, 4.0);
// Layer 0: hidden bias
dbn_B.preTrainingLayers[ 0 ].getHiddenBias().set( 0, 0, 5.0 );
dbn_B.preTrainingLayers[ 0 ].getHiddenBias().set( 0, 1, 6.0 );
// Layer 0: visible bias
dbn_B.preTrainingLayers[ 0 ].getVisibleBias().set( 0, 0, 5.0 );
dbn_B.preTrainingLayers[ 0 ].getVisibleBias().set( 0, 1, 6.0 );
// layer 2
dbn_B.preTrainingLayers[ 1 ].getConnectionWeights().set(0, 0, 2.0);
dbn_B.preTrainingLayers[ 1 ].getConnectionWeights().set(0, 1, 1.0);
dbn_B.preTrainingLayers[ 1 ].getConnectionWeights().set(1, 0, 3.0);
dbn_B.preTrainingLayers[ 1 ].getConnectionWeights().set(1, 1, 4.0);
dbn_B.logisticRegressionLayer.connectionWeights.set(0, 0, 1.0);
dbn_B.logisticRegressionLayer.connectionWeights.set(0, 1, 2.0);
dbn_B.logisticRegressionLayer.connectionWeights.set(1, 0, 3.0);
dbn_B.logisticRegressionLayer.connectionWeights.set(1, 1, 4.0);
dbn_B.logisticRegressionLayer.biasTerms.set( 0, 0, 5.0 );
dbn_B.logisticRegressionLayer.biasTerms.set( 0, 1, 6.0 );
// MatrixUtils.debug_print( dbn_B.preTrainingLayers[ 0 ].getConnectionWeights() );
int[] hiddenLayerSizesTmp = new int[] {1};
// now setup a DBN based on a clone operation via initBasedOn()
// DeepBeliefNetwork dbn_merge_load = new DeepBeliefNetwork(1, hiddenLayerSizesTmp, 1, hiddenLayerSizesTmp.length, null);
// this only works if the workers have been initialized on data
DeepBeliefNetwork dbn_master = new DeepBeliefNetwork(1, hiddenLayerSizesTmp, 1, hiddenLayerSizesTmp.length, null);
dbn_master.initBasedOn(dbn_A);
ArrayList<DeepBeliefNetwork> workers = new ArrayList<DeepBeliefNetwork>();
workers.add(dbn_A);
workers.add(dbn_B);
dbn_master.computeAverageDBNParameterVector(workers);
assertEquals( 1.5, dbn_master.preTrainingLayers[ 0 ].getConnectionWeights().get(0, 0), 0.0 );
assertEquals( 1.0, dbn_master.preTrainingLayers[ 0 ].getConnectionWeights().get(0, 1), 0.0 );
assertEquals( 2.0, dbn_master.preTrainingLayers[ 0 ].getConnectionWeights().get(1, 0), 0.0 );
assertEquals( 2.5, dbn_master.preTrainingLayers[ 0 ].getConnectionWeights().get(1, 1), 0.0 );