public override void Create(int input, int layers, int neurons, int output)
        {
            //Setup network
            IActivationFunction function = new SigmoidFunction();

            switch (layers)
            {
            case 1:
                AccordNetwork = new ActivationNetwork(function, input, neurons, output);     //Activation function, input, hidden, hidden, output.
                break;

            case 2:
                AccordNetwork = new ActivationNetwork(function, input, neurons, neurons, output);     //Activation function, input, hidden, hidden, output.
                break;

            case 3:
                AccordNetwork = new ActivationNetwork(function, input, neurons, neurons, neurons, output);     //Activation function, input, hidden, hidden, output.
                break;

            case 4:
                AccordNetwork = new ActivationNetwork(function, input, neurons, neurons, neurons, neurons, output);     //Activation function, input, hidden, hidden, output.
                break;

            case 5:
                AccordNetwork = new ActivationNetwork(function, input, neurons, neurons, neurons, neurons, neurons, output);     //Activation function, input, hidden, hidden, output.
                break;
            }
        }
        public void ShouldHaveCorrectNetValuesInverseWithOffset()
        {
            var myFunction = new SigmoidFunction(new SigmoidFunctionConfig
            {
                offset = 0f,
                range  = 10f,
                yRange = 1f
            });

            var offsettedValue = 0.988565420571308328;

            var expectedValueTable = new Dictionary <float, float>
            {
                { 0f, (float)(0 - offsettedValue) },
                { 1f, (float)(0.988565420571308328 - offsettedValue) },
                { 2f, (float)(1.958127996915376009 - offsettedValue) },
                { 6f, (float)(4.693453660970895236 - offsettedValue) },
                { 7f, (float)(4.879787337446145572 - offsettedValue) },
                { 10f, (float)(5f - offsettedValue) },
            };

            foreach (var expectedPair in expectedValueTable)
            {
                Assert.AreEqual(expectedPair.Key, myFunction.GetPointFromNetExtraValueFromPoint(expectedPair.Value, 1), 1e-5);
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var numberOfNeurons = int.Parse(InputNumber.Text);

            Network = new Network(numberOfNeurons);

            foreach (var item in Layers.Items)
            {
                var properties = item.ToString().Split(' ');
                var neurons    = int.Parse(properties[0]);
                IActivationFunction activation;
                if (properties[1] == "S")
                {
                    activation = new SigmoidFunction();
                }
                else
                {
                    activation = new IdentityFunction();
                }

                ILayerUtility utility;
                if (properties[2] == "B")
                {
                    utility = new BiasedUtility();
                }
                else
                {
                    utility = new UnbiasedUtility();
                }

                Network.AddLayer(new Layer(neurons, activation, utility));
            }
        }
        public void TeachNeuralteacher(List <string> list)
        {
            double[][] outputs = new double[outputsC45.Length][];
            for (int i = 0; i < outputsC45.Length; i++)
            {
                outputs[i] = new double[1] {
                    outputsC45[i] - 1
                };
            }
            var inputs = GetC45Data(list);
            IActivationFunction function = new SigmoidFunction(2);

            network = new ActivationNetwork(function, 12, 4, 4, 1);
            teacher = new BackPropagationLearning(network);
            var    input   = GetC45Data(list);
            double tempMin = 9999999999;
            double error   = 0;
            int    count   = 0;

            while (count != 3)
            {
                error = teacher.RunEpoch(input, outputs);
                if (error + 0.00001 < tempMin)
                {
                    tempMin = error;
                    count   = 0;
                }
                else
                {
                    count++;
                }
            }
        }
Example #5
0
    /// <summary>
    /// Calculates the layer data.
    /// </summary>
    public void Calculate()
    {
        double sum = 0;

        foreach (var nit in this.Neurons)
        {
            foreach (var cit in nit.Connections)
            {
                if (cit == nit.Connections[0])
                {
                    sum = this.Weights[(int)cit.WeightIndex].Value;
                }
                else
                {
                    if (this.previousLayer is null)
                    {
                        continue;
                    }

                    sum += this.Weights[(int)cit.WeightIndex].Value
                           * this.previousLayer.Neurons[(int)cit.NeuronIndex].Output;
                }
            }

            nit.Output = SigmoidFunction.Sigmoid(sum);
        }
    }
Example #6
0
        public IActivationFunction CreateActivationFunction()
        {
            IActivationFunction activationFunction = null;

            Func <string, bool> equals = value => string.Equals(ActivationFunction, value, StringComparison.InvariantCultureIgnoreCase);

            if (equals("UnipolarBinaryFunction"))
            {
                activationFunction = new UnipolarBinaryFunction();
            }
            else if (equals("BipolarBinaryFunction"))
            {
                activationFunction = new BipolarBinaryFunction();
            }
            else if (equals("SigmoidFunction"))
            {
                activationFunction = new SigmoidFunction();
            }
            else if (equals("TanhFunction"))
            {
                activationFunction = new TanhFunction();
            }
            else
            {
                Console.WriteLine($"Wrong activation function: {ActivationFunction}");
            }

            return(activationFunction);
        }
Example #7
0
        public void AddResult(int point, double[] input)
        {
            gamesPlayedCount++;
            var sig    = new SigmoidFunction();
            var result = 0;

            if (point == -1)
            {
                gamesLostCount++;
            }
            else if (point == 0)
            {
                gamesTiedCount++;
                result = 1;
            }
            else
            {
                result = 2;
                gamesWonCount++;
            }

            for (int i = 0; i < weights.Length; i++)
            {
                Weights[i] += sig.Derivative(Weights[i]) * (result - Weights[i]);
            }

            biasWeight += sig.Derivative(biasWeight) * (biasWeight);
        }
        public void ShouldHaveCorrectNetValuesInverseWithOffsetPast0()
        {
            var myFunction = new SigmoidFunction(new SigmoidFunctionConfig
            {
                offset = 0f,
                range  = 10f,
                yRange = 1f
            });

            var offsettedValue = 0.988565420571308328;

            var expectedValueTable = new Dictionary <float, float>
            {
                { 0f, (float)(0 - offsettedValue) },
                { -1f, (float)(-0.99576033664861238091444299431088089366184175169765377856 - offsettedValue) },
                { -2f, (float)(-1.99419611796465617607528580607077258667289101133381732908 - offsettedValue) },
                { -6f, (float)(-5.99330135307220032534204550450772727429328160638888197171 - offsettedValue) },
                { -7f, (float)(-6.99329079570435966418901789133356611158827908472468216254 - offsettedValue) },
                { -10f, (float)(-9.99328495741315564510406920928653520521498975323882941468 - offsettedValue) },
            };

            foreach (var expectedPair in expectedValueTable)
            {
                Assert.AreEqual(expectedPair.Key, myFunction.GetPointFromNetExtraValueFromPoint(expectedPair.Value, 1), 1e-5);
            }
        }
        public void ShouldScaleAndOffsetCorrectlyWithYRange()
        {
            var myFunction = new SigmoidFunction(new SigmoidFunctionConfig
            {
                offset = 1f,
                range  = 10f,
                yRange = 3f
            });

            var expectedValueTable = new Dictionary <float, float>
            {
                { 0f, 0.997527376843365225f * 3 },

                { 2f, 0.982013790037908442f * 3 },

                { 4f, 0.880797077977882444f * 3 },

                { 6f, 0.5f * 3 },
                { 7f, 0.268941421369995120f * 3 },


                { 10f, 0.01798620996209156f * 3 },
            };

            foreach (var expectedPair in expectedValueTable)
            {
                Assert.AreEqual(expectedPair.Value, myFunction.GetValueAtPoint(expectedPair.Key), 1e-5);
            }
        }
Example #10
0
 public AForgeNetwork()
 {
     m_activationFunc = new SigmoidFunction();
     m_network1       = new ActivationNetwork(m_activationFunc, m_inputsCount, m_layers);
     m_network2       = new ActivationNetwork(m_activationFunc, m_inputsCount, m_layers);
     m_network3       = new ActivationNetwork(m_activationFunc, m_inputsCount, m_layers);
     m_network4       = new ActivationNetwork(m_activationFunc, m_inputsCount, new int[] { 4 });
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NeuronalNetworkLayer"/> class.
 /// </summary>
 /// <param name="label">The label.</param>
 /// <param name="previousLayer">The previous layer.</param>
 public NeuronalNetworkLayer(string label, NeuronalNetworkLayer?previousLayer)
 {
     this.label           = label;
     this.previousLayer   = previousLayer;
     this.sigmoidFunction = new SigmoidFunction();
     this.Weights         = new NeuronalNetworkWeightList();
     this.Neurons         = new NeuronalNetworkNeuronList();
 }
Example #12
0
        //---------------------------------------------


        #region Public Methods
        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);
        }
Example #13
0
        public override void Load(BinaryReader r, uint id)
        {
            base.Load(r, id);

            Bias = DoubleMinMax.Read(r);
            LoadListInfo(Connections, r);

            SigmoidFunction = BinarySerializable.GetObject <SigmoidFunction>(r);
        }
Example #14
0
        public void ImprintGene(RMP_NeuronGene gene)
        {
            Name   = gene.Name;
            GeneID = gene.ID;

            Bias = gene.Bias.Value;

            SigmoidFunction = (SigmoidFunction)gene.SigmoidFunction.Clone();
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NeuronalNetworkLayer"/> class.
 /// </summary>
 public NeuronalNetworkLayer()
 {
     this.label           = string.Empty;
     this.previousLayer   = null;
     this.sigmoidFunction = new SigmoidFunction();
     this.Weights         = new NeuronalNetworkWeightList();
     this.Neurons         = new NeuronalNetworkNeuronList();
     this.Initialize();
 }
        public void NeuronInitalizeActivationSigmoid()
        {
            int    InputCount  = 3;
            double outputValue = 0;
            IActivationFunction ActivationSigmoid = new SigmoidFunction();
            Neuron ActNeuron = new ActivationNeuron(InputCount, ActivationSigmoid);

            ActNeuron.FeedForward(InputValues);
            outputValue = ActNeuron.Compute();

            Assert.True(outputValue != 0);
        }
Example #17
0
        /// <summary>
        /// 训练神经网络
        /// </summary>
        public void Train()
        {
            updateConsoleEvent("---------神经网络训练开始------");
            var samples = getSamples(this.numOfSample);

            double[][] inputs = (from cell in samples
                                 select getOneInput(cell)).ToArray <double[]>();


            int[] classes = (from cell in samples
                             select getOneClass(cell)).ToArray <int>();

            double[][] outputs = Accord.Statistics.Tools.Expand(classes, 0, +1);

            // Create an activation function for the net
            //var function = new BipolarSigmoidFunction();
            var function = new SigmoidFunction();


            // Create an activation network with the function and
            //  4 inputs, 5 hidden neurons and 3 possible outputs:
            int numOfInput  = inputs[0].Length;
            int numOfHidden = numOfInput * 2 / 3;
            int numOfOut    = outputs[0].Length;

            this.network = new ActivationNetwork(function, numOfInput, numOfHidden, numOfOut);

            // Randomly initialize the network
            new NguyenWidrow(this.network).Randomize();

            // Teach the network using parallel Rprop:
            var teacher = new ParallelResilientBackpropagationLearning(this.network);

            double correctRate = 0.0;
            int    times       = this.timesOfTrain;
            int    cnt         = 0;

            while (cnt < times)
            {
                teacher.RunEpoch(inputs, outputs);
                if (cnt % 10 == 0)
                {
                    correctRate = GetError(inputs, outputs, classes);
                    updateConsoleEvent("正确率:" + correctRate * 100 + "%");
                }
                cnt++;
            }
            updateConsoleEvent("训练结束。最终正确率:" + correctRate * 100 + "%");
            updateConsoleEvent("---------神经网络训练结束------");
        }
Example #18
0
        private void UpDownBias_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double?> e)
        {
            if (!UpDownBias.Value.HasValue)
            {
                return;
            }

            if (UpDownT?.Value != null && Function is SigmoidFunction)
            {
                Function = new SigmoidFunction(UpDownT.Value.Value);
            }

            var bias = UpDownBias.Value.Value;

            ActivationFunctionChartValues.ForEach(point => point.Y = Math.Round(Function.GetValue(point.X + bias), 3));
        }
Example #19
0
        public override void Load(BinaryReader r, uint id)
        {
            base.Load(r, id);

            Net    = BinarySerializable.GetObject <RMP_Net>(r);
            GeneID = r.ReadUInt32();

            Bias = r.ReadDouble();

            SigmoidFunction = BinarySerializable.GetObject <SigmoidFunction>(r);

            Activation = r.ReadDouble();
            Output     = r.ReadDouble();

            LoadListInfo(Connections, r);
        }
Example #20
0
        public static trainerParams BuildNet(FlowLayoutPanel layers, FileDialog LoadData_dlg, Result r, Telerik.WinControls.UI.RadDiagram radDiagram1)
        {
            Training.Trainer     trainer = new Training.Trainer();
            NeuralNetworkBuilder b       = new NeuralNetworkBuilder();
            L_ctrl_mat           temp;
            int neuronsnumber;
            IActivatorFunction AF = null;
            FunctionApplier    functionApplier = new FunctionApplier();

            foreach (var layer in layers.Controls)
            {
                temp          = layer as L_ctrl_mat;
                neuronsnumber = Convert.ToInt16(temp.NN_drpdn.Value);
                if (ActivatorFunctions.FunctionName.SIGMOID.ToString() == temp.AF_drpdn.SelectedItem.Text)
                {
                    AF = new SigmoidFunction();
                    imgs.Add(Resources.Layer__Sigmoid);
                }
                if (ActivatorFunctions.FunctionName.TANH.ToString() == temp.AF_drpdn.SelectedItem.Text)
                {
                    AF = new TanhFunction();
                    imgs.Add(Resources.Layer_Tan_H);
                }
                functionApplier.ActivatorFunction = AF;
                b.Layer(neuronsnumber, functionApplier, (double)temp.Lr_drpdn.Value);
            }
            NeuralNetwork.NeuralNetwork nn = b.Build();
            string FileName = LoadData_dlg.FileName;
            var    tuples   = DataReader.DataReader.Instance.ReadFromFile(FileName);

            var inputs  = tuples.Item1;
            var outputs = tuples.Item2;

            // StaticDivider Divider = new StaticDivider(.6,.3);
            //var temp2 = Divider.Divide(inputs, outputs);
            //ActivatorFunctions.FunctionName applier ;

            //// test case (should belong to the second class = [0 1 0])
            //var tt = nn.ForwardInput(Vector<double>.Build.DenseOfArray(new double[] { 5.5, 2.5, 4.0, 1.3 }));
            Params       = new trainerParams();
            Params.nn    = nn;
            Params.Tuple = tuples;
            NetGraph(nn, radDiagram1);

            return(Params);
        }
Example #21
0
        ///<summary>
        /// Process data
        ///</summary>
        public List <double> Run(List <double> input)
        {
            if (input.Count != this.Layers[0].Neurons.Count)
            {
                throw new ArgumentOutOfRangeException("Number of inputs must match the number of neurons on in the input layer");
            }

            for (int l = 0; l < Layers.Count; l++)
            {
                Layer layer = Layers[l];

                for (int n = 0; n < layer.Neurons.Count; n++)
                {
                    Neuron neuron = layer.Neurons[n];

                    if (l == 0)
                    {
                        neuron.Value = input[n];
                    }
                    else
                    {
                        neuron.Value = 0;
                        for (int np = 0; np < this.Layers[l - 1].Neurons.Count; np++)
                        {
                            neuron.Value = neuron.Value + Layers[l - 1].Neurons[np].Value * neuron.Dendrites[np].Weight;
                        }

                        neuron.Value = SigmoidFunction.logistic(neuron.Value + neuron.Bias);
                    }
                }
            }

            Layer         outputLayer  = Layers[Layers.Count - 1];
            int           numOfOutputs = outputLayer.Neurons.Count;
            List <double> output       = new List <double>(numOfOutputs);

            foreach (Neuron neuron in outputLayer.Neurons)
            {
                output.Add(neuron.Value);
            }

            return(output);
        }
        public void NeuronUpdateWeights()
        {
            double learningRate = 0.3;
            double delta        = -0.3;

            int    InputCount        = 3;
            double outputValue       = 0;
            double outputAfterUpdate = 0;
            IActivationFunction ActivationSigmoid = new SigmoidFunction();
            Neuron ActNeuron = new ActivationNeuron(InputCount, ActivationSigmoid);

            ActNeuron.FeedForward(InputValues);
            outputValue = ActNeuron.Compute();
            Assert.True(outputValue != 0);

            ActNeuron.UpdateWeight(learningRate, delta);
            outputAfterUpdate = ActNeuron.Compute();
            Assert.NotEqual(outputValue, outputAfterUpdate);
        }
        public void ShouldHaveCorrectNetValuesInverseWhenPastLimitOfIntegral()
        {
            var myFunction = new SigmoidFunction(new SigmoidFunctionConfig
            {
                offset = 0f,
                range  = 10f,
                yRange = 1f
            });

            var expectedValueTable = new Dictionary <float, float>
            {
                { float.MaxValue, (float)(100f) },
            };

            foreach (var expectedPair in expectedValueTable)
            {
                Assert.AreEqual(expectedPair.Key, myFunction.GetPointFromNetExtraValueFromPoint(expectedPair.Value, 1), 1e-5);
            }
        }
Example #24
0
        public Network(int inputsCount, int[] neuronsCount)
        {
            this.inputsCount  = inputsCount;
            this.neuronsCount = neuronsCount;

            activationFunction = new HyperbolicTangentFunction();
            IActivationFunction activationFunction2 = new SigmoidFunction();

            network = new ActivationNetwork(activationFunction, inputsCount, neuronsCount);
            new NguyenWidrow(network).Randomize();
            teacher = new BackPropagationLearning(network);

            for (int i = 0; i < network.Layers.Length - 1; ++i)
            {
                ((ActivationLayer)network.Layers[i]).SetActivationFunction(activationFunction);
            }
            ((ActivationLayer)network.Layers[network.Layers.Length - 1]).SetActivationFunction(activationFunction2);

            learningLoopIterator = 0;
        }
Example #25
0
        public ISupervisedOperations SupervisedOperations(EActivationFunction act,
                                                          EErrorFunction err,
                                                          EOptimizerFunction opt)
        {
            IActivationFunction activationFunction = null;
            IErrorFunction      errorFunction      = null;
            IOptimizerFunction  optimizerFunction  = null;

            switch (act)
            {
            case EActivationFunction.Sigmoid:
                activationFunction = new SigmoidFunction();
                break;

            case EActivationFunction.LeakRelu:
                activationFunction = new LeakReluFunction();
                break;
            }

            switch (err)
            {
            case EErrorFunction.Dense:
                errorFunction = new DenseErrorFunction();
                break;

            case EErrorFunction.Desired:
                errorFunction = new DesiredErrorFunction();
                break;
            }

            switch (opt)
            {
            case EOptimizerFunction.SGD:
                optimizerFunction = new SGDOptimizerFunction();
                break;
            }

            return(new AnnBasicOperations(activationFunction,
                                          errorFunction,
                                          optimizerFunction));
        }
Example #26
0
        public override double Compute(double[] input)
        {
            if (_index == 0)
            {
                return(0);
            }
            else
            {
                var sigmoid = new SigmoidFunction();

                return(sigmoid.Function(weights[1] * input[1] +
                                        weights[2] * input[2] +
                                        weights[3] * input[3] +
                                        weights[4] * input[4] +
                                        weights[5] * input[5] +
                                        weights[6] * input[6] +
                                        weights[7] * input[7] +
                                        weights[8] * input[8] +
                                        weights[9] * input[9] + biasWeight));
            }
        }
Example #27
0
        private void SetupSelfForResource(ResourceType resource)
        {
            currentResource = resource;

            var color             = ResourceConfiguration.resourceColoring[currentResource];
            var inventoryCapacity = (market._inventory as ISpaceFillingInventoryAccess <ResourceType>)?.GetInventoryCapacity() ?? maxTargetValueDefaultWhenInfiniteCapacity;

            var priceFunctionConfig = market.GetSellPriceFunctions()[currentResource];
            var priceFunction       = new SigmoidFunction(priceFunctionConfig);

            var functionAdapter = new PlottableFunctionToSeriesAdapter(
                x => priceFunction.GetValueAtPoint(x),
                new PlottableFunctionConfig
            {
                start = 0,
                end   = inventoryCapacity,
                steps = inventoryCapacity
            },
                new PlottableConfig
            {
                dotColor  = default,
        public void ShouldHaveCorrectNetValuesInverse()
        {
            var myFunction = new SigmoidFunction(new SigmoidFunctionConfig
            {
                offset = 0f,
                range  = 10f,
                yRange = 1f
            });

            var expectedValueTable = new Dictionary <float, float>
            {
                { 0f, 0f },
                { 1f, 0.988565420571308328f },
                { 2f, 1.958127996915376009f },
                { 6f, 4.693453660970895236f },
                { 7f, 4.879787337446145572f },
                { 10f, 5f },
            };

            foreach (var expectedPair in expectedValueTable)
            {
                Assert.AreEqual(expectedPair.Key, myFunction.GetPointFromNetValue(expectedPair.Value), 1e-5);
            }
        }
Example #29
0
        public ItemNetwork(ParsedItem[] items, KnownAffix[] knownImplicits, KnownAffix[] knownExplicits)
        {
            this.items          = items;
            this.knownImplicits = knownImplicits;
            this.knownExplicits = knownExplicits;

            SigmoidFunction f = new SigmoidFunction(0.5);

            //Regression mode
            network = new ActivationNetwork(
                f,
                // Input layer. Corruption, implicits, explicits.
                1 + knownImplicits.Count() + knownExplicits.Count(),
                5,
                // Regression mode: one output
                1
                );

            teacher = new BackPropagationLearning(network)
            {
                LearningRate = 1,
                Momentum     = 0.5
            };
        }
Example #30
0
        private void TrainBtnClick(object sender, RoutedEventArgs e)
        {
            double learningRate;
            double momentum;
            int    iterations;

            if (TypeComboBox.SelectedItem is null)
            {
                return;
            }
            if (TypeComboBox.SelectedValue.ToString() == "Classification")
            {
                networkType = new ClassificationNetwork();
            }
            else
            {
                networkType = new RegressionNetwork();
            }
            int classesCount    = 0;
            int attributesCount = 0;

            if (!Double.TryParse(this.EtaTb.Text, out learningRate))
            {
                return;
            }
            if (!Double.TryParse(this.AlphaTb.Text, out momentum))
            {
                return;
            }


            // parse neuron counts separated by commas
            var neurons = this.HiddenNeuronsTb.Text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x =>
            {
                var res = 0;
                if (!Int32.TryParse(x, out res))
                {
                    return(0);
                }
                return(res);
            }).ToList();

            if (neurons.Any(x => x <= 0))
            {
                return;
            }

            if (!Int32.TryParse(this.IterationsTb.Text, out iterations))
            {
                return;
            }
            var trainSet = this.GetSetFromFile(ref classesCount, ref attributesCount)?.NormalizedData;

            if (trainSet == null)
            {
                return;
            }
            // TODO: permit user to model network and edit parameters
            int         outputNeurons      = classesCount;
            IActivation activationFunction = new SigmoidFunction();

            if (networkType is RegressionNetwork)
            {
                outputNeurons      = 1;
                activationFunction = new IdentityFunction();
            }
            this.network = new Network().BuildNetwork(attributesCount, neurons, outputNeurons, learningRate, momentum, activationFunction, networkType);

            var tb = ShowWaitingDialog();

            Task.Run(() =>
            {
                var errors = this.network.Train(trainSet, iterations);

                tb.Dispatcher.Invoke(() =>
                {
                    this.DrawChart
                    (
                        "Error function",
                        new List <IEnumerable <Tuple <double, double> > >()
                    {
                        Enumerable.Range(1, iterations).Zip(errors, (it, val) => new Tuple <double, double>((double)it, val))
                    },
                        1,
                        iterations,
                        errors.Min(),
                        errors.Max()
                    );
                    DialogHost.CloseDialogCommand.Execute(null, tb);
                });
            });

            // TODO: update GUI
        }
        private void NextButtonClick(object sender, RoutedEventArgs e)
        {
            switch (selectedNetworkType)
            {
                case 0:
                    int[] neuronsCount = Layers.Select(l => l.NeuronsCount).ToArray();
                    ActivationFunction[] activationFunctions = new ActivationFunction[Layers.Count];
                    int i = 0;
                    foreach (var layer in Layers)
                    {
                        if(layer.ActivationFunction == GuiActivationFunction.ThresholdFunction)
                        {
                            activationFunctions[i] = new ThresholdFunction();
                        }
                        else if (layer.ActivationFunction == GuiActivationFunction.LinearFunction)
                        {
                            activationFunctions[i] = new LinearFunction();
                        }
                        else
                        {
                            activationFunctions[i] = new SigmoidFunction();
                        }
                        i++;
                    }

                    this.Network = new ActivationNetwork(activationFunctions, selectedInputCount, neuronsCount);

                    break;
                case 1:
                    this.Network = new KohonenNetwork(this.selectedInputCount, Layers[0].NeuronsCount);
                    break;
                case 2:

                    if (Layers[0].ActivationFunction == GuiActivationFunction.ThresholdFunction)
                    {
                        this.Network = new CounterPropagationNetwork(this.selectedInputCount, new ThresholdFunction(), Layers[0].NeuronsCount, Layers[1].NeuronsCount);

                    }
                    else
                    {
                        this.Network = new CounterPropagationNetwork(this.selectedInputCount, new SigmoidFunction(), Layers[0].NeuronsCount, Layers[1].NeuronsCount);

                    }

                   break;
            }

            this.Close();
        }