Ejemplo n.º 1
0
        public void Experiment3()
        {
            String filename = "Function3";
            StringBuilder expected = new StringBuilder();
            StringBuilder result = new StringBuilder();

            int fuzzySetsCount = 10;

            Range range = new Range(-5, 5);
            IFunction function = FunctionsHelper.GetConcreteFunction(FunNumber.F3);
            List<FuzzySet> fuzzySets = FuzzySet.coverRangeWithFuzzySets(range, fuzzySetsCount);

            SimpleFuzzyRules3D fuzzyRules = new SimpleFuzzyRules3D(generateRandom2DPoints(range, RANDOM_POINTS_COUNT), function, fuzzySets);

            double[][] testPoints = generateRandom2DPoints(range, RANDOM_POINTS_COUNT);

            foreach (double[] xs in testPoints)
            {
                double output = fuzzyRules.getOutput(xs);

            //			Console.WriteLine(String.format("f(" + Arrays.toString(xs) + ") = %.2f, expected %.2f", output, function.evaluate(xs)));

                expected.Append(StringUtils.Join(xs, " ") + " " + output + "\n");
                result.Append(StringUtils.Join(xs, " ") + " " + function.evaluate(xs) + "\n");
            }

            // Save results to files.
            FileManagement.WriteToFile(outputDirectory + "//fuzzy_" + filename + "_expected.dat", expected.ToString());
            FileManagement.WriteToFile(outputDirectory + "//fuzzy_" + filename + "_result.dat", result.ToString());

            double error = fuzzyRules.getError(testPoints);
            Console.WriteLine("Error = " + error);
        }
Ejemplo n.º 2
0
        public void Experiment3()
        {
            Range range = new Range(-5, 5);
            double[][] testPoints = generateRandom2DPoints(range, RANDOM_POINTS_COUNT);

            IFunction function = FunctionsHelper.GetConcreteFunction(FunNumber.F3);
            NeuroBackPropagation backPropagation = new NeuroBackPropagation(generateRandom2DPoints(range, RANDOM_POINTS_COUNT), function);

            WriteResults(function, backPropagation, testPoints, "Function3");
        }
Ejemplo n.º 3
0
 private double[][] generateRandom2DPoints(Range range, int randomPointsCount)
 {
     double[] xs = generateRandomPoints(range, randomPointsCount);
     double[] ys = generateRandomPoints(range, randomPointsCount, false);
     double[][] result = new double[randomPointsCount][];
     for (int i = 0; i < xs.Length; i++)
     {
         result[i] = new double[] { xs[i], ys[i] };
     }
     return result;
 }
Ejemplo n.º 4
0
        public static List<FuzzySet> coverRangeWithFuzzySets(Range range, int fuzzySetsCount)
        {
            double halfFuzzySetWidth = range.getWidth() / (fuzzySetsCount - 1);

            List<FuzzySet> fuzzySets = new List<FuzzySet>();

            fuzzySets.Add(new FuzzySet(Double.NegativeInfinity, range.getBegin(), range.getBegin() + halfFuzzySetWidth));

            for (double a = range.getBegin(); a + 2 * halfFuzzySetWidth <= range.getEnd();
                    a += halfFuzzySetWidth)
            {
                double b = a + halfFuzzySetWidth;
                double c = b + halfFuzzySetWidth;
                fuzzySets.Add(new FuzzySet(a, b, c));
            }

            fuzzySets.Add(new FuzzySet(range.getEnd() - halfFuzzySetWidth, range.getEnd(), Double.PositiveInfinity));

            return fuzzySets;
        }
Ejemplo n.º 5
0
 private double[] generateRandomPoints(Range range, int randomPointsCount, bool sort)
 {
     double[] randomPoints = new double[randomPointsCount];
     for (int i = 0; i < randomPoints.Length; i++)
     {
         randomPoints[i] = randomPoint(range);
     }
     if (sort)
     {
         Array.Sort(randomPoints);
     }
     return randomPoints;
 }
Ejemplo n.º 6
0
 private double[] generateRandomPoints(Range range, int randomPointsCount)
 {
     return generateRandomPoints(range, randomPointsCount, true);
 }
Ejemplo n.º 7
0
 public void testOneDimensionalFunction(IFunction function, Range range, String filename)
 {
     NeuroBackPropagation backPropagation = new NeuroBackPropagation(to2DArray(generateRandomPoints(range, RANDOM_POINTS_COUNT)), function);
     double[][] testPoints = to2DArray(generateRandomPoints(range, RANDOM_POINTS_COUNT));
     WriteResults(function, backPropagation, testPoints, filename);
 }
Ejemplo n.º 8
0
 private double randomPoint(Range range)
 {
     return range.getBegin() + (random.NextDouble() * range.getWidth());
 }
Ejemplo n.º 9
0
        private void testOneDimensionalFunction(IFunction function, Range range, String filename)
        {
            double[][] testPoints = to2DArray(generateRandomPoints(range, RANDOM_POINTS_COUNT));

            List<FuzzySet> fuzzySets = FuzzySet.coverRangeWithFuzzySets(range, FUZZY_SETS_COUNT);
            SimpleFuzzyRules fuzzyRules = new SimpleFuzzyRules(to2DArray(generateRandomPoints(range, RANDOM_POINTS_COUNT)), function, fuzzySets);

            WriteResults(function, fuzzyRules, testPoints, filename);
        }