コード例 #1
0
        public void FitsAtSamplePoints()
        {
            IInterpolation it = CubicSpline.InterpolateAkima(_t, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
コード例 #2
0
        public void PolyomnialFitsAtSamplePoints()
        {
            IInterpolation it = Barycentric.InterpolateRationalFloaterHormann(_t, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
コード例 #3
0
        public void FixedFirstDerivativeFitsAtSamplePoints()
        {
            IInterpolation it = CubicSpline.InterpolateBoundaries(_t, _y, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
コード例 #4
0
        public void FitsAtSamplePoints()
        {
            IInterpolation it = Barycentric.InterpolatePolynomialEquidistant(Tmin, Tmax, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], it.Interpolate(i), "A Exact Point " + i);
            }
        }
コード例 #5
0
        public void FitsAtSamplePoints()
        {
            IInterpolation interpolation = BulirschStoerRationalInterpolation.Interpolate(_t, _x);

            for (int i = 0; i < _x.Length; i++)
            {
                Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
コード例 #6
0
        public void NaturalSupportsLinearCase(int samples)
        {
            LinearInterpolationCase.Build(out var x, out var y, out var xtest, out var ytest, samples);
            IInterpolation it = CubicSpline.InterpolateNatural(x, y);

            for (int i = 0; i < xtest.Length; i++)
            {
                Assert.AreEqual(ytest[i], it.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i);
            }
        }
コード例 #7
0
ファイル: Timeline.cs プロジェクト: bntre/cs-rationals
            public TDouble Interpolate(TTime time)
            {
                if (_interpolation == null)
                {
                    return(default(TDouble));
                }
                double value = _interpolation.Interpolate((double)time);

                return(value);
            }
コード例 #8
0
    public override InterpolatedObject InterpolatedState(int timeMilliseconds)
    {
        int curtimeMilliseconds           = timeMilliseconds;
        int interpolationtimeMilliseconds = curtimeMilliseconds - DELAYMILLISECONDS;
        int p1;
        int p2;

        if (receivedCount == 0)
        {
            return(null);
        }
        InterpolatedObject result;

        if (receivedCount > 0 && interpolationtimeMilliseconds < received[0].timestampMilliseconds)
        {
            p1 = 0;
            p2 = 0;
        }
        //extrapolate
        else if (EXTRAPOLATE && (receivedCount >= 2) &&
                 interpolationtimeMilliseconds > received[receivedCount - 1].timestampMilliseconds)
        {
            p1 = receivedCount - 2;
            p2 = receivedCount - 1;
            interpolationtimeMilliseconds = MathCi.MinInt(interpolationtimeMilliseconds, received[receivedCount - 1].timestampMilliseconds + EXTRAPOLATION_TIMEMILLISECONDS);
        }
        else
        {
            p1 = 0;
            for (int i = 0; i < receivedCount; i++)
            {
                if (received[i].timestampMilliseconds <= interpolationtimeMilliseconds)
                {
                    p1 = i;
                }
            }
            p2 = p1;
            if (receivedCount - 1 > p1)
            {
                p2++;
            }
        }
        if (p1 == p2)
        {
            result = received[p1].content;
        }
        else
        {
            float one = 1;
            result = req.Interpolate(received[p1].content, received[p2].content,
                                     (one * (interpolationtimeMilliseconds - received[p1].timestampMilliseconds)
                                      / (received[p2].timestampMilliseconds - received[p1].timestampMilliseconds)));
        }
        return(result);
    }
コード例 #9
0
        /// <summary>
        ///    Returns the yValue defined for the xValue in base unit given as parameter. If the table contains no point, 0 is
        ///    returned
        /// </summary>
        public virtual double ValueAt(double xValue)
        {
            if (_allPoints.Count == 0)
            {
                return(0);
            }

            var knownSamples = _allPoints.Select(point => new Sample(point.X, point.Y));

            return(_interpolation.Interpolate(knownSamples, xValue));
        }
コード例 #10
0
        public void SupportsLinearCase(int samples)
        {
            double[] x, y, xtest, ytest;
            LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);
            IInterpolation it = CubicSpline.InterpolatePchip(x, y);

            for (int i = 0; i < xtest.Length; i++)
            {
                Assert.AreEqual(ytest[i], it.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i);
            }
        }
コード例 #11
0
ファイル: ParameterFactory.cs プロジェクト: yvkashyap/PK-Sim
        private ParameterDistributionMetaData closestDistributionMetaDataFor(IReadOnlyList <ParameterDistributionMetaData> distributions, OriginData originData)
        {
            if (!originData.Age.HasValue)
            {
                return(distributions.First());
            }

            var samples = distributions.Select(x => new Sample <ParameterDistributionMetaData>(x.Age, x));

            return(_interpolation.Interpolate(samples, originData.Age.Value));
        }
コード例 #12
0
        public void SupportsLinearCase(int samples)
        {
            double[] x, y, xtest, ytest;
            LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);
            IInterpolation it = Barycentric.InterpolateRationalFloaterHormann(x, y);

            for (int i = 0; i < xtest.Length; i++)
            {
                Assert.AreEqual(ytest[i], it.Interpolate(xtest[i]), 1e-14, "Linear with {0} samples, sample {1}", samples, i);
            }
        }
コード例 #13
0
        public Func <double, double> MakeInterpolator(IEnumerable <double> x, IEnumerable <double> y)
        {
            SplineBoundaryCondition bc;
            int xlength = x.Count();
            int mode    = InterpolationModeComboBox.SelectedIndex;

            if (mode == 0 || mode == 1)
            {
                int order;
                order = mode * 2 + 1; // linear => 1; cubic => 3
                int npoints;
                if (!int.TryParse(extrapolationPointsTextBox.Text, out npoints))
                {
                    throw new Exception("Cannot parse number of points");
                }
                if (npoints > xlength)
                {
                    throw new Exception("Too many points required");
                }
                if (npoints < order)
                {
                    throw new Exception("More points must be used");
                }
                var leftInterp = Fit.PolynomialFunc(x.Take(npoints).ToArray(), y.Take(npoints).ToArray(),
                                                    order);
                var rightInterp = Fit.PolynomialFunc(x.Reverse().Take(npoints).Reverse().ToArray(),
                                                     y.Reverse().Take(npoints).Reverse().ToArray(),
                                                     order);
                double middlex = x.Skip((int)(xlength / 2)).First();
                return(x2 => (x2 < middlex)?leftInterp(x2) : rightInterp(x2));
            }
            else if (mode == 5)
            {
                IInterpolation I = LinearSpline.Interpolate(x, y);
                return(x2 => I.Interpolate(x2));
            }
            else
            {
                if (InterpolationModeComboBox.SelectedIndex == 1)
                {
                    bc = SplineBoundaryCondition.ParabolicallyTerminated;
                }
                else
                {
                    bc = SplineBoundaryCondition.Natural;
                }

                IInterpolation I = CubicSpline.InterpolateBoundaries(
                    x, y,
                    bc, 0, bc, 0); // Values are unused for natural and parabolic termination
                return(x2 => I.Interpolate(x2));
            }
        }
コード例 #14
0
        private void loadApproximatedPolyline()
        {
            int    segmentCount  = (int)(this.PlineRepresentationLength * _numberOfPointsPerUniteOfLength) + 1;
            double segmentLength = this.PlineRepresentationLength / segmentCount;

            this._approximatedPoints = new UV[segmentCount + 1];
            for (int i = 0; i < segmentCount + 1; i++)
            {
                double time = _lengthToTime.Interpolate(i * segmentLength);
                this._approximatedPoints[i] = getLocation(time);
            }
        }
コード例 #15
0
ファイル: OntogenyRepository.cs プロジェクト: valdiman/PK-Sim
        public double OntogenyFactorFor(Ontogeny ontogeny, string containerName, double?age, double?gestationalAge, RandomGenerator randomGenerator)
        {
            var allOntogenies = AllValuesFor(ontogeny, containerName);

            if (!allOntogenies.Any())
            {
                return(CoreConstants.DEFAULT_ONTOGENY_FACTOR);
            }

            var factorRetriever = ontogenyFactorRetriever(randomGenerator, allOntogenies);

            return(_interpolation.Interpolate(allOntogenies.Select(x => new Sample(x.PostmenstrualAge, factorRetriever(x))), postmenstrualAgeInYearsFor(age, gestationalAge)));
        }
コード例 #16
0
        private double Interpolate(IInterpolation interpolation, double x)
        {
            if (interpolation is null)
            {
                throw new InvalidOperationException("Missing Interpolation type.");
            }

            if (Changed)
            {
                Sort();
                interpolation.Calculate(Points);
            }

            return(interpolation.Interpolate(x));
        }
コード例 #17
0
ファイル: Interpolated.cs プロジェクト: lulzzz/SpiceSharp
 /// <summary>
 /// Calculate the value at a timepoint
 /// </summary>
 /// <param name="time">Timepoint</param>
 /// <returns></returns>
 public override double At(double time)
 {
     if (time < Time[0])
     {
         return(Value[0]);
     }
     else if (time > Time[Time.Length - 1])
     {
         return(Value[Value.Length - 1]);
     }
     else
     {
         return(interpolation.Interpolate(time));
     }
 }
コード例 #18
0
        public void RationalFitsAtSamplePoints()
        {
            var t = new double[40];
            var x = new double[40];

            const double Step = 10.0 / 39.0;

            for (int i = 0; i < t.Length; i++)
            {
                double tt = -5 + (i * Step);
                t[i] = tt;
                x[i] = 1.0 / (1.0 + (tt * tt));
            }

            IInterpolation it = Barycentric.InterpolateRationalFloaterHormann(t, x);

            for (int i = 0; i < x.Length; i++)
            {
                Assert.AreEqual(x[i], it.Interpolate(t[i]), "A Exact Point " + i);
            }
        }
コード例 #19
0
        private void CalculateCoefficients()
        {
            int quantity = PointsContainer.PlotPoints.Points.Count;

            double[] x       = new double[quantity];
            double[] y       = new double[quantity];
            int      counter = 0;

            foreach (DataPoint Point in PointsContainer.PlotPoints.Points)
            {
                x[counter] = Point.X;
                y[counter] = Point.Y;
                counter++;
            }
            IInterpolation cubicSpline = Interpolate.CubicSpline(x, y);

            for (double i = this.AxisMinimum; i < this.AxisMaximum; i += this.Step)
            {
                PointsContainer.PolynomSeries.Points.Add(new DataPoint(i, cubicSpline.Interpolate(i)));
            }
        }
コード例 #20
0
        /// <summary>
        /// Interpolates the potentials at the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>System.Nullable&lt;System.Double&gt;.</returns>
        public double?Interpolate(UV point)
        {
            Index index = this._cellularFloor.FindIndex(point);

            try
            {
                IInterpolation u_Interpolation = this.interpolation_U(point, index);
                return(u_Interpolation.Interpolate(point.U));
            }
            catch (Exception)
            {
            }
            try
            {
                IInterpolation v_Interpolation = this.interpolation_V(point, index);
                return(v_Interpolation.Interpolate(point.V));
            }
            catch (Exception)
            {
            }
            return(null);
        }
コード例 #21
0
ファイル: MainWindow.xaml.cs プロジェクト: Legomaniak/TestFit
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            show.addData(sample0.ToArray(), sample1.ToArray(), 0);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var            x      = new double[Wnum];
            var            y      = new double[Wnum];
            IInterpolation spline = null;

            switch (cbM.SelectedIndex)
            {
            case 1:
                spline = CubicSpline.InterpolateAkimaSorted(sample0, sample1);
                break;

            default:
                spline = LinearSpline.Interpolate(sample0, sample1);
                break;
            }
            var Wdelta = (Wstop - Wstart) / Wnum;

            for (int i = 0; i < Wnum; i++)
            {
                y[i] = Wstart + i * Wdelta;
                x[i] = spline.Interpolate(y[i]);
            }
            sw.Stop();
            var tm = sw.ElapsedMilliseconds;

            show.addData(y, x, 1);

            var sb = new StringBuilder();

            sb.AppendLine("Time [ms] " + tm);

            Results = sb.ToString();
        }
コード例 #22
0
        public void FitsAtNagExamplePoints(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = CubicSpline.InterpolatePchip(_tNag, _yNag);

            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #23
0
        public void FitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = CubicSpline.InterpolatePchip(_t, _y);

            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #24
0
 /// <summary>
 /// Interpolate at point t.
 /// </summary>
 /// <param name="t">Point t to interpolate at.</param>
 /// <returns>Interpolated value x(t).</returns>
 public double Interpolate(double t) => _transform(_interpolation.Interpolate(t));
コード例 #25
0
        public void PolynomialFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = Barycentric.InterpolateRationalFloaterHormann(_t, _y);

            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #26
0
        public void FitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = Barycentric.InterpolatePolynomialEquidistant(Tmin, Tmax, _y);

            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #27
0
 public static double GetReff(double n)
 {
     return(interpolator.Interpolate(n));
 }
コード例 #28
0
        public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
        {
            IInterpolation interpolation = BulirschStoerRationalInterpolation.Interpolate(_t, _x);

            Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #29
0
 /// <summary>
 /// Interpolate at point t.
 /// </summary>
 /// <param name="t">Point t to interpolate at.</param>
 /// <returns>Interpolated value x(t).</returns>
 public double Interpolate(double t)
 {
     return(_transform(_interpolation.Interpolate(t)));
 }
コード例 #30
0
        public void FixedSecondDerivativeFitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = CubicSpline.InterpolateBoundaries(_t, _y, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0);

            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }