Beispiel #1
0
        /// <summary>Reports the shrinked (without zero Frequency) Similars of the specified pattern.</summary>
        /// <param name="seedNumber">The number of the seed-word.</param>
        /// <returns>If Similars have zero-frequency items, the shrinked (without zero Frequency) Similars; otherwise initial Similars.</returns>
        public Similars GetSimilars(int seedNumber)
        {
            Similars smls        = Similars.GetSimilars(seedNumber);
            bool     isNotCopied = true;

            // We have to remove from the total Similars all the numbers with zero Frequency
            int  j;
            bool isFound = true;

            for (int i = 0; i < smls.Count; i++)
            {
                // scan throw the whole collection to check for real existing similars
                for (j = 0; j < Count; j++)
                {
                    if (isFound = this[j].SeedNumber == smls[i])
                    {
                        break;
                    }
                }
                if (!isFound)
                {
                    // if zero-frequence element is finded, Similars should be copied
                    // because it change its Count by shrinking
                    if (isNotCopied)
                    {
                        smls        = smls.Copy();
                        isNotCopied = false;
                    }
                    smls[i] = Similars.UndefNumber;
                }
            }
            return(isNotCopied ? smls : smls.Shrink());
        }
Beispiel #2
0
        ///// <summary>Removes all the elements with the zero Frequency from the instance.</summary>
        ///// <remarks>Sorts the collection by Frequency.</remarks>
        //void Shrink ()
        //{
        //    if (_isShrinked == true)
        //        return;
        //    Sort();
        //    //System.Console.Beep(400, 100);
        //    // start from the end because zero Frequencies are much more less then unzero
        //    for (int i = Count-1; i >= 0; i--)
        //        //if (this[i].Freq > 0)
        //        if (this[i] > 0)
        //        {
        //            Array.Resize(ref _coll, _insCount = i+1);
        //            break;
        //        }
        //    _isShrinked = true;
        //}

        #endregion
        #region Statistic methods

        /// <summary>Reports the shrinked (without zero Frequency) Similars of the specified unsorted pattern.</summary>
        /// <param name="seedNumber">The number of the seed-word in the collection.</param>
        /// <returns>If Similars have zero-frequency items, the shrinked (without zero Frequency) Similars; otherwise initial Similars.</returns>
        public Similars GetSimilars(int seedNumber)
        {
            Similars smls        = Similars.GetSimilars(seedNumber);
            bool     isNotCopied = true;

            // We have to remove from the total Similars all the numbers with zero Frequency
            // this is a variant used in ScanWindows
            // we may use direct indexing to check zero-frequency seeds
            for (int i = 0; i < smls.Count; i++)
            {
                if (this[smls[i]] == 0)
                {
                    // if zero-frequence element is finded, Similars should be copied
                    // because it change its Count by shrinking
                    if (isNotCopied)
                    {
                        smls        = smls.Copy();
                        isNotCopied = false;
                    }
                    smls[i] = Similars.UndefNumber;
                }
            }
            return(isNotCopied ? smls : smls.Shrink());
        }
Beispiel #3
0
        /// <summary>Initializes an instance of the Patterns.</summary>
        /// <param name="worker">The BackgroundWorker in wich Processing is run.</param>
        /// <param name="sequence">The 'names' sequence.</param>
        /// <param name="startIndex">The index in the inputArray at which scanning begins.</param>
        /// <param name="strictLength">The precise length of range of inputArray for scanning.</param>
        /// <param name="strictFreqs">The external array of strict frequencies; needed to avoid memory overallotment.</param>
        /// <param name="loopsPerStep">The amount of loops per one progress bar step; -1 if without progress bar steps.</param>
        /// <param name="maxFreqNumber">Return number of Pattern with max Frequence: if init value = -1, then no return.</param>
        /// <param name="isFirstCall">True if method is called first time in cycle; otherwise, false.</param>
        /// <param name="isDrawPlot">True if plot is drawing; otherwise, false.</param>
        /// <returns>Maximum frequency value in the instance; if init maxFreqNumber param = -1, then 0.</returns>
        int Init(
            BackgroundWorker worker, byte[] sequence,
            int startIndex, int strictLength, int[] strictFreqs, int loopsPerStep, ref int maxFreqNumber,
            bool isFirstCall, bool isDrawPlot)
        {
            #region Comments

            /*
             * Patterns are generated from inputArray sequence on 2 steps.
             *
             * Step 1: Initialization strict frequency
             * We create a new collection with the maximum possible length and an temporary array of strict frequencies.
             * Index of each element for both collections is equal to absolute word number,
             * so we scan through the input sequence and increase strict frequency in array directly by indexing.
             *
             * Step 2: Initialization Frequency
             * From each pattern in collection we added the Frequency of all his Similars.
             * In ALL POSSIBLE mode we search all the patterns, because their Similars may have Frequency > 0;
             * in FROM INPUT mode we skip zero-frequency patterns.
             *
             * In TURBO mode all the Similars are keeping in memory after first generation,
             * so we should go through the given Similars collection and adding thier Frequency directly by word number, equls to index in this instance.
             * In ORDINARY mode we receive the sum of Frequencies of all Similars through single call of Similars.SumUp().
             *
             * So we receive the frequencies with mismatches for all the Patterns in this instance.
             *
             * This is the maximum fastest method because of using only direct indexing.
             * We scan input sequence just once? and no searches through collection are required.
             */
            #endregion

            //System.Windows.Forms.MessageBox.Show(loopsPerStep.ToString());

            int i, maxFreq = 0;

            worker.ReportProgress(TreatSCANNING);
            OnPrgBarReseat();

            this.Clear();
            Array.Clear(strictFreqs, 0, strictFreqs.Length);

            //System.Windows.Forms.MessageBox.Show(startIndex.ToString("startIndex= 0  ") + strictLength.ToString("strictLength= 0  "));
            //*** Step_1: Look over all the patterns in a range of sequence
            for (i = 0; i <= strictLength; i++)
            {
                strictFreqs[Words.GetNumber(sequence, startIndex + i)]++;
            }

            //*** Step_2: expanding to mismatches
            int      k;
            Similars smls;
            //Pattern ptn;
            // compare each Pattern to all the Pattern's in the same collection with a glance of mismathes;
            // collection is still unsorted
            for (i = 0; i < Count; i++)
            {
                if (worker.CancellationPending)     // Canceled by user.
                {
                    throw new ApplicationException(string.Empty);
                }

                if (IsAllPossible || (strictFreqs[i] > 0))
                {
                    //ptn = this[i];
                    if (Similars.IsTurbo)
                    {
                        smls = Similars.GetSimilars(i);
                        for (k = 0; k < smls.Count; k++)
                        {
                            //ptn.Freq += strictFreqs[smls[k]];
                            this[i] += strictFreqs[smls[k]];
                        }
                    }
                    else
                    {
                        //ptn.Freq += Similars.SumUp(i, strictFreqs);
                        this[i] += Similars.SumUp(i, strictFreqs);
                    }

                    //ptn.WordNumber = i;             // initialize number
                    //ptn.Freq += strictFreqs[i];     // frequency itself
                    this[i] += strictFreqs[i];     // frequency itself
                    //this[i] = ptn;
                    // keep index of maximum Freq without sorting: needs only in case of Max Average Choice or Global task.
                    //if (maxFreqNumber >= 0 && ptn.Freq > maxFreq)
                    if (maxFreqNumber >= 0 && this[i] > maxFreq)
                    {
                        //maxFreq = ptn.Freq;
                        maxFreq       = this[i];
                        maxFreqNumber = i;
                    }
                }
                OnPrgBarIncreased(worker, loopsPerStep);
            }
            if (isDrawPlot)
            {
                // if it needs to keep sorting by name, we should clone collection for drawing,
                // because it will be sorted by Freq during drawing
                worker.ReportProgress(TreatSORTING);
                worker.ReportProgress(Convert.ToInt32(isFirstCall), Clone());
            }
            return(maxFreq);
        }