예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        network = new Neural();
        network.learningRate = learningRate;

        ReadData();
    }
예제 #2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            neural = new Neural(INPUT, HIDDEN, OUTPUT);

            using (StreamReader reader = new StreamReader(inputWeightsFile))
            {
                INeuron[] inputNeuron = neural.InputNeurons;
                for (int i = 0; i < inputNeuron.Length; i++)
                {
                    double[] weights = new double[HIDDEN];
                    for (int j = 0; j < weights.Length; j++)
                    {
                        weights[j] = Convert.ToDouble(reader.ReadLine());
                    }
                    inputNeuron[i].LoadWeights(weights);
                }
            }

            using (StreamReader reader = new StreamReader(hiddenWeightsFile))
            {
                HNeuron[] hiddenNeuron = neural.HiddenNeurons;
                for (int i = 0; i < hiddenNeuron.Length; i++)
                {
                    double[] weights = new double[OUTPUT];
                    for (int j = 0; j < weights.Length; j++)
                    {
                        weights[j] = Convert.ToDouble(reader.ReadLine());
                    }
                    hiddenNeuron[i].LoadWeights(weights);
                }
            }

            MessageBox.Show("Weights Loaded!");
        }
예제 #3
0
    void FixedUpdate()
    {
        if (ballCtrl.GetPosition().y - diskCtrl.GetPosition().y < -5 ||
            Mathf.Abs(ballCtrl.GetPosition().x - diskCtrl.GetPosition().x) > 5 ||
            Mathf.Abs(ballCtrl.GetPosition().z - diskCtrl.GetPosition().z) > 5)
        {
            Restart();
        }
        switch (mode)
        {
        case EvaluationMode.Neural:
            OutputData neuralOutput = Neural.Evaluate(PrepareData());
            diskCtrl.SetAngularVelocity(FloatToVector3(neuralOutput.outputDiskRotationSpeedVector));
            break;

        case EvaluationMode.Fuzzy:
            OutputData fuzzyOutput = FuzzyLogic.Evaluate(PrepareData());
            //	fuzzyOutput.outputDiskRotationSpeedVector[2] = -fuzzyOutput.outputDiskRotationSpeedVector[2];
            diskCtrl.SetAngularVelocity(FloatToVector3(fuzzyOutput.outputDiskRotationSpeedVector));
            break;

            /*		case EvaluationMode.TrainNeural:
             *                      OutputData neuralOutputExp = new OutputData(Vector3ToFloat(diskCtrl.GetAngularVelocity()));
             *                      if (diskCtrl.GetAngularVelocity() != Vector3.zero)
             *                              Neural.Train(PrepareData(), neuralOutputExp);
             *                      break;*/
        }
    }
예제 #4
0
        public NeuralDemo()
        {
            InitializeComponent();
            neural = new Neural(INPUT, HIDDEN, OUTPUT);

            LoadXMLFiles();
            lblEpoch.Text    = string.Empty;
            lblCardName.Text = string.Empty;
        }
예제 #5
0
        public void Neuron_With_Valid_Testdata(double[] ws, double[] ins, double output)
        {
            Func <double, double> a0 = x => x;
            Func <double, double> a1 = x => x * 2;
            Func <double, double> a2 = x => x - 10;
            Func <double, double> a3 = x => x * x - x * 4 + 23;

            Assert.Equal(a0(output), Neural.Neuron(a0, ws, ins));
            Assert.Equal(a1(output), Neural.Neuron(a1, ws, ins));
            Assert.Equal(a2(output), Neural.Neuron(a2, ws, ins));
            Assert.Equal(a3(output), Neural.Neuron(a3, ws, ins));
        }
예제 #6
0
    public void BenchNeural()
    {
        NNetStruct t = new Neural();

        t.loops  = 1;
        t.adjust = 1;

        for (int i = 0; i < NeuralIterations; i++)
        {
            t.Run();
        }
    }
예제 #7
0
        public void FoldExpression_With_Testdata(double[] expressedGenes, uint[] config, int wsssLength)
        {
            double[][][] wsss = Neural.FoldExpression(expressedGenes, config);

            Assert.Equal(wsssLength, wsss.Length);
            for (int i = 0; i < wsssLength; i++)
            {
                Assert.Equal((int)config[i + 1], wsss[i].Length);
                for (int j = 0; j < wsss[i].Length; j++)
                {
                    Assert.Equal((int)config[i] + 1, wsss[i][j].Length);
                }
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            Learning.TrainingExample[] exs_pics = new Learning.TrainingExample[100];

            for (int i = 1; i <= 50; i++)
            {
                exs_pics[i - 1] = new Learning.TrainingExample(readImage(new Bitmap($"{string.Format("o{00:00}.bmp", i)}")).Select(b => (double)b).ToArray(), new double[] { 0, 1 });
            }

            for (int i = 1; i <= 50; i++)
            {
                exs_pics[i + 49] = new Learning.TrainingExample(readImage(new Bitmap($"{string.Format("x{00:00}.bmp", i)}")).Select(b => (double)b).ToArray(), new double[] { 1, 0 });
            }

            uint[] config = new uint[] { 16 * 16, 30, 4, 2 };

            //double[] solution = Learning.TrainNeuralNetworkRuleofTwo(exs_pics, config, Genetics.Hash, 1);
            double[] solution = Learning.TrainNeuralNetworkSelectiveBreeding(exs_pics, config, Genetics.Hash, 50);
            //double[] solution = Learning.TrainNeuralNetworkRoulette(exs_pics, config, Genetics.Hash, 1);

            double[][][] wsss   = Neural.FoldExpression(solution, config);
            double[]     cross  = Neural.Network(Neural.Sigmoid, wsss, readImage(new Bitmap("test01o.bmp")).Select(b => (double)b)).ToArray();
            double[]     circle = Neural.Network(Neural.Sigmoid, wsss, readImage(new Bitmap("test11x.bmp")).Select(b => (double)b)).ToArray();

            int nCorrects = 0;

            for (int i = 1; i <= 10; i++)
            {
                double[] outs = Neural.Network(Neural.Sigmoid, wsss, readImage(new Bitmap(string.Format("test{00:00}o.bmp", i))).Select(b => (double)b)).ToArray();
                Console.WriteLine($"TESTING CROSS\n\tProbability of cross: {outs[0]}, Probability of circle: {outs[1]}");
                if (outs[0] < outs[1])
                {
                    nCorrects++;
                }
            }
            for (int i = 11; i <= 20; i++)
            {
                double[] outs = Neural.Network(Neural.Sigmoid, wsss, readImage(new Bitmap(string.Format("test{00:00}x.bmp", i))).Select(b => (double)b)).ToArray();
                Console.WriteLine($"TESTING CIRCLE\n\tProbability of cross: {outs[0]}, Probability of circle: {outs[1]}");
                if (outs[0] > outs[1])
                {
                    nCorrects++;
                }
            }
            Console.WriteLine($"nCorrects={nCorrects}");
        }
    public NetworkPorts(Neural.Network network,
    IDictionary<int, IReceptiveField> upperNeurons,
    IDictionary<int, IReceptiveField> lowerNeurons,
    IDictionary<int, IReceptiveField> positionNeurons,
    IDictionary<int, IReceptiveField> speedNeurons
  )
    {
        this.network = network;

        this.input = new double[network.NeuronCount];
        this.output = new double[network.NeuronCount];

        UpperTheta = new NetworkInputPort(input, upperNeurons);
        LowerTheta = new NetworkInputPort(input, lowerNeurons);
        Position = new NetworkInputPort(input, positionNeurons);

        Speed = new NetworkSumOutputPort(output, speedNeurons);
    }
예제 #10
0
파일: Common.cs 프로젝트: ewgraf/HBMET
        //private double moduleValidation(double[] input, )
        //{
        //    double testQuality = 0.0;
        //    double validate = 0.0;
        //    double[] res;
        //    for (int count = 0; count < input.Length; count++)
        //    {
        //        res = network.Compute(input[count]);
        //        double value = Math.Abs(trainClasses[count] - classesList[ANNUtils.max(res)]);
        //        validate += value;
        //    }
        //    testQuality = (1 - (validate / input.Length)) * 100;
        //    return testQuality;
        //}
        //валидация по модулю
        internal static double AbsValidation(Neural.ActivationNetwork network, double[][] input, double[] trainClasses, List<int> classes)
        {
            double testQuality = 0.0;
            double validate = 0.0;
            double[] res;
            for (int count = 0; count < input.Length; count++)
            {
                res = network.Compute(input[count]);
                var a = Common.Max(res);
                var b = classes[Common.Max(res)];
                var c = trainClasses[count];
                double value = Math.Abs(trainClasses[count] - classes[Common.Max(res)]);

                validate += value;
            }
            testQuality = (1 - (validate / input.Length)) * 100;
            return testQuality;
        }
예제 #11
0
    public static void BenchNeural()
    {
        Setup();
        NNetStruct t = new Neural();

        t.loops  = 1;
        t.adjust = 1;

        foreach (var iteration in Benchmark.Iterations)
        {
            using (iteration.StartMeasurement())
            {
                for (int i = 0; i < NeuralIterations; i++)
                {
                    t.Run();
                }
            }
        }
    }
예제 #12
0
        public void IsJagged_With_Jagged_Testdata()
        {
            double[][] arrays0 = new double[][] {
                new double[] { },
                new double[] { 0 }
            };

            double[][] arrays1 = new double[][] {
                new double[] { 0, 0 },
                new double[] { 0 }
            };

            double[][] arrays2 = new double[][] {
                new double[] { 0, 0 },
                new double[] { 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0 },
                new double[] { 0, 0 }
            };

            double[][] arrays3 = new double[][] {
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0 }
            };

            double[][] arrays4 = new double[][] {
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 },
                new double[] { },
                new double[] { 0, 0, 0, 0 }
            };

            Assert.True(Neural.IsJagged(arrays0));
            Assert.True(Neural.IsJagged(arrays1));
            Assert.True(Neural.IsJagged(arrays2));
            Assert.True(Neural.IsJagged(arrays3));
            Assert.True(Neural.IsJagged(arrays4));
        }
예제 #13
0
    public void ChangeNet(bool next)
    {
        selectedNet += next ? 1 : -1;
        if (selectedNet < 0)
        {
            selectedNet = maxNet;
        }
        if (selectedNet > maxNet)
        {
            selectedNet = 0;
        }

        Neural.CreateNetwork(netsSizes[selectedNet], netsWeights[selectedNet]);
        nn = Neural.GetNetwork();

        netName.text = "Network Name\n" + netNames[selectedNet];
        for (int i = 0; i < 4; i++)
        {
            biasSliders[i].value = nn.GetLayers()[0].GetNodes()[i].bias;
        }
    }
예제 #14
0
        public void Network_With_Test_Data()
        {
            double[]     ins  = new double[] { 2.3, 4.8, 9.2 };
            double[][][] wsss = new double[][][] {
                new double[][] {
                    new double[] { 1.2, 0.8, 9.1, 2.9 },
                    new double[] { 9.3, 4.7, 8.3, 7.4 },
                    new double[] { 2.9, 3.8, 5.8, 9.2 }
                },
                new double[][] {
                    new double[] { 6.3, 5.6, 3.4, 4.3 },
                    new double[] { 3.4, 3.4, 5.6, 6.7 }
                }
            };

            Func <double, double> fa = x => x * x;
            Func <double, double> fb = x => x * 3;

            double n00a = fa(2.3 * 1.2 + 4.8 * 0.8 + 9.2 * 9.1 + 2.9);
            double n01a = fa(2.3 * 9.3 + 4.8 * 4.7 + 9.2 * 8.3 + 7.4);
            double n02a = fa(2.3 * 2.9 + 4.8 * 3.8 + 9.2 * 5.8 + 9.2);

            double n00b = fb(2.3 * 1.2 + 4.8 * 0.8 + 9.2 * 9.1 + 2.9);
            double n01b = fb(2.3 * 9.3 + 4.8 * 4.7 + 9.2 * 8.3 + 7.4);
            double n02b = fb(2.3 * 2.9 + 4.8 * 3.8 + 9.2 * 5.8 + 9.2);

            double n10a = fa(n00a * 6.3 + n01a * 5.6 + n02a * 3.4 + 4.3);
            double n11a = fa(n00a * 3.4 + n01a * 3.4 + n02a * 5.6 + 6.7);

            double n10b = fb(n00b * 6.3 + n01b * 5.6 + n02b * 3.4 + 4.3);
            double n11b = fb(n00b * 3.4 + n01b * 3.4 + n02b * 5.6 + 6.7);

            double[] outputa = new double[] { n10a, n11a };
            double[] outputb = new double[] { n10b, n11b };

            Assert.Equal(outputa, Neural.Network(fa, wsss, ins));
            Assert.Equal(outputb, Neural.Network(fb, wsss, ins));
        }
예제 #15
0
    public void Evolve(Neural from, float x)
    {
        for (int i = 0; i < Layer0; ++i)
        {
            bias0[i] = Random.Range(0.0f, 1.0f) < x ? from.bias0[i] : bias0[i];
        }
        for (int i = 0; i < Layer1; ++i)
        {
            bias1[i] = Random.Range(0.0f, 1.0f) < x ? from.bias1[i] : bias1[i];
        }
        for (int i = 0; i < Layer2; ++i)
        {
            bias2[i] = Random.Range(0.0f, 1.0f) < x ? from.bias2[i] : bias2[i];
        }

        for (int i = 0; i < Layer0 * Layer1; ++i)
        {
            weights10[i] = Random.Range(0.0f, 1.0f) < x ? from.weights10[i] : weights10[i];
        }
        for (int i = 0; i < Layer1 * Layer2; ++i)
        {
            weights21[i] = Random.Range(0.0f, 1.0f) < x ? from.weights21[i] : weights21[i];
        }
    }
예제 #16
0
    public void LerpTowards(Neural from, float x)
    {
        for (int i = 0; i < Layer0; ++i)
        {
            bias0[i] = Mathf.Lerp(bias0[i], from.bias0[i], x);
        }
        for (int i = 0; i < Layer1; ++i)
        {
            bias1[i] = Mathf.Lerp(bias1[i], from.bias1[i], x);
        }
        for (int i = 0; i < Layer2; ++i)
        {
            bias2[i] = Mathf.Lerp(bias2[i], from.bias2[i], x);
        }

        for (int i = 0; i < Layer0 * Layer1; ++i)
        {
            weights10[i] = Mathf.Lerp(weights10[i], from.weights10[i], x);
        }
        for (int i = 0; i < Layer1 * Layer2; ++i)
        {
            weights21[i] = Mathf.Lerp(weights21[i], from.weights21[i], x);
        }
    }
예제 #17
0
        public void Layer_With_Valid_TestData()
        {
            double[]   ins0    = new double[] { };
            double[][] wss0    = new double[][] { };
            double[]   output0 = new double[] { };

            double[]   ins1    = new double[] { 1, 29, 19, 4 };
            double[][] wss1    = new double[][] { new double[] { 23, 2, 3, 899 } };
            double[]   output1 = new double[] { 1 * 23 + 29 * 2 + 19 * 3 + 4 * 899 + 899 };

            double[]   ins2 = new double[] { -9, 3.4, 7, 8.94, 3 };
            double[][] wss2 = new double[][] {
                new double[] { 2.03, 9, 8, 40.9, 0.2, -3 },
                new double[] { 1.2, 1, -9, 8, 0, 1.2 },
                new double[] { -9, 2, 3.9, 2.8, -8, 9.2 },
                new double[] { 3.2, 8, 9, 2.3, 9, 8.29 }
            };
            double[] output2 = new double[] {
                -9 * 2.03 + 3.4 * 9 + 7 * 8 + 8.94 * 40.9 + 3 * 0.2 - 3,
                -9 * 1.2 + 3.4 * 1 - 7 * 9 + 8.94 * 8 + 3 * 0 + 1.2,
                9 * 9 + 3.4 * 2 + 7 * 3.9 + 8.94 * 2.8 - 3 * 8 + 9.2,
                -9 * 3.2 + 3.4 * 8 + 7 * 9 + 8.94 * 2.3 + 3 * 9 + 8.29
            };

            Assert.Equal(output0.Select(x => x).ToArray(), Neural.Layer(x => x, wss0, ins0));
            Assert.Equal(output1.Select(x => x).ToArray(), Neural.Layer(x => x, wss1, ins1));
            Assert.Equal(output2.Select(x => x).ToArray(), Neural.Layer(x => x, wss2, ins2));

            Assert.Equal(output0.Select(x => x * 5).ToArray(), Neural.Layer(x => x * 5, wss0, ins0));
            Assert.Equal(output1.Select(x => x * 5).ToArray(), Neural.Layer(x => x * 5, wss1, ins1));
            Assert.Equal(output2.Select(x => x * 5).ToArray(), Neural.Layer(x => x * 5, wss2, ins2));

            Assert.Equal(output0.Select(x => x * x + x - 10).ToArray(), Neural.Layer(x => x * x + x - 10, wss0, ins0));
            Assert.Equal(output1.Select(x => x * x + x - 10).ToArray(), Neural.Layer(x => x * x + x - 10, wss1, ins1));
            Assert.Equal(output2.Select(x => x * x + x - 10).ToArray(), Neural.Layer(x => x * x + x - 10, wss2, ins2));
        }
예제 #18
0
 public void Layer_With_Null_Arguments()
 {
     Assert.Throws <ArgumentNullException>(() => Neural.Layer(x => x, null, null));
     //Assert.Throws<ArgumentNullException>(() => Neural.Layer(x => x, new double[][] { }, null));
     Assert.Throws <ArgumentNullException>(() => Neural.Layer(x => x, null, new double[] { }));
 }
예제 #19
0
 public void BiasUpdate(int i)
 {
     selectedBias = i;
     Neural.SetWeight(0, selectedBias, Neural.GetNetwork().firstLayerSize, biasSliders[selectedBias].value);
 }
예제 #20
0
 private void InitData()
 {
     _trainDataSeries = new List<double>();
     _testDataSeries = new List<double>();
     _dataForTest = new List<double>();
     _dataForForecast = new List<double>();
     modelType = ModelType.SARIMA_ANN;
     isReadTrainData = false;
     isReadTestData = false;
     ARIMAModel = new ARIMA();
     NeuralModel = new Neural();
 }
예제 #21
0
		/// <summary>
		/// Update the given data reader without changing the data storage tag.
		/// </summary>
		/// <param name="name">The name of the data reader to update</param>
		/// <param name="reader">The data reader configuration</param>
		public void UpdateReader(Neural.Data.DataReader reader, string name) 
		{
			myManager.UpdateFile(name, reader);
		}
예제 #22
0
		/// <summary>
		/// Add a new data reader to the vault.
		/// </summary>
		/// <param name="name">The name of the network</param>
		/// <param name="reader">The data reader</param>
		/// <param name="tag">The storage tag for this network</param>
		public void AddNetwork(Neural.Data.DataReader reader, DataStorageTag tag, string name) 
		{
			myManager.AddObject(reader, tag, name);
		}
예제 #23
0
        private double[,] ConvertNeural(double datasize)
        {
            int
                iter = 0,
                i    = 0,
                j    = 0,
                k    = 0,
                l    = 0,
                Gen  = 0;

            char[]
            NeuralChar = Neural.ToCharArray();

            double
                DataSize = datasize;

            double[,]
            Components = new double[14, 10],
            NeuralData = new double[Convert.ToInt32(datasize), 10];

            while (iter < 14 && Gen < 300000)
            {
                for (i = 0; i < NeuralChar.Length; i++)
                {
                    if ((NeuralChar[i] == ':'))
                    {
                        NeuralChar[i] = ',';
                    }
                    if (iter == 13)
                    {
                        Gen++;
                        iter = 0;
                    }
                    if ((NeuralChar[i] == ','))
                    {
                        iter++;
                        //i++;
                        j = 0;
                    }
                    switch (iter)
                    {
                    case 0:
                        Components[0, j] = (int)Char.GetNumericValue(NeuralChar[i]);
                        j++;
                        break;

                    case 1:
                        Components[1, j] = (int)Char.GetNumericValue(NeuralChar[i]);
                        j++;
                        break;

                    case 2:
                        Components[2, j] = (int)Char.GetNumericValue(NeuralChar[i]);
                        j++;
                        break;

                    case 3:
                        F3[j]            = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[3, j] = F3[j];
                        j++;
                        break;

                    case 4:
                        F4[j]            = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[4, j] = F4[j];
                        j++;
                        break;

                    case 5:
                        F8[j]            = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[5, j] = F8[j];
                        j++;
                        break;

                    case 6:
                        FC5[j]           = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[6, j] = FC5[j];
                        j++;
                        break;

                    case 7:
                        FC6[j]           = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[7, j] = FC6[j];
                        j++;
                        break;

                    case 8:
                        T7[j]            = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[8, j] = T7[j];
                        j++;
                        break;

                    case 9:
                        T8[j]            = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[9, j] = T8[j];
                        j++;
                        break;

                    case 10:
                        P7[j]             = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[10, j] = P7[j];
                        j++;
                        break;

                    case 11:
                        P8[j]             = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[11, j] = P8[j];
                        j++;
                        break;

                    case 12:
                        O1[j]             = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[12, j] = O1[j];
                        j++;
                        break;

                    case 13:
                        O2[j]             = (int)Char.GetNumericValue(NeuralChar[i]);
                        Components[13, j] = O2[j];
                        j++;
                        break;
                    }
                    if (iter == 13)
                    {
                        l = j;
                        for (j = 0; ((j <= 13) && (Gen < 300000)); j++)
                        {
                            for (k = 0; (Components[j, k] != 0) || (k < 7); k++)
                            {
                                SortedData[0, Gen, j, k] = Components[j, k];
                            }
                        }
                        j = l;
                    }
                }
            }
            return(NeuralData);
        }
예제 #24
0
 public void InitNeural(NetworkParams serialized)
 {
     neural = new Neural(serialized);
 }
예제 #25
0
		/// <summary>
		/// Add result sets to the vault.
		/// </summary>
		/// <param name="data">The result set</param>
		/// <param name="name">The name of the result set</param>
		public void AddInputData(Neural.ResultSet data, string name) {
			manager.AddObject(data, name);
		}
예제 #26
0
    public static void BenchNeural()
    {
        Setup();
        NNetStruct t = new Neural();
        t.loops = 100;
        t.adjust = 0;

        foreach (var iteration in Benchmark.Iterations)
        {
            using (iteration.StartMeasurement())
            {
                for (int i = 0; i < NeuralIterations; i++) 
                {
                    t.Run();
                }
            }
        }
    }
예제 #27
0
        public void IsJagged_With_Nonjagged_Testdata()
        {
            double[][] arrays0 = new double[][] { };
            double[][] arrays1 = new double[][] {
                new double[] { }
            };

            double[][] arrays2 = new double[][] {
                new double[] { 0 }
            };

            double[][] arrays3 = new double[][] {
                new double[] { },
                new double[] { }
            };

            double[][] arrays4 = new double[][] {
                new double[] { 0, 0 },
                new double[] { 0, 0 }
            };

            double[][] arrays5 = new double[][] {
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 },
                new double[] { 0, 0, 0 }
            };

            double[][] arrays6 = new double[][] {
                new double[] { 0, 0 },
                new double[] { 0, 0 },
                new double[] { 0, 0 },
                new double[] { 0, 0 }
            };

            double[][] arrays7 = new double[][] {
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 },
                new double[] { 0, 0, 0, 0 }
            };

            double[][] arrays8 = new double[][] {
                new double[] { 0 },
                new double[] { 0 },
                new double[] { 0 },
                new double[] { 0 },
                new double[] { 0 }
            };

            Assert.False(Neural.IsJagged(arrays0));
            Assert.False(Neural.IsJagged(arrays1));
            Assert.False(Neural.IsJagged(arrays2));
            Assert.False(Neural.IsJagged(arrays3));
            Assert.False(Neural.IsJagged(arrays4));
            Assert.False(Neural.IsJagged(arrays5));
            Assert.False(Neural.IsJagged(arrays6));
            Assert.False(Neural.IsJagged(arrays7));
            Assert.False(Neural.IsJagged(arrays8));
        }
예제 #28
0
 public void Neuron_With_Null_Arguments(double[] ws, double[] ins)
 {
     Assert.Throws <ArgumentNullException>(() => Neural.Neuron(x => x, ws, ins));
 }
예제 #29
0
		/// <summary>
		/// Adds a result set to the vault with the given storage tag.
		/// </summary>
		/// <param name="data">The result set</param>
		/// <param name="name">The name of throws the result set</param>
		/// <param name="tag">The data storage tag</param>
		public void AddInputData(Neural.ResultSet data, DataStorageTag tag, string name) {
			manager.AddObject(data, tag, name);
		}
예제 #30
0
 public void InitNeural()
 {
     neural = new Neural(new int[] { 9, 7, 5, 4, 2 });
 }
예제 #31
0
        private void btnNetworkClear_Click(object sender, EventArgs e)
        {
            NeuralModel = new Neural();
            NeuralModel.SetData(_errorSeries);

            this.txtNumInput.Text = "";
            this.txtNumHidden.Text = "";
            this.txtNumInput.Enabled = true;
            this.txtNumHidden.Enabled = true;

            this.btnNetworkNew.Enabled = true;
            this.btnNetworkLoad.Enabled = true;
            this.btnNetworkSave.Enabled = false;
            this.btnNetworkClear.Enabled = false;

            this.btnTrainNeural.Enabled = false;
            this.btnTestNeural.Enabled = false;
            this.btnForecastNeural.Enabled = false;
        }
예제 #32
0
		/// <summary>
		/// Update the data set in the vault with the data and name.
		/// </summary>
		/// <param name="data">The result set</param>
		/// <param name="name">The name of the result set</param>
		public void UpdateDataSet(Neural.ResultSet data, string name) {
			manager.UpdateFile(name, data);
		}
예제 #33
0
        private void btnNetworkLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Title = "Load Network Config File";
            fileDialog.DefaultExt = "xml";
            DialogResult result = fileDialog.ShowDialog();
            string dataFile = "";
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                dataFile = fileDialog.FileName;
                Neural temp = Neural.Import(dataFile);
                if (temp == null)
                {
                    System.Windows.Forms.MessageBox.Show("The Input file is not correct format !!!", null, System.Windows.Forms.MessageBoxButtons.OK);
                }
                else
                {
                    NeuralModel = temp;
                    NeuralModel.SetData(_errorSeries);

                    this.txtNumInput.Text = NeuralModel.m_iNumInputNodes.ToString();
                    this.txtNumHidden.Text = NeuralModel.m_iNumHiddenNodes.ToString();
                    this.btnNetworkNew.Enabled = false;
                    this.btnNetworkLoad.Enabled = false;
                    this.btnNetworkSave.Enabled = true;
                    this.btnNetworkClear.Enabled = true;

                    this.btnTrainNeural.Enabled = true;
                    this.btnForecastNeural.Enabled = true;
                    this.btnTestNeural.Enabled = true;

                    this.btnForecast.Enabled = true;
                    this.btnTest.Enabled = true;
                }
            }
            else
                return;
        }
예제 #34
0
		/// <summary>
		/// Implements the listener interface and handles the end of epoch event.
		/// If ther number of training iterations is &gt; the maximum iterations
		/// value, then training is stopped.
		/// </summary>
		/// <param name="evt">The epoch end event</param>
		public void EpochEnd(Neural.TrainingEpochEvent evt) {
			// TODO Auto-generated method stub
			Trainer t = evt.Trainer;
			if(t.EpochCount >= maxIterations) {
				t.RequestTermination();
			}
		}
예제 #35
0
        private void btnNetworkNew_Click(object sender, EventArgs e)
        {
            string numInputs = this.txtNumInput.Text;
            string numHiddens = this.txtNumHidden.Text;
            string numOutputs = this.txtNumOutput.Text;

            if (numInputs == "" || numHiddens == "" || numOutputs == "")
            {
                System.Windows.Forms.MessageBox.Show("Please insert the number of Input Nodes, Hidden Nodes, Output Nodes", null, System.Windows.Forms.MessageBoxButtons.OK);
                return;
            }
            try
            {
                NeuralModel = new Neural(Int32.Parse(numInputs), Int32.Parse(numHiddens), Int32.Parse(numOutputs));
                NeuralModel.SetData(_errorSeries);
                System.Windows.Forms.MessageBox.Show("NetWork configuration successfull, You can train it");

                this.txtNumOutput.Enabled = false;
                this.txtNumHidden.Enabled = false;
                this.txtNumInput.Enabled = false;
                this.btnNetworkNew.Enabled = false;
                this.btnNetworkLoad.Enabled = false;
                this.btnNetworkSave.Enabled = true;
                this.btnNetworkClear.Enabled = true;

                this.btnTrainNeural.Enabled = true;
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show(exception.Message);
            }
        }
예제 #36
0
		/// <summary>
		/// Add a data reader to the vault, using the default data storage tag.
		/// </summary>
		/// <param name="name">The name of the network</param>
		/// <param name="reader">The data reader</param>
		public void AddNetwork(Neural.Data.DataReader reader, string name) 
		{
			myManager.AddObject(reader, name);
		}
예제 #37
0
 private void button1_Click(object sender, EventArgs e)
 {
     _errorSeries = _dataSeries.FindAll(item => true);
     NeuralModel = new Neural();
     NeuralModel.SetData(_errorSeries);
     btnNetworkNew.Enabled = true;
     btnNetworkLoad.Enabled = true;
     btnPlotNeural.Enabled = true;
     this.txtNumOutput.Enabled = false;
     this.txtNumHidden.Enabled = true;
     this.txtNumInput.Enabled = true;
 }
예제 #38
0
		/// <summary>
		/// Update the given data reader and the data storage tag.
		/// </summary>
		/// <param name="name">The name of the network</param>
		/// <param name="reader">The data reader configuration</param>
		/// <param name="tag">The storage tag to update</param>
		public void UpdateReader(Neural.Data.DataReader reader, DataStorageTag tag, string name) 
		{
			myManager.UpdateFile(reader, tag, name);
		}
예제 #39
0
 private void InitData()
 {
     _dataSeries = new List<double>();
     _errorSeries = new List<double>();
     ARIMAModel = new ARIMA();
     NeuralModel = new Neural();
 }
예제 #40
0
		/// <summary>
		/// Update the result set in the vault with the given storage tag.
		/// </summary>
		/// <param name="data">The result set</param>
		/// <param name="name">The name of the storage tag</param>
		/// <param name="tag">The data storage tag</param>
		public void UpdateDataSet(Neural.ResultSet data, DataStorageTag tag, string name) {
			manager.UpdateFile(data, tag, name);
		}
예제 #41
0
 public void NWeightsFromConfig_With_Testdata(uint[] config, uint length)
 {
     Assert.Equal(length, Neural.NWeightsFromConfig(config));
 }
예제 #42
0
        private void btnGetData_Click(object sender, EventArgs e)
        {
            _dataSeries = new List<double>();
            System.IO.StreamReader file = null;
            string line = null;
            bool isFormatFileRight = true;
            int beginRow = Convert.ToInt32(this.txtTrainDataFromRow.Text);
            int endRow = Convert.ToInt32(this.txtTrainDataToRow.Text);
            int columnSelected = Convert.ToInt32(this.txtTrainDataColumn.Text);
            int idxRow = 0;
            try
            {
                file = new System.IO.StreamReader(m_TrainingDataFile);
                while ((line = file.ReadLine()) != null)
                {
                    idxRow++;
                    if (idxRow < beginRow || idxRow > endRow)
                        continue;

                    char[] delimiterChars = { ' ', ',' };
                    List<String> words = new List<string>();
                    words.AddRange(line.Split(delimiterChars));
                    words.RemoveAll(item => "" == item);

                    if (columnSelected <= words.Count)
                    {
                        _dataSeries.Add(Double.Parse(words[columnSelected - 1]));
                    }
                    else
                    {
                        isFormatFileRight = false;
                        break;
                    }
                }
                if (!isFormatFileRight)
                {
                    MessageBox.Show("Input is wrong format", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _dataSeries = null;
                }
            }
            catch (System.OutOfMemoryException outOfMemory)
            {
                _dataSeries = null;
                MessageBox.Show("File does not found", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.IO.IOException io)
            {
                _dataSeries = null;
                MessageBox.Show("File does not found", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.Exception excp)
            {
                _dataSeries = null;
                MessageBox.Show("Input is wrong format", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (file != null)
                    file.Close();
            }

            if (_dataSeries != null)
            {
                SettingGetData();
                ARIMAModel = new ARIMA();
                NeuralModel = new Neural();
                ARIMAModel.SetData(_dataSeries);
            }
            else
            {
                MessageBox.Show("Load data fail", null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #43
0
        public void Validation_With_Valid_Testdata()
        {
            double[]     ins0  = new double[] { };
            double[][][] wsss0 = new double[][][] {
                new double[][] { new double[] { 0 } }
            };

            double[]     ins1  = new double[] { 0 };
            double[][][] wsss1 = new double[][][] {
                new double[][] { new double[] { 0, 0 } }
            };

            double[]     ins2  = new double[] { 0 };
            double[][][] wsss2 = new double[][][] {
                new double[][] {
                    new double[] { 0, 0 },
                    new double[] { 0, 0 }
                }
            };

            double[]     ins3  = new double[] { 0, 0 };
            double[][][] wsss3 = new double[][][] {
                new double[][] {
                    new double[] { 0, 0, 0 },
                    new double[] { 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0 },
                    new double[] { 0, 0, 0 },
                    new double[] { 0, 0, 0 },
                    new double[] { 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0, 0 }
                }
            };

            double[]     ins4  = new double[] { 0, 0, 0 };
            double[][][] wsss4 = new double[][][] {
                new double[][] {
                    new double[] { 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0 },
                    new double[] { 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0 },
                    new double[] { 0, 0 },
                    new double[] { 0, 0 },
                    new double[] { 0, 0 },
                    new double[] { 0, 0 },
                },
                new double[][] {
                    new double[] { 0, 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0, 0 }
                },
                new double[][] {
                    new double[] { 0, 0, 0, 0, 0 }
                }
            };

            Assert.True(Neural.Validation(wsss0, ins0));
            Assert.True(Neural.Validation(wsss1, ins1));
            Assert.True(Neural.Validation(wsss2, ins2));
            Assert.True(Neural.Validation(wsss3, ins3));
            Assert.True(Neural.Validation(wsss4, ins4));
        }