示例#1
0
        private void ButtonRecognize_Click(object sender, EventArgs e)
        {
            var bitmap = (Bitmap)pictureBox1.Image;

            var array = FromImageToArray(bitmap);

            var result = new StochasticGradient().NeuronFunc(array, _weights);

            MessageBox.Show(result.ToString());
        }
示例#2
0
        private void ButtonLearn_Click(object sender, EventArgs e)
        {
            Abort.Abort = false;
            if (_samples == null)
            {
                var dict = GetLearningSamples();
                _samples = dict.Keys.ToArray();
                foreach (var input in _samples)
                {
                    for (var i = 0; i < input.Length; i++)
                    {
                        input[i] = input[i] > 0 ? 1 : 0;
                    }
                }
                _answers = dict.Values.ToArray();
            }

            var eta   = double.Parse(etaTextBox.Text, CultureInfo.InvariantCulture);
            var stab  = double.Parse(stabilityTextBox.Text, CultureInfo.InvariantCulture);
            var wstab = double.Parse(wstabTextBox.Text, CultureInfo.InvariantCulture);

            _weights = new double[_samples[0].Length];
            thread   = new Thread(() =>
            {
                var SG = new StochasticGradient {
                    Abort = Abort
                };
                SG.IterationChange += (o, args) => iterNew = SG.Iterations.ToString();
                SG.DQChanged       += (o, args) => dqNew = SG.D_Q.ToString("e2");
                SG.VectorChanged   += (o, args) => vectDelta = SG.VectDelta.ToString("e2");

                _weights = SG.SG(_samples, _answers, eta, 1.0 / _samples.Length, stab, wstab);
                if (!SG.Abort.Abort)
                {
                    isSetted = true;
                }
            })
            {
                IsBackground = true, Priority = ThreadPriority.Highest
            };
            thread.Start();
        }