// Prepare input data for prediction.
        public static void PreparePredictor(ref NetworkContainer container, ref ImageNetworkPredictSettings 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 image Transformer.
            ImageTransformerSettings imageSettings = new ImageTransformerSettings
            {
                focusJoints = (LeapMotionJoint[])Enum.GetValues(typeof(LeapMotionJoint)),
                samples     = data,
                size        = settings.imgSize
            };
            ImageTransformer imageTransformer = new ImageTransformer();


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

            settings.predictSettings.data = imageTransformer.GetNeuralInput(imageSettings);

            if (settings.predictSettings.data.Length != container.network.InputCount)
            {
                throw new NoNetworkMatchException("Sample count doesn't match network input count.");
            }
        }
Ejemplo n.º 2
0
        // Convert data from a CSV file to the actual input array for the network.
        private static void ComputeData(
            uint sampleCount,
            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 image Transformer.
                ImageTransformerSettings imageSettings = new ImageTransformerSettings
                {
                    focusJoints = (LeapMotionJoint[])Enum.GetValues(typeof(LeapMotionJoint)),
                    samples     = data,
                    size        = sampleCount
                };
                ImageTransformer imageTransformer = new ImageTransformer();

                BaseTrainHelper.Project1DInto2D(
                    imageTransformer.GetNeuralInput(imageSettings),
                    ref outputData,
                    index);

                // Set answer to given value.
                outputAnswers[index] = new double[] { outputValue };
                index++;
            }
        }
Ejemplo n.º 3
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++;
            }
        }