我写了一个如下函数处理二次规划,调用accord.net:using Accord.Math;
using Accord.Math.Optimization;
public AccordQP()
{
double x= 0, y = 0;
// Create our objective function using a lambda expression
var f = new QuadraticObjectiveFunction(()=>2 * (x* x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y);
var solver = new GoldfarbIdnani(f, constraints);
// And attempt solve for the min:
bool success = solver.Minimize();
}
以上函数的目标就是求2 * (x* x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y的最小值
请问如何生成不定数量的double对象并加入lambda表达式中
比如我有N个变量(实际我要用到300个变量),嵌入lambda表达式内
using Accord.Math.Optimization;
public AccordQP()
{
double x= 0, y = 0;
// Create our objective function using a lambda expression
var f = new QuadraticObjectiveFunction(()=>2 * (x* x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y);
var solver = new GoldfarbIdnani(f, constraints);
// And attempt solve for the min:
bool success = solver.Minimize();
}
以上函数的目标就是求2 * (x* x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y的最小值
请问如何生成不定数量的double对象并加入lambda表达式中
比如我有N个变量(实际我要用到300个变量),嵌入lambda表达式内
应该作为 AccordQP() 的参数传入
2 * (x* x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y比如如果你现在是3个参数,那么又应该怎么表示?
如果你只是说 这个式子会变化,那么可以
static void Main(string[] args)
{
double x = 1, y = 2;
Func<double> f =() => 2 * (x * x) - (x * y) + 4 * (y * y) - 5 * x - 6 * y; Get(f); Console.ReadKey();
} public static void Get(Func<double> func)
{
double result = func();
Console.WriteLine(result);
}
using Microsoft.SolverFoundation.Common;
using Microsoft.SolverFoundation.Services;
using Microsoft.SolverFoundation.Solvers;InteriorPointSolver solver = new InteriorPointSolver();
public void Step3SetTargetFunction(double coefficient, int variable_index1, int variable_index2)
{
if(targetfunction<0)
{
solver.AddRow("targetfunction", out targetfunction);
}
solver.SetCoefficient(targetfunction, coefficient, variable_index1, variable_index2);
}
1输入一组数据,不定长度,N
2计算这组数据波动率(RETURN),长度N-1
3最优lambda函数目标最小方差=∑Wi*Wi*Variance+∑Wi*Wj*Covariance
这里可以看出 目标函数是动态变化的