コード例 #1
0
        ///// <summary>Gets a copy of sorted Similars without elements with undefined number.</summary>
        ///// <returns>The sorted Similars without elements with undefined number</returns>
        //public Similars GetShrink()
        //{
        //    int i;
        //    Array.Sort(_numbers);
        //    for (i = 0; i < Count; i++)
        //        if (this[i] == UndefNumber)
        //            break;
        //    Similars res = new Similars(i);
        //    Array.Copy(_numbers, res._numbers, i);
        //    return res;
        //}

        /// <summary>Returns the Coefficient of Variation.</summary>
        /// <param name="startIndex">The index in the input sequence at which scanning begins.</param>
        /// <param name="length">The length of scanning range.</param>
        /// <param name="seedNumber">The serial number of seed word.</param>
        /// <returns>Coefficient of Variation</returns>
        /// <remarks>This instance should be shrinked.</remarks>
        public float GetCV(int startIndex, int length, int seedNumber)
        {
            if (Count == 0)
            {
                return(0);
            }
            int i, j = 0, number, lastFound = -1;
            int stopInd = startIndex + length - Words.WordLength;

            // set the array of count of neighbouring word's (clusters) with max possible capacity
            int[] grps = new int[length];
            int   k    = 1;

            for (i = startIndex; i < stopInd; i++)
            {
                number = Words.GetNumber(Sequence.Original, i);
                // this collection is sorted by increasing!
                if (number != seedNumber &&
                    Array.BinarySearch(_numbers, number) < 0)   // word is not belong to similars
                {
                    continue;
                }
                if (lastFound >= 0)                          // count began
                {
                    if (i - lastFound <= _DepthOfClastering) // founded word is in group
                    {
                        k++;                                 // increase group counter
                    }
                    else                                     // founded word is out of group
                    {
                        grps[j++] = k;                       // close current group
                        k         = 1;                       // start new group
                    }
                }
                lastFound = i;          // remember current position
            }

            // fill sum Counter
            Average.SumCounter counter = new Average.SumCounter();
            // check i<cnt needs when groups is full, in other words, when each "group" has just one member
            for (i = 0; i < Count && (k = grps[i]) > 0; i++)
            {
                counter += k;
            }

            return(new Average(counter).CV);
        }
コード例 #2
0
        /// <summary>Creates and filled a shrinked or 'crude' instance of Patterns class from the range of the inputArray array
        /// and calculate their averages and standart deviation values.
        /// </summary>
        /// <param name="worker">The BackgroundWorker in wich Processing is run.</param>
        /// <param name="startIndex">The index in the input sequence at which scanning begins.</param>
        /// <param name="length">The length of scanning range.</param>
        /// <param name="shakeCnt">The amount of shakes.</param>
        /// <param name="avrgs">Null in case of Individual mode; the array of single Average otherwise.</param>
        /// <param name="maxFreqNumber">The number of Pattern with max Frequence: used in 'Global' only.</param>
        /// <param name="stepCntOnShake">The number of progress bar steps generated by method within one shake; 0 if without progress bar steps.</param>
        /// <param name="isDrawPlot">True if a plot should be drawing; otherwise, false.</param>
        /// <returns>Sorted by Frequence and shrinked collection in case of isSortByFreq=true; otherwise sorted by Number and unshrinked.</returns>
        public static Patterns GetTreatedPatterns(
            BackgroundWorker worker,
            int startIndex, int length, short shakeCnt,
            ref Average[] avrgs, ref int maxFreqNumber, float stepCntOnShake,
            bool isDrawPlot)
        {
            int strictLength = length - Words.WordLength;

            int[] strictFreqs  = new int[Words.Count];
            int   loopsPerStep = stepCntOnShake > 0 ? (int)(Words.Count / stepCntOnShake) : -1;

            Patterns mainPtns = new Patterns();

            mainPtns.Init(
                worker, Sequence.Original, startIndex,
                strictLength, strictFreqs, loopsPerStep, ref maxFreqNumber, true, isDrawPlot
                );
            if (shakeCnt > 0)           // calculate mean & SD
            {
                int      i;
                int      maxFreqNumberTmp = 0;
                Patterns shakedPtns       = new Patterns();
                // corretcing ProgressBar steps for for shake and scanning
                int shakeSteps = 0;
                //if (loopsPerStep > 3)       shakeSteps = 3;
                //else if (loopsPerStep > 2)  shakeSteps = 2;
                //else if (loopsPerStep > 1)  shakeSteps = 1;
                loopsPerStep -= shakeSteps;

                if (avrgs != null)  //*** Max Average Choice mode set
                {
                    Average.SumCounter sumCounter = new Average.SumCounter();
                    // search patterns with max Frequance for each shake and add this value to the sumCounter
                    for (i = 0; i < shakeCnt; i++)
                    {
                        // we need only max Frequance from the shaked Patterns
                        sumCounter += shakedPtns.Init(worker,
                                                      Sequence.Shake(startIndex, length, worker, shakeSteps),
                                                      0, strictLength, strictFreqs, loopsPerStep, ref maxFreqNumberTmp, false, isDrawPlot
                                                      );
                    }
                    avrgs[0] = new Average(sumCounter); // set total Average on the first place;
                }
                else                                    //*** Individual Average Choice mode set
                {
                    // this case is possible only in Local task, so mainPtns is always sorted and shrinked
                    // create and fill the array of sum counters of frequencies from shaked Patterns;
                    // it is 'sinchronised' with shakedPtns, or the same order as a shakedPtns
                    Average.SumCounter[] SCounters = new Average.SumCounter[Words.Count];
                    maxFreqNumberTmp = -1;      // disable max frequency return
                    for (int j = 0; j < shakeCnt; j++)
                    {
                        shakedPtns.Init(worker,
                                        Sequence.Shake(startIndex, length, worker, shakeSteps),
                                        0, strictLength, strictFreqs, loopsPerStep, ref maxFreqNumberTmp, false, isDrawPlot
                                        );
                        for (i = 0; i < Words.Count; i++)
                        {
                            //if (shakedPtns[i].Freq > 0)
                            //    SCounters[i] += shakedPtns[i].Freq;
                            if (shakedPtns[i] > 0)
                            {
                                SCounters[i] += shakedPtns[i];
                            }
                        }
                    }
                    // set the average of frequency and SD for each Pattern in the initial collection
                    avrgs = new Average[mainPtns.Count];
                    for (i = 0; i < mainPtns.Count; i++)   // each initial pattern with unzero Frequency...
                    {
                        avrgs[i] = new Average(SCounters[i]);
                    }
                }
            }
            return(mainPtns);
        }