Search code examples
c#-4.0machine-learningmathematical-optimization

is there any direct way in C# to optimize a math function or minimize a parameter in an expression?


I am trying to implement an algorithm in C# that has some math function inside like :

Minimize a ||xu( i ) - ∑j aj( i ) bj ||2 + β || a( i ) ||1

but I'm not sure if there is any direct method in C# for optimizing and I couldn't find any thing in forums , or maybe you can offer any suggestion to solve this optimization problem in C# !?


Solution

  • There are several solvers with C# bindings that could be suitable for your problem, for example:

    • MS Solver Foundation, Microsoft's platform for mathematical optimization, that provides solvers for a large range of problems, including unconstrained and constrained least squares. Some effort to dig into the API, but in return derivatives are automatically computed etc.
    • ALGLIB provides a large range of different optimizers and is available in C#.
    • IPOPT was mentioned in Ali's comment above. I have developed the C# binding to IPOPT, and it is available for download here. I am of course biased, but personally I believe that the API is fairly straightforward. You need to manually provide the derivatives if you are using csipopt. (There is actually also a library that incorporates csipopt and provides automated derivative computation, Funclib.)
    • COBYLA2 (if you have nonlinear constraints) and BOBYQA (if you have bound or no constraints) are derivative-free direct search methods developed by Michael Powell. I have ported these solvers to C#, 100% managed code. The C# COBYLA2 project is available here, and the C# BOBYQA project is available here.