Пример #1
0
        private static void setIndexesToSheet(Subnet subnet)
        {
            int count = ANNUtils.getCountOfWeights(subnet.Network);

            for (int i = 1; i <= count; i++)
            {
                mediumsSheet.Cells[ i + 1, 1].Value = "Вес " + (i-1).ToString();
                coefvariationsSheet.Cells[i + 1, 1].Value = "Вес " + (i - 1).ToString();
                deviationSheet.Cells[i + 1, 1].Value = "Вес " + (i - 1).ToString();
            }
        }
Пример #2
0
        public virtual double[] Compute(double[] input, Subnet subnet, int numberLayer, List<Record> MinMaxValues)
        {
            // local variable to avoid mutlithread conflicts
            double[] output = new double[neuronsCount];

            // compute each neuron
            for (int i = 0; i < neurons.Length; i++)
            {
                output[i] = neurons[i].Compute(input, subnet, numberLayer, i, MinMaxValues);
            }

            // assign output property as well (works correctly for single threaded usage)
            this.output = output;
            return output;
        }
Пример #3
0
        //запись весов отобранных или скрещенных сетей
        public static void SubnetToFile(Subnet net, int reconnectingCount, Boolean cross, string parents = "", int population = 0)
        {
            try
            {
                string folder = "";
                if (cross)
                    folder = currentFolder + "\\" + CROSS_DIR + reconnectingCount.ToString() + "\\" + population + "\\";
                else
                    folder = currentFolder + "\\" + SELECTION_DIR + reconnectingCount.ToString() + "\\";

                LogHelper.checkDir(folder);

                string filename = Path.Combine(folder, net.ID + "-" + parents + "-" + net.quality + ".csv");

                System.IO.StreamWriter file = new System.IO.StreamWriter(filename);

                file.WriteLine("Layer;Neuron;Weight;Value;");

                LogHelper.allWeightsSheet.Cells[ 1, netsCounter + 1].Value = net.ID + "-" + parents + "-" + net.quality;

                int row = 0;
                for (int i = 0; i < net.Network.Layers.Length; i++)
                {
                    for (int j = 0; j < net.Network.Layers[i].Neurons.Length; j++)
                    {
                        for (int k = 0; k < net.Network.Layers[i].Neurons[j].Weights.Length; k++)
                        {

                            file.WriteLine(i.ToString() + ";" + j.ToString() + ";" + k.ToString() + ";" + net.Network.Layers[i].Neurons[j].Weights[k] + ";");

                            LogHelper.allWeightsSheet.Cells[row + 2, netsCounter + 1].Value = net.Network.Layers[i].Neurons[j].Weights[k];
                            row++;
                        }
                    }
                }
                file.Flush();
                file.Close();
                netsCounter++;
            }
            catch
            {
                // Перехватываем все и ничего не делаем
            }
        }
Пример #4
0
        //Инициализирует папки, файлы и spreadsheets
        public static void InitReporting(Subnet subnet = null, int reconnectingCount = 0)
        {
            LogHelper.checkDir(LogHelper.currentFolder);
            LogHelper.netsCounter = 0;

            //создание файла с результатами корректировки
            LogHelper.resultsFile = new FileInfo(LogHelper.currentFolder + "\\" + RESULT_CORRECT_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.results = new ExcelPackage(LogHelper.resultsFile);
            LogHelper.resultsSheet = LogHelper.results.Workbook.Worksheets.Add("Результаты");

            //создание файла с коэф.вариации
            LogHelper.covarFile = new FileInfo(LogHelper.currentFolder + "\\" + VARIATIONS_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.coefvariations = new ExcelPackage(LogHelper.covarFile);
            LogHelper.coefvariationsSheet = LogHelper.coefvariations.Workbook.Worksheets.Add("Коэф.вариации");

            //стандартное отклонение
            LogHelper.deviationFile = new FileInfo(LogHelper.currentFolder + "\\" + DEVIATION_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.deviationBook = new ExcelPackage(LogHelper.deviationFile);
            LogHelper.deviationSheet = LogHelper.deviationBook.Workbook.Worksheets.Add("Стандартные отклонения весов");

            //средние значения
            LogHelper.mediumsFile = new FileInfo(LogHelper.currentFolder + "\\" + MEDIUMS_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.mediumsBook = new ExcelPackage(LogHelper.mediumsFile);
            LogHelper.mediumsSheet = LogHelper.mediumsBook.Workbook.Worksheets.Add("Средние значения");

            //веса всех сетей
            LogHelper.allWeightsFile = new FileInfo(LogHelper.currentFolder + "\\" + ALLWEIGHTS_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.allWeightsBook = new ExcelPackage(LogHelper.allWeightsFile);
            LogHelper.allWeightsSheet = LogHelper.allWeightsBook.Workbook.Worksheets.Add("Веса всех сетей сессии");

            //параметры коррекции по поколениям
            LogHelper.correctParamsFile = new FileInfo(LogHelper.currentFolder + "\\" + PARAMS_CORRECT_FILE + reconnectingCount.ToString() + ".xlsx");
            LogHelper.correctParamsBook = new ExcelPackage(LogHelper.correctParamsFile);
            LogHelper.correctParamsSheet = LogHelper.correctParamsBook.Workbook.Worksheets.Add("Показатели коррекции по поколениям");
            LogHelper.correctParamsSheet = LogHelper.setCommonCorrectParamsSheetHeaders(correctParamsSheet);

            if (subnet != null)
                LogHelper.setIndexesToSheet(subnet);

            return;
        }
Пример #5
0
 public abstract double Compute(double[] input, Subnet subnet, int numberLayer, int numberNeuron, List<Record> MinMaxValues);
        public override double Compute(double[] input, Subnet subnet, int numberLayer, int numberNeuron, List<Record> MinMaxValues)
        {
            Random rnd = new Random();
            // check for corrent input vector
            if (input.Length != inputsCount)
                throw new ArgumentException("Wrong length of the input vector.");

            // initial sum value
            double sum = 0.0;

            // compute weighted sum of inputs
            for (int i = 0; i < weights.Length; i++)
            {
                if (subnet.outputAssosiated.Contains(numberLayer.ToString() + ":" + numberNeuron.ToString() + ":" + i.ToString()))
                {
                    double min = 0.0;
                    double max = 0.0;
                    foreach (Record elem in MinMaxValues)
                    {
                        if ((elem.numberLayer == numberLayer) && (elem.numberNeuron == numberNeuron) && (elem.numberWeight == i))
                        {
                            min = elem.min;
                            max = elem.max;
                        }
                    }
                    double normValue = (((subnet.res[0] - (-1)) * (max - min)) / (1 - (-1))) + min;
                    sum += (weights[i] * normValue ) * input[i];
                   // weights[i] = weights[i] * subnet.res[0];
                    subnet.res.RemoveAt(0);
                }
                else sum += weights[i] * input[i];
            }

            sum += threshold;

            // local variable to avoid mutlithreaded conflicts
            double output = function.Function(sum);
            // assign output property as well (works correctly for single threaded usage)
            this.output = output;

            return output;
        }
Пример #7
0
        //compute net with subnets
        public virtual double[] Compute(double[] input, Subnet subnet, List<Record> MinMaxValues)
        {
            List<String> inputs = subnet.inputAssosiated;
            double[] weights = this.getWeights(inputs, input);
            subnet.Compute(weights);
            // local variable to avoid mutlithread conflicts
            double[] output = input;

            // compute each layer
            for (int i = 0; i < layers.Length; i++)
            {
                output = layers[i].Compute(output, subnet, i, MinMaxValues);
            }

            // assign output property as well (works correctly for single threaded usage)
            this.output = output;

            return output;
        }