Ejemplo n.º 1
0
        void AnalyzeMaxMin()
        {
            // Find max-min value for each column
            analyzer = new MaxMinAnalyzer(Parameter.InputSize);
            double[]      input  = new double[Parameter.InputSize];
            DataSetReader reader = new DataSetReader(Parameter.TrainingFile,
                                                     Parameter.InputSize, Parameter.TargetSize);

            // Analyze training file.
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    analyzer.AnalyzeValue(i, input[i]);
                }
            }
            // Analyze testing file.
            reader = new DataSetReader(Parameter.TestingFile, Parameter.InputSize, Parameter.TargetSize);
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    analyzer.AnalyzeValue(i, input[i]);
                }
            }
        }
Ejemplo n.º 2
0
        public void Train()
        {
            // Read all training data and transforming them.
            trainingData = new DataSetReader(Parameter.TrainingFile,
                                             Parameter.InputSize, Parameter.TargetSize);
            double[][] data, target;
            trainingData.ReadAll(out data, out target);
            for (int i = 0; i < trainingData.Count; ++i)
            {
                // transform input level 1
                for (int j = 0; j < Parameter.InputSize; ++j)
                {
                    data[i][j] = inputTransformers1[j].TransformToValue(data[i][j]);
                }
                // transform input level 2
                data[i] = inputTransformers2.TransformToDimension(data[i]);

                // transform target
                target[i] = targetTransform.TransformToDimension(target[i]);
            }

            oldArtAWeights = new List <double[]>();
            bool isWeightsChanged = true, completedLimited = false;

            // Order input and target pattern before.
            if (param.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL ||
                param.Mode == ProcessModifiedHybridFuzzyARTMapMode.DUAL)
            {
                mcoa.OrderSequence(data, target);
            }
            do
            {
                SaveOldWeights();

                // Training ordered fuzzy art map
                if (param.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL)
                {
                    fartmap.Run(data, target);
                }
                else
                {
                    mfartmap.Run(data, target);
                }

                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                {
                    isWeightsChanged = false;
                }

                performanceCounter.Increment();

                if (param.LimitedEpochs != 0 &&
                    param.LimitedEpochs <= performanceCounter.Count)
                {
                    completedLimited = true;
                }
            }while (!completedLimited && isWeightsChanged);
        }
Ejemplo n.º 3
0
        public void Test()
        {
            testData = new DataSetReader(Parameter.TestingFile, Parameter.InputSize,
                                         Parameter.TargetSize);

            outputData = new DataSetWriter(Parameter.OutputFile, false,
                                           Parameter.InputSize, Parameter.TargetSize);

            double[] data1  = new double[Parameter.InputSize];   // Original data from dataset file.
            double[] data2  = new double[Parameter.InputSize];   // Temporaly transformed data (from data1).
            double[] target = new double[Parameter.TargetSize];
            double[] output = new double[1];
            while (testData.Read(data1, target))
            {
                // transform input level 1
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    data2[i] = inputTransformers1[i].TransformToValue(data1[i]);
                }
                // transform input level 2
                double[] dataInput = inputTransformers2.TransformToDimension(data2);

                if (Parameter.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL)
                {
                    fartmap.Run(dataInput);
                    output[0] = outputTransformers.TransformToValue(fartmap.Output);
                }
                else
                {
                    mfartmap.Run(dataInput);
                    output[0] = outputTransformers.TransformToValue(mfartmap.Output);
                }
                outputData.Write(data1, output, target);

                if (((int)output[0]) != 0)
                {
                    if (((int)output[0]) == ((int)target[0]))
                    {
                        performanceCounter.RightIncrement();
                    }
                    else
                    {
                        performanceCounter.WrongIncrement();
                    }
                }
                else
                {
                    performanceCounter.NonPredictIncrement();
                }
            }
            outputData.Close();
        }
Ejemplo n.º 4
0
        public void TestWrite()
        {
            double[] dataBuffer = new double[] { 1.5 , 2.399 , 3.1234, 4.0555, 5.01111 };
            double[] testBuffer = new double[] { 6.0 };

            DataSetWriter dwr = new DataSetWriter(FILENAME, false, 5, 1);
            for (int i = 0; i < 3; ++i)
            {
                dwr.Write(dataBuffer, testBuffer, testBuffer);
            }
            dwr.Close();

            DataSetReader dsr = new DataSetReader(FILENAME, 5, 1);
            for (;dsr.Read(dataBuffer, testBuffer);) ;

            Assert.AreEqual(3, dsr.Count);
        }
Ejemplo n.º 5
0
        public void TestRead()
        {
            DataSetReader dsr = new DataSetReader(FILENAME, DATA_SIZE, TEST_SIZE);

            int counter = 0;
            List<double[]> result = new List<double[]>();
            while (true)
            {
                // In testing, create new buffer for each iteration.
                double[] dataBuffer = new double[DATA_SIZE];
                double[] testBuffer = new double[TEST_SIZE];

                if (!dsr.Read(dataBuffer, testBuffer))
                    break;
                ++counter;
            }
               Assert.AreEqual(3, counter);
        }
Ejemplo n.º 6
0
        public void Train()
        {
            // Read all training data and transforming them.
            trainingData = new DataSetReader(Parameter.TrainingFile,
                                             Parameter.InputSize, Parameter.TargetSize);
            double[][] data, target;
            trainingData.ReadAll(out data, out target);
            for (int i = 0; i < trainingData.Count; ++i)
            {
                // transform input level 1
                for (int j = 0; j < Parameter.InputSize; ++j)
                {
                    data[i][j] = inputTransformers1[j].TransformToValue(data[i][j]);
                }
                // transform input level 2
                data[i] = inputTransformers2.TransformToDimension(data[i]);

                // transform target
                target[i] = targetTransform.TransformToDimension(target[i]);
            }

            oldArtAWeights = new List <double[]>();
            bool isWeightsChanged = true, completedLimited = false;

            do
            {
                SaveOldWeights();

                // Training ordered fuzzy art map
                network.Run(data, target);

                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                {
                    isWeightsChanged = false;
                }
                performanceCounter.Increment();
                if (parameter.LimitedEpochs != 0 &&
                    parameter.LimitedEpochs <= performanceCounter.Count)
                {
                    completedLimited = true;
                }
            }while (!completedLimited && isWeightsChanged);
        }
Ejemplo n.º 7
0
        public void TestReadValidData()
        {
            DataSetReader dsr = new DataSetReader(FILENAME, DATA_SIZE, TEST_SIZE);

            double[] dataBuffer = new double[DATA_SIZE];
            double[] testBuffer = new double[TEST_SIZE];
            bool success = dsr.Read(dataBuffer, testBuffer);

            Assert.IsTrue(success);

            double[] targetData = new double[] { 5.1000, 3.5000, 1.4000, 0.2000 };
            double[] targetTest = new double[] { 1 };

            Assert.AreEqual(targetData.Length, dataBuffer.Length);
            Assert.AreEqual(targetTest.Length, testBuffer.Length);
            for (int i = 0; i < targetData.Length; ++i)
                Assert.AreEqual(targetData[i], dataBuffer[i], "Mismatch read data at " + (i + 1));
            for (int i = 0; i < targetTest.Length; ++i)
                Assert.AreEqual(targetTest[i], testBuffer[i], "Mismatch read test at " + (i + 1));
        }
Ejemplo n.º 8
0
        void AnalyzeMaxMin()
        {
            // Find max-min value for each column
            analyzer = new MaxMinAnalyzer(Parameter.InputSize);
            double[]      input  = new double[Parameter.InputSize];
            DataSetReader reader = null;

            if (File.Exists(Parameter.TrainingFile))
            {
                reader = new DataSetReader(Parameter.TrainingFile,
                                           Parameter.InputSize, Parameter.TargetSize);
            }
            else if (File.Exists(Parameter.TestingFile))
            {
                reader = new DataSetReader(Parameter.TestingFile,
                                           parameter.InputSize, Parameter.TargetSize);
            }

            if (reader == null)
            {
                throw new ArgumentException("Process must have a trainging file or testing file.");
            }

            // Analyze training file.
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    analyzer.AnalyzeValue(i, input[i]);
                }
            }
            // Analyze testing file.
            reader = new DataSetReader(Parameter.TestingFile, Parameter.InputSize, Parameter.TargetSize);
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    analyzer.AnalyzeValue(i, input[i]);
                }
            }
        }
Ejemplo n.º 9
0
        public void Train()
        {
            oldArtAWeights = new List <double[]>();
            bool isWeightsChanged = true, completedLimited = false;

            do
            {
                SaveOldWeights();
                trainingData = new DataSetReader(Parameter.TrainingFile,
                                                 Parameter.InputSize, Parameter.TargetSize);
                double[] data   = new double[Parameter.InputSize];
                double[] target = new double[Parameter.TargetSize];
                while (trainingData.Read(data, target))
                {
                    // transform input level 1
                    for (int i = 0; i < Parameter.InputSize; i++)
                    {
                        data[i] = inputTransformers1[i].TransformToValue(data[i]);
                    }
                    // transform input level 2
                    double[] dataInput = inputTransformers2.TransformToDimension(data);

                    // transform target
                    double[] targetInput = targetTransform.TransformToDimension(target);

                    network.Run(dataInput, targetInput);
                }
                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                {
                    isWeightsChanged = false;
                }
                performanceCounter.Increment();
                if (parameter.LimitedEpochs != 0 &&
                    parameter.LimitedEpochs <= performanceCounter.Count)
                {
                    completedLimited = true;
                }
            }while (!completedLimited && isWeightsChanged);
        }
Ejemplo n.º 10
0
        public void Test()
        {
            Performance.Reset();

            testData = new DataSetReader(Parameter.TestingFile, Parameter.InputSize,
                                         Parameter.TargetSize);
            outputData = new DataSetWriter(Parameter.OutputFile, false,
                                           Parameter.InputSize, Parameter.TargetSize);

            double[] data1  = new double[Parameter.InputSize];   // Original data from dataset file.
            double[] data2  = new double[Parameter.InputSize];   // Temporaly transformed data (from data1).
            double[] target = new double[Parameter.TargetSize];
            double[] output = new double[1];
            while (testData.Read(data1, target))
            {
                // transform input level 1
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    data2[i] = inputTransformers1[i].TransformToValue(data1[i]);
                }
                // transform input level 2
                double[] dataInput = inputTransformers2.TransformToDimension(data2);

                network.Run(dataInput);
                output[0] = outputTransformers.TransformToValue(network.Output);
                outputData.Write(data1, output, target);

                if (Math.Round(output[0], 1) == Math.Round(target[0], 1))
                {
                    performanceCounter.RightIncrement();
                }
                else
                {
                    performanceCounter.WrongIncrement();
                }
            }
            outputData.Close();
        }
        public void Test()
        {
            testData = new DataSetReader(Parameter.TestingFile, Parameter.InputSize,
                Parameter.TargetSize);

            outputData = new DataSetWriter(Parameter.OutputFile, false,
                Parameter.InputSize, Parameter.TargetSize);

            double[] data1 = new double[Parameter.InputSize];    // Original data from dataset file.
            double[] data2 = new double[Parameter.InputSize];    // Temporaly transformed data (from data1).
            double[] target = new double[Parameter.TargetSize];
            double[] output = new double[1];
            while (testData.Read(data1, target))
            {
                // transform input level 1
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    data2[i] = inputTransformers1[i].TransformToValue(data1[i]);
                }
                // transform input level 2
                double[] dataInput = inputTransformers2.TransformToDimension(data2);

                if (Parameter.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL)
                {
                    fartmap.Run(dataInput);
                    output[0] = outputTransformers.TransformToValue(fartmap.Output);
                }
                else
                {
                    mfartmap.Run(dataInput);
                    output[0] = outputTransformers.TransformToValue(mfartmap.Output);
                }
                outputData.Write(data1, output, target);

                if (((int)output[0]) != 0)
                {
                    if (((int)output[0]) == ((int)target[0]))
                        performanceCounter.RightIncrement();
                    else
                        performanceCounter.WrongIncrement();
                }
                else
                {

                    performanceCounter.NonPredictIncrement();
                }
            }
            outputData.Close();
        }
Ejemplo n.º 12
0
        public void Train()
        {
            // Read all training data and transforming them.
            trainingData = new DataSetReader(Parameter.TrainingFile,
                Parameter.InputSize, Parameter.TargetSize);
            double[][] data, target;
            trainingData.ReadAll(out data, out target);
            for (int i = 0; i < trainingData.Count; ++i)
            {
                // transform input level 1
                for (int j = 0; j < Parameter.InputSize; ++j)
                {
                    data[i][j] = inputTransformers1[j].TransformToValue(data[i][j]);
                }
                // transform input level 2
                data[i] = inputTransformers2.TransformToDimension(data[i]);

                // transform target
                target[i] = targetTransform.TransformToDimension(target[i]);
            }

            oldArtAWeights = new List<double[]>();
            bool isWeightsChanged = true, completedLimited = false;
            do
            {
                SaveOldWeights();

                // Training ordered fuzzy art map
                network.Run(data, target);

                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                    isWeightsChanged = false;
                performanceCounter.Increment();
                if (parameter.LimitedEpochs != 0
                    && parameter.LimitedEpochs <= performanceCounter.Count)
                {
                    completedLimited = true;
                }
            }
            while (!completedLimited && isWeightsChanged);
        }
        public void Train()
        {
            // Read all training data and transforming them.
            trainingData = new DataSetReader(Parameter.TrainingFile,
                Parameter.InputSize, Parameter.TargetSize);
            double[][] data, target;
            trainingData.ReadAll(out data, out target);
            for (int i = 0; i < trainingData.Count; ++i)
            {
                // transform input level 1
                for (int j = 0; j < Parameter.InputSize; ++j)
                {
                    data[i][j] = inputTransformers1[j].TransformToValue(data[i][j]);
                }
                // transform input level 2
                data[i] = inputTransformers2.TransformToDimension(data[i]);

                // transform target
                target[i] = targetTransform.TransformToDimension(target[i]);
            }

            oldArtAWeights = new List<double[]>();
            bool isWeightsChanged = true, completedLimited = false;

            // Order input and target pattern before.
            if (param.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL ||
                    param.Mode == ProcessModifiedHybridFuzzyARTMapMode.DUAL)
            {
                mcoa.OrderSequence(data, target);
            }
            do
            {
                SaveOldWeights();

                // Training ordered fuzzy art map
                if (param.Mode == ProcessModifiedHybridFuzzyARTMapMode.EXTERNAL)
                {
                    fartmap.Run(data, target);
                }
                else
                {
                    mfartmap.Run(data, target);
                }

                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                {
                    isWeightsChanged = false;
                }

                performanceCounter.Increment();

                if (param.LimitedEpochs != 0
                    && param.LimitedEpochs <= performanceCounter.Count)
                {
                    completedLimited = true;
                }
            }
            while (!completedLimited && isWeightsChanged);
        }
 void AnalyzeMaxMin()
 {
     // Find max-min value for each column
     analyzer = new MaxMinAnalyzer(Parameter.InputSize);
     double[] input = new double[Parameter.InputSize];
     DataSetReader reader = new DataSetReader(Parameter.TrainingFile,
         Parameter.InputSize, Parameter.TargetSize);
     // Analyze training file.
     while (reader.Read(input, null))
     {
         for (int i = 0; i < Parameter.InputSize; i++)
             analyzer.AnalyzeValue(i, input[i]);
     }
     // Analyze testing file.
     reader = new DataSetReader(Parameter.TestingFile, Parameter.InputSize, Parameter.TargetSize);
     while (reader.Read(input, null))
     {
         for (int i = 0; i < Parameter.InputSize; i++)
             analyzer.AnalyzeValue(i, input[i]);
     }
 }
        void AnalyzeMaxMin()
        {
            // Find max-min value for each column
            analyzer = new MaxMinAnalyzer(Parameter.InputSize);
            double[] input = new double[Parameter.InputSize];
            DataSetReader reader = null;
            if (File.Exists(Parameter.TrainingFile))
            {
                reader = new DataSetReader(Parameter.TrainingFile,
                    Parameter.InputSize, Parameter.TargetSize);
            }
            else if (File.Exists(Parameter.TestingFile))
            {
                reader = new DataSetReader(Parameter.TestingFile,
                    parameter.InputSize, Parameter.TargetSize);
            }

            if (reader == null)
                throw new ArgumentException("Process must have a trainging file or testing file.");

            // Analyze training file.
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                    analyzer.AnalyzeValue(i, input[i]);
            }
            // Analyze testing file.
            reader = new DataSetReader(Parameter.TestingFile, Parameter.InputSize, Parameter.TargetSize);
            while (reader.Read(input, null))
            {
                for (int i = 0; i < Parameter.InputSize; i++)
                    analyzer.AnalyzeValue(i, input[i]);
            }
        }
        public void Train()
        {
            oldArtAWeights = new List<double[]>();
            bool isWeightsChanged = true, completedLimited = false;
            do
            {
                SaveOldWeights();
                trainingData = new DataSetReader(Parameter.TrainingFile,
                    Parameter.InputSize, Parameter.TargetSize);
                double[] data = new double[Parameter.InputSize];
                double[] target = new double[Parameter.TargetSize];
                while (trainingData.Read(data, target))
                {
                    // transform input level 1
                    for (int i = 0; i < Parameter.InputSize; i++)
                    {
                        data[i] = inputTransformers1[i].TransformToValue(data[i]);
                    }
                    // transform input level 2
                    double[] dataInput = inputTransformers2.TransformToDimension(data);

                    // transform target
                    double[] targetInput = targetTransform.TransformToDimension(target);

                    network.Run(dataInput, targetInput);
                }
                double mseValue = CalculateMse();
                if (mseValue < Parameter.LimitedMseValue)
                    isWeightsChanged = false;
                performanceCounter.Increment();
                if (parameter.LimitedEpochs != 0
                    && parameter.LimitedEpochs <= performanceCounter.Count)
                    completedLimited = true;
            }
            while (!completedLimited && isWeightsChanged);
        }
        public void Test()
        {
            Performance.Reset();

            testData = new DataSetReader(Parameter.TestingFile, Parameter.InputSize,
                Parameter.TargetSize);
            outputData = new DataSetWriter(Parameter.OutputFile, false,
                Parameter.InputSize, Parameter.TargetSize);

            double[] data1 = new double[Parameter.InputSize];    // Original data from dataset file.
            double[] data2 = new double[Parameter.InputSize];    // Temporaly transformed data (from data1).
            double[] target = new double[Parameter.TargetSize];
            double[] output = new double[1];
            while (testData.Read(data1, target))
            {
                // transform input level 1
                for (int i = 0; i < Parameter.InputSize; i++)
                {
                    data2[i] = inputTransformers1[i].TransformToValue(data1[i]);
                }
                // transform input level 2
                double[] dataInput = inputTransformers2.TransformToDimension(data2);

                network.Run(dataInput);
                output[0] = outputTransformers.TransformToValue(network.Output);
                outputData.Write(data1, output, target);

                if (Math.Round(output[0], 1) == Math.Round(target[0], 1))
                    performanceCounter.RightIncrement();
                else
                    performanceCounter.WrongIncrement();
            }
            outputData.Close();
        }