本文整理汇总了C#中System.Function.SetValues方法的典型用法代码示例。如果您正苦于以下问题:C# Function.SetValues方法的具体用法?C# Function.SetValues怎么用?C# Function.SetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Function
的用法示例。
在下文中一共展示了Function.SetValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSimpleFunction
//TODO: get this near functiontest. This is not a general function.
public static IFunction CreateSimpleFunction(IFunctionStore store)
{
var function = new Function("test");
store.Functions.Add(function);
// initialize schema
IVariable x = new Variable<double>("x", 3);
IVariable y = new Variable<double>("y", 2);
IVariable f1 = new Variable<double>("f1");
function.Arguments.Add(x);
function.Arguments.Add(y);
function.Components.Add(f1);
// write some data
var xValues = new double[] {0, 1, 2};
var yValues = new double[] {0, 1};
var fValues = new double[] {100, 101, 102, 103, 104, 105};
function.SetValues(fValues,
new VariableValueFilter<double>(x, xValues),
new VariableValueFilter<double>(y, yValues),
new ComponentFilter(f1));
return function;
}
示例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);
}
示例3: 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);
}
示例4: Clear
public void Clear()
{
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);
f.SetValues(new[] {100.0, 200.0, 300.0}, new VariableValueFilter<double>(x, new[] {1.0, 2.0, 3.0}));
IList values = f.GetValues();
Assert.AreEqual(3, values.Count);
f.Clear();
Assert.AreEqual(0, values.Count);
}
示例5: SetValuesNonExistingFilter
public void SetValuesNonExistingFilter()
{
IVariable<float> f = new Variable<float>("f");
IVariable<float> x = new Variable<float>("x1");
IFunction function = new Function("Fail Test");
function.Components.Add(f);
function.Arguments.Add(x);
function.SetValues(new float[] {100},
new VariableValueFilter<float>(x, new[] {0.0f}));
}
示例6: AssignFloatValuesToIntVariable
public void AssignFloatValuesToIntVariable()
{
IVariable f = new Variable<int>("f");
IVariable x = new Variable<float>("x1");
IFunction function = new Function("Fail Test");
function.Components.Add(f);
function.Arguments.Add(x);
x.Values.Add(0.0f);
function.SetValues(new[] {1.7}, // should be rounded to int
new VariableValueFilter<float>(x, new[] {0.0f}));
Assert.AreEqual(2, f.Values[0]);
}
示例7: SetMultiValues
public void SetMultiValues()
{
object defaultValue = -1.0f;
var x = new Variable<float>("x");
var y = new Variable<float>("y");
var z = new Variable<float>("z");
var t = new Variable<int>("t");
var vx = new Variable<float>("vx");
var vy = new Variable<float>("vy");
var vz = new Variable<float>("vz");
vx.DefaultValue = defaultValue;
vy.DefaultValue = defaultValue;
vz.DefaultValue = defaultValue;
var function = new Function("3D Test");
function.Arguments.Add(x);
function.Arguments.Add(y);
function.Arguments.Add(z);
function.Arguments.Add(t);
function.Components.Add(vx);
function.Components.Add(vy);
function.Components.Add(vz);
IList values;
// (vx, vy, vz)(0.0, 0.0, 0.0, 0) = (0.0, 0.0, 0.0)
function[0.0f, 0.0f, 0.0f, 0] = new[] {0.0f, 0.0f, 0.0f};
// 0.0 0.0 0.0 0 0.0 0.0 0.0
function.SetValues(
new[] {3.0f, 4.0f, 5.0f},
new VariableValueFilter<float>(x, 1.0F), new VariableValueFilter<float>(y, 2.0F));
// 0.0 0.0 0.0 0 0.0 0.0 0.0
// 0.0 2.0 0.0 0 default default default
// 1.0 0.0 0.0 0 default default default
// 1.0 2.0 0.0 0 3.0 4.0 5.0
Assert.AreEqual(0.0F, vx.Values[0, 0, 0, 0]);
Assert.AreEqual(0.0F, vy.Values[0, 0, 0, 0]);
Assert.AreEqual(0.0F, vz.Values[0, 0, 0, 0]);
Assert.AreEqual(defaultValue, vx.Values[0, 1, 0, 0]);
Assert.AreEqual(defaultValue, vy.Values[0, 1, 0, 0]);
Assert.AreEqual(defaultValue, vz.Values[0, 1, 0, 0]);
Assert.AreEqual(defaultValue, vx.Values[1, 0, 0, 0]);
Assert.AreEqual(defaultValue, vx.Values[1, 0, 0, 0]);
Assert.AreEqual(defaultValue, vx.Values[1, 0, 0, 0]);
Assert.AreEqual(3.0F, vx.Values[1, 1, 0, 0]);
Assert.AreEqual(4.0F, vy.Values[1, 1, 0, 0]);
Assert.AreEqual(5.0F, vz.Values[1, 1, 0, 0]);
function.SetValues(new[] {7.0f, 8.0f, 9.0f}, new VariableValueFilter<int>(t, 1));
// 0.0 0.0 0.0 0 0.0 0.0 0.0
// 0.0 0.0 0.0 1 7.0 8.0 9.0
// 0.0 2.0 0.0 0 default default default
// 0.0 2.0 0.0 1 7.0 8.0 9.0
// 1.0 0.0 0.0 0 default default default
// 1.0 0.0 0.0 1 7.0 8.0 9.0
// 1.0 2.0 0.0 0 3.0 4.0 5.0
// 1.0 2.0 0.0 1 7.0 8.0 9.0
Assert.AreEqual(0.0F, vx.Values[0]);
Assert.AreEqual(0.0F, vy.Values[0]);
Assert.AreEqual(0.0F, vz.Values[0]);
Assert.AreEqual(7.0F, vx.Values[1]);
Assert.AreEqual(8.0F, vy.Values[1]);
Assert.AreEqual(9.0F, vz.Values[1]);
Assert.AreEqual(defaultValue, vx.Values[2]);
Assert.AreEqual(defaultValue, vy.Values[2]);
Assert.AreEqual(defaultValue, vz.Values[2]);
Assert.AreEqual(7.0F, vx.Values[3]);
Assert.AreEqual(8.0F, vy.Values[3]);
Assert.AreEqual(9.0F, vz.Values[3]);
Assert.AreEqual(defaultValue, vx.Values[4]);
Assert.AreEqual(defaultValue, vy.Values[4]);
Assert.AreEqual(defaultValue, vz.Values[4]);
Assert.AreEqual(7.0F, vx.Values[5]);
Assert.AreEqual(8.0F, vy.Values[5]);
Assert.AreEqual(9.0F, vz.Values[5]);
Assert.AreEqual(3.0F, vx.Values[6]);
Assert.AreEqual(4.0F, vy.Values[6]);
Assert.AreEqual(5.0F, vz.Values[6]);
Assert.AreEqual(7.0F, vx.Values[7]);
Assert.AreEqual(8.0F, vy.Values[7]);
Assert.AreEqual(9.0F, vz.Values[7]);
function.SetValues(
new[] {10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f},
new VariableValueFilter<int>(t, 1));
// 0.0 0.0 0.0 0 0.0 0.0 0.0
// 0.0 0.0 0.0 1 10.0 11.0 12.0
// 0.0 2.0 0.0 0 default default default
// 0.0 2.0 0.0 1 13.0 14.0 15.0
// 1.0 0.0 0.0 0 default default default
// 1.0 0.0 0.0 1 16.0 17.0 18.0
// 1.0 2.0 0.0 0 3.0 4.0 5.0
// 1.0 2.0 0.0 1 19.0 20.0 21.0
Assert.AreEqual(0.0F, vx.Values[0]);
Assert.AreEqual(0.0F, vy.Values[0]);
Assert.AreEqual(0.0F, vz.Values[0]);
Assert.AreEqual(10.0F, vx.Values[1]);
//.........这里部分代码省略.........
示例8: SetValues
public void SetValues()
{
object defaultValue = default(float);
var f = new Variable<float>("f");
var x1 = new Variable<float>("x1");
var x2 = new Variable<float>("x2");
var function = new Function("OneComponentTwoArguments Test");
function.Components.Add(f);
function.Arguments.Add(x1);
function.Arguments.Add(x2);
function[0.0f, 0.0f] = 0.0f;
// x1 x2 f
// 0.0 0.0 0.0
Assert.AreEqual(1, x1.Values.Count);
var x2values = new[] {0.1f, 0.2f};
// set multiple values
function.SetValues(new[] {5.0f},
new VariableValueFilter<float>(x1, 1.0f), new VariableValueFilter<float>(x2, x2values));
// x1 x2 f
// 0.0 0.0 0.0
// 1.0 0.0 default
// 0.0 0.1 default
// 1.0 0.1 5.0
// 0.0 0.2 default
// 1.0 0.2 5.0
Assert.AreEqual(2, x1.Values.Count);
Assert.AreEqual(3, x2.Values.Count);
Assert.AreEqual(6, function.GetValues().Count);
Assert.AreEqual(0.0F,
function.GetValues(new VariableValueFilter<float>(x1, 0.0F), new VariableValueFilter<float>(x2, 0.0F))[0]);
Assert.AreEqual(defaultValue, function.GetValues(
new VariableValueFilter<float>(x1, 1.0F),
new VariableValueFilter<float>(x2, 0.0F))[0]
);
Assert.AreEqual(defaultValue, function.GetValues(
new VariableValueFilter<float>(x1, 0.0F),
new VariableValueFilter<float>(x2, 0.1F))[0]
);
Assert.AreEqual(5.0F, function.GetValues(
new VariableValueFilter<float>(x1, 1.0F),
new VariableValueFilter<float>(x2, 0.1F))[0]
);
Assert.AreEqual(defaultValue, function.GetValues(
new VariableValueFilter<float>(x1, 0.0F),
new VariableValueFilter<float>(x2, 0.2F))[0]
);
Assert.AreEqual(5.0F, function.GetValues(
new VariableValueFilter<float>(x1, 1.0F),
new VariableValueFilter<float>(x2, 0.2F))[0]
);
function.SetValues(new[] { 6.0f }, new VariableValueFilter<float>(x1, 2.0f));
// x1 x2 f
// 0.0 0.0 0.0
// 1.0 0.0 default
// 0.0 0.1 default
// 1.0 0.1 5.0
// 0.0 0.2 default
// 1.0 0.2 5.0
// 2.0 0.0 6.0
// 2.0 0.1 6.0
// 2.0 0.2 6.0
Assert.AreEqual(x1.Values.Count, 3);
Assert.AreEqual(x2.Values.Count, 3);
Assert.AreEqual(function.GetValues().Count, 9);
Assert.AreEqual(0.0F,
function.GetValues(new VariableValueFilter<float>(x1, 0.0F),
new VariableValueFilter<float>(x2, 0.0F))[0]);
Assert.AreEqual(defaultValue,
function.GetValues(new VariableValueFilter<float>(x1, 1.0F), new VariableValueFilter<float>(x2, 0.0F))[0]);
Assert.AreEqual(defaultValue,
function.GetValues(new VariableValueFilter<float>(x1, 0.0F), new VariableValueFilter<float>(x2, 0.1F))[0]);
Assert.AreEqual(5.0F,
function.GetValues(new VariableValueFilter<float>(x1, 1.0F),
new VariableValueFilter<float>(x2, 0.1F))[0]);
Assert.AreEqual(defaultValue,
function.GetValues(new VariableValueFilter<float>(x1, 0.0F), new VariableValueFilter<float>(x2, 0.2F))[0]);
Assert.AreEqual(5.0F,
function.GetValues(new VariableValueFilter<float>(x1, 1.0F),
new VariableValueFilter<float>(x2, 0.2F))[0]);
Assert.AreEqual(6.0F,
function.GetValues(new VariableValueFilter<float>(x1, 2.0F),
new VariableValueFilter<float>(x2, 0.0F))[0]);
Assert.AreEqual(6.0F,
function.GetValues(new VariableValueFilter<float>(x1, 2.0F),
new VariableValueFilter<float>(x2, 0.1F))[0]);
Assert.AreEqual(6.0F,
function.GetValues(new VariableValueFilter<float>(x1, 2.0F),
new VariableValueFilter<float>(x2, 0.2F))[0]);
function.SetValues(new[] {3.0f},
//.........这里部分代码省略.........
示例9: SetValuesPreconditions
public void SetValuesPreconditions()
{
var arg1 = new Variable<double>();
var comp1 = new Variable<double>();
var function = new Function();
function.Arguments.Add(arg1);
function.Components.Add(comp1);
arg1.SetValues(new[]{1.0, 2.0});
Assert.AreEqual(2, arg1.Values.Count);
Assert.AreEqual(2, comp1.Values.Count);
try
{
function.SetValues(new double[] { });
Assert.Fail("Should have thrown an ArgumentOutOfRangeException");
}
catch (Exception e)
{
Assert.AreEqual(typeof(ArgumentOutOfRangeException), e.GetType(), "Expected an ArgumentOutOfRangeException to be thrown");
Assert.AreEqual("Size of 'values' argument must be greater than 0.\r\nParameter name: values", e.Message);
}
// Exception should not have affected specified data
Assert.AreEqual(2, arg1.Values.Count);
Assert.AreEqual(2, comp1.Values.Count);
try
{
function.SetValues(new[] { 1.1, 2.2, 3.3, 4.4, 5.5 });
Assert.Fail("Should have thrown an ArgumentException");
}
catch (Exception e)
{
Assert.AreEqual(typeof(ArgumentException), e.GetType(), "Expected an ArgumentException to be thrown");
Assert.AreEqual("Number of values to be written to dependent variable 'variable' exceeds argument values range. Got 5 values expected at most 2.", e.Message);
}
// Exception should not have affected specified data
Assert.AreEqual(2, arg1.Values.Count);
Assert.AreEqual(2, comp1.Values.Count);
// TODO: If possible, add test case to cover scenario when collection of IVariableFilters results in a would return a subspace size of 0 permutations
}
示例10: RemoveValues
public void RemoveValues()
{
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);
f.SetValues(new[] { 100.0, 200.0, 300.0 }, new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));
//update argument
f.Store.RemoveFunctionValues(x);
//component resizes
Assert.AreEqual(0,y.Values.Count);
}
示例11: InterpolatedLinear2D
public void InterpolatedLinear2D()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IVariable<double> f1 = new Variable<double>("f1");
var function = new Function("testfunction");
function.Arguments.Add(x);
function.Arguments.Add(y);
function.Components.Add(f1);
var xValues = new[] { 1.0, 2.0, 3.0 };
var yValues = new[] { 10.0, 20.0, 30.0, 40.0 };
var fValues = new[,]
{
{100.0, 200.0, 300.0, 400.0},
{1000.0, 2000.0, 3000.0, 4000.0},
{10000.0, 20000.0, 30000.0, 40000.0}
};
function.SetValues(fValues, new VariableValueFilter<double>(x, xValues), new VariableValueFilter<double>(y, yValues), new ComponentFilter(f1));
//no interpolation..on a defined spot
Assert.AreEqual(100, f1.Evaluate<double>(new VariableValueFilter<double>(x, 1.0), (new VariableValueFilter<double>(y, 10.0))));
//interpolation among first argument
Assert.AreEqual(640.0, f1.Evaluate<double>(new VariableValueFilter<double>(x, 1.6), (new VariableValueFilter<double>(y, 10.0))), 0.001);
//interpolation among second argument
Assert.AreEqual(260.0, f1.Evaluate<double>(new VariableValueFilter<double>(x, 1.0), (new VariableValueFilter<double>(y, 26.0))), 0.001);
//interpolation among two arguments
Assert.AreEqual(1664.0, f1.Evaluate<double>(new VariableValueFilter<double>(x, 1.6), (new VariableValueFilter<double>(y, 26.0))), 0.001);
}
示例12: GetExtrapolatedNoneThrowsException
public void GetExtrapolatedNoneThrowsException()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IFunction f1 = new Function();
f1.Arguments.Add(x);
f1.Components.Add(y);
// set (fx, fy) values to (100.0, 200.0) for a combination of x and y values.
f1.SetValues(
new[] { 100.0, 200.0, 300.0 },
new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));
IFunction f = f1;
//No extrapolation
x.ExtrapolationType = ExtrapolationType.None;
//x0 < f.Arguments[0], extrapolation at begin is set to true
var value = f.Evaluate<double>(new VariableValueFilter<double>(x, 0.5));
Assert.AreEqual(f.Components[0].Values[0], value);
}
示例13: 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)));
}
示例14: GetExceptionExtrapolatingValuesAtBeginAndEnd1ArgsFunction
public void GetExceptionExtrapolatingValuesAtBeginAndEnd1ArgsFunction()
{
IVariable<double> x = new Variable<double>("x");
IVariable<double> y = new Variable<double>("y");
IFunction f1 = new Function();
f1.Arguments.Add(x);
f1.Components.Add(y);
// set (fx, fy) values to (100.0, 200.0) for a combination of x and y values.
f1.SetValues(
new[] { 100.0, 200.0, 300.0 },
new VariableValueFilter<double>(x, new[] { 1.0, 2.0, 3.0 }));
IFunction f = f1;
x.ExtrapolationType = ApproximationType.None;
//x0 < f.Arguments[0], extrapolation at begin is set to false
var value = f.Evaluate<double>(new VariableValueFilter<double>(x, 0.5));
}
示例15: 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);
}