/// <summary>
 ///   Initializes a new instance of the <see cref="StochasticNeuron"/> class.
 /// </summary>
 /// 
 /// <param name="inputs">Number of inputs for the neuron.</param>
 /// <param name="function">Activation function for the neuron.</param>
 /// 
 public StochasticNeuron(int inputs, IStochasticFunction function)
     : base(inputs, function)
 {
     this.ActivationFunction = function;
     this.Threshold = 0; // Ruslan Salakhutdinov and Geoff Hinton
                         // also start with zero thresholds
 }
Пример #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="StochasticLayer"/> class.
 /// </summary>
 /// 
 /// <param name="function">The activation function for the neurons in the layer.</param>
 /// <param name="neuronsCount">The neurons count.</param>
 /// <param name="inputsCount">The inputs count.</param>
 /// 
 public StochasticLayer(IStochasticFunction function, int neuronsCount, int inputsCount)
     : base(neuronsCount, inputsCount, function)
 {
     neurons = new StochasticNeuron[neuronsCount];
     for (int i = 0; i < neurons.Length; i++)
         base.neurons[i] = this.neurons[i] =
             new StochasticNeuron(inputsCount, function);
 }
Пример #3
0
        /// <summary>
        ///   Creates a new <see cref="DeepBeliefNetwork"/>.
        /// </summary>
        /// 
        /// <param name="function">The activation function to be used in the network neurons.</param>
        /// <param name="inputsCount">The number of inputs for the network.</param>
        /// <param name="hiddenNeurons">The number of hidden neurons in each layer.</param>
        /// 
        public DeepBeliefNetwork(IStochasticFunction function, int inputsCount, params int[] hiddenNeurons)
            : base(function, inputsCount, hiddenNeurons)
        {
            machines = new List<RestrictedBoltzmannMachine>();

            // Create first layer
            machines.Add(new RestrictedBoltzmannMachine(
                hidden: new StochasticLayer(function, hiddenNeurons[0], inputsCount),
                visible: new StochasticLayer(function, inputsCount, hiddenNeurons[0]))
            );

            // Create other layers
            for (int i = 1; i < hiddenNeurons.Length; i++)
            {
                machines.Add(new RestrictedBoltzmannMachine(
                    hidden: new StochasticLayer(function, hiddenNeurons[i], hiddenNeurons[i - 1]),
                    visible: new StochasticLayer(function, hiddenNeurons[i - 1], hiddenNeurons[i])));
            }

            // Override AForge layers
            layers = new Layer[machines.Count];
            for (int i = 0; i < layers.Length; i++)
                layers[i] = machines[i].Hidden;
        }
Пример #4
0
        /// <summary>
        ///   Creates a Mixed-Bernoulli network.
        /// </summary>
        /// 
        /// <param name="visible">The <see cref="IStochasticFunction"/> to be used in the first visible layer.</param>
        /// <param name="hidden">The <see cref="IStochasticFunction"/> to be used in all other layers.</param>
        /// 
        /// <param name="inputsCount">The number of inputs for the network.</param>
        /// <param name="hiddenNeurons">The number of hidden neurons in each layer.</param>
        /// 
        public static DeepBeliefNetwork CreateMixedNetwork(IStochasticFunction visible,
            IStochasticFunction hidden, int inputsCount, params int[] hiddenNeurons)
        {
            DeepBeliefNetwork network = new DeepBeliefNetwork(hidden, inputsCount, hiddenNeurons);

            foreach (StochasticNeuron neuron in network.machines[0].Visible.Neurons)
                neuron.ActivationFunction = visible;

            return network;
        }
Пример #5
0
        /// <summary>
        ///   Inserts a new layer at the end of this network.
        /// </summary>
        /// 
        /// <param name="neurons">The number of neurons in the layer.</param>
        /// <param name="visibleFunction">The activation function which should be used by the visible neurons.</param>
        /// <param name="hiddenFunction">The activation function which should be used by the hidden neurons.</param>
        /// 
        public void Push(int neurons, IStochasticFunction visibleFunction, IStochasticFunction hiddenFunction)
        {
            int lastLayerNeurons;

            if (machines.Count > 0)
                lastLayerNeurons = machines[machines.Count - 1].Hidden.Neurons.Length;
            else lastLayerNeurons = inputsCount;

            machines.Add(new RestrictedBoltzmannMachine(
                hidden: new StochasticLayer(hiddenFunction, neurons, lastLayerNeurons),
                visible: new StochasticLayer(visibleFunction, lastLayerNeurons, neurons)));

            // Override AForge layers
            layers = new Layer[machines.Count];
            for (int i = 0; i < layers.Length; i++)
                layers[i] = machines[i].Hidden;
        }
Пример #6
0
 /// <summary>
 ///   Inserts a new layer at the end of this network.
 /// </summary>
 /// 
 /// <param name="neurons">The number of neurons in the new layer.</param>
 /// <param name="function">The activation function which should be used by the neurons.</param>
 /// 
 public void Push(int neurons, IStochasticFunction function)
 {
     Push(neurons, function, function);
 }
        /// <summary>
        ///   Creates a new <see cref="RestrictedBoltzmannMachine"/>.
        /// </summary>
        /// 
        /// <param name="function">The activation function to use in the network neurons.</param>
        /// <param name="inputsCount">The number of inputs for the machine.</param>
        /// <param name="hiddenNeurons">The number of hidden neurons in the machine.</param>
        /// 
        public RestrictedBoltzmannMachine(IStochasticFunction function, int inputsCount, int hiddenNeurons)
            : base(function, inputsCount, 1)
        {
            this.visible = new StochasticLayer(function, inputsCount, hiddenNeurons);
            this.hidden = new StochasticLayer(function, hiddenNeurons, inputsCount);

            base.layers[0] = hidden;
        }