示例#1
0
        private List <MethodData> drawGraphic(TestFunctionBase testFunction, PointPairList basisPoints, PointPairList correctFuncValue, InterpolationBase[] interpolations)
        {
            List <MethodData> methodDatas = new List <MethodData>();
            GraphPane         pane        = zedGraph.GraphPane;

            int symbol = 1;

            foreach (InterpolationBase intrplMethod in interpolations)
            {
                PointPairList interpolatedPoints = doInterpolation(intrplMethod, basisPoints);
                MethodData    methodData         = new MethodData()
                {
                    Method = intrplMethod,
                    InterpolatedFuncValue = interpolatedPoints
                };

                {
                    // add interpolation to graphic
                    LineItem myCurve = null;
                    myCurve                = pane.AddCurve($"F(x) = {intrplMethod.Name}", interpolatedPoints, Color.Black, (SymbolType)symbol);
                    myCurve.Symbol.Size    = 4;
                    myCurve.Symbol.Fill    = new Fill(Color.FromKnownColor((KnownColor)(10 * symbol++)));
                    myCurve.Line.IsVisible = false;
                }

                if (correctFuncValue != null)
                {
                    var(deltaBetweenMethod, methodMark) = countAlgorithmScore(correctFuncValue, interpolatedPoints);
                    setScore(methodMark, intrplMethod);
                    methodData.DeltaBetweenMethod = deltaBetweenMethod;
                    methodData.MethodMark         = methodMark;
                }

                methodDatas.Add(methodData);
            }

            {
                // add basis curve to graphic
                title = testFunction == null ? "Covid-19 Statistics" : $"Interpolation for y = F({testFunction.Name})";
                LineItem myCurve;
                myCurve                = pane.AddCurve($"y_basis = {(testFunction == null ? "" : testFunction.Name)}", basisPoints, Color.Red, SymbolType.TriangleDown);
                myCurve.Symbol.Size    = 7;
                myCurve.Symbol.Fill    = new Fill(Color.Red);
                myCurve.Line.IsVisible = false;
                if (correctFuncValue != null)
                {
                    myCurve                = pane.AddCurve($"y_basis = {(testFunction == null ? "" : testFunction.Name)}", correctFuncValue, Color.Green, SymbolType.TriangleDown);
                    myCurve.Symbol.Size    = 3;
                    myCurve.Symbol.Fill    = new Fill(Color.Green);
                    myCurve.Line.IsVisible = false;
                }
            }

            return(methodDatas);
        }
示例#2
0
        private (PointPairList basisPoints, PointPairList correctFuncValue) constructBasisAndCorrectFuncValues(TestFunctionBase testFunction)
        {
            PointPairList basisPoints      = new PointPairList();
            PointPairList correctFuncValue = new PointPairList();

            Func <int, double> getStepFunc = null;

            if (stepFixedMode.Checked)
            {
                if (!double.TryParse(stepTb.Text, out double fixedStep))
                {
                    fixedStep   = 0.2;
                    stepTb.Text = fixedStep.ToString();
                }
                getStepFunc = new Func <int, double>((int _) => fixedStep);
            }
            else
            {
                getStepFunc = new Func <int, double>((int iter) => testFunction.GetStep(iter));
            }

            // generate basis points and basis points with middle points from func
            int    currIter    = 0;
            double correctXMax = testFunction.XMax + 0.0001;

            for (double x = testFunction.XMin; x < correctXMax; x += getStepFunc(currIter))
            {
                basisPoints.Add(new PointPair(x, testFunction.GetValue(x)));

                if (double.IsNaN(basisPoints.Last().Y) || double.IsInfinity(basisPoints.Last().Y))
                {
                    throw new ArgumentException($"XMin == {testFunction.XMin} correctXMax == {correctXMax}\n" +
                                                $"basisPoints.Last() == {basisPoints.Last()}\n" +
                                                $"double.IsNaN(basisPoints.Last().Y) == {double.IsNaN(basisPoints.Last().Y)}\n" +
                                                $"double.IsInfinity(basisPoints.Last().Y) == {double.IsInfinity(basisPoints.Last().Y)}", nameof(testFunction));
                }

                PointPair curPoint = basisPoints.Last();
                correctFuncValue.Add(curPoint);

                double nextX = x + getStepFunc(currIter + 1);
                if (nextX < correctXMax)
                {
                    // here we should put middle points
                    double delta = (nextX - x) / (pointsBetweenBasisNumber + 1);
                    for (int pbi = 1; pbi <= pointsBetweenBasisNumber; pbi++)                       // pbi means Point Between Bassis Iter
                    {
                        double xMiddle = curPoint.X + pbi * delta;
                        correctFuncValue.Add(new PointPair(xMiddle, testFunction.GetValue(xMiddle)));
                    }
                }
                currIter++;
            }

            return(basisPoints, correctFuncValue);
        }
示例#3
0
        private async void button1_Click(object sender, EventArgs e)
        {
            stepGb.Enabled = false;
            ReportData[] reportData = new ReportData[testFunctions.Length];

            for (funcIt = 0; funcIt < testFunctions.Length; funcIt++)
            {
                try {
                    TestFunctionBase testFunction = testFunctions[funcIt];
                    PointPairList    basisPoints;
                    PointPairList    correctFuncValue;

                    (basisPoints, correctFuncValue) = constructBasisAndCorrectFuncValues(testFunction);

                    setAxisTitleName();

                    // create an array from different interpolations types
                    double normalAlpha = countAlpha(0, basisPoints.Count - 1, basisPoints.XMin(), basisPoints.XMax());
                    InterpolationBase[] interpolations = constructInterpolationList(basisPoints, normalAlpha);

                    // setup Alpha for Gaussian methods of interpolation
                    intrplHelper(interpolations).gaussParametricIntrpl.Alpha = countAlpha(0, basisPoints.Count - 1, intrplHelper(interpolations).gaussParametricIntrpl.TMin, intrplHelper(interpolations).gaussParametricIntrpl.TMax);
                    intrplHelper(interpolations).gaussSummaryIntrpl.Alpha    = countAlpha(0, basisPoints.Count - 1, intrplHelper(interpolations).gaussSummaryIntrpl.TMin, intrplHelper(interpolations).gaussSummaryIntrpl.TMax);
                    alphaNonParametricTb.Text = normalAlpha.ToDoubString();
                    alphaParametricTb.Text    = intrplHelper(interpolations).gaussParametricIntrpl.Alpha.ToDoubString();
                    alphaSummaryTb.Text       = intrplHelper(interpolations).gaussSummaryIntrpl.Alpha.ToDoubString();

                    zedGraph.GraphPane.CurveList.Clear();
                    List <MethodData> methodData = drawGraphic(testFunction, basisPoints, correctFuncValue, interpolations);
                    zoomGraphic();

                    // waiting, while user check 'checkBox1'
                    while (!checkBox1.Checked && !autoReportChBx.Checked)
                    {
                        await Task.Delay(1000);

                        if (!standartFunctionMode.Checked)
                        {
                            return;
                        }
                        if (double.Parse(alphaNonParametricTb.Text) != intrplHelper(interpolations).gaussIntrpl.Alpha ||
                            double.Parse(alphaParametricTb.Text) != intrplHelper(interpolations).gaussParametricIntrpl.Alpha ||
                            double.Parse(alphaSummaryTb.Text) != intrplHelper(interpolations).gaussSummaryIntrpl.Alpha)
                        {
                            normalAlpha    = double.Parse(alphaNonParametricTb.Text);
                            interpolations = constructInterpolationList(basisPoints, normalAlpha);
                            intrplHelper(interpolations).gaussParametricIntrpl.Alpha = double.Parse(alphaParametricTb.Text);
                            intrplHelper(interpolations).gaussSummaryIntrpl.Alpha    = double.Parse(alphaSummaryTb.Text);
                            zedGraph.GraphPane.CurveList.Clear();
                            methodData = drawGraphic(testFunction, basisPoints, correctFuncValue, interpolations);
                            zoomGraphic();
                        }
                    }

                    reportData[funcIt] = new ReportData {
                        CorrectFuncValue = correctFuncValue,
                        TestFunction     = testFunction,
                        MethodsData      = methodData,
                        GraphicImage     = zedGraph.GraphPane.GetImage()
                    };
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message, testFunctions[funcIt].Name);
                } finally {
                    checkBox1.Checked = false;
                }
            }

            if (exportToWordCB.Checked)
            {
                await exportToMsWord(reportData);
            }

            autoReportChBx.Checked = false;
            stepGb.Enabled         = true;
        }