Exemple #1
0
        public void Algorithm01TestFromPublication()
        {
            var table = new FuzzyTable();

            output.WriteLine("Algorithm01TestFromPublication STARTED");
            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("../../../Algorithms/tests/test.txt"))
                {
                    String  json  = sr.ReadToEnd();
                    dynamic array = JsonConvert.DeserializeObject(json);
                    // Console.WriteLine(array.attributes);
                    Assert.True(true);
                    var aa = array.attributes;
                    for (int i = 0; i < array.attributes.Count - 1; i++)
                    {
                        table.addAttribute(array.attributes[i]);
                    }
                    table.addClassAttribute(array.attributes[array.attributes.Count - 1], "Name0", "Name1");

                    table.AddData(array.data);
                    var p = new int[20];
                    for (int i = 0; i < p.Length; i++)
                    {
                        p[i] = i;
                    }
                    alg01.init(table);
                    var rules = alg01.process();
                    for (int i = 0; i < rules.Count; i++)
                    {
                        output.WriteLine(rules[i].ToString());
                    }

                    var rulesString        = "a11 a33  ->c1;a11 a31  ->c1;a12 a32  ->c1;a23 a34  ->c1;a22 a34 a54  ->c2;a22 a34 a52  ->c1;";
                    var currentRulesString = "";
                    for (int i = 0; i < rules.Count; i++)
                    {
                        currentRulesString += rules[i].ToStringOnlyTerm() + ";";
                    }
                    Assert.Equal(rulesString, currentRulesString);
                }
            }
            catch (Exception e)
            {
                output.WriteLine(e.Message.ToString());
                Assert.True(false);
            }
        }
        static void performAlg01(FuzzyTable table, int indexForParam)
        {
            Console.WriteLine("performAlg01: " + indexForParam);
            int size = 11;

            Double[] kriteriaArray = new Double[size];
            for (int i = 0; i < size; i++)
            {
                var beta     = 0.0 + 0.1 * i;
                var dataSize = 0;
                for (int j = 0; j < 200; j++)
                {
                    Algorithm01 alg01;
                    switch (indexForParam)
                    {
                    case 0:
                        alg01 = new Algorithm01(beta, 0.7);
                        break;

                    case 1:
                    default:
                        alg01 = new Algorithm01(0, beta);
                        break;
                    }

                    alg01.init(table);
                    var validation02 = new TenCrossValidation();
                    var matrix02     = validation02.Validate(10, table, alg01);
                    if (matrix02 != null)
                    {
                        var kriteria = (matrix02.Sensitivity() + matrix02.Specificity()) / 2;
                        kriteriaArray[i] += kriteria;
                        dataSize++;
                    }
                }
                Console.WriteLine(indexForParam + " CURRENT beta: " + (beta) + "  :" + kriteriaArray[i] / dataSize);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var table = new FuzzyTable();

            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("./data/bupa_fuzzy.json"))

                {
                    String  json  = sr.ReadToEnd();
                    dynamic array = JsonConvert.DeserializeObject(json);

                    for (int i = 0; i < array.attributes.Count - 1; i++)
                    {
                        table.addAttribute(array.attributes[i]);
                    }

                    table.addClassAttribute(array.attributes[array.attributes.Count - 1], "yes", "no");
                    table.AddData(array.data);
                    Console.WriteLine("Started");

                    var alg = new Algorithm01(0, 0.6);
                    // var alg = new Algorithm01Modification(0, 0.62, 0.2);
                    int maxReplications = 30;

                    int    replications = 0;
                    double TP           = 0;
                    double FP           = 0;
                    double TN           = 0;
                    double FN           = 0;
                    double accuracy     = 0;
                    double sensitivity  = 0;
                    double specificity  = 0;
                    double precision    = 0;
                    for (int i = 0; i < maxReplications; i++)
                    {
                        alg.init(table);
                        var validation01 = new TenCrossValidation();
                        var matrix       = validation01.Validate(10, table, alg);
                        if (matrix != null)
                        {
                            accuracy    += matrix.Accuracy();
                            sensitivity += matrix.Sensitivity();
                            specificity += matrix.Specificity();
                            precision   += matrix.Precision();
                            TP          += matrix.TruePositivePercent;
                            FP          += matrix.FalsePositivePercent;
                            TN          += matrix.TrueNegativePercent;
                            FN          += matrix.FalseNegativePercent;
                            replications++;
                        }
                        Console.WriteLine(i + " Criteria: " + ((sensitivity / replications) + (specificity / replications)) / 2);
                    }

                    Console.WriteLine();
                    Console.WriteLine("Replications: " + replications);
                    Console.WriteLine("TP: " + TP / replications);
                    Console.WriteLine("FP: " + FP / replications);
                    Console.WriteLine("TN: " + TN / replications);
                    Console.WriteLine("FN: " + FN / replications);
                    Console.WriteLine("Accuracy: " + accuracy / replications);
                    Console.WriteLine("Sensitivity: " + sensitivity / replications);
                    Console.WriteLine("Specificity: " + specificity / replications);
                    Console.WriteLine("Precision: " + precision / replications);
                    Console.WriteLine("Criteria: " + ((sensitivity / replications) + (specificity / replications)) / 2);

                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
                Console.WriteLine(e);
            }
        }