Ejemplo n.º 1
0
        private void btnDeleteNeuroNet_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("После удаления все данные об нейронной сети, включая обученные веса, будут потеряны. Хотите продолжить?", "Предупреждение потери данных", MessageBoxButtons.OKCancel);

            if (res == DialogResult.OK)
            {
                LoadingWindow loadingWindow = new LoadingWindow();
                loadingWindow.MakeLoading(
                    () => dbHandler.DeleteTopologyAndWeightsMatrix(dgwNeuroNets.SelectedRows[0].Cells[0].Value.ToString(), loadingWindow),
                    "Удаление нейронной сети из БД");
                dbHandler.DeleteNeuroNet(dgwNeuroNets.SelectedRows[0].Cells[0].Value.ToString());

                LoadInformationForUsingNeuroNets();
                FillNeuroNetChangingTable();
                btnChangeNeuroNet.Enabled = false;
                btnDeleteNeuroNet.Enabled = false;

                dgwNeuronsInLayers.Rows.Clear();
                dgwParamsAF.Rows.Clear();
            }
        }
Ejemplo n.º 2
0
        private void LoadNeuroNetIntoDB()
        {
            if (mode == form_destination.Creating)
            {
                try
                {
                    string NameNN = tbNameNeuroNet.Text;
                    if (NameNN == "")
                        throw new Exception("Имя НС не может быть пустым");

                    if (dbHandler.IsNeuroNetExist(NameNN))
                        throw new Exception("Такое имя НС уже используется");

                    if (cbTopology.SelectedItem == null)
                        throw new Exception("Необходимо выбрать топологию");
                    string TopologyTypeName = LibraryOfTopologies.GetTopologyTypeName(cbTopology.SelectedItem.ToString());

                    if (cbTask.SelectedItem == null)
                        throw new Exception("Необходимо выбрать задачу");
                    string TaskName = cbTask.SelectedItem.ToString();

                    int CountNeurons = Convert.ToInt32(numNeuronsNumber.Value);
                    int CountLayers = Convert.ToInt32(numLayersNumber.Value);
                    string typeAF = LibraryOfActivateFunctions.GetActivateFunctionTypeName(cbActivateFunction.SelectedItem.ToString());
                    if (cbActivateFunction.SelectedIndex < 0)
                        throw new Exception("Необходимо выбрать активационную функцию");

                    string NeuronsInLayers = "";
                    int[] NeuInL = new int[CountLayers];
                    string ParametersAF = "";

                    int sumNeurons = 0;
                    for (int i = 0; i < CountLayers; i++)
                    {
                        int neurs = Convert.ToInt32(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (neurs <= 0)
                            throw new Exception("В каждом слое должен быть по крайней мере 1 нейрон");
                        sumNeurons += neurs;

                        NeuInL[i] = neurs;

                        NeuronsInLayers += Convert.ToString(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (i != CountLayers - 1)
                            NeuronsInLayers += " ";
                    }
                    if (sumNeurons != CountNeurons)
                        throw new Exception("Сумма нейронов по слоям должна равняться общему числу нейронов");

                    for (int i = 0; i < LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                        LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName); i++)
                    {
                        double par = Convert.ToDouble(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        ParametersAF += Convert.ToString(par);
                        if (i != LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                        LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName) - 1)
                            ParametersAF += " ";
                    }

                    dbHandler.InsertNeuroNet(NameNN, TopologyTypeName, TaskName, CountNeurons, CountLayers, NeuronsInLayers, typeAF, ParametersAF);

                    LoadingWindow loadingWindow = new LoadingWindow();
                    loadingWindow.MakeLoading(
                        () => dbHandler.InsertTopologyOfNeuroNet(NameNN, TopologyTypeName, CountNeurons, CountLayers, NeuInL, loadingWindow),
                        "Запись нейронной сети в БД");
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (mode == form_destination.Editing)
            {
                try
                {
                    string NameNN = tbNameNeuroNet.Text;
                    if (NameNN == "")
                        throw new Exception("Имя НС не может быть пустым");

                    if (cbTopology.SelectedItem == null)
                        throw new Exception("Необходимо выбрать топологию");
                    string TopologyTypeName = LibraryOfTopologies.GetTopologyTypeName(cbTopology.SelectedItem.ToString());

                    string TaskName = cbTask.SelectedItem.ToString();

                    int CountNeurons = Convert.ToInt32(numNeuronsNumber.Value);
                    int CountLayers = Convert.ToInt32(numLayersNumber.Value);
                    string typeAF = LibraryOfActivateFunctions.GetActivateFunctionTypeName(cbActivateFunction.SelectedItem.ToString());

                    string NeuronsInLayers = "";
                    int[] NeuInL = new int[CountLayers];
                    double[] ParAF = new double[LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                        LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName)];
                    string ParametersAF = "";

                    int sumNeurons = 0;
                    for (int i = 0; i < CountLayers; i++)
                    {
                        int neurs = Convert.ToInt32(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (neurs <= 0)
                            throw new Exception("В каждом слое должен быть по крайней мере 1 нейрон");
                        sumNeurons += neurs;

                        NeuInL[i] = neurs;

                        NeuronsInLayers += Convert.ToString(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (i != CountLayers - 1)
                            NeuronsInLayers += " ";
                    }
                    if (sumNeurons != CountNeurons)
                        throw new Exception("Сумма нейронов по слоям должна равняться общему числу нейронов");

                    for (int i = 0; i < LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                        LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName); i++)
                    {
                        ParAF[i] = Convert.ToDouble(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        ParametersAF += Convert.ToString(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        if (i != LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                            LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName) - 1)
                            ParametersAF += " ";
                    }

                    bool isContining = true;
                    bool isNeuronsInLayersSame = false;
                    bool isParametersAFSame = false;
                    bool isNeedToDelete = false;

                    if (CountLayers == definition_of_editing_net.LayerCount)
                    {
                        int k = 0;
                        for (int i = 0; i < CountLayers; i++)
                        {
                            if (NeuInL[i] == definition_of_editing_net.NeuronsInLayer[i])
                            {
                                k++;
                            }
                        }
                        if (k == CountLayers)
                            isNeuronsInLayersSame = true;
                    }
                    if (String.Compare(cbActivateFunction.SelectedItem.ToString(), definition_of_editing_net.ActivateFunction) == 0)
                    {
                        int k = 0;
                        for (int i = 0; i < definition_of_editing_net.AFParameters.Length; i++)
                        {
                            if (ParAF[i] == definition_of_editing_net.AFParameters[i])
                            {
                                k++;
                            }
                        }
                        if (k == definition_of_editing_net.AFParameters.Length)
                            isParametersAFSame = true;
                    }
                    if (String.Compare(TaskName, definition_of_editing_net.TaskName) != 0 ||
                        String.Compare(TopologyTypeName, definition_of_editing_net.TopologyName) != 0 ||
                        CountNeurons != definition_of_editing_net.NeuronsCount ||
                        isNeuronsInLayersSame == false || isParametersAFSame == false)
                    {
                        DialogResult res = MessageBox.Show("Данные изменения влекут удаление обученных весов сети. " +
                        "Нейронную сеть необходимо будет обучать заново.", "Предупреждение потери данных", MessageBoxButtons.OKCancel);

                        isNeedToDelete = true;
                        if (res == DialogResult.Cancel)
                            isContining = false;
                    }

                    if (isContining == true)
                    {
                        if (isNeedToDelete == true)
                        {
                            LoadingWindow loadingWindow = new LoadingWindow();

                            if (isNeuronsInLayersSame && (String.Compare(cbTopology.SelectedItem.ToString(), definition_of_editing_net.TopologyName) == 0))
                            {
                                loadingWindow.MakeLoading(
                                    ()=>dbHandler.DeleteWeightsMatrix(definition_of_editing_net.Name, loadingWindow),
                                    "Удаление устаревших весовых коэффициентов");
                            }
                            else
                            {
                                loadingWindow.MakeLoading(
                                () => dbHandler.DeleteTopologyAndWeightsMatrix(definition_of_editing_net.Name, loadingWindow),
                                "Удаление старой топологии нейронной сети");
                                loadingWindow.MakeLoading(
                                    () => dbHandler.InsertTopologyOfNeuroNet(definition_of_editing_net.Name, TopologyTypeName, CountNeurons, CountLayers, NeuInL, loadingWindow),
                                    "Запись измененной нейронной сети в БД");
                            }
                        }

                        dbHandler.UpdateNeuroNet(NameNN, definition_of_editing_net.Name, TopologyTypeName, TaskName, CountNeurons, CountLayers,
                           NeuronsInLayers, typeAF, ParametersAF);
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnDeleteNeuroNet_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("После удаления все данные об нейронной сети, включая обученные веса, будут потеряны. Хотите продолжить?", "Предупреждение потери данных", MessageBoxButtons.OKCancel);

            if (res == DialogResult.OK)
            {
                LoadingWindow loadingWindow = new LoadingWindow();
                loadingWindow.MakeLoading(
                    () => dbHandler.DeleteTopologyAndWeightsMatrix(dgwNeuroNets.SelectedRows[0].Cells[0].Value.ToString(), loadingWindow),
                "Удаление нейронной сети из БД");
                dbHandler.DeleteNeuroNet(dgwNeuroNets.SelectedRows[0].Cells[0].Value.ToString());

                LoadInformationForUsingNeuroNets();
                FillNeuroNetChangingTable();
                btnChangeNeuroNet.Enabled = false;
                btnDeleteNeuroNet.Enabled = false;

                dgwNeuronsInLayers.Rows.Clear();
                dgwParamsAF.Rows.Clear();
            }
        }
Ejemplo n.º 4
0
        private void LoadNeuroNetIntoDB()
        {
            if (mode == form_destination.Creating)
            {
                try
                {
                    string NameNN = tbNameNeuroNet.Text;
                    if (NameNN == "")
                    {
                        throw new Exception("Имя НС не может быть пустым");
                    }

                    if (dbHandler.IsNeuroNetExist(NameNN))
                    {
                        throw new Exception("Такое имя НС уже используется");
                    }

                    if (cbTopology.SelectedItem == null)
                    {
                        throw new Exception("Необходимо выбрать топологию");
                    }
                    string TopologyTypeName = LibraryOfTopologies.GetTopologyTypeName(cbTopology.SelectedItem.ToString());

                    if (cbTask.SelectedItem == null)
                    {
                        throw new Exception("Необходимо выбрать задачу");
                    }
                    string TaskName = cbTask.SelectedItem.ToString();

                    int    CountNeurons = Convert.ToInt32(numNeuronsNumber.Value);
                    int    CountLayers  = Convert.ToInt32(numLayersNumber.Value);
                    string typeAF       = LibraryOfActivateFunctions.GetActivateFunctionTypeName(cbActivateFunction.SelectedItem.ToString());
                    if (cbActivateFunction.SelectedIndex < 0)
                    {
                        throw new Exception("Необходимо выбрать активационную функцию");
                    }

                    string NeuronsInLayers = "";
                    int[]  NeuInL          = new int[CountLayers];
                    string ParametersAF    = "";

                    int sumNeurons = 0;
                    for (int i = 0; i < CountLayers; i++)
                    {
                        int neurs = Convert.ToInt32(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (neurs <= 0)
                        {
                            throw new Exception("В каждом слое должен быть по крайней мере 1 нейрон");
                        }
                        sumNeurons += neurs;

                        NeuInL[i] = neurs;

                        NeuronsInLayers += Convert.ToString(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (i != CountLayers - 1)
                        {
                            NeuronsInLayers += " ";
                        }
                    }
                    if (sumNeurons != CountNeurons)
                    {
                        throw new Exception("Сумма нейронов по слоям должна равняться общему числу нейронов");
                    }

                    for (int i = 0; i < LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                                                                                          LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName); i++)
                    {
                        double par = Convert.ToDouble(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        ParametersAF += Convert.ToString(par);
                        if (i != LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                                                                                   LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName) - 1)
                        {
                            ParametersAF += " ";
                        }
                    }

                    dbHandler.InsertNeuroNet(NameNN, TopologyTypeName, TaskName, CountNeurons, CountLayers, NeuronsInLayers, typeAF, ParametersAF);

                    LoadingWindow loadingWindow = new LoadingWindow();
                    loadingWindow.MakeLoading(
                        () => dbHandler.InsertTopologyOfNeuroNet(NameNN, TopologyTypeName, CountNeurons, CountLayers, NeuInL, loadingWindow),
                        "Запись нейронной сети в БД");
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (mode == form_destination.Editing)
            {
                try
                {
                    string NameNN = tbNameNeuroNet.Text;
                    if (NameNN == "")
                    {
                        throw new Exception("Имя НС не может быть пустым");
                    }

                    if (cbTopology.SelectedItem == null)
                    {
                        throw new Exception("Необходимо выбрать топологию");
                    }
                    string TopologyTypeName = LibraryOfTopologies.GetTopologyTypeName(cbTopology.SelectedItem.ToString());

                    string TaskName = cbTask.SelectedItem.ToString();

                    int    CountNeurons = Convert.ToInt32(numNeuronsNumber.Value);
                    int    CountLayers  = Convert.ToInt32(numLayersNumber.Value);
                    string typeAF       = LibraryOfActivateFunctions.GetActivateFunctionTypeName(cbActivateFunction.SelectedItem.ToString());

                    string   NeuronsInLayers = "";
                    int[]    NeuInL          = new int[CountLayers];
                    double[] ParAF           = new double[LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                                                                                                            LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName)];
                    string ParametersAF = "";

                    int sumNeurons = 0;
                    for (int i = 0; i < CountLayers; i++)
                    {
                        int neurs = Convert.ToInt32(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (neurs <= 0)
                        {
                            throw new Exception("В каждом слое должен быть по крайней мере 1 нейрон");
                        }
                        sumNeurons += neurs;

                        NeuInL[i] = neurs;

                        NeuronsInLayers += Convert.ToString(dgwEditNeuronsInLayers.Rows[i].Cells[1].Value);
                        if (i != CountLayers - 1)
                        {
                            NeuronsInLayers += " ";
                        }
                    }
                    if (sumNeurons != CountNeurons)
                    {
                        throw new Exception("Сумма нейронов по слоям должна равняться общему числу нейронов");
                    }

                    for (int i = 0; i < LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                                                                                          LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName); i++)
                    {
                        ParAF[i]      = Convert.ToDouble(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        ParametersAF += Convert.ToString(dgwEditParametersAF.Rows[i].Cells[1].Value);
                        if (i != LibraryOfActivateFunctions.GetCountParametersOfAF(typeAF,
                                                                                   LibraryOfActivateFunctions.GetterParameter.TypeOfActivateFunctionName) - 1)
                        {
                            ParametersAF += " ";
                        }
                    }

                    bool isContining           = true;
                    bool isNeuronsInLayersSame = false;
                    bool isParametersAFSame    = false;
                    bool isNeedToDelete        = false;

                    if (CountLayers == definition_of_editing_net.LayerCount)
                    {
                        int k = 0;
                        for (int i = 0; i < CountLayers; i++)
                        {
                            if (NeuInL[i] == definition_of_editing_net.NeuronsInLayer[i])
                            {
                                k++;
                            }
                        }
                        if (k == CountLayers)
                        {
                            isNeuronsInLayersSame = true;
                        }
                    }
                    if (String.Compare(cbActivateFunction.SelectedItem.ToString(), definition_of_editing_net.ActivateFunction) == 0)
                    {
                        int k = 0;
                        for (int i = 0; i < definition_of_editing_net.AFParameters.Length; i++)
                        {
                            if (ParAF[i] == definition_of_editing_net.AFParameters[i])
                            {
                                k++;
                            }
                        }
                        if (k == definition_of_editing_net.AFParameters.Length)
                        {
                            isParametersAFSame = true;
                        }
                    }
                    if (String.Compare(TaskName, definition_of_editing_net.TaskName) != 0 ||
                        String.Compare(TopologyTypeName, definition_of_editing_net.TopologyName) != 0 ||
                        CountNeurons != definition_of_editing_net.NeuronsCount ||
                        isNeuronsInLayersSame == false || isParametersAFSame == false)
                    {
                        DialogResult res = MessageBox.Show("Данные изменения влекут удаление обученных весов сети. " +
                                                           "Нейронную сеть необходимо будет обучать заново.", "Предупреждение потери данных", MessageBoxButtons.OKCancel);

                        isNeedToDelete = true;
                        if (res == DialogResult.Cancel)
                        {
                            isContining = false;
                        }
                    }

                    if (isContining == true)
                    {
                        if (isNeedToDelete == true)
                        {
                            LoadingWindow loadingWindow = new LoadingWindow();

                            if (isNeuronsInLayersSame && (String.Compare(cbTopology.SelectedItem.ToString(), definition_of_editing_net.TopologyName) == 0))
                            {
                                loadingWindow.MakeLoading(
                                    () => dbHandler.DeleteWeightsMatrix(definition_of_editing_net.Name, loadingWindow),
                                    "Удаление устаревших весовых коэффициентов");
                            }
                            else
                            {
                                loadingWindow.MakeLoading(
                                    () => dbHandler.DeleteTopologyAndWeightsMatrix(definition_of_editing_net.Name, loadingWindow),
                                    "Удаление старой топологии нейронной сети");
                                loadingWindow.MakeLoading(
                                    () => dbHandler.InsertTopologyOfNeuroNet(definition_of_editing_net.Name, TopologyTypeName, CountNeurons, CountLayers, NeuInL, loadingWindow),
                                    "Запись измененной нейронной сети в БД");
                            }
                        }

                        dbHandler.UpdateNeuroNet(NameNN, definition_of_editing_net.Name, TopologyTypeName, TaskName, CountNeurons, CountLayers,
                                                 NeuronsInLayers, typeAF, ParametersAF);
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }