Esempio n. 1
0
        private void OnApplyClick(object sender, EventArgs e)
        {
            if (DataChart.IdealCurve.Points.Count == 0)
            {
                log.Info(MethodBase.GetCurrentMethod().Name + '(' + nameof(DataChart.IdealCurve) + ')');
                AppMessages.MainWindow.ExclamationOfSeriesSelection();
                return;
            }

            MeanType meanType = (MeanType)UiControls.TryGetSelectedIndex(uiPnlAvg_MeanT_ComBx);
            int      curvesNo = UiControls.TryGetValue <int>(uiPnlAvg_Crvs2No_Num);
            bool?    result   = DataChart.TryMakeAverageCurve(meanType, curvesNo);

            log.Info(MethodBase.GetCurrentMethod().Name + '(' + meanType + ',' + curvesNo + ',' + result.HasValue + ')');

            if (!result.Value)
            {
                DataChart.RemoveInvalidPoints(DataSetCurveType.Average);
                AppMessages.MainWindow.ExclamationOfPointsNotValidToChart();
            }

            UiControls.TrySetSelectedIndex(uiPnlMod_CrvT_ComBx, (int)DataSetCurveType.Average);
            UpdateUiByShowingCurveOnChart(DataSetCurveType.Average);
            double standardDeviation = Mathematics.GetRelativeStandardDeviation(SeriesAssist.GetValues(DataChart.AverageCurve), SeriesAssist.GetValues(DataChart.IdealCurve));

            uiPnlAvg_StdDev2_TxtBx.Text = Strings.TryFormatAsNumeric(8, standardDeviation);
        }
Esempio n. 2
0
        private void OnToleranceFinisherFunctionSelection(object sender, EventArgs e)
        {
            MeanType before = (MeanType)UiControls.TryGetSelectedIndex(uiGrid_TolerFin_ComBx);

            switch (before)
            {
            case MeanType.Tolerance:
            case MeanType.NN:
            case MeanType.NadarayaWatson:
                UiControls.TrySetSelectedIndex(uiGrid_TolerFin_ComBx, (int)MeansParams.Tolerance.Finisher);
                AppMessages.MeansSettings.WarningOfNotSupportedFinisherFunction();
                break;

            default:
                MeansParams.Tolerance.Finisher = (MeanType)UiControls.TryGetSelectedIndex(uiGrid_TolerFin_ComBx);
                break;
            }

            MeanType after = (MeanType)UiControls.TryGetSelectedIndex(uiGrid_TolerFin_ComBx);

            log.Info(MethodBase.GetCurrentMethod().Name + '(' + before + ',' + after + ')');
        }
Esempio n. 3
0
        public bool?TryMakeAverageCurve(MeanType method, int curvesNo)
        {
            if (curvesNo < 0)
            {
                return(null);
            }

            string         signature = string.Empty;
            IList <double> result    = new List <double>();

            try {
                signature = MethodBase.GetCurrentMethod().Name + '(' + method + ',' + curvesNo + ')';
                IList <IList <double> > orderedSetOfCurves = SeriesAssist.GetOrderedCopy(ModifiedCurves, curvesNo);

                switch (method)
                {
                case MeanType.Median:
                    result = Averages.Median(orderedSetOfCurves);
                    break;

                case MeanType.Maximum:
                    result = Averages.Maximum(orderedSetOfCurves);
                    break;

                case MeanType.Minimum:
                    result = Averages.Minimum(orderedSetOfCurves);
                    break;

                case MeanType.Arithmetic:
                    result = Averages.Arithmetic(orderedSetOfCurves);
                    break;

                case MeanType.Geometric:
                    result = Averages.Geometric(orderedSetOfCurves, MeansParams.Geometric.Variant);
                    break;

                case MeanType.AGM:
                    result = Averages.AGM(orderedSetOfCurves, MeansParams.AGM.Variant);
                    break;

                case MeanType.Heronian:
                    result = Averages.Heronian(orderedSetOfCurves, MeansParams.Heronian.Variant);
                    break;

                case MeanType.Harmonic:
                    result = Averages.Harmonic(orderedSetOfCurves, MeansParams.Harmonic.Variant);
                    break;

                case MeanType.Generalized:
                    result = Averages.Generalized(orderedSetOfCurves, MeansParams.Generalized.Variant, MeansParams.Generalized.Rank);
                    break;

                case MeanType.SMA:
                    result = Averages.SMA(orderedSetOfCurves);
                    break;

                case MeanType.Tolerance:
                    result = Averages.Tolerance(orderedSetOfCurves, MeansParams.Tolerance.Tolerance, MeansParams.Tolerance.Finisher);
                    break;

                case MeanType.Central:
                    result = Averages.Central(orderedSetOfCurves, MeansParams.Central.MassPercent);
                    break;

                case MeanType.NN:
                    result = Smoothers.NearestNeighbors(orderedSetOfCurves, MeansParams.NN.Amount);
                    break;

                case MeanType.NadarayaWatson:
                    result = Smoothers.NadarayaWatson(orderedSetOfCurves, MeansParams.NadarayaWatson.Variant, MeansParams.NadarayaWatson.KernelType, MeansParams.NadarayaWatson.KernelSize);
                    break;
                }
            }
            catch (ArgumentOutOfRangeException ex) {
                log.Error(signature, ex);
                return(false);
            }
            catch (OverflowException ex) {
                log.Error(signature, ex);
                return(false);
            }
            catch (InvalidOperationException ex) {
                log.Error(signature, ex);
                return(false);
            }
            catch (Exception ex) {
                log.Fatal(signature, ex);
                return(false);
            }

            AverageCurve.Points.Clear();
            SeriesAssist.CopyPoints(AverageCurve, IdealCurve, result);
            return(SeriesAssist.IsChartAcceptable(AverageCurve));
        }
Esempio n. 4
0
        public static IList <double> Tolerance(IList <IList <double> > orderedSet, double tolerance, MeanType finisher = MeanType.Harmonic, MeansParameters @params = null)
        {
            if (orderedSet == null || orderedSet.Count == 0)
            {
                return(new List <double>().AsReadOnly());
            }

            double         comparer   = Median(Maximum(orderedSet)).Value - Median(Minimum(orderedSet)).Value;
            double         classifier = comparer * tolerance;
            IList <double> tolerants  = new List <double>();

            for (int x = 0; x < orderedSet.Count; x++)
            {
                tolerants.Add(Tolerance(orderedSet[x], classifier, finisher, @params).Value);
            }

            return(tolerants);
        }
Esempio n. 5
0
        public static double?Tolerance(IList <double> set, double classifier, MeanType finisher = MeanType.Harmonic, MeansParameters @params = null)
        {
            if (set == null || set.Count == 0)
            {
                return(null);
            }

            if (@params == null)
            {
                @params = new MeansParameters();
            }

            IList <double> acceptables = new List <double>();
            IList <double> oscillators = Lists.GetCopy(set);

            Lists.Subtract(oscillators, Median(set).Value);

            for (int i = 0; i < set.Count; i++)
            {
                if (Math.Abs(oscillators[i]) < Math.Abs(classifier))
                {
                    acceptables.Add(set[i]);
                }
            }

            switch (finisher)
            {
            case MeanType.Median:
                return(Median(acceptables));

            case MeanType.Maximum:
                return(Maximum(acceptables));

            case MeanType.Minimum:
                return(Minimum(acceptables));

            case MeanType.Arithmetic:
                return(Arithmetic(acceptables));

            case MeanType.Geometric:
                return(Geometric(acceptables, @params.Geometric.Variant));

            case MeanType.AGM:
                return(AGM(acceptables, @params.AGM.Variant));

            case MeanType.Heronian:
                return(Heronian(acceptables, @params.Heronian.Variant));

            case MeanType.Harmonic:
                return(Harmonic(acceptables, @params.Harmonic.Variant));

            case MeanType.Generalized:
                return(Generalized(acceptables, @params.Generalized.Variant, @params.Generalized.Rank));

            case MeanType.SMA:
                return(SMA(acceptables));

            case MeanType.Central:
                return(Central(acceptables, @params.Central.MassPercent));
            }

            return(null);
        }