Exemplo n.º 1
0
 //initialize the distribution
 public void initializeContinuosDistribution(interval range, double interval)
 {
     this.intervalDim = interval;
     this.distributionCont.Clear();
     total      = range.value;
     range.freq = 1.0;
     range.perc = 100.0;
     this.distributionCont.Add(range);
 }
Exemplo n.º 2
0
        // interval [start, end)
        public void OnlineContinuosDistribution(double value, int step)
        {
            interval range = new interval();

            this.total += step;
            if (distributionCont.Count == 0) //if the distribution is not initialized then it will be initialized
            {
                range.start = Math.Round(value, MidpointRounding.AwayFromZero);
                range.end   = range.start + intervalDim;
                range.value = step;
                this.initializeContinuosDistribution(range, this.intervalDim);
                Debug.WriteLine("inizialization");
            }
            else
            {
                int q;
                int p = 0;                             //first index
                int r = distributionCont.Count - 1;    //last index

                if (value < distributionCont[p].start) //add value before the list
                {
                    do
                    {
                        range       = new interval();
                        range.end   = distributionCont[p].start;
                        range.start = Math.Round(distributionCont[p].start - intervalDim, 2);
                        if (range.start <= value)
                        {
                            range.value = step;
                        }
                        else
                        {
                            range.value = 0;
                        }
                        distributionCont.Insert(0, range);
                        r++;
                        Debug.WriteLine("add range before");
                    } while (range.start > value);
                }

                else if (value >= distributionCont[r].end) //add value after the list
                {
                    do
                    {
                        range       = new interval();
                        range.start = distributionCont[r].end;
                        range.end   = Math.Round(distributionCont[r].end + intervalDim, 2);
                        if (range.end > value)
                        {
                            range.value = step;
                        }
                        else
                        {
                            range.value = 0;
                        }
                        distributionCont.Add(range);
                        r++;
                        Debug.WriteLine("add range after");
                    } while (range.end <= value);
                }



                else // search in the list with a binary search
                {
                    Debug.WriteLine("search in list");
                    while (p <= r)
                    {
                        q = (p + r) / 2;
                        if (distributionCont[q].end > value)
                        {
                            if (distributionCont[q].start <= value)
                            {
                                distributionCont[q].value += step;
                                distributionCont[q].freq   = distributionCont[q].value / this.total;
                                break;
                            }
                            else
                            {
                                r = q - 1;
                            }
                        }
                        else
                        {
                            p = q + 1;
                        }
                    }
                }


                //update freq and perc
                foreach (interval i in distributionCont)
                {
                    i.freq = i.value / (double)this.total;
                    i.perc = i.freq * 100.00;
                }
            }
        }