示例#1
0
        private void Start()
        {
            _process.Start();

            int count = 0;

            while (_isRunning)
            {
                using (var reader = _process.StandardOutput)
                {
                    var files = Directory.GetFiles($@"{AppDomain.CurrentDomain.BaseDirectory}script\output");

                    while (!reader.EndOfStream)
                    {
                        ConsolePrint?.Invoke(reader.ReadLine(), null);
                    }


                    if (count != files.Length)
                    {
                        count = files.Length;
                        EpochResult?.Invoke(this, null);
                    }
                }
                Thread.Sleep(TimeSpan.FromMinutes(1));
            }
        }
示例#2
0
 public void OnEpochFinished(EpochResult result)
 {
     _loss     = 0;
     _accuracy = 0;
     _elapsed  = 0;
 }
        private EpochResult Backpropagate(IReadOnlyCollection <IDataWindow> trainingData)
        {
            var output = new EpochResult();
            var correctClassifications = 0;

            var costs = new List <float>();

            var n1Costs = new List <float>();
            var n2Costs = new List <float>();

            var n1S = new List <float>();
            var n2S = new List <float>();



            //create adjustment neurons
            for (var layer = 1; layer < Options.LayerStructure.Length; layer++)
            {
                for (var neuron = 0; neuron < Options.LayerStructure[layer]; neuron++)
                {
                    _proposedNeurons[layer, neuron] =
                        new ProposedNeuron(NeuronLayers[layer, neuron].Weights.Length, trainingData.Count);
                }
            }

            // for window
            foreach (var window in trainingData)
            {
                //get activation
                CreateActivationArray(window);
                FillActivationArray();

                var n1   = _exampleActivations[Options.LayerStructure.Length - 1, 0];
                var diff = n1 - window.OutputLayer[0];
                if (Math.Abs(diff) > 0.5F)
                {
                    correctClassifications++;
                }

                n1S.Add(_exampleActivations[Options.LayerStructure.Length - 1, 0]);
                n2S.Add(_exampleActivations[Options.LayerStructure.Length - 1, 1]);

                //calculate offset
                // var offset = _exampleActivations[_exampleActivations.GetLength(0) - 1, 0] - window.OutputLayer[0];
                // offset *= offset < 0 ? -1 : 1; //if less than 0 times with -1
                // successes.Add(offset < 0.5F);

                //get cost
                ResetExampleCostArray();
                FillExampleCostArray(window.OutputLayer);
                costs.Add(_exampleCosts[Options.LayerStructure.Length - 1, 0] + _exampleCosts[Options.LayerStructure.Length - 1, 1]);

                n1Costs.Add(_exampleCosts[Options.LayerStructure.Length - 1, 0]);
                n2Costs.Add(_exampleCosts[Options.LayerStructure.Length - 1, 1]);

                // n1S.Add(_exampleActivations[Options.LayerStructure.Length-1, 0]);
                // n2S.Add(_exampleActivations[Options.LayerStructure.Length-1, 1]);

                //for each neuron
                for (var layer = 1; layer < Options.LayerStructure.Length; layer++)
                {
                    for (var neuron = 0; neuron < Options.LayerStructure[layer]; neuron++)
                    {
                        //get adjustments
                        var neuronCost = _exampleCosts[layer, neuron];

                        var biasAdjustment = NeuronLayers[layer, neuron]
                                             .GetBiasAdjust(_exampleActivations, neuronCost);

                        var weightAdjustment = NeuronLayers[layer, neuron]
                                               .GetWeightAdjust(_exampleActivations, neuronCost);

                        //set adjustment

                        _proposedNeurons[layer, neuron].AddBiasProposal(biasAdjustment);
                        _proposedNeurons[layer, neuron].AddWeightProposal(weightAdjustment);
                    }
                }
            }

            //after for
            //make adjustment

            for (var layer = 1; layer < Options.LayerStructure.Length; layer++)
            {
                for (var neuron = 0; neuron < Options.LayerStructure[layer]; neuron++)
                {
                    NeuronLayers[layer, neuron].Adjust(_proposedNeurons[layer, neuron], Options.LearningRate);
                }
            }

            //var accuracy = (float)successes.Count(x => x) / trainingData.Count;

            //output.AverageOffset = accuracy;
            //output.AverageOffset = _exampleCosts[Options.LayerStructure.Length - 1, 0];

            var totalCost = costs.Sum();

            output.AverageOffset = totalCost / costs.Count;

            output.AverageCost = new NeuronPairing(n1Costs.Average(), n2Costs.Average());

            output.Accuracy = (float)correctClassifications / trainingData.Count;

            output.AverageOutputLayerActivation = new NeuronPairing(n1S.Average(), n2S.Average());
            return(output);
        }
示例#4
0
 protected void RaiseEpochFinishedEvent(EpochResult result)
 {
     OnEpochFinished?.Invoke(result);
 }