Beispiel #1
0
        public static void BasicTests()
        {
            Assert.Equal(1, new Dual(1).Magnitude);
            Assert.Equal(3, (new Dual(1) + new Dual(2)).Magnitude);
            Assert.Equal(new Dual(1), new Dual(1));
            Assert.NotEqual(new Dual(2), new Dual(1));
            var x = new Dual(2);

            Assert.Equal(4, (x + x).Magnitude);
            Assert.Equal(0, (x + x).Derivative);
            Assert.Equal(0, (x - x).Magnitude);
            Assert.Equal(0, (-x + x).Magnitude);
            Assert.Equal(6, (x * 3).Magnitude);
            Assert.Equal(6, (3 * x).Magnitude);
            Assert.Equal(Math.Sin(x.Magnitude), x.Sin().Magnitude);
            Assert.Equal(Math.Cos(x.Magnitude), x.Cos().Magnitude);
            Assert.Equal(4, (x ^ 2).Magnitude);
            Assert.Equal(4, (x * x).Magnitude);
            Assert.Equal(x, x);
            Assert.Equal(0, x.CompareTo(x));
            //Assert.Equal(default, x - x);
            Assert.Equal(Math.Cos(3), Calculus.DerivativeAt(3, (Dual x) => x.Cos()).Magnitude);
            Assert.Equal(-Math.Sin(3), Calculus.DerivativeAt(3, (Dual x) => x.Cos()).Derivative);
            Assert.Equal(Math.Sin(3), Calculus.DerivativeAt(3, (Dual x) => x.Sin()).Magnitude);
            Assert.Equal(Math.Cos(3), Calculus.DerivativeAt(3, (Dual x) => x.Sin()).Derivative);
        }
Beispiel #2
0
        public static void TestPoly3()
        {
            var z = Calculus.DerivativeAt(1, 0.5, 2, SimplePoly3);

            Assert.Equal(4.5, z.Magnitude);
            Assert.Equal(6, z.Derivative(0));
        }
Beispiel #3
0
        public static void TestFunc(double y, double x, double dx)
        {
            var dy = Calculus.DerivativeAt(x, Func);

            Assert.Equal(y, dy.Magnitude);
            Assert.Equal(dx, dy.Derivative);
        }
Beispiel #4
0
        public static void TestSample()
        {
            var y = Calculus.DerivativeAt(2, 3, Sample);

            Assert.Equal(5.947664043757056, y.Magnitude);
            Assert.Equal(1.0013704652454263, y.Derivative(1));
        }
Beispiel #5
0
        public void findTarget(List <Enemy> enemies)
        {
            if (enemies.Count == 0)
            {
                return;
            }
            List <DistanceEnemy> distancias = new List <DistanceEnemy>();

            for (int i = 0; i < enemies.Count; i++)
            {
                DistanceEnemy dE = new DistanceEnemy(i, Calculus.distanceFromPoints(centerRealPosition, enemies[i].CenterPosition));
                distancias.Add(dE);
            }

            distancias.Sort((d1, d2) => d1.distance.CompareTo(d2.distance));

            // Si la distancia al objetivo más cercano es menor de qje el rango entonces actualizar el enemigo
            // actual, si no asignar valor nulo
            currentEnemy = distancias[0].distance < range ? enemies[distancias[0].index] : null;

            if (currentEnemy == null)
            {
                return;
            }
        }
Beispiel #6
0
        public static void TestQuintile2(double y, double x, double dx)
        {
            var dy = Calculus.DerivativeAt(x, Quintile2);

            Assert.Equal(y, dy.Magnitude);
            Assert.Equal(dx, dy.Derivative);
        }
Beispiel #7
0
        public static Expression ChooseWithDiff(Expression h, int k, int times, int sign)
        {
            if (k < 1)
            {
                return(0);
            }

            var u = Expression.Symbol("u");

            var d = (u.Factorial(k - 1, sign));

            for (var i = 0; i < times; i++)
            {
                d = Calculus.Differentiate(u, d);
            }

            var result = d / k.Factorial();


            var floatingPoint = Evaluate.Evaluate(
                new Dictionary <string, FloatingPoint> {
                {
                    "u", FloatingPoint.NewReal(h.ToReal())
                }
            },
                result);

            var frac = (Expression)floatingPoint.RealValue.ToFraction(); // k.Factorial();


            return(frac);
        }
 public void CustomUpdate()
 {
     if (this.isOrbiting)
     {
         this.direction = Calculus.PerpendicularVector2((this.orbitCenter - this.rigidbody.transform.position).normalized, this.ballSide);
     }
 }
    // Update is called once per frame
    public void CustomUpdate()
    {
        if (this.isActive)
        {
            //Compute current ball side and check if it passes the lineOrbit
            this.ballRelativeToVortex = Calculus.PointSideRelativeToALine(this.vortexInstance.transform.position, this.vortexInstance.transform.position + this.orbitLine.normalized, this.ballController.Rigidbody.position);

            Side currentBallSide;
            if (this.ballRelativeToVortex > 0)
            {
                currentBallSide = Side.Left;
            }
            else if (this.ballRelativeToVortex < 0)
            {
                currentBallSide = Side.Right;
            }
            else
            {
                currentBallSide = Side.Collinear;
            }

            if (currentBallSide != this.initialBallSide && !this.isOrbitActive)
            {
                if (Vector2.Distance(this.ballController.Rigidbody.position, this.vortexInstance.transform.position) <= 1.35f)
                {
                    //Start Orbit
                    Debug.Log("Start Orbit" + this.ballController.Rigidbody.transform.position);
                    this.isOrbitActive = true;
                    this.ballInput.StartOrbit(this.vortexInstance.transform.position);
                }
            }
        }
    }
        public void AddQuestion(Guid quizId, Guid questionId)
        {
            var collectionAdder = Calculus.Carry <Guid, IEnumerable <Guid>, IEnumerable <Guid> >
                                      (Calculus.AddIdToCollection, questionId);

            ModifyQuizQuestionCollection(quizId, collectionAdder);
        }
Beispiel #11
0
    private void Start()
    {
        var int1DP = new Dictionary <float, float>()
        {
            { 1, 1 },
            { 2, 8 },
            { 3, 27 },
        };

        var int1Test = new Dictionary <float, float>()
        {
            { 8, 302 },
            { -5, 211 },
            { 0, 6 },
        };

        Debug.Log("Interpolating");

        var interpolation1 = Calculus.LagrangeInterpolate(int1DP);

        foreach (var kv in int1DP)
        {
            Debug.Log("Tesing supplied data points. Input is " + kv.Key + ", output should be " + kv.Value + " and interpolation says " + interpolation1(kv.Key));
        }

        foreach (var kv in int1Test)
        {
            Debug.Log("Tesing supplied data points. Input is " + kv.Key + ", output should be " + kv.Value + " and interpolation says " + interpolation1(kv.Key));
        }
    }
Beispiel #12
0
        public static void TestFunc2(double f, double y, double dy, double x, double dx)
        {
            var df = Calculus.DerivativeAt(x, y, Func2);

            Assert.Equal(f, df.Magnitude);
            Assert.Equal(dx, df.Derivative(0));
            Assert.Equal(dy, df.Derivative(1));
        }
Beispiel #13
0
        public static void TestPoly2()
        {
            var z = Calculus.DerivativeAt(5, 2, SimplePoly2);

            Assert.Equal(59, z.Magnitude);
            Assert.Equal(30, z.Derivative(0));
            Assert.Equal(-24, z.Derivative(1));
        }
Beispiel #14
0
        public void AllCalculus_CalculateAllMethods_ExpectCorrectResult()
        {
            var originalCalculus = new List <int> {
                15, 5, -5, 50, 2, 1
            };
            var calculus = Calculus.AllCalculus(10, 5);

            CollectionAssert.AreEqual(originalCalculus, calculus);
        }
        public void Berechne_a()
        {
            BigInteger expected = 8;
            Calculus   calculus = new Calculus();

            BigInteger result = calculus.Berechne_a();

            Assert.AreEqual(expected, result);
        }
Beispiel #16
0
        public void DefiniteIntegralTest1()
        {
            int    n = 500;
            double a = 0;
            double b = 1;

            double result = Calculus.RectangularMethod(TestFunction1, a, b, n);

            Assert.AreEqual(2.5, result, 0.01);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            const string PATH = "../../IOFile.txt";

            string fileContents = FileInputOutput.ReadFileContents(PATH);

            FileInputOutput.OutputSum(Calculus.CalculateSum(fileContents), PATH);
            Console.WriteLine(File.ReadAllText(PATH));
            Console.ReadLine();
        }
Beispiel #18
0
        public void AdaptiveTest1()
        {
            int    n = 100;
            double a = 0;
            double b = 1;

            double result = Calculus.AdaptiveRectangularMethod(TestFunction1, a, b, n, 0.01);

            Assert.AreEqual(2.5, result, 0.01);
        }
        public void Calc_Setpoly_Error()
        {
            var sr = new StringReader("error.");

            Console.SetIn(sr);
            var calculus = new Calculus();

            var result = calculus.SetPolynomial();

            Assert.AreEqual(false, result);
        }
        private async Task startHardWork()
        {
            worker         = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(imageBitmap);
            var result = FaceSdkHelper.Detect(sdkImg);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                var shape = SdkHelper.results.FirstOrDefault();

                var defaultFaceCalculations = Calculus.ReadDefaultFaceCalculations();
                var array = FaceCalculationsHelpers.FromFaceCalculationsToVector(defaultFaceCalculations);

                var calculatedFaceCalculations = Calculus.GetFaceCalculationsFromShape(shape);
                var resultArray = FaceCalculationsHelpers.FromFaceCalculationsToVector(calculatedFaceCalculations);

                var conditions         = new Conditions();
                var resultFromCalculus = conditions.GetLevelVerifierFunction(Level).Invoke(array, resultArray);

                if (resultFromCalculus != 0)
                {
                    using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
                    {
                        var passedLevels = db.Settings.FirstOrDefault()._16_PassedLevels;
                        db.Settings.FirstOrDefault()._16_PassedLevels = Math.Max(passedLevels, Level);

                        var level = db.Levels.FirstOrDefault(t => t.Level == Level);
                        level.Stars = Math.Max(resultFromCalculus, level.Stars);

                        db.SubmitChanges();
                    }
                    MessageBox.Show("Level passed. You won " + resultFromCalculus + " point" + (resultFromCalculus > 1 ? "s!" : "!"));
                }
                else
                {
                    InGameLifeHelpers.LoseLife();
                    MessageBox.Show("Level failed");
                }
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
            }

            NavigationService.Navigate(new Uri(Pages.GeneralGameplay_Adventure, UriKind.RelativeOrAbsolute));
            FaceSdkHelper = null;
            GC.Collect();
        }
        public void Calc_Setpoly2()
        {
            var sr = new StringReader("-0.5 3.666 558");

            Console.SetIn(sr);
            var calculus = new Calculus();

            var result = calculus.SetPolynomial();

            Assert.AreEqual(true, result);
        }
Beispiel #22
0
        public void Update(Vector2?target)
        {
            Position      += Calculus.velFromPoints(Position, target ?? Position, 10);
            CenterPosition = Position - new Vector2(textura.Width / 2, textura.Height / 2);
            rect           = new Rectangle((int)Position.X, (int)Position.Y, textura.Width, textura.Height);

            if (Calculus.distanceFromPoints(Position, target ?? Position) < 5)
            {
                Visible = false;
            }
        }
        public void Calc_EvalDer3()
        {
            var sr = new StringReader("2 2 0 -1");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomialDerivative(2);

            Assert.AreEqual(32, result);
        }
        public void Calc_EvalDer4()
        {
            var sr = new StringReader("1 -0.56 25 35 -7.25 1.5 0.005               000");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomialDerivative(2);

            Assert.AreEqual(3379.485, result);
        }
        public void GetMatchingPositions()
        {
            List <BigInteger> expected = new List <BigInteger>()
            {
                1, 4
            };
            Calculus calculus = new Calculus();

            List <BigInteger> result = calculus.Tinder();

            testEachValue(expected, result);
        }
        public void BerechneVWerte()
        {
            List <BigInteger> expected = new List <BigInteger>()
            {
                125, 119, 107, 83, 35, 70, 9, 18, 36, 72, 13, 26, 52
            };
            Calculus calculus = new Calculus();

            List <BigInteger> result = calculus.BerechneVWerte();

            testEachValue(expected, result);
        }
        public void Calc_EvalPoly1()
        {
            var sr = new StringReader("2 5 9");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomial(2);

            Assert.AreEqual(27, result);
        }
        public void Calc_EvalInte5()
        {
            var sr = new StringReader("2 0 1");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomialIntegral(-1, 0);

            Assert.AreEqual(1.666, result, 0.01);
        }
        public void Calc_EvalInte3()
        {
            var sr = new StringReader("0");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomialIntegral(2, 5);

            Assert.AreEqual(0, result);
        }
        public void Calc_EvalInte1()
        {
            var sr = new StringReader("1 -0.56 25 35 -7.25 1.5 0.005               000");

            Console.SetIn(sr);
            var calculus = new Calculus();

            calculus.SetPolynomial();
            var result = calculus.EvaluatePolynomialIntegral(-1, 1);

            Assert.AreEqual(14.839, result, 0.001);
        }
Beispiel #31
0
        /// <summary>
        /// generate roc plot data for all models in the best-fit models list and makes the plots.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl2.SelectedIndex == 3) //do nothing if not roc curves tab selected
            {
                if (listBox1.Items.Count < 1) return;

                if (_list.Count > 0) //if we have models, make plots
                {
                    double lowerbound = 0.0d;
                    double upperbound = 1.0d;
                    listView3.Items.Clear();
                    GraphPane pane = zgcROC.GraphPane;
                    if (pane.CurveList.Count > 0) pane.CurveList.Clear();
                    pane.Title.Text = "Receiver Operating Characteristic Curves \n for Best-Fit Models";
                    pane.XAxis.Title.Text = "1 - Specificity";
                    pane.YAxis.Title.Text = "Sensitivity";

                    object[] colors = new object[] {Color.DarkSeaGreen, Color.Green, Color.Indigo,
                        Color.ForestGreen, Color.CadetBlue,
                        Color.DarkBlue, Color.DarkViolet, Color.DarkCyan,
                        Color.Blue, Color.DarkGray};

                    object[] symbols = new object[] {SymbolType.Circle, SymbolType.Diamond, SymbolType.Plus,
                        SymbolType.Square, SymbolType.Star, SymbolType.Triangle,
                        SymbolType.TriangleDown, SymbolType.XCross, SymbolType.VDash, SymbolType.HDash};

                    string[] item = new string[2];

                    PointPairList ppl = new PointPairList();

                    //generate the data, make the plots, and fill the listbox with model/areaundercurve info
                    int maxmodelptr = -1;
                    double maxmodelauc = 0;

                    //if there are more models in list than showing... use 10 or use the number in the list
                    int maxNmodels = _list.Count <= 10 ? _list.Count : 10;

                    //initialize a structure for storing roc curve information for all curves...
                    _tableVals = new Dictionary<string,List<object>>();
                    //...and one for individual model
                    List<object> modelRocVals = null;

                    //for (int li = 0; li < list.Count; li++)
                    for (int li = 0; li < maxNmodels; li++)
                    {
                        //PointPairList ppl = ROCpoints( (MLRIndividual)list[li]);
                        ppl = ROCpoints((MLRIndividual)_list[li], out modelRocVals);
                        string key = _list[li].Fitness.ToString("##.####");
                        if (!_tableVals.ContainsKey(key))
                        {
                            _tableVals.Add(key, modelRocVals);
                        }
                        if (ppl != null && ppl.Count > 0)
                        {
                            //BasicArrayPointList ppl = ROCpoints((MLRIndividual)list[li]);
                            LineItem curve = pane.AddCurve(_list[li].Fitness.ToString("##.####"), ppl,
                                (Color)colors[li], (SymbolType)symbols[li]);

                            double[] X = new double[ppl.Count];
                            double[] Y = new double[ppl.Count];
                            for (int i = 0; i < ppl.Count; i++) //there must be a smarter way to do this
                            {
                                X[i] = ppl[i].X;
                                Y[i] = ppl[i].Y;
                            }

                            //performing integral evaluation with EM Piecewise constant curve instance
                            //(another possibility is the Piecewise linear curve class... splines and
                            //other curve definitions seem like overkill and delegate realfunctions seem
                            //like the wrong approach entirely - requires curve fitting/definition and all
                            //we have are data points for VERY similar curves)
                            Calculus calc = new Calculus(X, Y, lowerbound, upperbound);
                            double auc = calc.PieceWiseConstantCurveIntegrate();

                            //maybe piecewise linear curve is better?
                            calc = new Calculus(X, Y, lowerbound, upperbound);
                            double auc2 = calc.PieceWiseLinearCurveIntegrate();
                            double idiff = auc - auc2;

                            //comment next line to use piecewiseconstant integral calc
                            auc = auc2;

                            item[0] = _list[li].Fitness.ToString("##.####");
                            //item[1] = string.Format("{0:f6}", auc.ToString());
                            item[1] = auc.ToString("#.######");
                            ListViewItem lvi = new ListViewItem(item);
                            listView3.Items.Add(lvi);

                            if (auc > maxmodelauc)
                            {
                                maxmodelauc = auc;
                                maxmodelptr = li;
                            }
                        }
                    }

                    //add the no information trace
                    PointPair orig = new PointPair(0, 0);
                    PointPair extent = new PointPair(1, 1);
                    PointPairList ppl2 = new PointPairList();
                    ppl2.Add(orig);
                    ppl2.Add(extent);
                    LineItem curve2 = pane.AddCurve("", ppl2, Color.Black);
                    //curve2.Tag = "NoInfo";
                    curve2.IsVisible = true;

                    pane.XAxis.Scale.Max = 1.0;
                    pane.YAxis.Scale.Max = 1.0;
                    zgcROC.AxisChange();

                    if (pane.CurveList.Count > 1)
                    {
                        //highlight the max auc trace
                        LineItem bestcurve = (LineItem)pane.CurveList[maxmodelptr];
                        //bestcurve.Symbol.Size = 12.0f;
                        bestcurve.Line.Width = 3.0f;
                        bestcurve.Line.Color = Color.Red;

                        //highlight the model with the max auc in the listbox
                        //listView3.Items[maxmodelptr].BackColor = Color.Pink;
                        listView3.Items[maxmodelptr].ForeColor = Color.Red;

                        //dump the roc parameters to the table (list)
                        string temp = listView3.Items[maxmodelptr].Text;
                        List<object> vals = _tableVals[temp];
                        updateList(vals);

                    }
                    else
                    {
                        MessageBox.Show("The current values for the decision criterion and regulatory standard do not permit ROC curves to be calculated.",
                            "No Appropriate Plot Data", MessageBoxButtons.OK);
                    }
                }
            }
        }