Ejemplo n.º 1
0
        public List <double> GetMode()
        {
            var sampleFrequencies = EmpericalSampleRepository.GetGeneralSample()
                                    .GroupBy(elem => elem)
                                    .Select(group => new { Key = group.Key, Frequency = group.Count() })
                                    .ToList();
            var sampleMode = sampleFrequencies.Where(elem => elem.Frequency == sampleFrequencies.Max(el => el.Frequency)).Select(x => x.Key).FirstOrDefault();

            var intervals     = GetIntervalEmpericalSample();
            var modeIntervals = intervals.Where(interval => interval.HasElement(sampleMode)).ToList();
            var result        = new List <double>();

            foreach (var modeInterval in modeIntervals)
            {
                var preModeInterval  = intervals.Where(interval => interval.IntervalEnd == modeInterval.IntervalStart).FirstOrDefault();
                var nextModeInterval = intervals.Where(interval => interval.IntervalStart == modeInterval.IntervalEnd).FirstOrDefault();
                result.Add(Math.Round(
                               modeInterval.IntervalStart
                               + (double)(modeInterval.IntervalData.Count - preModeInterval.IntervalData.Count)
                               / (2 * modeInterval.IntervalData.Count - preModeInterval.IntervalData.Count - nextModeInterval.IntervalData.Count)
                               * IntervalSize
                               , 2));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public double GetStartEmpericalMoment(int k)
        {
            var intervals = GetIntervalEmpericalSample();
            var result    = 0.0;

            foreach (var interval in intervals)
            {
                result += Math.Pow(interval.DiscreteValue, k) * interval.IntervalData.Count;
            }

            return(result / EmpericalSampleRepository.GetGeneralSample().Count);
        }
Ejemplo n.º 3
0
        public double GetMedian()
        {
            var sampleMedian       = GetSampleMedian();
            var intervals          = GetIntervalEmpericalSample();
            var medianInterval     = intervals.FirstOrDefault(elem => elem.HasElement(sampleMedian));
            var preMedianIntervals = intervals.Where(elem => elem.IntervalStart < medianInterval.IntervalStart).ToList();

            return(medianInterval.IntervalStart
                   + (IntervalSize / medianInterval.IntervalData.Count)
                   * ((double)EmpericalSampleRepository.GetGeneralSample().Count / 2 - preMedianIntervals.Sum(x => x.IntervalData.Count))
                   * IntervalSize);
        }
Ejemplo n.º 4
0
        public Dictionary <string, double> GetIntervalRowByVirtualFrequency()
        {
            var result    = new Dictionary <string, double>();
            var intervals = this.GetIntervalEmpericalSample();

            foreach (var element in intervals)
            {
                result.Add(
                    intervals.IndexOf(element) == intervals.Count - 1
                    ? element.Name.Replace(")", "]")
                    : element.Name,
                    (double)element.IntervalData.Count / EmpericalSampleRepository.GetGeneralSample().Count);
            }

            return(result);
        }
Ejemplo n.º 5
0
        private double GetSampleMedian()
        {
            var sample = EmpericalSampleRepository.GetGeneralSample();

            sample.Sort();

            if (sample.Count % 2 == 0)
            {
                var middleId = sample.Count / 2;
                return((sample[middleId] + sample[middleId - 1]) / 2);
            }
            else
            {
                return(sample[sample.Count / 2]);
            }
        }
Ejemplo n.º 6
0
        public List <ChartViewModel> GetEmpericalFunction()
        {
            var intervals            = GetIntervalEmpericalSample();
            var sampleSize           = EmpericalSampleRepository.GetGeneralSample().Count;
            var dictionaryOfElements = new Dictionary <double, double>();

            foreach (var interval in intervals)
            {
                dictionaryOfElements.Add(interval.DiscreteValue, intervals.Where(elem => elem.IntervalStart < interval.IntervalStart).Sum(elem => elem.IntervalData.Count) / (double)sampleSize);
            }
            var result = dictionaryOfElements.ToChartList().Round();

            result.Add(new ChartViewModel {
                x = intervals.Max(x => x.DiscreteValue), y = 1
            });

            return(result);
        }
Ejemplo n.º 7
0
        public List <TableViewModel> GetHistogramByVirtualFrequency()
        {
            var intervals = GetIntervalEmpericalSample();
            var result    = new List <TableViewModel>();

            foreach (var interval in intervals)
            {
                result.Add(new TableViewModel
                {
                    x = intervals.IndexOf(interval) == intervals.Count - 1
                        ? interval.Name.Replace(")", "]")
                        : interval.Name,
                    y = interval.IntervalData.Count
                        / (double)EmpericalSampleRepository.GetGeneralSample().Count
                        / IntervalSize
                });
            }

            return(result);
        }