コード例 #1
0
ファイル: Timeline.cs プロジェクト: bntre/cs-rationals
            protected void UpdateInterpolation()
            {
                int count = _keyFrames.Count;
                var xs    = new double[count];
                var ys    = new double[count];

                for (int i = 0; i < count; ++i)
                {
                    xs[i] = (double)_keyFrames[i].time;
                    ys[i] = (double)_keyFrames[i].value;
                }
                if (count <= 1)
                {
                    _interpolation = StepInterpolation.Interpolate(xs, ys);
                }
                else if (count <= 2)
                {
                    _interpolation = LinearSpline.Interpolate(xs, ys);
                }
                else if (count <= 3)
                {
                    _interpolation = MathNet.Numerics.Interpolate.Polynomial(xs, ys);
                }
                else if (count <= 4)
                {
                    _interpolation = CubicSpline.InterpolateNatural(xs, ys);
                }
                else
                {
                    _interpolation = CubicSpline.InterpolateAkima(xs, ys);
                }
            }
 public UniformDistributionFormulaSpecificationFactory(
     IInterpolation interpolation,
     OSPSuite.Core.Domain.Formulas.IDistributionFormulaFactory distributionFormulaFactory)
 {
     _interpolation = interpolation;
     _distributionFormulaFactory = distributionFormulaFactory;
 }
コード例 #3
0
 public DistributedParameterToTableParameterConverter(
     IFormulaFactory formulaFactory,
     IEntityPathResolver entityPathResolver,
     IParameterFactory parameterFactory,
     ICloneManager cloneManager,
     IParameterQuery parameterQuery,
     IDimensionRepository dimensionRepository,
     IOntogenyRepository ontogenyRepository,
     IFullPathDisplayResolver fullPathDisplayResolver,
     IInterpolation interpolation,
     IParameterStartValuesCreator parameterStartValuesCreator,
     IObjectPathFactory objectPathFactory,
     IGenderRepository genderRepository)
 {
     _formulaFactory              = formulaFactory;
     _entityPathResolver          = entityPathResolver;
     _parameterFactory            = parameterFactory;
     _cloneManager                = cloneManager;
     _parameterQuery              = parameterQuery;
     _dimensionRepository         = dimensionRepository;
     _ontogenyRepository          = ontogenyRepository;
     _fullPathDisplayResolver     = fullPathDisplayResolver;
     _interpolation               = interpolation;
     _parameterStartValuesCreator = parameterStartValuesCreator;
     _objectPathFactory           = objectPathFactory;
     _genderRepository            = genderRepository;
     _timeDimension               = dimensionRepository.Time;
     _yearUnit = _timeDimension.Unit(dimensionRepository.AgeInYears.BaseUnit.Name);
 }
コード例 #4
0
        private static void SaveMoleculePixelsToFile(IInterpolation molInterpolation, Molecule molecule, int channel, string outputDir)
        {
            int[] fitPositions = new int[molecule.Pixels[channel - 1].Length];
            for (int pixelPosition = 0; pixelPosition < molecule.Pixels[channel - 1].Length; pixelPosition++)
            {
                fitPositions[pixelPosition] = (int)(Math.Round(molInterpolation.Interpolate(pixelPosition)));
            }
            string outputFileName = "molecule_" + molecule.MoleculeId.ToString() + "_channel" + channel.ToString() + ".txt";
            string subdirPath     = Path.Combine(outputDir, "channel" + channel.ToString());

            if (!Directory.Exists(subdirPath))
            {
                Directory.CreateDirectory(subdirPath);
            }
            string outputFilePath = Path.Combine(subdirPath, outputFileName);

            using (StreamWriter sw = new StreamWriter(outputFilePath))
            {
                sw.WriteLine("track type=bedGraph name=\"molecule_" + molecule.MoleculeId.ToString() + "_channel" + channel.ToString() + "\"");
                if (molecule.Orientation == "+")
                {
                    WritePlusOrientationMol(molecule, fitPositions, channel, sw);
                }
                else
                {
                    WriteMinusOrientationMol(molecule, fitPositions, channel, sw);
                }
            }
        }
コード例 #5
0
        protected override void Context()
        {
            _interpolation = A.Fake <IInterpolation>();

            _distrFormulaFactory = A.Fake <IDistributionFormulaFactory>();
            sut = new NormalDistributionFormulaSpecificationFactory(_interpolation, _distrFormulaFactory);
        }
コード例 #6
0
 //http://numerics.mathdotnet.com/api/MathNet.Numerics.Interpolation/CubicSpline.htm
 /// <summary>
 /// Sets the interpolation formula.
 /// </summary>
 /// <param name="interpolation">The interpolation.</param>
 public void SetInterpolation(IInterpolation interpolation)
 {
     this.GetCost             = null;
     this.GetCost             = new CalculateCost(interpolation.Interpolate);
     interpolation            = null;
     this.CostCalculationType = CostCalculationMethod.Interpolation;
 }
コード例 #7
0
ファイル: OktofsPolicyEsses.cs プロジェクト: sibaoli/Moirai
            //XXXIS add more things if we need them?

            public EssesFlowCacheContext(Flow flow, UInt64 cacheSizeAllocated, CacheWritePolicy writePolicy, CacheWriteBuffer cacheWrites, string cacheCurvePointsFile, string tenantID)
            {
                Flow = flow;
                this.cacheSizeAllocated = cacheSizeAllocated;
                this.writePolicy        = writePolicy;
                this.cacheWrites        = cacheWrites;
                this.hitRate            = 0.0F;
                this.tenantID           = tenantID;

                this.demandPointsSerializationFile = cacheCurvePointsFile;

                if (File.Exists(this.demandPointsSerializationFile))
                {
                    readInCacheCurve();
                    this.useSerializedCurve = true;
                }
                else
                {
                    this.cacheDemandCurvePoints = null;
                    this.cacheDemandFunc        = null;
                    this.useSerializedCurve     = false;
                }

#if COLLECT_CACHE_CURVE
                Console.CancelKeyPress += new ConsoleCancelEventHandler(Controller_CancelKeyPress);
#endif
            }
コード例 #8
0
        public void FitsAtArbitraryPoints(double t, double x, double maxAbsoluteError)
        {
            IInterpolation it = CubicSpline.InterpolateAkima(_t, _y);

            // TODO: Verify the expected values (that they are really the expected ones)
            Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
        }
コード例 #9
0
        private void BtnSelect_Click(object sender, RoutedEventArgs e)
        {
            City city = cbCities.SelectedItem as City;

            if (city != null)
            {
                string[] timeString = dpDate.Text.Split('/');
                DateTime dateVal    = new DateTime(int.Parse(timeString[2]), int.Parse(timeString[1]), int.Parse(timeString[0]));
                Report   rp         = city.GetReport(dateVal);
                Report   rpBefore   = city.GetReport(dateVal.AddDays(-1));
                Report   rpAfter    = city.GetReport(dateVal.AddDays(1));

                //Create polynomial interpolation for temperatures
                IInterpolation interpolation = Utils.TemperaturesInterpolation(rpBefore.TMax, rp.TMin, rp.TMax, rpAfter.TMin);

                //Create polynomial interpolation for pressures
                IInterpolation interpolationPressure = Utils.PressuresInterpolation(rpBefore.LastPressure(), rp.Pressures, rpAfter.FirstPressure());

                dgForecast.Items.Clear();

                for (int i = 0; i < 24; i++)
                {
                    double tempe    = interpolation.Interpolate(i);
                    double pressure = interpolationPressure.Interpolate(i);
                    double weather  = rp.Weather[i];
                    dgForecast.Items.Add(new HourlyReport {
                        Hour = i + "h", Temperature = tempe.ToString("0.0") + "°", Color = GetTemperatureColor(tempe), Pressure = pressure.ToString("0.0 hp"), Icon = ViewUtils.IconPath(ViewUtils.WeatherToIcon(weather))
                    });
                }
            }
        }
コード例 #10
0
        public static void Apply(
            IInterpolation interpolator,
            Span <Color> toPixels,
            Color color,
            float time,
            float intensity,
            int effectLength)
        {
            var   start      = Math.Abs(time) % toPixels.Length;
            int   startPixel = (int)start;
            float tStep      = 1 / (float)effectLength;
            float timeOffset = tStep * (1 - Math.Abs(start - (int)start));

            for (int i = 0; i < effectLength; i++)
            {
                float t              = 1 - (tStep * i + timeOffset);
                var   interpolation  = interpolator.Interpolate(t);
                float colorIntensity = (float)MathUtil.Clamp(0, 1, interpolation * intensity);

                int index = (startPixel + i) % toPixels.Length;
                if (index < toPixels.Length)
                {
                    toPixels[index] =
                        toPixels[index].Add(
                            Color.FromArgb(
                                (int)(color.R * colorIntensity),
                                (int)(color.G * colorIntensity),
                                (int)(color.B * colorIntensity)));
                }
            }
        }
コード例 #11
0
        private static Task <Location> InterpolateLocationAsync(DateTime relativeTo, Location initialLocation, IEnumerable <Segment> segments)
        {
            IList <double> longitudes      = new List <double>();
            IList <double> latitudes       = new List <double>();
            IList <double> timeSpans       = new List <double>();
            TimeSpan       currentTimeSpan = TimeSpan.Zero;
            TimeSpan       myTimeSpan      = TimeSpan.Zero;

            longitudes.Add(initialLocation.Longitude);
            latitudes.Add(initialLocation.Latitude);
            timeSpans.Add(currentTimeSpan.TotalSeconds);
            foreach (Segment segment in segments)
            {
                longitudes.Add(segment.Longitude);
                latitudes.Add(segment.Latitude);
                currentTimeSpan += segment.TimeSpan;
                timeSpans.Add(currentTimeSpan.TotalSeconds);
            }

            myTimeSpan = relativeTo - initialLocation.DateTime;
            IInterpolation longitudesInterpolation = Interpolate.Linear(timeSpans, longitudes);
            IInterpolation latitudesInterpolation  = Interpolate.Linear(timeSpans, latitudes);

            return(Task.FromResult(
                       new Location
            {
                Longitude = longitudesInterpolation.Interpolate(myTimeSpan.TotalSeconds),
                Latitude = latitudesInterpolation.Interpolate(myTimeSpan.TotalSeconds),
                DateTime = relativeTo
            }));
        }
コード例 #12
0
        public IMask GetQuarterFadedCircle(int radius, float fade, IInterpolation interpolation)
        {
            if (radius < 0 || fade > 1 || fade < 0)
            {
                throw new ArgumentException();
            }
            int fadeBegin = (int)(radius * (1 - fade));
            var brushmask = new Mask(new Vector2(radius, radius));

            for (int y = 0; y < radius; y++)
            {
                var li = (int)JryMath.Sqrt(radius * radius - (radius - y) * (radius - y));

                for (int x = 0; x < li; x++)
                {
                    var   yCor = radius - y;
                    float val  = 1;
                    var   dis  = JryMath.Sqrt(x * x + yCor * yCor);
                    if (dis > fadeBegin)
                    {
                        val = interpolation.Interpolate(1, 0, (dis - fadeBegin) / (radius - fadeBegin));
                    }

                    brushmask[x, yCor - 1] = val;
                }
            }
            return(brushmask);
        }
コード例 #13
0
        /// <summary>
        /// Main ctor.
        /// </summary>
        /// <param name="discreteCurve"></param>
        /// <param name="interpolation"></param>
        /// <param name="allowExtrapolation"></param>
        public InterpolatedCurve(IDiscreteSpace discreteCurve, IInterpolation interpolation, bool allowExtrapolation)
            : base(discreteCurve, interpolation, allowExtrapolation)
        {
            var xArray = GetDiscreteSpace().GetCoordinateArray(1);
            var yArray = GetDiscreteSpace().GetFunctionValueArray();

            Interpolation.Initialize(xArray, yArray);
        }
コード例 #14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="edgeWavelength">Absorbtion edge wavelength
        /// calibration array.</param>
        /// <param name="tempetature">Temperature calibration array.</param>
        public Calibration_Points(double[] edgeWavelength, double[] tempetature)
        {
            EdgeWavelength = edgeWavelength;
            Temperature    = tempetature;

            // interpolation = MathNet.Numerics.Interpolate.Linear(EdgeWavelength, Temperature);
            interpolation = MathNet.Numerics.Interpolate.CubicSpline(EdgeWavelength, Temperature);
        }
コード例 #15
0
        public static IInterpolation GetLinearInterpolationMethod(Peak peak)
        {
            peak.GetXAndYValuesAsLists(out var xValues, out var yValues);

            IInterpolation interpolation = LinearSpline.Interpolate(xValues, yValues);

            return(interpolation);
        }
コード例 #16
0
        /// <summary>
        /// Gets the skew.
        /// </summary>
        /// <param name="wingParameterList">The wing parameter list.</param>
        /// <param name="xInterp">The x interp.</param>
        /// <param name="time">The time.</param>
        /// <param name="strike">The strike.</param>
        /// <returns></returns>
        public static double GetWingSkew(List <OrcWingParameters> wingParameterList, IInterpolation xInterp, double time, double strike)
        {
            const double eps = 0.0001;
            double       f1  = GetWingValue(wingParameterList, xInterp, time, strike * (1 + eps));
            double       f0  = GetWingValue(wingParameterList, xInterp, time, strike * (1 - eps));

            return((f1 - f0) / (2 * eps * strike));
        }
コード例 #17
0
        private IInterpolation interpolation_U(UV point, Index index)
        {
            IndexRange horizontalExpansion = this.horizontalRange(index);

            //getting all vertical ranges of the horizontal
            IndexRange[] verticals = new IndexRange[horizontalExpansion.Length];
            Index        next      = horizontalExpansion.Min.Copy();

            for (int i = 0; i < horizontalExpansion.Length; i++)
            {
                verticals[i] = this.verticalRange(next);
                next.I++;
            }
            //getting interpolators for u values
            IInterpolation[] verticalsU = new IInterpolation[horizontalExpansion.Length];
            for (int i = 0; i < verticals.Length; i++)
            {
                verticalsU[i] = this.toInterpolation(verticals[i]);
            }
            //generating u interpolation
            double[] x = new double[horizontalExpansion.Length];
            double[] y = new double[horizontalExpansion.Length];
            next = horizontalExpansion.Min.Copy();
            for (int i = 0; i < horizontalExpansion.Length; i++)
            {
                x[i] = this._cellularFloor.FindCell(next).U;
                y[i] = verticalsU[i].Interpolate(point.V);
                next.I++;
            }
            IInterpolation interpolatorU = null;

            switch (Activity.InterpolationMethod)
            {
            case SpatialAnalysis.FieldUtility.InterpolationMethod.CubicSpline:
                if (x.Length > 1)
                {
                    interpolatorU = CubicSpline.InterpolateBoundariesSorted(x, y,
                                                                            SplineBoundaryCondition.Natural, 0,
                                                                            SplineBoundaryCondition.Natural, 0);
                }
                else
                {
                    interpolatorU = LinearSpline.InterpolateSorted(x, y);
                }
                break;

            //case FieldUtility.InterpolationMethod.Barycentric:
            //    interpolatorU = Barycentric.InterpolatePolynomialEquidistantSorted(x, y);
            //    break;
            case SpatialAnalysis.FieldUtility.InterpolationMethod.Linear:
                interpolatorU = LinearSpline.InterpolateSorted(x, y);
                break;

            default:
                break;
            }
            return(interpolatorU);
        }
コード例 #18
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);
            }
        }
コード例 #19
0
 public CurveEffect(
     NeoPixelSetup neoPixelSetup,
     IColorProvider colorProvider,
     IInterpolation interpolator)
 {
     this.neoPixelSetup = neoPixelSetup;
     this.ColorProvider = colorProvider;
     this.Interpolator  = interpolator;
 }
コード例 #20
0
        /// <summary>
        /// Main ctor.
        /// </summary>
        /// <param name="discreteSurface">The discrete surface ie 2 dimensional.</param>
        /// <param name="forwards">The forwards to be used for calibration.</param>
        /// <param name="xInterpolation">The basic interpolation to be applied to the x axis.</param>
        /// <param name="yInterpolation">The interpolation type for the y axis</param>
        /// <param name="allowExtrapolation">Not implemented in EO.</param>
        protected ExtendedInterpolatedSurface(DiscreteSurface discreteSurface, ParametricAdjustmentPoint[] forwards, IInterpolation xInterpolation,
                                              IInterpolation yInterpolation, bool allowExtrapolation)
            : base(discreteSurface, xInterpolation, yInterpolation, allowExtrapolation)
        {
            var values = discreteSurface.GetMatrixOfValues();
            var x      = discreteSurface.XArray;
            var width  = values.ColumnCount;

            if (forwards != null)
            {
                SpotValue = (double)forwards[0].parameterValue;
                var length = forwards.Length;
                var fwds   = new double[length - 1];
                for (var index = 1; index < length; index++)
                {
                    fwds[index - 1] = (double)forwards[index].parameterValue;
                }
                var fwdcurve = new LinearInterpolation();
                fwdcurve.Initialize(x, fwds);
                ForwardCurve = fwdcurve;
            }
            if (yInterpolation.GetType() == typeof(SABRModelInterpolation))
            {
                var y      = discreteSurface.YArray;
                var length = values.RowCount;
                for (int i = 0; i < length; i++)
                {
                    //interpolate each maturity first (in strike) with SABR
                    var yinterp = (SABRModelInterpolation)yInterpolation.Clone();
                    yinterp.ExpiryTime = x[i];
                    if (Forward != null && Spot != null)
                    {
                        yinterp.AssetPrice = Convert.ToDecimal(Forward);
                    }
                    else
                    {
                        var fwd = ForwardCurve.ValueAt(yinterp.ExpiryTime, true);
                        yinterp.AssetPrice = Convert.ToDecimal(fwd);
                    }
                    yinterp.Initialize(y, values.Row(i).Data);
                    var curve           = new DiscreteCurve(y, values.Row(i).Data);
                    var interpolatedCol = new InterpolatedCurve(curve, yinterp, true);
                    _interpolatedColumns.Add(interpolatedCol);
                }
            }
            else //o.w interpolate at each strike point (in time)
            {
                for (int i = 0; i < width; i++)
                {
                    var interp = xInterpolation.Clone();
                    interp.Initialize(x, values.Column(i).Data);
                    var curve           = new DiscreteCurve(x, values.Column(i).Data);
                    var interpolatedCol = new InterpolatedCurve(curve, interp, true);
                    _interpolatedColumns.Add(interpolatedCol);
                }
            }
        }
コード例 #21
0
        public void FitsAtSamplePoints()
        {
            IInterpolation it = CubicSpline.InterpolatePchip(_t, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
コード例 #22
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);
            }
        }
コード例 #23
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);
            }
        }
コード例 #24
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);
            }
        }
コード例 #25
0
        public void TestAllInterpolations()
        {
            Random r = new Random(Environment.TickCount);

            foreach (string interp in _linearInterpolations)
            {
                TearDown();
                IInterpolation interpolation = InterpolationFactory.Create(interp);
                interpolation.Initialize(_times, _rates);
                Debug.WriteLine($"interpolationType : {interp}");
                for (int i = 1; i < 100; ++i)
                {
                    double time       = (i + r.Next(-10000, 10000) / 10000) / 10.0;
                    double interpRate = interpolation.ValueAt(time, true);
                    Debug.WriteLine($"interpolatedRate : {interpRate} Time: {time}");
                }
                int index = 0;
                foreach (double time in _times)
                {
                    if (time != 0.0)
                    {
                        double interpRate  = interpolation.ValueAt(time, true);
                        double interpValue = _rates[index];
                        Assert.AreEqual(interpRate, interpValue, 10 - 8);
                    }
                    index++;
                }
            }
            foreach (string interp in _logLinearInterpolations)
            {
                TearDown();
                double[] exp  = SetUp();
                double[] temp = new double[exp.Length];
                exp.CopyTo(temp, 0);
                IInterpolation interpolation = InterpolationFactory.Create(interp);
                interpolation.Initialize(_times, temp);
                Debug.WriteLine($"interpolationType : {interp}");
                for (int i = 1; i < 100; ++i)
                {
                    double time       = (i + r.Next(-10000, 10000) / 10000) / 10.0;
                    double interpRate = interpolation.ValueAt(time, true);
                    Debug.WriteLine($"interpolatedRate : {interpRate} Time: {time}");
                }
                int index = 0;
                foreach (double time in _times)
                {
                    if (time != 0.0)
                    {
                        double interpRate  = interpolation.ValueAt(time, true);
                        double interpValue = exp[index];
                        Assert.AreEqual(interpRate, interpValue, 10 - 8);
                    }
                    index++;
                }
            }
        }
コード例 #26
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);
            }
        }
コード例 #27
0
        //http://numerics.mathdotnet.com/api/MathNet.Numerics.Interpolation/CubicSpline.htm
        /// <summary>
        /// Sets the interpolation formula.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public void SetInterpolation(IEnumerable <double> x, IEnumerable <double> y)
        {
            this.GetCost = null;
            IInterpolation interpolation = CubicSpline.InterpolateBoundariesSorted(x.ToArray(), y.ToArray(),
                                                                                   SplineBoundaryCondition.Natural, 0, SplineBoundaryCondition.Natural, 0);

            this.GetCost             = new CalculateCost(interpolation.Interpolate);
            interpolation            = null;
            this.CostCalculationType = CostCalculationMethod.Interpolation;
        }
コード例 #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WalkingTrail"/> class. For Internal Use ONLY!
        /// </summary>
        /// <param name="observedPoints">The observed locations.</param>
        /// <param name="velocityMagnitude">The velocity magnitude.</param>
        internal WalkingTrail(UV[] observedPoints, double velocityMagnitude)
        {
            this._length      = new double[observedPoints.Length];
            this._trailLength = 0;
            this._length[0]   = 0;
            for (int i = 0; i < observedPoints.Length - 1; i++)
            {
                double d = observedPoints[i].DistanceTo(observedPoints[i + 1]);
                this._length[i + 1] = this._length[i] + d;
            }
            this._trailLength = this._length[this._length.Length - 1];
            double[] observation_time = new double[this._length.Length];
            observation_time[0] = 0;
            for (int i = 0; i < observedPoints.Length - 1; i++)
            {
                double deltaT = observedPoints[i].DistanceTo(observedPoints[i + 1]) / velocityMagnitude;
                observation_time[i + 1] = observation_time[i] + deltaT;
            }

            this._trailInput      = TrailInput.Location;
            this._observationTime = observation_time;
            this._startTime       = _observationTime[0];
            this._endTime         = _observationTime[_observationTime.Length - 1];
            this._duration        = _observationTime[_observationTime.Length - 1] - _observationTime[0];
            this._timeToLength    = Interpolate.CubicSplineRobust(this._observationTime, this._length);
            this._lengthToTime    = Interpolate.CubicSplineRobust(this._length, this._observationTime);

            //create interpolations
            double[] location_U_values = new double[this._observationTime.Length];
            double[] location_V_values = new double[this._observationTime.Length];
            for (int i = 0; i < this._observationTime.Length; i++)
            {
                location_U_values[i] = observedPoints[i].U;
                location_V_values[i] = observedPoints[i].V;
            }
            this._interpolate_location_U = Interpolate.CubicSplineRobust(this._observationTime, location_U_values);
            this._ULinearInterpolation   = Interpolate.Linear(this._observationTime, location_U_values);

            this._interpolate_location_V = Interpolate.CubicSplineRobust(this._observationTime, location_V_values);
            this._VLinearInterpolation   = Interpolate.Linear(this._observationTime, location_V_values);


            this._observedStates = new StateBase[this._observationTime.Length];
            //this._controlPoints = new UV[this._time.Length];
            for (int i = 0; i < this._observedStates.Length; i++)
            {
                UV location  = observedPoints[i];
                UV velocity  = this.getVelocity(this._observationTime[i]);
                UV direction = this.getDirection(this._observationTime[i]);
                //this._controlPoints[i] = location;
                this._observedStates[i] = new StateBase(location, direction, velocity);
            }
            this.loadNormalizedStates();
            loadApproximatedPolyline();
        }
コード例 #29
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);
            }
        }
コード例 #30
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);
            }
        }
コード例 #31
0
ファイル: MoveXModifier.cs プロジェクト: backviet01/winengine
 public MoveXModifier(double duration, double fromX, double toX,
     IEntityModifierListener listener, IInterpolation function)
     : base(duration, fromX, toX, listener, function)
 {
 }
コード例 #32
0
            private void readInCacheCurve()
            {
                string[] lines = System.IO.File.ReadAllLines(this.demandPointsSerializationFile);
                Double[] xVals = new Double[lines.Length];
                Double[] yVals = new Double[lines.Length];

                int i = 0;
                foreach (string inputRecord in lines)
                {
                    string[] inputTokens = inputRecord.Split(',');
                    xVals[i] = Convert.ToDouble(inputTokens[0]);
                    yVals[i] = Convert.ToDouble(inputTokens[1]);
                    i++;
                }
                this.cacheDemandCurvePoints = new CacheCurvePoints(xVals, yVals);
                //this.cacheDemandFunc = Interpolate.LinearBetweenPoints(this.cacheDemandCurvePoints.xVals, this.cacheDemandCurvePoints.yVals);
                //this.cacheDemandFunc = Interpolate.Linear(this.cacheDemandCurvePoints.xVals, this.cacheDemandCurvePoints.yVals);

                this.cacheDemandFunc = Interpolate.PolynomialEquidistant(this.cacheDemandCurvePoints.xVals, this.cacheDemandCurvePoints.yVals);

            }
コード例 #33
0
ファイル: MenuView.cs プロジェクト: backviet01/winengine
        //================================================================
        //Methodes
        //================================================================
        public void BuildAnimation(IInterpolation interpolation, double duration)
        {
            if (NeedBuidAnimation)
            {
                byte direction = Direction;
                switch (direction)
                {
                    case LEFT_RIGHT:
                        for (int i = 0; i < countchildren; i++)
                        {
                            if (childrens[i].NeedBuildUI)
                            {
                                continue;
                            }
                            if (!childrens[i].IgnoreUpdate && !(childrens[i] is Text))
                            {
                                float x = -childrens[i].Width;

                                MoveXModifier modifier = new MoveXModifier(duration, x, childrens[i].Position.X,
                                    null, interpolation);
                                childrens[i].RegisterModifier(modifier);
                            }
                        }
                        break;

                    case RIGHT_LEFT:
                        for (int i = 0; i < countchildren; i++)
                        {
                            if (childrens[i].NeedBuildUI)
                            {
                                continue;
                            }
                            if (!childrens[i].IgnoreUpdate && !(childrens[i] is Text))
                            {
                                float x = camera.width;

                                MoveXModifier modifier = new MoveXModifier(duration, x, childrens[i].Position.X,
                                    null, interpolation);
                                childrens[i].RegisterModifier(modifier);
                            }
                        }
                        break;

                    case TOP_BOTTOM:
                        for (int i = 0; i < countchildren; i++)
                        {
                            if (childrens[i].NeedBuildUI)
                            {
                                continue;
                            }
                            if (!childrens[i].IgnoreUpdate && !(childrens[i] is Text))
                            {
                                float y = -childrens[i].Height;

                                MoveYModifier modifier = new MoveYModifier(duration, y, childrens[i].Position.Y,
                                    null, interpolation);
                                childrens[i].RegisterModifier(modifier);
                            }
                        }
                        break;

                    case BOTTOM_TOP:
                        for (int i = 0; i < countchildren; i++)
                        {
                            if (childrens[i].NeedBuildUI)
                            {
                                continue;
                            }
                            if (!childrens[i].IgnoreUpdate && !(childrens[i] is Text))
                            {
                                float y = camera.height;

                                MoveYModifier modifier = new MoveYModifier(duration, y, childrens[i].Position.Y,
                                    null, interpolation);
                                childrens[i].RegisterModifier(modifier);
                            }
                        }
                        break;

                    case MIX_HORIZONTAL:

                        break;

                    case MIX_VERTICAL:

                        break;

                    default:
                        break;
                }
            }
        }
コード例 #34
0
 public TransformedInterpolation(IInterpolation interpolation, Func<double, double> transform)
 {
     _interpolation = interpolation;
     _transform = transform;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LcImsPeptideSearchWorkfow"/> class.
 /// </summary>
 /// <param name="uimfFileLocation">
 /// The uimf file location.
 /// </param>
 /// <param name="parameters">
 /// The parameters.
 /// </param>
 /// <param name="netAlignment">
 /// The net alignment.
 /// </param>
 public LcImsPeptideSearchWorkfow(string uimfFileLocation, LcImsPeptideSearchParameters parameters, IInterpolation netAlignment)
     : this(uimfFileLocation, parameters)
 {
     this._netAlignment = netAlignment;
 }
コード例 #36
0
            //XXXIS add more things if we need them?

            public EssesFlowCacheContext(Flow flow, UInt64 cacheSizeAllocated, CacheWritePolicy writePolicy, CacheWriteBuffer cacheWrites, string cacheCurvePointsFile, string tenantID)
            {
                Flow = flow;
                this.cacheSizeAllocated = cacheSizeAllocated;
                this.writePolicy = writePolicy;
                this.cacheWrites = cacheWrites;
                this.hitRate = 0.0F;
                this.tenantID = tenantID;

                this.demandPointsSerializationFile = cacheCurvePointsFile;
                
                if (File.Exists(this.demandPointsSerializationFile))
                {
                    readInCacheCurve();
                    this.useSerializedCurve = true;
                }
                else
                {
                    this.cacheDemandCurvePoints = null;
                    this.cacheDemandFunc = null;
                    this.useSerializedCurve = false;
                }

#if COLLECT_CACHE_CURVE
                Console.CancelKeyPress += new ConsoleCancelEventHandler(Controller_CancelKeyPress);
#endif
            }
コード例 #37
0
ファイル: MoveModifier.cs プロジェクト: backviet01/winengine
 public MoveModifier(double duration, Vector2 from, Vector2 to, IEntityModifierListener listener,
     IInterpolation function)
     : this(duration, from.X, to.X, from.Y, to.Y, listener, function)
 {
 }
コード例 #38
0
ファイル: PathModifier.cs プロジェクト: backviet01/winengine
        public PathModifier(float pDuration, IEntity entity, Path path, IEntityModifierListener entityModiferListener,
            IInterpolation function)
            : base(entityModiferListener)
        {
            int pathSize = path.Size();

            if (pathSize < 2)
            {
                throw new Exception("Path needs at least 2 waypoints!");
            }

            this.entity = entity;

            this.path = path;

            MoveModifier[] moveModifiers = new MoveModifier[pathSize - 1];

            float[] coordinatesX = path.CoordinatesX();
            float[] coordinatesY = path.CoordinatesY();

            float velocity = path.Length() / pDuration;

            int modifierCount = moveModifiers.Length;
            for (int i = 0; i < modifierCount; i++)
            {
                float duration = path.SegmentLength(i) / velocity;
                moveModifiers[i] = new MoveModifier(duration, coordinatesX[i], coordinatesX[i + 1], coordinatesY[i],
                    coordinatesY[i + 1], null, function);
            }

            /* Create a new SequenceModifier and register the listeners that
             * call through to mEntityModifierListener and mPathModifierListener. */

            sequenceModifier = new SequenceModifier<IEntity>(moveModifiers);
            sequenceModifier.StartSequenceAction += (sender => SequenceStarted());
            sequenceModifier.FinishSequenceAction += (sender => SequenceFinished());
            sequenceModifier.StartModifierAction += (sender => SequenceListenerStarted(this.entity));
            sequenceModifier.FinishModifierAction += (sender => SequenceListenerFinished(this.entity));
        }