Пример #1
0
        public static double Calculate(this HRBFNeuronet neuronet, double[] x)
        {
            var hiddenLayerOutput = neuronet.HiddenLayer.Calculate(x);
            var h      = hiddenLayerOutput.Zip(neuronet.HiddenLayer.Neurons, (t1, t2) => t1 * t2.W).ToList();
            var output = neuronet.HiddenLayer.CalculateWeightedSum(hiddenLayerOutput);

            return(output);
        }
Пример #2
0
        public void test2()
        {
            var hiddenNeuronCount = 50;
            var inputNeuronCount  = 2;

            var data = MeteoData.Read();

            var normalizedData = DataPreparated.NormalizedData(data);

            data = normalizedData.Data;

            var allDataSets = DataPreparated.GetLearningSets(data, inputNeuronCount);


            var learningDataSize = (int)(allDataSets.Count * 0.95);
            var testDataSize     = allDataSets.Count - learningDataSize;

            Pair <double[], double>[] learningData = new Pair <double[], double> [learningDataSize];
            Pair <double[], double>[] testData     = new Pair <double[], double> [testDataSize];

            Array.Copy(allDataSets.ToArray(), learningData, learningDataSize);
            Array.Copy(allDataSets.ToArray(), learningDataSize, testData, 0, testDataSize);


            var centers = DataPreparated.ExtractCenters(data, inputNeuronCount, hiddenNeuronCount);

            var nn = new HRBFNeuronet(hiddenNeuronCount, inputNeuronCount, centers.Select(t1 => t1.Item1).ToList());


            for (int i = 0; i < 6; i++)
            {
                var l1 = new Pair <double[], double> [31];
                Array.Copy(learningData, i * 31, l1, 0, 31);
                nn.Learning(l1.ToList(), 2500, 0.00002);
            }



            var d = learningData.Select(o => o.Item2).ToList();
            var y = testData.Select(o => nn.Calculate(o.Item1)).ToList();



            chart1.Series.Add("y");
            chart1.Series.Add("d");

            chart1.Series["y"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series["d"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            for (int i = 1; i < y.Count; i++)
            {
                chart1.Series["y"].Points.AddXY(i, y[i]);
                chart1.Series["d"].Points.AddXY(i, d[i]);
            }
        }
Пример #3
0
        private static double OneLearningIteration(HRBFNeuronet neuronet, double[] xSet, double d, double y, double learningCoef)
        {
            var error = y - d;

            var newW = neuronet.HiddenLayer.RecalculatedW(error, xSet, learningCoef, neuronet.HiddenLayer.ActivationW);
            var newC = neuronet.HiddenLayer.RecalculatedC(error, xSet, learningCoef);
            var newQ = neuronet.HiddenLayer.RecalculatedQ(error, xSet, learningCoef);

            neuronet.HiddenLayer.SetParams(newW, newC, newQ);

            return(error);
        }
Пример #4
0
        public static List <double> Learning(this HRBFNeuronet neuronet, List <Pair <double[], double> > learningSet, int epochCount, double learningCoef)
        {
            var errors = new List <double>();

            for (int epochInd = 0; epochInd < epochCount; epochInd++)
            {
                var xSet = learningSet[0].Item1.ToList();
                for (int learningSetInd = 0; learningSetInd < learningSet.Count; learningSetInd++)
                {
                    var y     = neuronet.Calculate(xSet.ToArray());
                    var error = OneLearningIteration(neuronet, xSet.ToArray(), learningSet[learningSetInd].Item2, y, learningCoef);
                    errors.Add(error);
                    xSet.RemoveAt(0);
                    xSet.Add(y);
                }
            }
            return(errors);
        }
Пример #5
0
        public void test2()
        {
            var hiddenNeuronCount = 5;
            var inputNeuronCount  = 5;

            var data = MeteoData.Read();

            data = DataPreparated.NormalizedData(data).Data;
            var testdata = DataPreparated.GetLearningSets(data, inputNeuronCount);
            var centers  = DataPreparated.ExtractCenters(data, inputNeuronCount, hiddenNeuronCount);


            var nn = new HRBFNeuronet(hiddenNeuronCount, inputNeuronCount, centers.Select(t1 => t1.Item1).ToList());

            nn.Learning(testdata, 200, 0.02);

            var d = testdata.Select(o => o.Item2).ToList();
            var y = testdata.Select(o => nn.Calculate(o.Item1)).ToList();

            var l = nn.Calculate(testdata[200].Item1);
        }