当前位置: 首页>>代码示例>>C#>>正文


C# Function.Evaluate方法代码示例

本文整理汇总了C#中System.Function.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Function.Evaluate方法的具体用法?C# Function.Evaluate怎么用?C# Function.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Function的用法示例。


在下文中一共展示了Function.Evaluate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: invokeInternal

        /**
         * Formats nicer error messages for the junit output
         */
        private static double invokeInternal(Function target, ValueEval[] args, int srcCellRow, int srcCellCol)
        {
            ValueEval EvalResult = null;
            try
            {
                EvalResult = target.Evaluate(args, srcCellRow, (short)srcCellCol);
            }
            catch (NotImplementedException e)
            {
                throw new NumericEvalEx("Not implemented:" + e.Message);
            }

            if (EvalResult == null)
            {
                throw new NumericEvalEx("Result object was null");
            }
            if (EvalResult is ErrorEval)
            {
                ErrorEval ee = (ErrorEval)EvalResult;
                throw new NumericEvalEx(formatErrorMessage(ee));
            }
            if (!(EvalResult is NumericValueEval))
            {
                throw new NumericEvalEx("Result object type (" + EvalResult.GetType().Name
                        + ") is invalid.  Expected implementor of ("
                        + typeof(NumericValueEval).Name + ")");
            }

            NumericValueEval result = (NumericValueEval)EvalResult;
            return result.NumberValue;
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:34,代码来源:NumericFunctionInvoker.cs

示例2: InterpolateLinear1D

        public void InterpolateLinear1D()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            var function = new Function();
            function.Arguments.Add(x);
            function.Components.Add(y);

            var xValues = new[] {1.0, 2.0, 3.0};
            var yValues = new[] {100.0, 200.0, 300.0};

            function.SetValues(yValues, new VariableValueFilter<double>(x, xValues), new ComponentFilter(y));

            var value = function.Evaluate<double>(new VariableValueFilter<double>(x, 1.5));
            Assert.AreEqual(150.0, value);

            value = function.Evaluate<double>(new VariableValueFilter<double>(x, 2.5));
            Assert.AreEqual(250.0, value);

            value = function.Evaluate<double>(new VariableValueFilter<double>(x, 1.75));
            Assert.AreEqual(175, value);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:23,代码来源:FunctionApproximationTest.cs

示例3: EvaluateReturnsDefaultValueOnEmptyFunction

        public void EvaluateReturnsDefaultValueOnEmptyFunction()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction f = new Function();
            f.Arguments.Add(x);
            f.Components.Add(y);
            x.ExtrapolationType = ApproximationType.Constant; 

            y.DefaultValue = 10.0;
            
            Assert.AreEqual(10.0, f.Evaluate<double>(x.CreateValueFilter(1.0)));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:14,代码来源:FunctionApproximationTest.cs

示例4: InterpolateConstant1D

        public void InterpolateConstant1D()
        {
            //defines a piece-wise-constant function. Value is always equals to the value of the neareast smaller 
            //argument
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            Function function = new Function();
            function.Arguments.Add(x);
            function.Components.Add(y);

            var xValues = new[] { 1.0, 2.0, 3.0 };
            var yValues = new[] { 100.0, 200.0, 300.0 };

            function.SetValues(yValues, new VariableValueFilter<double>(x, xValues), new ComponentFilter(y));

            x.InterpolationType = ApproximationType.Constant;
            var value = function.Evaluate<double>(new VariableValueFilter<double>(x, 1.5));
            Assert.AreEqual(100.0, value);

            value = function.Evaluate<double>(new VariableValueFilter<double>(x, 2.5));
            Assert.AreEqual(200.0, value);

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:24,代码来源:FunctionApproximationTest.cs

示例5: GetExtraPolatedValueFor2dFunctionWithOnePointDefined

        public void GetExtraPolatedValueFor2dFunctionWithOnePointDefined()
        {
            IVariable<double> x1 = new Variable<double>("x1");
            IVariable<double> x2 = new Variable<double>("x2");
            IVariable<double> y = new Variable<double>("y");

            IFunction function = new Function();
            function.Arguments.Add(x1);
            function.Arguments.Add(x2);
            x2.ExtrapolationType = ExtrapolationType.Constant;
            function.Components.Add(y);

            function[1.0,1.0] = 2.0;

            //get the value on a point that is defined in one dimension and not in the other.
            Assert.AreEqual(2.0, function.Evaluate<double>(new VariableValueFilter<double>(x1, 1.0), new VariableValueFilter<double>(x2, 2.0)));
            
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:18,代码来源:FunctionApproximationTest.cs

示例6: GetInterpolatedValues2ArgsFunctionDateTime

        public void GetInterpolatedValues2ArgsFunctionDateTime()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable t = new Variable<DateTime>("t");
            IVariable<double> f1 = new Variable<double>("f1");

            IFunction function = new Function("testfunction");
            function.Arguments.Add(t);
            function.Arguments.Add(x);
            function.Components.Add(f1);

            var tValue = DateTime.Now;
            var tValues = new[] { tValue, tValue.AddSeconds(1), tValue.AddSeconds(2), tValue.AddSeconds(3) };

            var xValues = new[] { 1.0, 2.0, 3.0 };

            var fValues = new[,]
                              {
                                  {100.0, 200.0, 300.0},
                                  {1000.0, 2000.0, 3000.0},
                                  {10000.0, 20000.0, 30000.0},
                                  {100000.0, 200000.0, 300000.0}
                              };

            function.SetValues(fValues,
                               new VariableValueFilter<DateTime>(t, tValues),
                               new VariableValueFilter<double>(x, xValues), new ComponentFilter(f1));

            // now get interpolated value on 2d function
            var value = function.Evaluate<double>(
                new VariableValueFilter<double>(x, 2.5),
                new VariableValueFilter<DateTime>(t, tValue.AddSeconds(1.5)));

            Assert.AreEqual(13750, value);

            var value1 = function.Evaluate<double>(
                new VariableValueFilter<double>(x, 1.5),
                new VariableValueFilter<DateTime>(t, tValue.AddSeconds(2.5)));

            Assert.AreEqual(82500, value1);

            var value2 = function.Evaluate<double>(
                new VariableValueFilter<double>(x, 1.6),
                new VariableValueFilter<DateTime>(t, tValue.AddSeconds(2.5)));

            Assert.AreEqual(88000, value2);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:47,代码来源:FunctionApproximationTest.cs

示例7: invoke

 private static ValueEval invoke(Function function, ValueEval xArray, ValueEval yArray)
 {
     ValueEval[] args = new ValueEval[] { xArray, yArray, };
     return function.Evaluate(args, -1, (short)-1);
 }
开发者ID:ctddjyds,项目名称:npoi,代码行数:5,代码来源:TestXYNumericFunction.cs

示例8: Evaluate

 private static ValueEval Evaluate(Function instance, params double[] dArgs)
 {
     ValueEval[] evalArgs;
     evalArgs = new ValueEval[dArgs.Length];
     for (int i = 0; i < evalArgs.Length; i++)
     {
         evalArgs[i] = new NumberEval(dArgs[i]);
     }
     ValueEval r = instance.Evaluate(evalArgs, -1, (short)-1);
     return r;
 }
开发者ID:89sos98,项目名称:npoi,代码行数:11,代码来源:TestMinusZeroResult.cs

示例9: Evaluate

 private static ValueEval Evaluate(Function oper, ValueEval[] args, int srcRowIx, int srcColIx)
 {
     return oper.Evaluate(args, srcRowIx, (short)srcColIx);
 }
开发者ID:ctddjyds,项目名称:npoi,代码行数:4,代码来源:TestEqualEval.cs

示例10: ThrowCorrectExceptionWhenVariableIsNotInArgumentsOfFunction

        public void ThrowCorrectExceptionWhenVariableIsNotInArgumentsOfFunction()
        {
            var argument = new Variable<int>("x") { Values = { 0, 10, 20 } };
            var component = new Variable<int>("y") { Values = { 3, 4, 5 } };
            var function = new Function{ Name = "Pietje",Arguments = { argument }, Components = { component}};

            //try to filter on an unknown argument. This is a common mistake
            //should give a nice exception.
            function.Evaluate<int>(new VariableValueFilter<double>(new Variable<double>{Name = "Kees"}, 2.0));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:10,代码来源:VariableValueFilterTest.cs

示例11: GetExtrapolatedValuesLinear1D

        public void GetExtrapolatedValuesLinear1D()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction function = new Function();
            function.Arguments.Add(x);
            function.Components.Add(y);

            // set (fx, fy) values to (100.0, 200.0) for a combination of x and y values.
            function.SetValues(
                new[] { 100.0, 200.0, 300.0 },
                new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));

            //Extrapolate linear
            x.ExtrapolationType = ApproximationType.Linear;

            //before the 1st argument value
            Assert.AreEqual(50, function.Evaluate<double>(new VariableValueFilter<double>(x, 0.5)));

            //after the las
            Assert.AreEqual(350, function.Evaluate<double>(new VariableValueFilter<double>(x, 3.5)));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:23,代码来源:FunctionApproximationTest.cs

示例12: GetExtrapolatedValuesConstant1D

        public void GetExtrapolatedValuesConstant1D()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction function = new Function();
            function.Arguments.Add(x);
            function.Components.Add(y);

            // set (fx, fy) values to (100.0, 200.0) for a combination of x and y values.
            function.SetValues(
                new[] { 100.0, 200.0, 300.0 },
                new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));
           

            //No extrapolation
            x.ExtrapolationType = ApproximationType.Constant;

            //x0 < f.Arguments[0], extrapolation at begin is set to true
            var value = function.Evaluate<double>(new VariableValueFilter<double>(x, 0.5));
            Assert.AreEqual(100, value);

            value = function.Evaluate<double>(new VariableValueFilter<double>(x, 3.5));
            Assert.AreEqual(300, value);

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:26,代码来源:FunctionApproximationTest.cs

示例13: AlphaInt

 /// <summary>
 /// Calculates the integral of alpha function to be used in the A() method.
 /// </summary>
 /// <param name="t">Lower value defining integration interval.</param>
 /// <param name="T">Upper value defining integration interval.</param>
 /// <param name="alpha">Hull-White alpha parameter.</param>
 /// <param name="sigma">Hull-White sigma parameter.</param>
 /// <param name="zeroRateCurve">Zero rate curve.</param>
 /// <returns>The integral of alpha function between t and T.</returns>
 private static double AlphaInt(double t, double T, double alpha, double sigma, Function zeroRateCurve)
 {
     double firstTerm = zeroRateCurve.Evaluate(T) * T - zeroRateCurve.Evaluate(t) * t;
     return firstTerm + sigma * sigma * (alpha * (T - t) - 2.0 * (Math.Exp(-alpha * t) - Math.Exp(-alpha * T))
         + 0.5 * (Math.Exp(-2.0 * alpha * t) - Math.Exp(-2.0 * alpha * T))) / (2.0 * Math.Pow(alpha, 3.0));
 }
开发者ID:fairmat,项目名称:InterestRatesModels,代码行数:15,代码来源:HW1.cs


注:本文中的System.Function.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。