Example #1
0
        private void ExcelImport(object sender, EventArgs e)
        {
            ExcelFile      exFile      = new ExcelFile();
            OpenFileDialog loadFileDlg = new OpenFileDialog();

            loadFileDlg.Filter = "Excel Files (.xls)| *.xls|All files (.)| *.";

            if (loadFileDlg.ShowDialog() == DialogResult.OK)
            {
                studyPairs.Clear();
                try
                {
                    exFile.LoadXls(loadFileDlg.FileName);
                }
                catch (Exception)
                {
                    MessageBox.Show("Нету файла", "ExcelImport", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                for (int i = 0; i < exFile.Worksheets.Count; i++)
                {
                    ExcelWorksheet sheet = exFile.Worksheets[i];
                    StudyPair      pair  = new StudyPair();
                    int            ii    = 0;
                    int            jj    = 0;
                    for (int j = 0; j < colorGrid.GridSize.Width * colorGrid.GridSize.Height; j++)
                    {
                        if (jj >= colorGrid.GridSize.Width)
                        {
                            ii++;
                            jj = 0;
                        }
                        if (sheet.Cells[ii, jj].Value.ToString() == "X")
                        {
                            pair.inputs.Add(1);
                        }
                        else
                        {
                            pair.inputs.Add(0);
                        }
                        jj++;
                    }
                    studyPairs.Add(pair);
                }
                colorGrid.SetData(studyPairs[currentStudyPair].inputs);
                ChangeNetSettings();
                CreatePreview();
            }
            else
            {
                MessageBox.Show("Нету образов", "ExcelImport", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        protected virtual void RecognizePicture(object sender, EventArgs e)
        {
            if (pairsLoaded)
            {
                StudyPair pair         = net.Recognize(colorGrid.Data);
                string    resultString = "";

                for (int i = 0; i < net.recognitionResults.Count; i++)
                {
                    resultString += string.Format("Образ : {0} Вероятность : {1}%", net.recognitionResults[i].pair.name, net.recognitionResults[i].result) + Environment.NewLine;
                }

                MessageBox.Show(resultString);
            }
        }
Example #3
0
        private StudyPair CurrentToStudyPair()
        {
            StudyPair pair = new StudyPair();

            for (int i = 0; i < net.InputsCount; i++)
            {
                pair.inputs.Add(float.Parse(ParametrGrid.Rows[i].Cells[2].Value.ToString()));
            }

            for (int i = 0; i < net.OutputsCount; i++)
            {
                pair.quits.Add(float.Parse(OutputGridView.Rows[i].Cells[1].Value.ToString()));
            }

            return(pair);
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            studyPairs.Clear();

            for (int i = 0; i < studyPairsBox.Lines.Length; i++)
            {
                if (studyPairsBox.Lines[i] == "")
                {
                    continue;
                }

                studyPairs.Add(StudyPair.FromString(studyPairsBox.Lines[i]));
            }

            studyPairsCount.Value      = studyPairs.Count;
            neuronNet.OutputsCount     = studyPairs[0].quits.Count;
            neuronNet.InputsCount      = studyPairs[0].inputs.Count;
            neuronNet.StudyPairsLoaded = true;
        }
Example #5
0
        private void LoadPairs(object sender, EventArgs e)
        {
            string[]       file;
            OpenFileDialog dlg = new OpenFileDialog();

            studyPairs.Clear();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                file = File.ReadAllLines(dlg.FileName, Encoding.Default);

                for (int i = 0; i < file.Length; i++)
                {
                    studyPairs.Add(StudyPair.FromString(file[i]));
                }

                colorGrid.SetData(studyPairs[currentStudyPair].inputs);
                ChangeNetSettings();
                CreatePreview();
            }
        }
Example #6
0
        private void AddPicture(object sender, EventArgs e)
        {
            StudyPair      pair = new StudyPair();
            ObjectNameForm form = new ObjectNameForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                pair.name = form.NewName;

                for (int i = 0; i < colorGrid.Data.GetLength(0); i++)
                {
                    for (int j = 0; j < colorGrid.Data.GetLength(1); j++)
                    {
                        if (IsClassification)
                        {
                            pair.inputs.Add(colorGrid.Data[j, i].FloatValueClassification);
                        }
                        else
                        {
                            pair.inputs.Add(colorGrid.Data[j, i].FloatValueAssociationMemory);
                        }
                    }
                }

                studyPairs.Add(pair);

                for (int i = 0; i < studyPairs.Count; i++)
                {
                    studyPairs[i].quits.Clear();

                    for (int j = 0; j < studyPairs.Count; j++)
                    {
                        studyPairs[i].quits.Add(i == j ? 1 : 0);
                    }
                }

                CreatePreview();
            }
        }
Example #7
0
        private void DataBaseExport(object sender, EventArgs e)
        {
            LoadMenu loadMenu = new LoadMenu();

            loadMenu.indexSave = 1;
            loadMenu.ShowDialog();

            string[] file;
            if (loadMenu.fileName != null)
            {
                string query = "select Graph from SaveGraphs where Name=" + "\"" + loadMenu.fileName + "\"";
                databaseSQLite.OpenConnection();
                SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                using (SQLiteDataReader reader = myCommand.ExecuteReader())
                {
                    if (reader.HasRows)       // если есть данные
                    {
                        while (reader.Read()) // построчно считываем данные
                        {
                            string data = (string)reader.GetValue(0);
                            File.WriteAllText("temp.txt", data);
                        }
                    }
                }
                databaseSQLite.CloseConnection();
                studyPairs.Clear();
                FileStream fs = new FileStream("temp.txt", FileMode.Open, FileAccess.Read);
                file = File.ReadAllLines("temp.txt", Encoding.Default);
                for (int i = 0; i < file.Length; i++)
                {
                    studyPairs.Add(StudyPair.FromString(file[i]));
                }
                colorGrid.SetData(studyPairs[currentStudyPair].inputs);
                ChangeNetSettings();
                CreatePreview();
                fs.Close();
            }
        }
Example #8
0
        private void LoadPairs(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            string[] strings;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                strings = File.ReadAllLines(dlg.FileName);
                studyPairs.Clear();

                for (int i = 0; i < strings.Length; i++)
                {
                    studyPairs.Add(StudyPair.FromString(strings[i]));
                }

                studyPairsCount.Value  = studyPairs.Count;
                neuronNet.OutputsCount = studyPairs[0].quits.Count;
                neuronNet.InputsCount  = studyPairs[0].inputs.Count;
                // DialogResult = DialogResult.OK;
                neuronNet.StudyPairsLoaded = true;
                ShowStudyPairs();
            }
        }
Example #9
0
        private void BuildNet(object sender, EventArgs e)
        {
            if (type == NetType.LINEAR && classes.Count == 0)
            {
                return;
            }
            if (type == NetType.KOHONEN && currentClass.values.Count == 0)
            {
                return;
            }

            switch (type)
            {
            case NetType.LINEAR:
                linearNet.InputsCount = 2;
                linearNet.SetNeuronsCount(linearNet.NeuronGroups.Count - 1, classes.Count);
                linearNet.GraphicsNeuron.Refresh();

                int count = GetObjectsCount();
                linearNet.StudyPairs.Clear();

                StudyPair pair;

                for (int i = 0; i < classes.Count; i++)
                {
                    for (int j = 0; j < classes[i].values.Count; j++)
                    {
                        pair = new StudyPair();
                        pair.inputs.Add(classes[i].values[j].X);
                        pair.inputs.Add(classes[i].values[j].Y);

                        for (int k = 0; k < classes.Count; k++)
                        {
                            pair.quits.Add(i == k ? 1 : 0);
                        }

                        linearNet.StudyPairs.Add(pair);
                    }
                }

                linearNet.StudyPairsLoaded = true;
                break;

            case NetType.KOHONEN:
                kohonenNet.InputsCount = 2;
                kohonenNet.StudyPairs.Clear();
                kohonenNet.GraphicsNeuron.Refresh();

                foreach (PointF obj in currentClass.values)
                {
                    pair = new StudyPair();

                    pair.inputs.Add(obj.X);
                    pair.inputs.Add(obj.Y);

                    kohonenNet.StudyPairs.Add(pair);
                }

                UpdateCenterClasses();
                break;
            }
        }
Example #10
0
 public RecognitionResult(StudyPair studyPair, int res)
 {
     pair   = studyPair;
     result = res;
 }
Example #11
0
        public static StudyPair FromString(string str)
        {
            string    tmp    = "";
            StudyPair pair   = new StudyPair();
            bool      output = false;
            bool      name   = false;

            pair.inputs.Clear();

            for (int i = 0; i < str.Length; i++)
            {
                switch (str[i])
                {
                case '-':
                case ',':
                case '.': tmp += str[i]; break;

                case '|':

                    if (!output)
                    {
                        pair.inputs.Add(Convert.ToSingle(tmp));
                    }
                    else
                    {
                        pair.quits.Add(Convert.ToSingle(tmp));
                        pair.realQuits.Add(0);
                    }
                    tmp = "";
                    break;

                case ';':
                    if (output)
                    {
                        pair.quits.Add(Convert.ToSingle(tmp));
                    }
                    else
                    {
                        pair.inputs.Add(Convert.ToSingle(tmp));
                        pair.realQuits.Add(0);
                    }
                    output = true;
                    tmp    = "";
                    break;

                case '&':
                    if (name)
                    {
                        pair.name = tmp;
                    }
                    name = true;
                    break;

                case '#': return(pair);

                default:
                    if (char.IsDigit(str[i]))
                    {
                        tmp += str[i];
                    }
                    if (name)
                    {
                        tmp += str[i];
                    }
                    break;
                }
            }

            return(pair);
        }
Example #12
0
        private void BuildNet(object sender, EventArgs e)
        {
            if (!pointsCreated)
            {
                return;
            }

            StudyPair pair;
            int       pointCount = Int32.Parse(PointCountX.Text);

            switch (type)
            {
            case FunctionType.ONE_ARGUMENT_FUNCTION:
                net.StudyPairs.Clear();
                net.InputsCount  = 1;
                net.OutputsCount = 1;

                PointF [] pts = drawer2D.GetPoints(1);

                for (int i = 0; i < pts.Length; i++)
                {
                    pair = new StudyPair();
                    pair.inputs.Add(pts[i].X);
                    pair.quits.Add(pts[i].Y);

                    net.StudyPairs.Add(pair);
                }
                net.LinearNormalizeInputs();
                net.LinearNormalizeOutputs();
                drawer2D.AddGraphic(3, Function2DNet, "Выход сети", typeView.Line);
                drawer2D.Functions[2].NeedCreateBuffer = true;
                drawer2D.Redraw();
                break;

            case FunctionType.TWO_ARGUMENT_FUNCTION:
                int pointCountX = Int32.Parse(PointCountX.Text);
                int pointCountY = Int32.Parse(PointCountZ.Text);
                net.StudyPairs.Clear();
                net.InputsCount  = 2;
                net.OutputsCount = 1;
                Vector3[] p = drawer3D.GetGraphicPoints(1, pointCountX, pointCountY);

                for (int i = 0; i < p.Length; i++)
                {
                    pair = new StudyPair();
                    pair.inputs.Add(p[i].X);
                    pair.inputs.Add(p[i].Z);
                    pair.quits.Add(p[i].Y);

                    net.StudyPairs.Add(pair);
                }
                net.LinearNormalizeInputs();
                net.LinearNormalizeOutputs();
                drawer3D.AddGraphic(netFunction);
                drawer3D.EnableCreateBuffers();
                drawer3D.RecreateGraphic();
                break;
            }

            net.StudyPairsLoaded = true;
            netCreated           = true;
        }
Example #13
0
        private NeuronNet AcceptJson(Root2 root2)
        {
            NeuronNet net = new NeuronNet();

            for (int i = 0; i < root2.inputss.Count; i++)
            {
                PointF pointF = new PointF();
                pointF.X = (float)root2.inputss[i].Position.X;
                pointF.Y = (float)root2.inputss[i].Position.Y;
                NeuronInput neuron = new NeuronInput((float)root2.inputss[i].value, root2.inputss[i].Name, pointF);
                neuron.positionChanged = root2.inputss[i].positionChanged;
                neuron.wasPainted      = root2.inputss[i].wasPainted;
                net.inputss.Add(neuron);
            }
            for (int i = 0; i < root2.NeuronGroups.Count; i++)
            {
                NeuronGroup neurongroup = new NeuronGroup();
                neurongroup.Neurons              = root2.NeuronGroups[i].Neurons;
                neurongroup.SecondActivate       = root2.NeuronGroups[i].SecondActivate;
                neurongroup.SumForSoftMax        = (float)root2.NeuronGroups[i].SumForSoftMax;
                neurongroup.allNeuronsWasPainted = root2.NeuronGroups[i].allNeuronsWasPainted;
                net.NeuronGroups.Add(neurongroup);
            }
            for (int i = 0; i < root2.studyPairss.Count; i++)
            {
                StudyPair studyPair = new StudyPair();
                for (int j = 0; j < root2.studyPairss[i].inputs.Count; j++)
                {
                    studyPair.inputs.Add((float)root2.studyPairss[i].inputs[j]);
                }
                for (int j = 0; j < root2.studyPairss[i].quits.Count; j++)
                {
                    studyPair.quits.Add((float)root2.studyPairss[i].quits[j]);
                }
                for (int j = 0; j < root2.studyPairss[i].realQuits.Count; j++)
                {
                    studyPair.realQuits.Add((float)root2.studyPairss[i].realQuits[j]);
                }
                net.studyPairss.Add(studyPair);
            }
            net.E      = (float)root2.E;
            net.moment = (float)root2.moment;
            for (int i = 0; i < root2.errors.Count; i++)
            {
                PointF pointF = new PointF();
                pointF.X = (float)root2.errors[i].X;
                pointF.Y = (float)root2.errors[i].Y;
                net.errors.Add(pointF);
            }
            for (int i = 0; i < root2.normalizedErrors.Count; i++)
            {
                PointF pointF = new PointF();
                pointF.X = (float)root2.normalizedErrors[i].X;
                pointF.Y = (float)root2.normalizedErrors[i].Y;
                net.normalizedErrors.Add(pointF);
            }
            net.EraCount             = root2.EraCount;
            net.currentSelection     = new NeuronGroup(0);
            net.recognitionResults   = new List <RecognitionResult>();
            net.StudyPairsLoaded     = root2.StudyPairsLoaded;
            net.InputsSum            = (float)root2.InputsSum;
            net.allInputsWasPainted  = root2.allInputsWasPainted;
            net.minError             = (float)root2.minError;
            net.NormalizeOutputValue = (float)root2.NormalizeOutputValue;
            net.biasX           = (float[])root2.biasX;
            net.biasY           = (float[])root2.biasY;
            net.scaleX          = (float[])root2.scaleX;
            net.scaleY          = (float[])root2.scaleY;
            net.StudyLimit      = (float)root2.StudyLimit;
            net.AccessChangeNet = root2.AccessChangeNet;
            return(net);
        }