예제 #1
0
        /// <summary>
        /// Converts the array of strings represented ScanWindows to its instance.
        /// </summary>
        /// <param name="inputs">Array of strings represented ScanWindows to convert.</param>
        /// <returns></returns>
        static ScanWindows Parse(ArrayList inputs)
        {
            int i = 0;

            string[] images;
            byte[]   name;

            // read the name of first pattern and inizialise session by given word length
            string tmp = inputs[0] as string;

            Words.Init((byte)tmp.Substring(tmp.LastIndexOf(Abbr.TAB) + 1).Length, 0, false);

            ScanWindows sWins = new ScanWindows(inputs.Count, BY_DEF);   // Default sort mode was set by writing to a file

            // initialises sWins member
            foreach (string str in inputs)
            {
                // each string contains 6 number separated by TAB
                images     = str.Split(Abbr.TAB);
                name       = Sequence.Parse(images[4]);
                sWins[i++] = new ScanWindow(
                    int.Parse(images[0]),
                    int.Parse(images[1]),
                    //new Pattern(Words.GetNumber(name) * Words.WordLength, 1),
                    Words.GetNumber(name),
                    float.Parse(images[2]),
                    float.Parse(images[3]));
            }

            return(sWins);
        }
예제 #2
0
        /// <summary>Reads ScanWindows data saved in a file.</summary>
        /// <param name="fileName">The name of file</param>
        /// <param name="header">The string buffer to which data header is write.</param>
        /// <returns></returns>
        public static ScanWindows Read(string fileName, ref string header)
        {
            ScanWindows sWins = null;

            using (StreamReader sr = File.OpenText(fileName))
            {
                // first line
                string tmp = sr.ReadLine();
                // pre check of format
                if (tmp.IndexOf(Abbr.FTT) < 0 ||
                    tmp.IndexOf(Abbr.Global, Abbr.FTT.Length, 30) < 0)
                {
                    throw new ApplicationException(Abbr.Incorrect + Abbr.SavedData);
                }

                bool isHeader = true;
                header = string.Empty;
                ArrayList issue = new ArrayList();

                while ((tmp = sr.ReadLine()) != null)
                {
                    if (isHeader)
                    {
                        if (tmp.Length > 0)                                             // if string is not empty
                        {
                            if (tmp[0] != Abbr.SEP_LINE && tmp[0] != Abbr.SEP_LINE0)    // check for separte line
                            {
                                header += tmp + Abbr.EOL;                               // grown header string
                            }
                            else
                            {
                                isHeader = false;
                            }
                        }
                    }
                    else
                    {
                        issue.Add(tmp);                     // grown issues (body) array
                    }
                }
                sWins = ScanWindows.Parse(issue);
            }
            return(sWins);
        }
예제 #3
0
        /// <summary>Calculates the patterns frequency.</summary>
        /// <param name="shakeCnt">The amount of shakes.</param>
        /// <param name="winStartLenght">The start lenght of window.</param>
        /// <param name="winStopLenght">The stop lenght of window.</param>
        /// <param name="winIncr">TYhe increment of the window.</param>
        /// <param name="winShift">The shift of the window.</param>
        public ScanWindows ScanGlobal(
            short shakeCnt, short winStartLenght, short winStopLenght, short winIncr, short winShift)
        {
            // check input sequence
            int seqLength = Sequence.Length;

            if (winStopLenght >= seqLength)
            {
                throw new ApplicationException(Abbr.SmallInput);
            }

            // calculate total number of scannings
            int scanCnt = (seqLength - winStopLenght) / winShift + 1;

            if (((seqLength - winStopLenght) % winShift) > 0)
            {
                scanCnt++;
            }

            return(ScanWindows.GetTreatedWindows(
                       _worker, _prgBar, shakeCnt,
                       winStartLenght, winStopLenght, winIncr, winShift, scanCnt
                       ));
        }
예제 #4
0
        /// <summary>Creates and calculate an instance of ScanWindows class.</summary>
        /// <param name="worker">BackgroundWorker in wich Processing is run.</param>
        /// <param name="prgBar">ProgressBar to modify its Maximum.</param>
        /// <param name="shakeCnt">Number of shakes.</param>
        /// <param name="winStartLenght">Initial length of current scanned window.</param>
        /// <param name="winStopLenght">Final length of of current scanned window.</param>
        /// <param name="winIncr">Incriment of length of current scanned window.</param>
        /// <param name="winShift">Shift of current scanned window.</param>
        /// <param name="scanCnt">Nnumber of scanned window.</param>
        /// <returns>The sorted ScanWindow's collection.</returns>
        public static ScanWindows GetTreatedWindows(
            System.ComponentModel.BackgroundWorker worker,
            ProgressBar prgBar,
            short shakeCnt,
            short winStartLenght, short winStopLenght, short winIncr, short winShift,
            int scanCnt)
        {
            int j, length, startInd = 0, maxFreqInd, maxFreqNumber = 0;
            int winCnt       = (winStopLenght - winStartLenght) / winIncr + 1; // the amount of windows from start to stop lengths
            int loopsPerStep = scanCnt * winCnt / prgBar.Maximum;              // ProgressBar.DefaultMaximum;

            if (loopsPerStep < 10)                                             // modify Maximum in case of appreciable cumulative error
            {
                prgBar.Maximum = scanCnt * winCnt / loopsPerStep;
            }
            float      F, maxF;
            Patterns   ptns;                                       // threated patterns within inner loop
            ScanWindow sWin;                                       // scanWindow with max Frequency

            int[]       maxFreqNumbers = new int[winCnt];          // array for keeping maxFreqNumber within inner loop
            Patterns[]  ptnsArray      = new Patterns[winCnt];     // array for keeping Patterns within inner loop
            Average[]   avrgs          = new Average[1];           // single Average from threated patterns
            ScanWindows sWins          = new ScanWindows(winCnt);  // ScanWindows within inner loop
            ScanWindows sWinsRes       = new ScanWindows(scanCnt); // result ScanWindows

            OnPrgBarReseat();
            for (int i = 0; i < scanCnt; i++)
            {
                length = winStartLenght;
                // choose patterns with max F within inner loop (among increasing subsequenses)
                for (maxF = 0, maxFreqInd = 0, j = 0; j < winCnt; length += winIncr, j++)
                {
                    ptnsArray[j] = ptns = Patterns.GetTreatedPatterns(
                        worker, startInd, length, shakeCnt,
                        ref avrgs,
                        ref maxFreqNumber, 0, false);
                    // ptns is unsorted
                    maxFreqNumbers[j] = maxFreqNumber;
                    sWins[j]          = new ScanWindow(
                        startInd, length, maxFreqNumber,
                        F = avrgs[0].F(ptns[maxFreqNumber]),
                        0);
                    // keep index of maxF element to avoid sorting by F at the end
                    if (F > maxF)
                    {
                        maxF = F; maxFreqInd = j;
                    }
                    // increase progress bar
                    OnPrgBarIncreased(worker, loopsPerStep);
                }
                // calculate CV for sWin with max F
                maxFreqNumber = maxFreqNumbers[maxFreqInd];
                sWin          = sWins[maxFreqInd];
                sWin.CV       = ptnsArray[maxFreqInd].
                                GetSimilars(maxFreqNumber).
                                GetCV(sWin.StartIndex, sWin.Length, maxFreqNumber);

                // save sWin with max F
                sWinsRes[i] = sWin;
                startInd   += winShift;

                // corrects startInd on the last step
                if (startInd + winStopLenght > Sequence.Length)
                {
                    startInd = Sequence.Length - winStopLenght;
                }
            }
            sWinsRes.Sort();
            return(sWinsRes);
        }