public void TrainDataSet()
        {
            do
            {
                _iterations++; _error = 0.0;
                _idx.Permute(DataSet.Size);

                for (int i = 0; i < DataSet.Size; i++)
                {
                    var input  = DataSet.Data[_idx[i]].Input;
                    var output = DataSet.Data[_idx[i]].Output;
                    _error += Network.Train(ref input,
                                            ref output,
                                            TrainingRate, Momentum);
                    DataSet.Data[_idx[i]].Input  = input;
                    DataSet.Data[_idx[i]].Output = output;
                }

                _errorHistory.Add(_error);

                if (_iterations % NudgeWindow == 0)
                {
                    CheckNudge();
                }

                IterationCompleted?.Invoke(this, new TrainingProgressReport(_iterations, _error));
            } while (_error > MaxError && _iterations < MaxIterations);
        }
Exemplo n.º 2
0
        public void CheckingPermutation()
        {
            var list = new List <int>()
            {
                1, 2, 3, 4, 5
            };
            var result = Permutator.Permute(list);

            Assert.True(result.Count == 120);
        }
Exemplo n.º 3
0
        public void CanPermute()
        {
            string str    = "ABC";
            int    n      = str.Length;
            var    result = Permutator.Permute(str);

            Assert.Equal(result, new[] {
                "ABC",
                "ACB",
                "BAC",
                "BCA",
                "CBA",
                "CAB"
            });
        }
Exemplo n.º 4
0
            public int FindShortestDistance(bool includePathBack)
            {
                var pathFinder  = new PathFinder();
                var points      = FindAllPoints();
                var permutatios = Permutator.Permute(points.Keys.ToArray());

                permutatios = permutatios.Where(p => p[0] == '0');

                // Remembering all the distances speed things up a bit...
                var knownDistances = new Dictionary <string, int>();

                var shortest = int.MaxValue;

                foreach (var permutation in permutatios)
                {
                    var    sum = 0;
                    char[] currentPermutation = permutation;
                    if (includePathBack)
                    {
                        currentPermutation = permutation.Concat(new[] { '0' }).ToArray();
                    }

                    for (int i = 0; i < currentPermutation.Length - 1; i++)
                    {
                        var key = "" + currentPermutation[i] + currentPermutation[i + 1];
                        if (!knownDistances.ContainsKey(key))
                        {
                            knownDistances.Add(key, pathFinder.FindShortestPath(
                                                   points[currentPermutation[i]],
                                                   points[currentPermutation[i + 1]],
                                                   NodeTypeAtPos));
                        }
                        sum += knownDistances[key];
                    }

                    shortest = Math.Min(shortest, sum);
                }

                return(shortest);
            }