/// <summary>Creates a new <see cref="IGridPointCurve<TLabel>"/> object with respect to specified interpolation and extrapolation approaches. /// </summary> /// <param name="curveInterpolator">The curve interpolator.</param> /// <param name="leftExtrapolator">The extrapolator on the left side, i.e. from the first grid point to -\infinity.</param> /// <param name="rightExtrapolator">The extrapolator on the right side, i.e. from the last grid point to \infinity.</param> /// <param name="capacity">The number of elements that the new grid point curve can initially store.</param> /// <returns>A <see cref="IGridPointCurve{TLabel}"/> object with respect to the desired interpolation and extrapolation approaches.</returns> public static IGridPointCurve <double> Create(Interpolator curveInterpolator, Extrapolator leftExtrapolator, Extrapolator rightExtrapolator, int capacity = 20) { if (curveInterpolator == null) { throw new ArgumentException(nameof(curveInterpolator)); } var interpolator = curveInterpolator.Create(); if (leftExtrapolator == null) { throw new ArgumentNullException(nameof(leftExtrapolator)); } if (leftExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromFirstGridPoint) { throw new ArgumentException("Wrong building direction of curve extrapolation", "leftExtrapolator"); } var left = leftExtrapolator.Create(interpolator); if (rightExtrapolator == null) { throw new ArgumentNullException(nameof(rightExtrapolator)); } var right = rightExtrapolator.Create(interpolator); if (rightExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromLastGridPoint) { throw new ArgumentException("Wrong building direction of curve extrapolation", "rightExtrapolation"); } if ((interpolator is IDifferentiableRealValuedCurve) && (left is IDifferentiableRealValuedCurve) && (right is IDifferentiableRealValuedCurve)) { return(new StandardGridPointCurveNoLabels.Differentiable(curveInterpolator, interpolator, leftExtrapolator, left, rightExtrapolator, right, capacity)); } return(new StandardGridPointCurveNoLabels(curveInterpolator, interpolator, leftExtrapolator, left, rightExtrapolator, right, capacity)); }
public void QuadraticThruZeroCalculateTest() { //y = 0.0804x2 + 1.9256x //R2 = 0.9212 QuadraticThruZeroInterpolator target = (QuadraticThruZeroInterpolator)Interpolator.Create(CurveFits.QuadraticThruZero, standards()); Assert.AreEqual("0.9212", target.RSquared().ToString("0.0000")); //passes thru origin Assert.AreEqual("0.000", target.Calculate(0).ToString("0.000")); Assert.AreEqual("222.7", target.Calculate(42).ToString("0.0")); }
public void Create() { List <DPoint> stds = standards(); Interpolator target = Interpolator.Create(CurveFits.LinearZero, stds); Assert.IsTrue(target is BestLineThruOriginInterpolation); Assert.AreEqual("0.9130", target.RSquared().ToString("0.0000")); target = Interpolator.Create(CurveFits.Linear, stds); Assert.IsTrue(target is BestLineInterpolation); Assert.AreEqual("0.9406", target.RSquared().ToString("0.0000")); target = Interpolator.Create(CurveFits.Interpolate, stds); Assert.IsTrue(target is SimpleInterpolator); Assert.AreEqual("1.0000", target.RSquared().ToString("0.0000")); target = Interpolator.Create(CurveFits.Quadratic, stds); Assert.IsTrue(target is QuadraticInterpolator); Assert.AreEqual("0.9987", target.RSquared().ToString("0.0000")); }
/// <summary>Creates a new read-only <see cref="IGridPointCurve<TLabel>"/> object with respect to specified interpolation and extrapolation approaches. /// </summary> /// <typeparam name="TLabel">The type of the label.</typeparam> /// <param name="curveInterpolator">The curve interpolator.</param> /// <param name="leftExtrapolator">The extrapolator on the left side, i.e. from the first grid point to -\infinity.</param> /// <param name="rightExtrapolator">The extrapolator on the right side, i.e. from the last grid point to \infinity.</param> /// <param name="gridPointCount">The number of grid points, i.e. the number of relevant elements of <paramref name="gridPointLabels"/>, <paramref name="gridPointArguments"/> and <paramref name="gridPointValues"/> to take into account.</param> /// <param name="gridPointLabels">The labels of the grid points (the reference will be stored only).</param> /// <param name="gridPointArguments">The arguments of the grid points, thus labels of the curve in its <see cref="System.Double"/> representation in ascending order.</param> /// <param name="gridPointValues">The values of the grid points corresponding to <paramref name="gridPointArguments"/>.</param> /// <param name="gridPointArgumentStartIndex">The null-based start index of <paramref name="gridPointArguments"/> and <paramref name="gridPointLabels"/> to take into account.</param> /// <param name="gridPointValueStartIndex">The null-based start index of <paramref name="gridPointValues"/> to take into account.</param> /// <param name="gridPointArgumentIncrement">The increment for <paramref name="gridPointArguments"/> and <paramref name="gridPointLabels"/>.</param> /// <param name="gridPointValueIncrement">The increment for <paramref name="gridPointValues"/>.</param> /// <returns>A read-only <see cref="IGridPointCurve<TLabel>"/> object with respect to the desired interpolation and extrapolation approaches.</returns> /// <remarks>This method is mainly used for two-dimensional surface interpolation. Assuming a large grid point matrix, for example 1.000 x 1.000 and one may apply for example a linear interpolation /// along horizontal direction and afterwards a linear interpolation along vertical direction. Then we create 1.000 curves in horizontal direction, where the (double) labels and values are constant. The /// standard implementation create a copy of 3 * 1.000 x 1.000 = 3.000.000 values and calles the update method of the underlying <see cref="ICurveDataFitting"/> object which again copy 2 * 1.000 * 1.000 = 2.000.000 values, i.e. in total 5 Mio values. /// This implementation takes into account references, the underlying <see cref="ICurveDataFitting"/> implementation creates deep copies of double values and grid point values only, i.e. 2 Mio double values.</remarks> public static IGridPointCurve <TLabel> Create <TLabel>(Interpolator curveInterpolator, Extrapolator leftExtrapolator, Extrapolator rightExtrapolator, int gridPointCount, IList <TLabel> gridPointLabels, IList <double> gridPointArguments, IList <double> gridPointValues, int gridPointArgumentStartIndex = 0, int gridPointValueStartIndex = 0, int gridPointArgumentIncrement = 1, int gridPointValueIncrement = 1) where TLabel : IEquatable <TLabel> { if (curveInterpolator == null) { throw new ArgumentException(nameof(curveInterpolator)); } var interpolator = curveInterpolator.Create(); if (leftExtrapolator == null) { throw new ArgumentNullException(nameof(leftExtrapolator)); } if (leftExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromFirstGridPoint) { throw new ArgumentException("Wrong building direction of curve extrapolation", "leftExtrapolator"); } var left = leftExtrapolator.Create(interpolator); if (rightExtrapolator == null) { throw new ArgumentNullException(nameof(rightExtrapolator)); } var right = rightExtrapolator.Create(interpolator); if (rightExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromLastGridPoint) { throw new ArgumentException("Wrong building direction of curve extrapolation", "rightExtrapolation"); } if ((interpolator is IDifferentiableRealValuedCurve) && (left is IDifferentiableRealValuedCurve) && (right is IDifferentiableRealValuedCurve)) { return(new SmartReadOnlyGridPointCurve <TLabel> .Differentiable(interpolator, left, right, gridPointCount, gridPointLabels, gridPointArguments, gridPointValues, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement)); } return(new SmartReadOnlyGridPointCurve <TLabel>(interpolator, left, right, gridPointCount, gridPointLabels, gridPointArguments, gridPointValues, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement)); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { m_cashier.Update(gameTime); m_hand.Update(gameTime); if (liste_client.FirstOrDefault() == null) { liste_client.Enqueue(new Client(new Vector2(500, 170), new Vector2(500, 400))); } foreach (Client cli in liste_client.ToList()) { cli.Update(gameTime); foreach (ItemBase produits in cli.Items.ToList()) { produits.Update(gameTime); } } time = time.AddSeconds(gameTime.ElapsedGameTime.TotalSeconds); //appuyer sur espace var key = Application.InputManager.GetDevice <KeyboardDevice>(SuperCaissiere.Engine.Input.LogicalPlayerIndex.One); if (key.GetState(SuperCaissiere.Engine.Input.MappingButtons.A).IsPressed&& boobool2 == false) { if (produit_courant == null) { boobool = false; produit_courant = liste_client.First().Items.First(); Timer.Create(0.02F, true, (t => { produit_courant.Location += new Vector2(-5, 0); if (produit_courant.Location.X < 300) { t.Stop(); } })); } else { if (boobool == false) { Timer.Create(0.02F, true, (t => { foreach (ItemBase item in liste_client.First().Items) { if (item != produit_courant) { item.Location += new Vector2(-5, 0); if (item.Location.X < 450) { t.Stop(); boobool = true; } } } })); } } } var mouse = Application.InputManager.GetDevice <MouseDevice>(SuperCaissiere.Engine.Input.LogicalPlayerIndex.One); if (mouse.GetState(SuperCaissiere.Engine.Input.MappingButtons.A).IsPressed) { scanner_color = 1; int larg = 50; int haut = 100; scanner_zone = new Rectangle(m_hand.DstRect.Left + larg, m_hand.DstRect.Top + haut, m_hand.DstRect.Width - (larg * 2), m_hand.DstRect.Height - (haut * 2)); if (produit_courant != null) { if (scanner_zone.Intersects(produit_courant.DstRect)) { boobool2 = true; Timer.Create(0.02F, true, (t => { produit_courant.Location += new Vector2(-5, 0); if (produit_courant.Location.X < 100) { t.Stop(); boobool2 = false; panier.AddItem(produit_courant); liste_client.First().Items.Dequeue(); produit_courant = null; } })); } } // Timer.Create(0.02F, true, (t => { if (scanner_interpolator != null) { scanner_interpolator.Stop(); scanner_interpolator = null; } scanner_interpolator = Interpolator.Create(1.0F, 0F, 0.35F, (i => { scanner_color = i.Value; }), (i => { scanner_zone = Rectangle.Empty; })); // })); } panier.Update(gameTime); base.Update(gameTime); }