Sigmoid activation function.

The class represents sigmoid activation function with the next expression: 1 f(x) = ------------------ 1 + exp(-alpha * x) alpha * exp(-alpha * x ) f'(x) = ---------------------------- = alpha * f(x) * (1 - f(x)) (1 + exp(-alpha * x))^2

Output range of the function: [0, 1].

Functions graph:

Inheritance: IActivationFunction
        public static void Test()
        {
            FractionalSigmoidFunction frac = new FractionalSigmoidFunction();
            SigmoidFunction norm = new SigmoidFunction();

            double left = frac.Derivative(0.5, 1);
            double right = norm.Derivative(0.5);

            Debugger.Break();
        }
Esempio n. 2
0
        public static void Test()
        {
            FractionalSigmoidFunction frac = new FractionalSigmoidFunction();
            SigmoidFunction           norm = new SigmoidFunction();

            double left  = frac.Derivative(0.5, 1);
            double right = norm.Derivative(0.5);

            Debugger.Break();
        }
Esempio n. 3
0
        public NetworkContainer CreateNetworkContainer()
        {
            NetworkContainer neuralNetwork = null;

            int[] hiddenLayers = new int[cbHiddenLayerNumber.SelectedIndex];

            switch (hiddenLayers.Length)
            {
                case 0:
                    break;
                case 1:
                    hiddenLayers[0] = (int)this.nHidden1.Value;
                    break;
                case 2:
                    hiddenLayers[1] = (int)this.nHidden2.Value;
                    goto case 1;
                case 3:
                    hiddenLayers[2] = (int)this.nHidden3.Value;
                    goto case 2;
                case 4:
                    hiddenLayers[3] = (int)this.nHidden4.Value;
                    goto case 3;
                default:
                    break;
            }

            IActivationFunction activationFunction = null;

            if (this.rbBipolarSigmoid.Checked)
            {
                activationFunction = new BipolarSigmoidFunction((double)numSigmoidAlpha.Value);
            }
            else if (this.rbSigmoid.Checked)
            {
                activationFunction = new SigmoidFunction((double)numSigmoidAlpha.Value);
            }
            else if (this.rbThreshold.Checked)
            {
                activationFunction = new ThresholdFunction();
            }

            neuralNetwork = new NetworkContainer(
                    tbNetworkName.Text,
                    m_networkSchema,
                    activationFunction,
                    hiddenLayers);

             //         neuralNetwork.Schema.DataRanges.ActivationFunctionRange = new AForge.DoubleRange((double)numRangeLow.Value, (double)numRangeHigh.Value);

            return neuralNetwork;
        }
Esempio n. 4
0
        static void NeuralNetworkAccompanimentTest()
        {
            // initialize input and output values
            double[][] input = new double[4][] {
            new double[] {0, 0}, new double[] {0, 1},
            new double[] {1, 0}, new double[] {1, 1}
            };
            double[][] output = new double[4][] {
            new double[] {0}, new double[] {1},
            new double[] {1}, new double[] {0}
            };
            SigmoidFunction sig = new SigmoidFunction();

            Accord.Neuro.Networks.RestrictedBoltzmannMachine boltz = new Accord.Neuro.Networks.RestrictedBoltzmannMachine(200, 200);

            // create neural network
            ActivationNetwork network = new ActivationNetwork(
                new SigmoidFunction(2),
                200,
                20,
                200);
            //BackPropagationLearning teacher = new BackPropagationLearning(network);
            //LevenbergMarquardtLearning teacher = new LevenbergMarquardtLearning(network);
            Accord.Neuro.Learning.ParallelResilientBackpropagationLearning teacher = new ParallelResilientBackpropagationLearning(network);
            Accord.Neuro.Networks.DeepBeliefNetwork dpn = new Accord.Neuro.Networks.DeepBeliefNetwork(200, 20);

            // teacher.IncreaseFactor = 1.01;
            Composition c = Composition.LoadFromMIDI("test/other/ff7tifa.mid");

            MusicPlayer player = new MusicPlayer();
            //player.Play(c.Tracks[0]);

            List<double[]> inputs = new List<double[]>(); List<double[]> outputs = new List<double[]>();

            inputs.Add(GetDoublesFromNotes((c.Tracks[0].GetMainSequence() as MelodySequence).ToArray()));
            outputs.Add(GetDoublesFromNotes((c.Tracks[1].GetMainSequence() as MelodySequence).ToArray()));

            //  inputs.Add(GetDoublesFromNotes((c.Tracks[1].GetMainSequence() as MelodySequence).ToArray()));
            //    outputs.Add(GetDoublesFromNotes((c.Tracks[2].GetMainSequence() as MelodySequence).ToArray()));

            // inputs.Add(GetDoublesFromNotes((c.Tracks[0].GetMainSequence() as MelodySequence).ToArray()));
            // outputs.Add(GetDoublesFromNotes((c.Tracks[3].GetMainSequence() as MelodySequence).ToArray()));

            int its = 0;
            while (its++ < 10000)
            {

                double error = teacher.RunEpoch(inputs.ToArray(), outputs.ToArray());
                Console.WriteLine("{0}: Error - {1}", its, error);
            }

            var input_melody = (c.Tracks[0].GetMainSequence() as MelodySequence);
            var new_notes = network.Compute(GetDoublesFromNotes(input_melody.ToArray()));

            var new_mel = GetMelodyFromDoubles(new_notes);

            player.Play(new_mel);

            Console.ReadLine();
        }
        public void Train()
        {
            var samples = GenerateSamples(category.Compositions);
            double[][] inputs = new double[samples.Length][];
            double[][] outputs = new double[samples.Length][];
            for (int i = 0; i < samples.Length; i++)
            {
                inputs[i] = samples[i].Inputs;
                outputs[i] = samples[i].Outputs;
            }
            // Create a Bernoulli activation function
            //var function = new BernoulliFunction(alpha: 0.5);
            var function = new SigmoidFunction(2);
            // Create a Restricted Boltzmann Machine for 6 inputs and with 1 hidden neuron
            //network = new RestrictedBoltzmannMachine(function, inputsCount: MAX_INPUTS, hiddenNeurons: MAX_OUTPUTS);
            network = new ActivationNetwork(function, MAX_INPUTS, 11, MAX_OUTPUTS);

            // Create the learning algorithm for RBMs
            /*    var teacher = new ContrastiveDivergenceLearning(network)
            {
                Momentum = 0.1,
                LearningRate = 0.02
            };*/

            // create neural network
             /*     network = new ActivationNetwork(
                new SigmoidFunction( 2 ),
                2, // two inputs in the network
                10, // two neurons in the first layer
                2 ); // one neuron in the second layer*/

            var teacher = new ResilientBackpropagationLearning(network as ActivationNetwork);

            // learn 5000 iterations

            for (int i = 0; i < Epochs; i++)
            {
                var e = teacher.RunEpoch(inputs,outputs);

                Console.WriteLine("{0} : {1}", i / (double)Epochs * 100, e);
            }

            Save();
        }
 public FractionalSigmoidFunction()
 {
     this.innerFunction = new SigmoidFunction();
     this.normal = new Normal(this.DistrubutionAverage, this.DistrubutionDeviation);
 }
Esempio n. 7
0
 public FractionalSigmoidFunction()
 {
     this.innerFunction = new SigmoidFunction();
     this.normal        = new Normal(this.DistrubutionAverage, this.DistrubutionDeviation);
 }
Esempio n. 8
0
        void Proc2(Model model)
        {
            int learnIterations = 100;
            double desiredError = 0;

            var activationFunc1 = new ThresholdFunction();
            var activationFunc2 = new SigmoidFunction(1);
            IActivationFunction activationFunc = activationFunc2;
            int inputsCount = model.InputsCount;
            int[] neuronsCount = new int[3];
            neuronsCount[0] = model.InputsCount;
            neuronsCount[1] = model.InputsCount * 2;
            neuronsCount[2] = model.desiredOutput[0].Length;

            ActivationNetwork net = new ActivationNetwork(activationFunc, inputsCount, neuronsCount);
            BackPropagationLearning lerning = new BackPropagationLearning(net);
            ErrorCalculator errorCalculator = new ErrorCalculator();

            Process(learnIterations, desiredError, net, lerning,
                model.input, model.desiredOutput, errorCalculator);

            Console.ReadLine();
        }
Esempio n. 9
0
        void Proc1()
        {
            int learnIterations = 100;
            double desiredError = 0;

            Model model = getModelAnd();
            var activationFunc1 = new ThresholdFunction();
            var activationFunc2 = new SigmoidFunction(1);
            IActivationFunction activationFunc = activationFunc2;
            int inputsCount = model.InputsCount;
            int neuronsCount = 1;

            ActivationNetwork net = new ActivationNetwork(activationFunc, inputsCount, neuronsCount);
            PerceptronLearning lerning = new PerceptronLearning(net);
            ErrorCalculator errorCalculator = new ErrorCalculator();

            Process(learnIterations, desiredError, net, lerning,
                model.input, model.desiredOutput, errorCalculator);

            Console.ReadLine();
        }