Re: calibration G2++ with defferential evolution

Posted by Peter Caspers-4 on
URL: http://quantlib.414.s1.nabble.com/calibration-G2-with-defferential-evolution-tp14969p14973.html

oh, ok. got it. On second thought, instead of "fixing"
CompositeConstraint we should rather

1 add upperBound() and lowerBound() implementations to
CalibratedModel::PrivateConstraint (for this we need access to the
parameters' constraints though to read their bounds, so an additional
inspector might be needed)

2 maybe change the default implementation in Constraint to return an
array with size params.size() and value numeric_limits::max() / min()
? If not overwritten in derived classes, at least the correct
structure is returned indicating no constraint

still does not feel like the perfect solution ...

Peter

On 17 February 2014 14:01, Ralph Schreyer <[hidden email]> wrote:

> Hi Peter,
>
> but the DifferentialEvolution in its minimize(...) implementation of the
> Optimizer interface calls DifferentialEvolution::fillInitialPopulation which
> in turn calls the upperBound() and lowerBound() methods of the problem
> given, no?
>
>
> Best
> Ralph
>
>
>
>
>
> 2014-02-17 13:54 GMT+01:00 Peter Caspers <[hidden email]>:
>
>> Hi Ralph,
>>
>> indeed, this looks like a bug in CompositeConstraint.
>>
>> This should however not cause trouble if André implements his
>> constraints via the test() method directly (as he did ?). The
>> CompositeConstraint then just returns c1_.test(params) &&
>> c2_.test(params) without referring to any upperBound() / lowerBound()
>> implementation ?
>>
>> I am just guessing though.
>>
>> best
>> Peter
>>
>> On 17 February 2014 13:39, Ralph Schreyer <[hidden email]>
>> wrote:
>> > Hi Andre, Peter,
>> >
>> > I think the current implementation is buggy. You would do something like
>> >
>> > Array lower(5); lower[0] = 0.0; lower[1] = 0.0; lower[2] = 0.0; lower[3]
>> > =
>> > -1.0; lower[4] = 0.0; Array upper(5); upper[0] = 10.0; upper[1] = 50.0;
>> > upper[2] = 10.0; upper[3] = 1.0; upper[4] = 10.0;
>> > model->calibrate(options,
>> > deOptimizer, EndCriteria(400, 40, 1.0e-8, 1.0e-8, Null<Real>()),
>> > NonhomogeneousBoundaryConstraint(lower, upper));
>> >
>> > Then, in model.cpp, line 88 ff, the CompositeConstraint is built from
>> > the
>> > PrivateConstraint of the model and the NonhomogeneousBoundaryConstraint.
>> > When you look at the implementation of e.g. upperBound(...) in
>> > constraint.hpp, line 156 ff., you find
>> >
>> > for (Size iter = 0; iter < c1ub.size(); iter++) { rtrnArray.at(iter) =
>> > std::min(c1ub.at(iter), c2ub.at(iter)); }
>> >
>> > Because c1ub is the upperBound of the PrivateConstraint and c1ub.size()
>> > = 0,
>> > the DifferentialEvolution does not get its bounds and therefore e.g.
>> > DifferentialEvolution::fillInitialPopulation(...) fails.
>> >
>> > Maybe one can change the CompositeConstraint upperBound and lowerBound
>> > implementations? Or is there a better place? Or isn't there a bug at
>> > all??
>> >
>> >
>> > Best
>> > Ralph
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > 2014-02-17 13:00 GMT+01:00 Peter Caspers <[hidden email]>:
>> >
>> >> Hi André,
>> >>
>> >> can you please post the complete code needed to reproduce the problem
>> >> ? With a short description of what the problem is (if not obvious) ?
>> >>
>> >> best regards
>> >> Peter
>> >>
>> >>
>> >> On 16 February 2014 17:28, André de Boer <[hidden email]> wrote:
>> >> > Hello,
>> >> >
>> >> > Two days ago I posted a question about differential evolution and the
>> >> > shortratemodel G2.
>> >> > Meanwhile I learned how to minimize the Rosenbrockfunction with
>> >> > differential
>> >> > evolution.
>> >> > But my goal is to calibrate the G2 shortratemodel.
>> >> >
>> >> > For the 5 parameters of the G2++ model I want to have
>> >> > boundedconstraints:
>> >> > For instance:
>> >> > 0 < a < 6
>> >> > 0 < b < 6
>> >> > 0 < sigma < 0.25
>> >> > 0 < eta < 0.25
>> >> > -1 < rho < 1
>> >> >
>> >> > To accomplish this I made a class MyConstraint, see code below.
>> >> > ...
>> >> > MyConstraint mc;
>> >> > DifferentialEvolution deOptim(conf);
>> >> > modelG2pp->calibrate(swaptions, deOptim,
>> >> > EndCriteria(100,10,1e-10,1e-8,Null<Real>()), mc);
>> >> > ...
>> >> > But still I isn't not working.
>> >> > Can someone give me a hint of parts of code?
>> >> >
>> >> > Kind regards,
>> >> > André
>> >> >
>> >> >
>> >> >
>> >> > #include <iostream>
>> >> > #include <vector>
>> >> > #include <ql/quantlib.hpp>
>> >> > using namespace QuantLib;
>> >> >
>> >> > class MyConstraint : public Constraint {
>> >> > class Impl : public Constraint::Impl {
>> >> > public:
>> >> >
>> >> > bool test(const Array& x) const {
>> >> > Real a1 = x[0], a2 = x[1], a3 = x[2], a4=x[3], a5=x[4];
>> >> >
>> >> > return (0.0 <= a1 && a1 <= 6.0) &&
>> >> > (0.0 <= a2 && a2 <= 6.0) &&
>> >> > (0.0 <= a3 && a3 <= 0.25) &&
>> >> > (0.0 <= a4 && a4 <= 0.25) &&
>> >> > (-1.0 <= a5 && a5 <= 1.0);
>> >> >
>> >> > }
>> >> >
>> >> > };
>> >> > public:
>> >> >
>> >> > MyConstraint()
>> >> > : Constraint(boost::shared_ptr<Constraint::Impl>(new
>> >> > MyConstraint::Impl)) {}
>> >> >
>> >> > };
>> >> >
>> >> > int main(){
>> >> >
>> >> > ...
>> >> > double a = 0.1;
>> >> >
>> >> > double b = 0.1;
>> >> > double sigma = 0.01;
>> >> > double eta = 0.01;
>> >> > double rho = -0.75;
>> >> > boost::shared_ptr<G2> modelG2pp(new G2(yieldCurve, a, b, sigma, eta,
>> >> > rho));
>> >> > std::cout << "G2 (analytic formulae) calibration" << std::endl;
>> >> >
>> >> > MyConstraint mc;
>> >> > DifferentialEvolution::Configuration conf =
>> >> > DifferentialEvolution::Configuration()
>> >> > .withStepsizeWeight(0.4)
>> >> > .withBounds()
>> >> > .withCrossoverProbability(0.35)
>> >> > .withPopulationMembers(100)
>> >> > .withStrategy(DifferentialEvolution::BestMemberWithJitter)
>> >> > .withCrossoverType(DifferentialEvolution::Normal)
>> >> > .withAdaptiveCrossover()
>> >> > .withSeed(0);
>> >> >
>> >> > MyConstraint mc;
>> >> > DifferentialEvolution deOptim(conf);
>> >> > modelG2pp->calibrate(swaptions, deOptim,
>> >> > EndCriteria(100,10,1e-10,1e-8,Null<Real>()), mc);
>> >> >
>> >> > }
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------------------------------------------------
>> >> > Android apps run on BlackBerry 10
>> >> > Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> >> > Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> >> > Get your Android app in front of a whole new audience.  Start now.
>> >> >
>> >> >
>> >> > http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> >> > _______________________________________________
>> >> > QuantLib-users mailing list
>> >> > [hidden email]
>> >> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
>> >> >
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Android apps run on BlackBerry 10
>> >> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> >> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> >> Get your Android app in front of a whole new audience.  Start now.
>> >>
>> >>
>> >> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> >> _______________________________________________
>> >> QuantLib-users mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>> >
>> >
>
>

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users