예제 #1
0
        public Hyperparameters Copy(Hyperparameters individ, string source, string destination)
        {
            Hyperparameters H = individ.Clone();

            var algorithmBranches = H.getNodesByparentID(H.getNodeByName("committee")[0].ID);

            List <Hyperparameters> hs = new List <Hyperparameters>();

            for (int j = 0; j < algorithmBranches.Count; j++)
            {
                var h = new Hyperparameters(H.toJSON(algorithmBranches[j].ID), form1);
                var new_save_folder = destination + "\\" + h.getValueByName("model_name") + "\\";
                //новые пути прописываются в h.json автоматически, если передать объект Hyperparameters по ссылке, а не по значению
                Algorithm.CopyFiles(h, h.getValueByName("save_folder"), new_save_folder);
                hs.Add(h);
            }

            //удаление старых записей
            for (int i = 0; i < algorithmBranches.Count; i++)
            {
                H.deleteBranch(algorithmBranches[i].ID);
            }

            //приращение новых записей к узлу  "committee"
            for (int i = 0; i < algorithmBranches.Count; i++)
            {
                H.addBranch(hs[i], hs[i].nodes[0].name(), H.getNodeByName("committee")[0].ID);
            }

            H.setValueByName("report_path", destination);
            H = H.Clone();
            File.WriteAllText(destination + "\\h.json", H.toJSON(0), System.Text.Encoding.Default);

            return(H);
        }
        public void hyperCubeRecursiveCalculation(int variableNodeId, string value)
        {
            if (form1.multiThreadTrainingRATE != threads && form1.multiThreadTrainingRATE != 0)
            {
                threads = form1.multiThreadTrainingRATE;
                initPool();
            }
            if (threads > Math.Pow(3.0, Convert.ToDouble(variablesCount)))
            {
                threads = Convert.ToInt32(Math.Pow(3.0, Convert.ToDouble(variablesCount)));
                initPool();
            }
            P.nodes[variableNodeId].setValue(value);



            for (int i = variableNodeId + 1; i < P.nodes.Count; i++)
            {
                if (P.nodes[i].getAttributeValue("variable") == "numerical")
                {
                    string min = P.nodes[i].getAttributeValue("min");
                    string max = P.nodes[i].getAttributeValue("max");

                    hyperCubeRecursiveCalculation(i, min);
                    hyperCubeRecursiveCalculation(i, max);
                    hyperCubeRecursiveCalculation(i, getVariableCenter(P.nodes[i]).Replace(',', '.'));

                    return;
                }
            }

            double Q = searchInExplored(P);

            if (Q == -1)
            {
                calculateTargetFunction(P);
            }
            else
            {// по идее среди этих точек не может быть максимума
                currentHypercube.Add(new TargetFunctionPoint(P.Clone(), Q));
            }
        }
예제 #3
0
        private Hyperparameters get_child(Hyperparameters parent1, Hyperparameters parent2, Hyperparameters old)
        {
            Hyperparameters child = old.Clone();

            foreach (int variableID in variablesIDs)
            {
                //родитель гена выбирается случайно
                int parent_of_gene = r.Next(0, 2);
                if (parent_of_gene == 0)
                {
                    child.nodes[variableID].setAttribute("value", parent1.nodes[variableID].getValue());
                }
                else
                {
                    child.nodes[variableID].setAttribute("value", parent2.nodes[variableID].getValue());
                }
            }
            return(child);
        }
예제 #4
0
        public void Process()
        {
            NetworkStream stream = null;

            /* try
            *  {   */
            stream = client.GetStream();
            BinaryReader reader = new BinaryReader(stream);
            BinaryWriter writer = new BinaryWriter(stream);

            while (true)
            {
                if (task != null)
                {
                    if (task.status != "done")
                    {
                        if (task.type == "train")
                        {
                            //log(hostName + ": " + task.h.getValueByName("code")+" .1");
                            status = "busy";
                            //объявление агенту типа задачи
                            sendCommand(writer, "train");

                            task.h.Save();

                            sendFile(writer, task.h.getValueByName("json_file_path"));
                            System.Threading.Thread.Sleep(10);
                            sendFile(writer, task.h.getValueByName("train_script_path"));
                            System.Threading.Thread.Sleep(10);
                            sendFile(writer, task.h.getValueByName("input_file"));
                            System.Threading.Thread.Sleep(10);
                            var trainingReport = recieveCommand(reader);
                            // log(trainingReport);
                            if (!trainingReport.Contains("Произошла ошибка"))
                            {
                                recieveFile(reader, task.h.getValueByName("json_file_path"));
                                System.Threading.Thread.Sleep(10);
                                recieveFile(reader, task.h.getValueByName("predictions_file_path"));
                                System.Threading.Thread.Sleep(10);
                                recieveFile(reader, task.h.getValueByName("save_folder") + "weights.h5");
                                System.Threading.Thread.Sleep(10);

                                // log(hostName + ": " + task.h.getValueByName("code") + " .2");


                                Hyperparameters hTemp = new Hyperparameters(File.ReadAllText(task.h.getValueByName("json_file_path"), Encoding.Default), form1);

                                hTemp.setValueByName("json_file_path", task.h.getValueByName("json_file_path"));
                                hTemp.setValueByName("predictions_file_path", task.h.getValueByName("predictions_file_path"));
                                hTemp.setValueByName("save_folder", task.h.getValueByName("save_folder"));
                                hTemp.setValueByName("train_script_path", task.h.getValueByName("train_script_path"));
                                hTemp.setValueByName("get_prediction_script_path", task.h.getValueByName("get_prediction_script_path"));
                                hTemp.setValueByName("input_file", task.h.getValueByName("input_file"));


                                task.h = hTemp.Clone();
                                task.h.Save();

                                log(hostName + ": " + task.h.getValueByName("code") + " trained;   accuracy = " + task.h.getValueByName("stdDev"));
                                task.status = "done";
                            }
                            else
                            {
                                task.status = "error";
                            }
                            status = "free";
                        }
                    }
                }
                System.Threading.Thread.Sleep(1000);
            }

            /*   }
             * catch (Exception ex)
             * {
             *     log(ex.Message);
             * }
             * finally
             * {
             *     if (stream != null)
             *         stream.Close();
             *     if (client != null)
             *         client.Close();
             * } */
        }