Inheritance: IStochasticFunction
Ejemplo n.º 1
0
        public void ConstructorTest()
        {
            // Create a Gaussian function with slope alpha = 4.2
            GaussianFunction function = new GaussianFunction(4.2);

            // Computes the function output (linear, y = alpha * x)
            double y = function.Function(x: 0.2); // 4.2 * 2 = 0.48

            // Draws a sample from a Gaussian distribution with
            // mean given by the function output y (previously 0.48)
            double z = function.Generate(x: 0.4); // (random, between 0 and 1)

            // Please note that the above is completely equivalent 
            // to computing the line below (remember, 0.48 == y)
            double w = function.Generate2(y: 0.48); // (random, between 0 and 1)


            // We can also compute the derivative of the sigmoid function
            double d = function.Derivative(x: 0.2); // 4.2 (the slope)

            // Or compute the derivative given the functions' output y
            double e = function.Derivative2(y: 0.2); // 4.2 (the slope)

            Assert.AreEqual(0.84, y, 1e-7);
            Assert.AreEqual(4.2, d, 1e-7);
            Assert.AreEqual(4.2, e, 1e-7);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Creates a Gaussian-Bernoulli network.
        /// </summary>
        /// 
        /// <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 CreateGaussianBernoulli(int inputsCount, params int[] hiddenNeurons)
        {
            DeepBeliefNetwork network = new DeepBeliefNetwork(inputsCount, hiddenNeurons);

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

            return network;
        }