Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimization with F#

I'm quite new to F# and have a problem. I want to solve a nonlinear, constrained optimization problem. The goal is to minimize a function minFunc with six parameters a, b, c, d, gamma and rho_infty, (the function is quite long so I don´t post it here) and the additional conditions:

a + d > 0,
d > 0,
c > 0,
gamma > 0,
0 <= gamma <= -ln(rho_infty),
0 < roh_infty <= 1.

I´ve tried it with with the Nelder Mead Solver from the Microsoft Solver Foundation, but I don´t know how to add the nonlinear conditions a + d > 0 and 0 <= gamma <= -ln(rho_infty).

My Code so far:

open Microsoft.SolverFoundation.Common
open Microsoft.SolverFoundation.Solvers

let funcFindParameters (startValues:float list) minimizationFunc =

let xInitial = startValues |> List.toArray
let lowerBound = [|-infinity; -infinity; 0.0; 0.0; 0.0; 0.0|]
let upperBound = [|infinity; infinity; infinity; infinity; infinity; 1.0|]

let solution = NelderMeadSolver.Solve(Func<float [], _>(fun parameters -> (minimizationFunc   
parameters.[0] parameters.[1] parameters.[2] parameters.[3] parameters.[4] parameters.[5])), 
xInitial, lowerBound, upperBound)

where parameters.[0] = a, and so one...

Is there perhaps some possibility to solve it with the Nelder Mead Solver or some other solver?

like image 458
user3489455 Avatar asked Apr 09 '26 07:04

user3489455


1 Answers

One comment, is that I would stay away from the Microsoft.SolverFoundation, I have wasted hours of my life on bad algorithms coded there. The R type provider is much better.

With that said, a common hack is simply to simply reparameterize the model to handle the constraints. For example, set:

e=a+d

as the parameter, and inside the optimzation calculate d as:

d=e-a

And now you just have to satisfy the constraint e>0, which is fixed. You can do something similar for the gamma parameter.

like image 144
evolvedmicrobe Avatar answered Apr 11 '26 03:04

evolvedmicrobe