public List<patternDetected> runDetection(int debut,int interval, double[,] matriceUser, String type)
        {
            System.Diagnostics.Debug.Write("BEGIN RUN DETECTION\n");
            List<patternDetected> patternsDetected = new List<patternDetected>();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        System.Diagnostics.Debug.Write("\n");
                        System.Diagnostics.Debug.Write(matriceUser[i, j] + "\t");
                    }
                    else
                        System.Diagnostics.Debug.Write(matriceUser[i,j] + "\t");
                }
            }
            PatternArray = this.createPatternFromUser(matriceUser);
            double[] f;
            double[] f2 = new double[10];
            double[,] k = new double[10,2];
            double[,] p;
            double[,] compress3 = new double[10,2];
            double[,] matrix10x10 = new double[10,10];
            double inc = 0;
            double pmax = 0;
            double pmin = 0;
            double sum = 0;
            double maxGlobal = 0;
            double minGlobal = 0;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        System.Diagnostics.Debug.WriteLine(PatternArray[i, j]);
                    }
                    else
                    System.Diagnostics.Debug.Write(PatternArray[i,j]);
                }
            }

            for (int i = debut; i < listOfDatas.Count - interval; i++)
            {
                maxGlobal = 0;
                minGlobal = 0;
                indexDebut = i;

                indexFin = indexDebut + interval;
                size = indexFin - indexDebut;
                f = new double[size+1];
                int indexBoucle = 0;

                for (int l = indexDebut; l < indexFin + 1; l++)
                {

                    f[indexBoucle] = (double)listOfDatas[l].close;
                    if (indexBoucle < indexFin - 1)
                    {
                        indexBoucle++;
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        matrix10x10[m, j] = 0;
                    }
                }
                for (int j = 0; j < 10; j++)
                {
                    compress3[j,1] = 0;
                    compress3[j,0] = 0;
                }
                inc =(double) (indexFin - indexDebut) / 10;
                p = new double[10, 2];

                for (int j = 0; j < 10; j++)
                {
                    p[j,1] = indexDebut + ((j+1) * inc);
                    p[j,0] = indexDebut + ((j) * inc);
                }
                for (int j = indexDebut; j < indexFin + 1; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        if (j >= p[m, 0] && j <= p[m, 1])
                        {
                            if (j == indexDebut)
                            {
                                maxGlobal = listOfDatas[j].close;
                                minGlobal = listOfDatas[j].close;

                            }
                            if (listOfDatas[j].close > maxGlobal)
                            {
                                maxGlobal = listOfDatas[j].close;
                            }
                            if (listOfDatas[j].close < minGlobal)
                            {
                                minGlobal = listOfDatas[j].close;
                            }
                            compress3[m, 0] = compress3[m, 0] + (double)listOfDatas[j].close;
                            compress3[m, 1] = compress3[m, 1] + 1;
                        }
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    if (compress3[j, 1] > 0)
                    {
                        f2[j] = compress3[j, 0] / compress3[j, 1];
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        pmax = f2[j];
                        pmin = f2[j];
                    }
                    if (f2[j] > pmax)
                    {
                        pmax = f2[j];
                    }
                    if (f2[j] < pmin)
                    {
                        pmin = f2[j];
                    }
                }
                inc = (pmax - pmin) / 10;
                for (int j = 0; j < 10; j++)
                {
                    k[j, 1] = pmin + ((j+1) * inc);
                    if (i ==0)
                    System.Diagnostics.Debug.WriteLine(k[j, 1]);
                    k[j, 0] = pmin + ((j) * inc);

                }

                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        if (f2[j] >= k[m, 0] && f2[j] <= k[m, 1])
                        {
                            matrix10x10[9-m, j] = 1;
                            break;
                        }
                    }
                }
                sum = 0;
                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        sum = sum + (PatternArray[j, m] * matrix10x10[j, m]);

                        if (i==0)
                        {
                            System.Diagnostics.Debug.Write(PatternArray[j, m] + "\t");
                        }

                    }
                    if(i==0)
                    System.Diagnostics.Debug.Write("\n");
                }

                if (sum > 3)
                {
                    patternDetected pat = new patternDetected(this.listOfDatas[this.indexDebut].datehour, this.listOfDatas[this.indexFin].datehour,maxGlobal,minGlobal,interval - 1,sum,type);
                    patternsDetected.Add(pat);
                    System.Diagnostics.Debug.Write("Index Début : " + this.indexDebut + "date debut" + this.listOfDatas[this.indexDebut].datehour + " Index FIn : " + this.indexFin);
                    for (int rouetourne = 0; rouetourne < 10; rouetourne++)
                    {
                        System.Diagnostics.Debug.Write(f[rouetourne]);
                        System.Diagnostics.Debug.Write(" ");
                        graph.color_interval(indexDebut, indexFin);
                    }
                    System.Diagnostics.Debug.WriteLine(" ");

                }

            }
            System.Diagnostics.Debug.Write("\nSTOP RUN DETECTION");
            return patternsDetected;
        }
Esempio n. 2
0
        public List <patternDetected> runDetection(int debut, int interval, double[,] matriceUser, String type)
        {
            System.Diagnostics.Debug.Write("BEGIN RUN DETECTION\n");
            List <patternDetected> patternsDetected = new List <patternDetected>();

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        System.Diagnostics.Debug.Write("\n");
                        System.Diagnostics.Debug.Write(matriceUser[i, j] + "\t");
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write(matriceUser[i, j] + "\t");
                    }
                }
            }
            PatternArray = this.createPatternFromUser(matriceUser);
            double[] f;
            double[] f2 = new double[10];
            double[,] k = new double[10, 2];
            double[,] p;
            double[,] compress3   = new double[10, 2];
            double[,] matrix10x10 = new double[10, 10];
            double inc       = 0;
            double pmax      = 0;
            double pmin      = 0;
            double sum       = 0;
            double maxGlobal = 0;
            double minGlobal = 0;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        System.Diagnostics.Debug.WriteLine(PatternArray[i, j]);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write(PatternArray[i, j]);
                    }
                }
            }

            for (int i = debut; i < listOfDatas.Count - interval; i++)
            {
                maxGlobal  = 0;
                minGlobal  = 0;
                indexDebut = i;

                indexFin = indexDebut + interval;
                size     = indexFin - indexDebut;
                f        = new double[size + 1];
                int indexBoucle = 0;


                for (int l = indexDebut; l < indexFin + 1; l++)
                {
                    f[indexBoucle] = (double)listOfDatas[l].close;
                    if (indexBoucle < indexFin - 1)
                    {
                        indexBoucle++;
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        matrix10x10[m, j] = 0;
                    }
                }
                for (int j = 0; j < 10; j++)
                {
                    compress3[j, 1] = 0;
                    compress3[j, 0] = 0;
                }
                inc = (double)(indexFin - indexDebut) / 10;
                p   = new double[10, 2];

                for (int j = 0; j < 10; j++)
                {
                    p[j, 1] = indexDebut + ((j + 1) * inc);
                    p[j, 0] = indexDebut + ((j) * inc);
                }
                for (int j = indexDebut; j < indexFin + 1; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        if (j >= p[m, 0] && j <= p[m, 1])
                        {
                            if (j == indexDebut)
                            {
                                maxGlobal = listOfDatas[j].close;
                                minGlobal = listOfDatas[j].close;
                            }
                            if (listOfDatas[j].close > maxGlobal)
                            {
                                maxGlobal = listOfDatas[j].close;
                            }
                            if (listOfDatas[j].close < minGlobal)
                            {
                                minGlobal = listOfDatas[j].close;
                            }
                            compress3[m, 0] = compress3[m, 0] + (double)listOfDatas[j].close;
                            compress3[m, 1] = compress3[m, 1] + 1;
                        }
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    if (compress3[j, 1] > 0)
                    {
                        f2[j] = compress3[j, 0] / compress3[j, 1];
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    if (j == 0)
                    {
                        pmax = f2[j];
                        pmin = f2[j];
                    }
                    if (f2[j] > pmax)
                    {
                        pmax = f2[j];
                    }
                    if (f2[j] < pmin)
                    {
                        pmin = f2[j];
                    }
                }
                inc = (pmax - pmin) / 10;
                for (int j = 0; j < 10; j++)
                {
                    k[j, 1] = pmin + ((j + 1) * inc);
                    if (i == 0)
                    {
                        System.Diagnostics.Debug.WriteLine(k[j, 1]);
                    }
                    k[j, 0] = pmin + ((j) * inc);
                }

                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        if (f2[j] >= k[m, 0] && f2[j] <= k[m, 1])
                        {
                            matrix10x10[9 - m, j] = 1;
                            break;
                        }
                    }
                }
                sum = 0;
                for (int j = 0; j < 10; j++)
                {
                    for (int m = 0; m < 10; m++)
                    {
                        sum = sum + (PatternArray[j, m] * matrix10x10[j, m]);

                        if (i == 0)
                        {
                            System.Diagnostics.Debug.Write(PatternArray[j, m] + "\t");
                        }
                    }
                    if (i == 0)
                    {
                        System.Diagnostics.Debug.Write("\n");
                    }
                }

                if (sum > 3)
                {
                    patternDetected pat = new patternDetected(this.listOfDatas[this.indexDebut].datehour, this.listOfDatas[this.indexFin].datehour, maxGlobal, minGlobal, interval - 1, sum, type);
                    patternsDetected.Add(pat);
                    System.Diagnostics.Debug.Write("Index Début : " + this.indexDebut + "date debut" + this.listOfDatas[this.indexDebut].datehour + " Index FIn : " + this.indexFin);
                    for (int rouetourne = 0; rouetourne < 10; rouetourne++)
                    {
                        System.Diagnostics.Debug.Write(f[rouetourne]);
                        System.Diagnostics.Debug.Write(" ");
                        graph.color_interval(indexDebut, indexFin);
                    }
                    System.Diagnostics.Debug.WriteLine(" ");
                }
            }
            System.Diagnostics.Debug.Write("\nSTOP RUN DETECTION");
            return(patternsDetected);
        }