Exemplo n.º 1
0
        /// <summary>
        /// Compute the output for this network.
        /// </summary>
        ///
        /// <param name="input">The input.</param>
        /// <param name="output">The output.</param>
        public void Compute(double[] input, double[] output)
        {
            var     input2  = new BasicMLData(input);
            IMLData output2 = Compute(input2);

            output2.CopyTo(output, 0, output2.Count);
        }
Exemplo n.º 2
0
        public virtual void Compute(IMLData input, double[] output)
        {
            int sourceIndex = _layerOutput.Length
                              - _layerCounts[_layerCounts.Length - 1];

            input.CopyTo(_layerOutput, sourceIndex, _inputCount);

            InnerCompute(output);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Note: for Boltzmann networks, you will usually want to call the "run"
        /// method to compute the output.
        /// This method can be used to copy the input data to the current state. A
        /// single iteration is then run, and the new current state is returned.
        /// </summary>
        ///
        /// <param name="input">The input pattern.</param>
        /// <returns>The new current state.</returns>
        public override sealed IMLData Compute(IMLData input)
        {
            var result = new BiPolarMLData(input.Count);

            input.CopyTo(CurrentState.Data, 0, input.Count);
            Run();
            EngineArray.ArrayCopy(CurrentState.Data, result.Data);
            return(result);
        }
Exemplo n.º 4
0
        private char Denormalize(IMLData value)
        {
            var query = new double[value.Count];

            value.CopyTo(query, 0, value.Count);
            var index = query.ToList().IndexOf(1D);

            return(_alphas[index]);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Note: for Hopfield networks, you will usually want to call the "run"
        /// method to compute the output.
        /// This method can be used to copy the input data to the current state. A
        /// single iteration is then run, and the new current state is returned.
        /// </summary>
        ///
        /// <param name="input">The input pattern.</param>
        /// <returns>The new current state.</returns>
        public override sealed IMLData Compute(IMLData input)
        {
            var result = new BiPolarMLData(input.Count);

            input.CopyTo(CurrentState.Data, 0, input.Count);
            Run();

            for (int i = 0; i < CurrentState.Count; i++)
            {
                result.SetBoolean(i,
                                  BiPolarUtil.Double2bipolar(CurrentState[i]));
            }
            EngineArray.ArrayCopy(CurrentState.Data, result.Data);
            return(result);
        }
Exemplo n.º 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            double[][]     x = { new double[] { 0.1, 0.2 },
                                 new double[]     { 0.4, 0.3 } };
            double[][]     y = { new double[] { 0.3 },
                                 new double[]     { 0.7 } };
            BasicMLDataSet dataset = new BasicMLDataSet(x, y);

            BasicNetwork rede = new BasicNetwork();

            rede.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 2));
            rede.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 3));
            rede.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 1));
            rede.Structure.FinalizeStructure();
            rede.Reset();

            Backpropagation train = new Backpropagation(rede, dataset, 0.5, 0.1);

            int epoch = 0;

            do
            {
                train.Iteration();
                if (epoch % 100 == 0)
                {
                    richTextBox2.AppendText("Época " + epoch.ToString() + " Erro " + train.Error + Environment.NewLine);
                }
                epoch++;
            } while (epoch < 3000);

            for (double t = 0.0; t <= 5; t += 0.05)
            {
                double[] d      = new double[] { t, t };
                IMLData  input  = new BasicMLData(d);
                IMLData  output = rede.Compute(input);
                double[] result = new double[output.Count];
                output.CopyTo(result, 0, output.Count);
                richTextBox2.AppendText(" " + t + "+" + t + "=" + result[0] + Environment.NewLine);
            }
        }
Exemplo n.º 7
0
        private double MaxInArray(IMLData result)
        {
            var array = new double[Network.OutputSize];
            result.CopyTo(array, 0, Network.OutputSize - 1);

            var maxValue = array.Max();
            var maxIndex = array.ToList().IndexOf(maxValue);

            return maxIndex + 1;
        }
Exemplo n.º 8
0
        public virtual void Compute(IMLData input, double[] output)
        {
            int sourceIndex = _layerOutput.Length
                              - _layerCounts[_layerCounts.Length - 1];

            input.CopyTo(_layerOutput, sourceIndex, _inputCount);

            InnerCompute(output);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Note: for Boltzmann networks, you will usually want to call the "run"
        /// method to compute the output.
        /// This method can be used to copy the input data to the current state. A
        /// single iteration is then run, and the new current state is returned.
        /// </summary>
        ///
        /// <param name="input">The input pattern.</param>
        /// <returns>The new current state.</returns>
        public override sealed IMLData Compute(IMLData input)
        {
            var result = new BiPolarMLData(input.Count);
			input.CopyTo(CurrentState.Data, 0, input.Count);
            Run();
            EngineArray.ArrayCopy(CurrentState.Data, result.Data);
            return result;
        }
        /// <summary>
        /// Note: for Hopfield networks, you will usually want to call the "run"
        /// method to compute the output.
        /// This method can be used to copy the input data to the current state. A
        /// single iteration is then run, and the new current state is returned.
        /// </summary>
        ///
        /// <param name="input">The input pattern.</param>
        /// <returns>The new current state.</returns>
        public override sealed IMLData Compute(IMLData input)
        {
            var result = new BiPolarMLData(input.Count);
            input.CopyTo(CurrentState.Data, 0, input.Count);
            Run();

            for (int i = 0; i < CurrentState.Count; i++)
            {
                result.SetBoolean(i,
                                  BiPolarUtil.Double2bipolar(CurrentState[i]));
            }
            EngineArray.ArrayCopy(CurrentState.Data, result.Data);
            return result;
        }