Posted by
Lapin on
URL: http://quantlib.414.s1.nabble.com/Least-square-without-knowing-the-gradient-tp6118p6120.html
Luigi,
Here is what I did:
1. I have create a new LeastSquare pb
class ParametricLocalVolFitting: public LeastSquareProblem
I am able to calculate the values I wish but I am not able to calculate the gradient (the solution is calculated on a PDE and since it ifor calibration, I don't wish to go numerically since it will increase my number of loops)
For the moment I pass the grad2fit[.]=0, but I have a crash.
2. In my resolution method, I use LevenbergMarquardt as optimization method.
boost::shared_ptr<OptimizationMethod> om(new LevenbergMarquardt(accuracy, accuracy, accuracy));
NonLinearLeastSquare lsLocal( con, accuracy, maxiter );
I apply the LeastSquare problem to my optimizer:
ParametricLocalVolFitting local(...);
lsLocal.setInitialValue(initialValue);
Array solution = lsLocal.perform(local);
The first loop is calculated as expected but since I don't have gradient there is a crash during the gradient calculation:
// compute derivative
grad_f = -2.0*(transpose(grad_fct2fit)*diff);
How could I do to make it work properly?
The best would be to use the targetAndValue function from the pb instead of the targetValueAndGradient function.
You have suggested to use different optimizer, but I already use LevenbergMarquardt. Would it work better with Simplex? if yes, do you have a sample of its use?
Regards
Luigi Ballabio wrote
On Mon, 2008-04-14 at 07:01 -0700, Yomi wrote:
> Hi,
>
> Could I use a LeastSquareProblem if I don't know the gradient of my cost
> function?
> I have a calibration problem to solve, but I don't know what the derivatives
> of my problem are.
You might calculate them numerically, but I don't know how effective
this would be.
> If we can not use the LeastSquareProblem (an overloaded one in fact), which
> method is recommended?
You can use one of the other optimizers (LevenbergMarquardt, Simplex...)
Luigi
--
So little done, so much to do.
-- Cecil Rhodes
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users