Esempio n. 1
0
        public static void PreparePredictor(ref NetworkContainer container, ref CountNetworkPredictSettings settings)
        {
            TestForErrors(ref settings);

            EncogWrapper.LoadNetworkFromFS(ref container, settings.trainedNetwork);

            List <ICSVFilter> baseFilters = new List <ICSVFilter>(1);
            ICSVFilter        quaternions = new CSVEvenColumnFilter();

            baseFilters.Add(quaternions);

            // Setup loader.
            CSVLoaderSettings CSVSettings = new CSVLoaderSettings
            {
                filePath = settings.predictData,
                trimUp   = 1,
                trimDown = 0,
                filters  = baseFilters
            };

            var data = CSVLoader <Vector3> .LoadData(ref CSVSettings);

            // Initialize CountBased Transformer settings.
            IntervalBasedTransformerSettings countSettings = new IntervalBasedTransformerSettings
            {
                sampleList = data,
                count      = settings.sampleCount
            };
            CountBasedTransformer countTransformer = new CountBasedTransformer();

            if (settings.predictSettings.threshold.Equals(null))
            {
                settings.predictSettings = new EncogPredictSettings
                {
                    threshold = 0.9
                };
            }

            settings.predictSettings.data = countTransformer.GetNeuralInput(countSettings);

            if (settings.predictSettings.data.Length != container.network.InputCount)
            {
                throw new NoNetworkMatchException("Sample count doesn't match network input count.");
            }
        }
        private static void ComputeData(
            uint networkInputSize,
            string inputDataDirectory,
            ref double[][] outputData,
            ref double[][] outputAnswers,
            double outputValue,
            int index)
        {
            DirectoryInfo inputDirectory = new DirectoryInfo(inputDataDirectory);

            foreach (var file in inputDirectory.GetFiles("*.csv"))
            {
                List <ICSVFilter> baseFilters = new List <ICSVFilter>(1);
                ICSVFilter        quaternions = new CSVEvenColumnFilter();
                baseFilters.Add(quaternions);

                // Setup loader.
                CSVLoaderSettings settings = new CSVLoaderSettings
                {
                    filePath = file.FullName,
                    trimUp   = 1,
                    trimDown = 0,
                    filters  = baseFilters
                };

                var data = CSVLoader <Vector3> .LoadData(ref settings);

                // Initialize CountBased Transformer settings.
                IntervalBasedTransformerSettings countSettings = new IntervalBasedTransformerSettings
                {
                    sampleList = data,
                    count      = networkInputSize
                };
                CountBasedTransformer countTransformer = new CountBasedTransformer();

                BaseTrainHelper.Project1DInto2D(
                    countTransformer.GetNeuralInput(countSettings),
                    ref outputData,
                    index);

                // Set answer to given value.
                outputAnswers[index] = new double[] { outputValue };
                index++;
            }
        }