Ejemplo n.º 1
0
        public NeuralTyresEntry Conjure(params double[] input)
        {
            var name      = Sources.Select(x => x.Name).GroupBy(x => x).MaxEntry(x => x.Count()).Key;
            var shortName = Sources.Select(x => x.ShortName).GroupBy(x => x).MaxEntry(x => x.Count()).Key;
            var result    = new NeuralTyresEntry(name, shortName, TyresVersion);

            SetInputs(input, result);

            if (_singleNetwork != null)
            {
                var data = _singleNetwork.Compute(input);
                if (data.Length != _outputKeys.Length)
                {
                    throw new Exception($"Amount of computed data doesn’t match output keys: {data.Length}≠{_outputKeys.Length}");
                }

                for (var i = 0; i < _outputKeys.Length; i++)
                {
                    SetValue(result, _outputKeys[i], _outputNormalizations[i].Denormalize(data[i]));
                }
            }
            else if (_networks != null)
            {
                for (var i = 0; i < _networks.Length; i++)
                {
                    SetValue(result, _outputKeys[i], _outputNormalizations[i].Denormalize(_networks[i].Compute(input)[0]));
                }
            }
            else
            {
                throw new Exception("Invalid state");
            }

            return(result);
        }
Ejemplo n.º 2
0
        public void Learn(INeuralNetwork net, ILearningSequence<ISupervisedLearningVector> seq)
        {
            LearningStory = new List<NeuronState>();
            bool isLearned = true;

            do
            {
                StoreState(net);
                isLearned = true;
                IEnumerator<ISupervisedLearningVector> en = seq.Vectors.GetEnumerator();
                while (en.MoveNext())
                {
                    net.SetInput(en.Current.Data);

                    net.Compute();

                    double delta = en.Current.CorrectOutput - net[0];
                    if (delta != 0.0)
                    {
                        isLearned = false;
                        CorrectWeights(net, delta > 0 ? 1.0 : -1.0);
                    }

                }
                seq.Shuffle();

            } while (!isLearned);
            StoreState(net);
        }
Ejemplo n.º 3
0
        public void Learn(INeuralNetwork net, ILearningSequence<ISupervisedLearningVector> seq)
        {
            LearningStory = new List<NeuronState>();

            bool isLearned = true;
            int counter = 0;
            do
            {
                StoreState(net);
                isLearned = true;
                IEnumerator<ISupervisedLearningVector> en = seq.Vectors.GetEnumerator();
                while (en.MoveNext())
                {
                    net.SetInput(en.Current.Data);
                    net.Compute();
                    CorrectWeights(net, en.Current.CorrectOutput - net.Layers[1][0].Potential);
                }

                en.Reset();

                while (en.MoveNext())
                {
                    net.SetInput(en.Current.Data);

                    net.Compute();

                    if (Math.Abs(en.Current.CorrectOutput - net[0]) > Epsilon)
                    {
                        isLearned = false;
                        break;
                    }
                }
                seq.Shuffle();
                counter++;
            } while (!isLearned && counter < EpochLimit);
            StoreState(net);
            Failed = !isLearned;
        }
Ejemplo n.º 4
0
 public List <float> Compute(List <float> inputs)
 {
     return(neuralNetwork.Compute(inputs));
 }