/// <summary>
 ///     Construct restricted Boltzmann machine.
 /// </summary>
 /// <param name="theLayer">The layer that this RBM works with.</param>
 public RestrictedBoltzmannMachine(HiddenLayer theLayer)
 {
     _layer = theLayer;
     _owner = theLayer.Owner;
     _hBias = _layer.Bias;
     _vBias = new double[VisibleCount];
 }
Пример #2
0
 /// <summary>
 /// Construct restricted Boltzmann machine. 
 /// </summary>
 /// <param name="theLayer">The layer that this RBM works with.</param>
 public RestrictedBoltzmannMachine(HiddenLayer theLayer)
 {
     _layer = theLayer;
     _owner = theLayer.Owner;
     _hBias = _layer.Bias;
     _vBias = new double[VisibleCount];
 }
Пример #3
0
 /// <summary>
 /// Construct the supervised trainer for DBN. 
 /// </summary>
 /// <param name="theNetwork">The network to train.</param>
 /// <param name="theTrainingInput">The input (x) to train.</param>
 /// <param name="theTrainingIdeal">The expected output (y, or labels) to train.</param>
 /// <param name="theLearningRate">The learning rate.</param>
 public SupervisedTrainDBN(DeepBeliefNetwork theNetwork, double[][] theTrainingInput, double[][] theTrainingIdeal,
     double theLearningRate)
 {
     _network = theNetwork;
     _trainingInput = theTrainingInput;
     _learningRate = theLearningRate;
     _trainingIdeal = theTrainingIdeal;
     ErrorCalc = new ErrorCalculationMSE();
 }
Пример #4
0
 /// <summary>
 /// Construct a trainer for upsupervised training for the DBNN.
 /// </summary>
 /// <param name="theNetwork">The DBNN to train.</param>
 /// <param name="theLevel">The level of the DBNN being trained.</param>
 /// <param name="theTrainingInput">The training input cases.</param>
 /// <param name="theLearningRate">The learning rate.</param>
 /// <param name="theK">The number of cycles to use per iteration.</param>
 public UnsupervisedTrainDBN(DeepBeliefNetwork theNetwork, int theLevel, double[][] theTrainingInput,
                             double theLearningRate, int theK)
 {
     _network       = theNetwork;
     _level         = theLevel;
     _trainingInput = theTrainingInput;
     _learningRate  = theLearningRate;
     _k             = theK;
 }
Пример #5
0
 /// <summary>
 /// Construct a trainer for upsupervised training for the DBNN. 
 /// </summary>
 /// <param name="theNetwork">The DBNN to train.</param>
 /// <param name="theLevel">The level of the DBNN being trained.</param>
 /// <param name="theTrainingInput">The training input cases.</param>
 /// <param name="theLearningRate">The learning rate.</param>
 /// <param name="theK">The number of cycles to use per iteration.</param>
 public UnsupervisedTrainDBN(DeepBeliefNetwork theNetwork, int theLevel, double[][] theTrainingInput,
     double theLearningRate, int theK)
 {
     _network = theNetwork;
     _level = theLevel;
     _trainingInput = theTrainingInput;
     _learningRate = theLearningRate;
     _k = theK;
 }
Пример #6
0
 /// <summary>
 ///     Construct the supervised trainer for DBN.
 /// </summary>
 /// <param name="theNetwork">The network to train.</param>
 /// <param name="theTrainingInput">The input (x) to train.</param>
 /// <param name="theTrainingIdeal">The expected output (y, or labels) to train.</param>
 /// <param name="theLearningRate">The learning rate.</param>
 public SupervisedTrainDBN(DeepBeliefNetwork theNetwork, double[][] theTrainingInput, double[][] theTrainingIdeal,
                           double theLearningRate)
 {
     _network       = theNetwork;
     _trainingInput = theTrainingInput;
     _learningRate  = theLearningRate;
     _trainingIdeal = theTrainingIdeal;
     ErrorCalc      = new ErrorCalculationMSE();
 }
Пример #7
0
        /// <summary>
        ///     The entry point for this example.  If you would like to make this example
        ///     stand alone, then add to its own project and rename to Main.
        /// </summary>
        /// <param name="args">Not used.</param>
        public static void ExampleMain(string[] args)
        {
            {

                // Create an dbnn belief network.
                int[] hidden = { 2, 3 };
                DeepBeliefNetwork dbn = new DeepBeliefNetwork(TRAINING_INPUT[0].Length, hidden, TRAINING_IDEAL[0].Length);
                dbn.Random = new MersenneTwisterGenerateRandom(54321);
                dbn.Reset();

                // Layer by layer unsupervised training.
                for (int level = 0; level < hidden.Length; level++)
                {
                    UnsupervisedTrainDBN trainUnsupervised = new UnsupervisedTrainDBN(
                            dbn, level, TRAINING_INPUT, LearningRateUnsupervised, K);
                    for (int i = 0; i < 2000; i++)
                    {
                        trainUnsupervised.Iteration();
                    }
                }

                // Supervised training.
                SupervisedTrainDBN trainSupervised = new SupervisedTrainDBN(
                        dbn, TRAINING_INPUT, TRAINING_IDEAL, LearningRateSupervised);
                int iteration = 0;
                do
                {
                    iteration++;
                    trainSupervised.Iteration();
                    Console.WriteLine("Iteration: " + iteration + ", Supervised training: error = "
                            + trainSupervised.LastError);
                } while (trainSupervised.LastError > 0.001);

                // Use test data.
                foreach (double[] input in TEST_INPUT)
                {
                    double[] output = dbn.ComputeRegression(input);
                    Console.WriteLine(string.Join(",",input) + " -> " + string.Join(",",output));
                }
            }
        }
Пример #8
0
 /// <summary>
 ///     Construct the layer.
 /// </summary>
 /// <param name="theOwner">The network that owns this layer.</param>
 /// <param name="inputCount">The input count for this layer.</param>
 /// <param name="outputCount">The output count for this layer.</param>
 public DeepLayer(DeepBeliefNetwork theOwner, int inputCount, int outputCount)
 {
     _weights = AIFH.Alloc2D <double>(outputCount, inputCount);
     _bias    = new double[outputCount];
     _owner   = theOwner;
 }
Пример #9
0
 /// <summary>
 ///     Create a hidden layer for a DBNN.
 /// </summary>
 /// <param name="theOwner">The DBNN that this layer belongs to.</param>
 /// <param name="theInputCount">The number of visible units, the input.</param>
 /// <param name="theOutputCount">The number of hidden units, the output.</param>
 public HiddenLayer(DeepBeliefNetwork theOwner, int theInputCount, int theOutputCount) :
     base(theOwner, theInputCount, theOutputCount)
 {
 }
Пример #10
0
 /// <summary>
 /// Create a hidden layer for a DBNN.
 /// </summary>
 /// <param name="theOwner">The DBNN that this layer belongs to.</param>
 /// <param name="theInputCount">The number of visible units, the input.</param>
 /// <param name="theOutputCount">The number of hidden units, the output.</param>
 public HiddenLayer(DeepBeliefNetwork theOwner, int theInputCount, int theOutputCount) :
     base(theOwner, theInputCount, theOutputCount)
 {
 }
Пример #11
0
 /// <summary>
 ///     Construct the layer.
 /// </summary>
 /// <param name="theOwner">The network that owns this layer.</param>
 /// <param name="inputCount">The input count for this layer.</param>
 /// <param name="outputCount">The output count for this layer.</param>
 public DeepLayer(DeepBeliefNetwork theOwner, int inputCount, int outputCount)
 {
     _weights = AIFH.Alloc2D<double>(outputCount, inputCount);
     _bias = new double[outputCount];
     _owner = theOwner;
 }