Exemplo n.º 1
0
        public void LoadCSVFileTrainingClass()
        {
            var path    = parameters.TrainFile;
            var csvRead = new ReadCSV(new FileStream(path, FileMode.Open), true, CSVFormat.DecimalPoint);
            var values  = new List <double[]>();
            var classes = new List <double[]>();

            while (csvRead.Next())
            {
                values.Add(new double[2] {
                    csvRead.GetDouble(0), csvRead.GetDouble(1)
                });
                classes.Add(new double[1] {
                    csvRead.GetDouble(2)
                });
            }
            csvRead.Close();

            var min = parameters.FunctionType == FunctionTypeEnum.Unipolar ? 0d : -1d;

            ArgNormalize = new NormalizedField[2] {
                new NormalizedField(NormalizationAction.Normalize, "X", values.Max(v => v[0]), values.Min(v => v[0]), 1.0, min),
                new NormalizedField(NormalizationAction.Normalize, "Y", values.Max(v => v[1]), values.Min(v => v[1]), 1.0, min)
            };
            for (int i = 0; i < values.Count; i++)
            {
                for (int argc = 0; argc < values[i].Length; argc++)
                {
                    values[i][argc] = ArgNormalize[argc].Normalize(values[i][argc]);
                }
            }
            //Normalization(values);

            classCount = classes.Select(c => c[0]).Distinct().Count();
            var normalizeClasses = new List <double[]>();

            for (int i = 0; i < classes.Count; ++i)
            {
                var newClasses = new double[classCount];
                for (int j = 0; j < newClasses.Length; j++)
                {
                    newClasses[j] = min;
                }
                newClasses[(int)classes[i][0] - 1] = 1;// dodoac normalizacje na -1
                normalizeClasses.Add(newClasses);
            }

            var trainSetCount = (int)((double)values.Count * ((100.0 - 15) / 100));

            values.Shuffle();
            normalizeClasses.Shuffle();
            MyExtensions.ResetStableShuffle();

            TrainSet = new BasicNeuralDataSet(values.Take(trainSetCount).ToArray(),
                                              normalizeClasses.Take(trainSetCount).ToArray());
            ValidationSet = new BasicNeuralDataSet(values.Skip(trainSetCount).ToArray(),
                                                   normalizeClasses.Skip(trainSetCount).ToArray());
        }
        public PlanogramSimulation(BasicNetwork network, Item[] items, SimulationSettings simSettings)
        {
            slotNormalizer = new NormalizedField(NormalizationAction.Normalize, "Slot", (simSettings.NumSlots * simSettings.NumShelves) - 1, 0, -1, 1);
            itemNormalizer = new NormalizedField(NormalizationAction.Normalize, "Item", items.Length - 1, 0, -1, 1);

            this.items       = items;
            this.simSettings = simSettings;
            this.network     = network;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct the training generator.
        /// </summary>
        /// <param name="thePath">The path to use.</param>
        public GenerateTraining(string thePath)
        {
            _path         = thePath;
            _trainingFile = FileUtil.CombinePath(new FileInfo(_path), Config.FilenameTrain);

            _fieldDifference = new NormalizedField(NormalizationAction.Normalize, "diff", Config.DiffRange,
                                                   -Config.DiffRange, 1, -1);
            _fieldOutcome = new NormalizedField(NormalizationAction.Normalize, "out", Config.PipRange, -Config.PipRange,
                                                1, -1);
        }
Exemplo n.º 4
0
        public NeuralPilot(BasicNetwork network, bool track)
        {
            _fuelStats     = new NormalizedField(NormalizationAction.Normalize, "fuel", 200, 0, -0.9, 0.9);
            _altitudeStats = new NormalizedField(NormalizationAction.Normalize, "altitude", 10000, 0, -0.9, 0.9);
            _velocityStats = new NormalizedField(NormalizationAction.Normalize, "velocity",
                                                 LanderSimulator.TerminalVelocity, -LanderSimulator.TerminalVelocity,
                                                 -0.9, 0.9);

            _track   = track;
            _network = network;
        }
        public EncogMazeTraveler(BasicNetwork network, MazeInfo maze)
        {
            this.network = network;
            this.maze    = maze;

            // set normalized fields
            xInput = new NormalizedField(NormalizationAction.Normalize, "X", maze.Width - 1, 0, -0.9, 0.9);
            yInput = new NormalizedField(NormalizationAction.Normalize, "Y", maze.Height - 1, 0, -0.9, 0.9);
            bumpedIntoWallInput = new NormalizedField(NormalizationAction.Normalize, "BumpedIntoWall", 1, 0, -0.9, 0.9);
            directionOutput     = new NormalizedField(NormalizationAction.Normalize, "Direction", 3, 0, -0.9, 0.9);

            tmr.Elapsed += Tmr_Elapsed;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Construct the indicator.
        /// </summary>
        /// <param name="theMethod">The machine learning method to use.</param>
        /// <param name="thePath">The path to use.</param>
        public MyInd(IMLRegression theMethod, string thePath)
            : base(theMethod != null)
        {
            _method = theMethod;
            _path   = thePath;

            RequestData("CLOSE[1]");
            RequestData("SMA(10)[" + Config.InputWindow + "]");
            RequestData("SMA(25)[" + Config.InputWindow + "]");

            _fieldDifference = new NormalizedField(NormalizationAction.Normalize, "diff", Config.DiffRange,
                                                   -Config.DiffRange, 1, -1);
            _fieldOutcome = new NormalizedField(NormalizationAction.Normalize, "out", Config.PipRange, -Config.PipRange,
                                                1, -1);
        }
Exemplo n.º 7
0
        public void Execute(IExampleInterface app)
        {
            // Normalize values with an actual range of (0 to 100) to (-1 to 1)
            var norm = new NormalizedField(NormalizationAction.Normalize,
                                           null, 100, 0, 1, -1);

            double x = 5;
            double y = norm.Normalize(x);

            Console.WriteLine(x + @" normalized is " + y);

            double z = norm.DeNormalize(y);

            Console.WriteLine(y + @" denormalized is " + z);
        }
Exemplo n.º 8
0
        static void Normalization()
        {
            //Single value
            var    weightNorm        = new NormalizedField(NormalizationAction.Normalize, "Weights", ahigh: 40.0, alow: 50.0, nhigh: -1.0, nlow: 1.0);
            double normalizedValue   = weightNorm.Normalize(42.5);
            double denormalizedValue = weightNorm.DeNormalize(normalizedValue);

            //Array
            double[] weights     = new double[] { 40.0, 42.5, 43.0, 49.0, 50.0 };
            var      weightNorm2 = new NormalizeArray();

            weightNorm2.NormalizedHigh = 1.0;
            weightNorm2.NormalizedLow  = -1.0;
            double[] normalizedWeights = weightNorm2.Process(weights);
        }
Exemplo n.º 9
0
        public void LoadCSVFileTrainingRegg()
        {
            var path    = parameters.TrainFile;
            var csvRead = new ReadCSV(new FileStream(path, FileMode.Open), true, CSVFormat.DecimalPoint);
            var valuesX = new List <double[]>();
            var valuesY = new List <double[]>();

            while (csvRead.Next())
            {
                valuesX.Add(new double[1] {
                    csvRead.GetDouble(0)
                });
                valuesY.Add(new double[1] {
                    csvRead.GetDouble(1)
                });
            }
            csvRead.Close();

            var min = parameters.FunctionType == FunctionTypeEnum.Unipolar ? 0d : -1d;

            ArgNormalize = new NormalizedField[] { new NormalizedField(NormalizationAction.Normalize, "X", valuesX.Max(v => v[0]), valuesX.Min(v => v[0]), 1.0, min) };
            YNormalize   = new NormalizedField(NormalizationAction.Normalize, "Y", valuesY.Max(v => v[0]), valuesY.Min(v => v[0]), 1.0, min);
            for (int i = 0; i < valuesX.Count; i++)
            {
                valuesX[i][0] = ArgNormalize[0].Normalize(valuesX[i][0]);
                valuesY[i][0] = YNormalize.Normalize(valuesY[i][0]);
            }
            //if(parameters.FunctionType==FunctionTypeEnum.Bipolar)
            //        ansMeans = means[0];
            //ansfactor = factor[0];

            //ansMIn = Min[0];
            var trainSetCount = (int)((double)valuesX.Count * ((100.0 - 15) / 100));

            valuesX.Shuffle();
            valuesY.Shuffle();
            MyExtensions.ResetStableShuffle();

            TrainSet = new BasicNeuralDataSet(valuesX.Take(trainSetCount).ToArray(),
                                              valuesY.Take(trainSetCount).ToArray());
            ValidationSet = new BasicNeuralDataSet(valuesX.Skip(trainSetCount).ToArray(),
                                                   valuesY.Skip(trainSetCount).ToArray());
        }
Exemplo n.º 10
0
        public static double[][] GetValues <T>(this IList <IParamDefinition <T> > @params, IList <T> dataSource)
        {
            double[][] input = new double[dataSource.Count][];

            for (int col = 0; col < @params.Count; col++)
            {
                NormalizedField _normalizedParam = new NormalizedField(NormalizationAction.Normalize,
                                                                       "Weights", @params[col].MaxValue, @params[col].MinValue, 1.0, -1.0);

                for (int row = 0; row < dataSource.Count; row++)
                {
                    if (col == 0)
                    {
                        input[row] = new double[@params.Count];
                    }
                    input[row][col] = Normalization.Normalize(@params[col].GetValue(dataSource[row], dataSource), _normalizedParam);
                }
            }
            return(input);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Normalize the array. Return the new normalized array.
        /// </summary>
        ///
        /// <param name="inputArray">The input array.</param>
        /// <returns>The normalized array.</returns>
        public double[] Process(double[] inputArray)
        {
            _stats = new NormalizedField();
            _stats.NormalizedHigh = _normalizedHigh;
            _stats.NormalizedLow  = _normalizedLow;

            foreach (double element in inputArray)
            {
                _stats.Analyze(element);
            }

            var result = new double[inputArray.Length];

            for (int i = 0; i < inputArray.Length; i++)
            {
                result[i] = _stats.Normalize(inputArray[i]);
            }

            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Normalize the array. Return the new normalized array.
        /// </summary>
        /// <param name="inputArray">The input array.</param>
        /// <param name="low">The low of the normalized array.</param>
        /// <param name="high">The high of the normalized array..</param>
        /// <returns>
        /// The normalized array.
        /// </returns>
        public double[] Process(double[] inputArray, int low, int high)
        {
            this.NormalizedHigh = high;
            this.NormalizedLow = low;
            _stats = new NormalizedField();
            _stats.NormalizedHigh = high;
            _stats.NormalizedLow = low;
            foreach (double element in inputArray)
            {
                _stats.Analyze(element);
            }

            var result = new double[inputArray.Length];

            for (int i = 0; i < inputArray.Length; i++)
            {
                result[i] = _stats.Normalize(inputArray[i]);
            }

            return result;
        }
Exemplo n.º 13
0
 public static void initalize()
 {
     location = new NormalizedField(NormalizationAction.Normalize, "Location", -800, 800, -0.9, 0.9);
     speed    = new NormalizedField(NormalizationAction.Normalize, "Speed", -10, 10, -0.9, 0.9);
 }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            double error = 0.00001;

            double[][] XOR_Input =
            {
                new[] { 0.0, 0.0 },
                new[] { 1.0, 0.0 },
                new[] { 0.0, 1.0 },
                new[] { 1.0, 1.0 }
            };

            double[][] XOR_Ideal =
            {
                new[] { 0.0 },
                new[] { 1.0 },
                new[] { 1.0 },
                new[] { 0.0 }
            };

            var trainingSet = new BasicMLDataSet(XOR_Input, XOR_Ideal);

            BasicNetwork network = CreateNetwork();

            //var train = new Backpropagation(network, trainingSet, 0.7, 0.2);
            //var train = new ManhattanPropagation(network, trainingSet, 0.001);
            // var train = new QuickPropagation(network, trainingSet, 2.0);
            //var train = new ResilientPropagation(network, trainingSet);
            //var train = new ScaledConjugateGradient(network, trainingSet);
            var train = new LevenbergMarquardtTraining(network, trainingSet);

            int epoch = 0;

            do
            {
                train.Iteration();
                Console.WriteLine("Iteration No: {0}, Error: {1}", ++epoch, train.Error);
            }while (train.Error > error);

            foreach (var item in trainingSet)
            {
                var output = network.Compute(item.Input);
                Console.WriteLine("Input: {0}, {1} \tIdeal: {2} \t Actual: {3}", item.Input[0], item.Input[1], item.Ideal[0], output[0]);
            }

            Console.WriteLine("Training done.");
            Console.WriteLine("press any key to continue");
            Console.ReadLine();

            // normalized value
            var weightNorm = new NormalizedField(NormalizationAction.Normalize, "Weights", 50.0, 40.0, 1.0, -1.0);

            double normalizedValue   = weightNorm.Normalize(42.5);
            double denormalizedValue = weightNorm.DeNormalize(normalizedValue);

            Console.WriteLine("Normalized value: {0}", normalizedValue.ToString());
            Console.WriteLine("press any key to continue");
            Console.ReadLine();

            // normalized array
            double[] weights         = new double[] { 40.0, 42.5, 43.0, 49.0, 50.0 };
            var      weightNormArray = new NormalizeArray();

            weightNormArray.NormalizedHigh = 1.0;
            weightNormArray.NormalizedLow  = -1.0;
            double[] normalizedWeights = weightNormArray.Process(weights);

            foreach (var item in normalizedWeights)
            {
                Console.WriteLine("Normalized value: {0}", item.ToString());
            }
            Console.WriteLine("press any key to continue");
            Console.ReadLine();
        }
Exemplo n.º 15
0
 public static double Normalize(double value, NormalizedField field)
 {
     return(field.Normalize(value));
 }
Exemplo n.º 16
0
 public SnakeGame()
 {
     location = new NormalizedField(NormalizationAction.Normalize, "Location", 600, 0, -0.9, 0.9);
     speed    = new NormalizedField(NormalizationAction.Normalize, "Speed", 20, -20, -0.9, 0.9);
 }