~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/optimization/demos/neldermead/nmplot_quadratic.fixed2.sce

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2
 
// Copyright (C) 2008-2009 - INRIA - Michael Baudin
3
 
// Copyright (C) 2010 - DIGITEO - Allan CORNET
4
 
// Copyright (C) 2011 - DIGITEO - Michael Baudin
5
 
//
6
 
// This file must be used under the terms of the CeCILL.
7
 
// This source file is licensed as described in the file COPYING, which
8
 
// you should have received as part of this distribution.  The terms
9
 
// are also available at
10
 
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11
 
 
12
 
function demo_nmplot_qfixed2()
13
 
 
14
 
  filename = 'nmplot_quadratic.fixed2.sce';
15
 
  dname = get_absolute_file_path(filename);
16
 
 
17
 
  mprintf(_("Illustrates that the fixed-shape Spendley et al. algorithm performs badly on a badly quadratic test case.\n"));
18
 
  mprintf(_("Defining quadratic function...\n"));
19
 
  a = 100;
20
 
  
21
 
  function [ y , index ] = quadratic ( x , index )
22
 
    y = a * x(1)^2 + x(2)^2;
23
 
  endfunction
24
 
  function y = quadraticC ( x1 , x2 )
25
 
    y = quadratic ( [x1 , x2] , 2 )
26
 
  endfunction
27
 
 
28
 
  mprintf(_("Creating nmplot object ...\n"));
29
 
  nm = nmplot_new ();
30
 
  nm = nmplot_configure(nm, "-numberofvariables",2);
31
 
  nm = nmplot_configure(nm, "-function",quadratic);
32
 
  nm = nmplot_configure(nm, "-x0",[10.0 10.0]');
33
 
  nm = nmplot_configure(nm, "-maxiter",400);
34
 
  nm = nmplot_configure(nm, "-maxfunevals",400);
35
 
  nm = nmplot_configure(nm, "-tolxmethod",%f);
36
 
  nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
37
 
  nm = nmplot_configure(nm, "-simplex0method","spendley");
38
 
  nm = nmplot_configure(nm, "-method","fixed");
39
 
  
40
 
  //
41
 
  // Setup output files
42
 
  //
43
 
  simplexfn = TMPDIR + filesep() + "history.simplex.txt";
44
 
  nm = nmplot_configure(nm, "-simplexfn",simplexfn);
45
 
  
46
 
  //
47
 
  // Perform optimization
48
 
  //
49
 
  mprintf(_("Searching (please wait) ...\n"));
50
 
  nm = nmplot_search(nm);
51
 
  //
52
 
  // Print a summary
53
 
  //
54
 
  exec(fullfile(dname,"nmplot_summary.sci"),-1);
55
 
  nmplot_summary(nm)
56
 
  //
57
 
  // Plot the contours of the cost function and the simplex history
58
 
  mprintf(_("Plotting contour (please wait) ...\n"));
59
 
  nm = nmplot_configure(nm, "-verbose", 0);
60
 
  xmin = -5.0 ; 
61
 
  xmax = 12.0 ; 
62
 
  ymin = -2.0 ; 
63
 
  ymax = 12.0 ; 
64
 
  nx = 50 ; 
65
 
  ny = 50;
66
 
  scf()
67
 
  drawlater();
68
 
  xdata=linspace(xmin,xmax,nx);
69
 
  ydata=linspace(ymin,ymax,ny);
70
 
  contour ( xdata , ydata , quadraticC , [10.0 50 100 1000 2000 5000 10000 20000] )
71
 
  nmplot_simplexhistory ( nm );
72
 
  drawnow();
73
 
  
74
 
  // Clean-up
75
 
  deletefile(simplexfn);
76
 
  nm = nmplot_destroy(nm);
77
 
  mprintf("End of demo.\n");
78
 
 
79
 
  //
80
 
  // Load this script into the editor
81
 
  //
82
 
  editor ( dname + filename, "readonly" );
83
 
 
84
 
endfunction
85
 
 
86
 
demo_nmplot_qfixed2();
87
 
clear demo_nmplot_qfixed2;
88
 
 
89
 
 
 
1
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 
2
// Copyright (C) 2008-2009 - INRIA - Michael Baudin
 
3
// Copyright (C) 2010 - DIGITEO - Allan CORNET
 
4
// Copyright (C) 2011 - DIGITEO - Michael Baudin
 
5
// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS
 
6
//
 
7
// This file must be used under the terms of the CeCILL.
 
8
// This source file is licensed as described in the file COPYING, which
 
9
// you should have received as part of this distribution.  The terms
 
10
// are also available at
 
11
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
12
 
 
13
function demo_nmplot_qfixed2()
 
14
 
 
15
    filename = 'nmplot_quadratic.fixed2.sce';
 
16
    dname = get_absolute_file_path(filename);
 
17
 
 
18
    mprintf(_("Illustrates that the fixed-shape Spendley et al. algorithm performs badly on a badly quadratic test case.\n"));
 
19
    mprintf(_("Defining quadratic function...\n"));
 
20
    a = 100;
 
21
 
 
22
    function [ y , index ] = quadratic ( x , index )
 
23
        y = a * x(1)^2 + x(2)^2;
 
24
    endfunction
 
25
    function y = quadraticC ( x1 , x2 )
 
26
        y = quadratic ( [x1 , x2] , 2 )
 
27
    endfunction
 
28
 
 
29
    mprintf(_("Creating nmplot object ...\n"));
 
30
    nm = nmplot_new ();
 
31
    nm = nmplot_configure(nm, "-numberofvariables",2);
 
32
    nm = nmplot_configure(nm, "-function",quadratic);
 
33
    nm = nmplot_configure(nm, "-x0",[10.0 10.0]');
 
34
    nm = nmplot_configure(nm, "-maxiter",400);
 
35
    nm = nmplot_configure(nm, "-maxfunevals",400);
 
36
    nm = nmplot_configure(nm, "-tolxmethod",%f);
 
37
    nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
 
38
    nm = nmplot_configure(nm, "-simplex0method","spendley");
 
39
    nm = nmplot_configure(nm, "-method","fixed");
 
40
 
 
41
    //
 
42
    // Setup output files
 
43
    //
 
44
    simplexfn = TMPDIR + filesep() + "history.simplex.txt";
 
45
    nm = nmplot_configure(nm, "-simplexfn",simplexfn);
 
46
 
 
47
    //
 
48
    // Perform optimization
 
49
    //
 
50
    mprintf(_("Searching (please wait) ...\n"));
 
51
    nm = nmplot_search(nm);
 
52
    //
 
53
    // Print a summary
 
54
    //
 
55
    exec(fullfile(dname,"nmplot_summary.sci"),-1);
 
56
    nmplot_summary(nm)
 
57
    //
 
58
    // Plot the contours of the cost function and the simplex history
 
59
    mprintf(_("Plotting contour (please wait) ...\n"));
 
60
    nm = nmplot_configure(nm, "-verbose", 0);
 
61
    xmin = -5.0 ; 
 
62
    xmax = 12.0 ; 
 
63
    ymin = -2.0 ; 
 
64
    ymax = 12.0 ; 
 
65
    nx = 50 ; 
 
66
    ny = 50;
 
67
    scf()
 
68
    drawlater();
 
69
    xdata=linspace(xmin,xmax,nx);
 
70
    ydata=linspace(ymin,ymax,ny);
 
71
    contour ( xdata , ydata , quadraticC , [10.0 50 100 1000 2000 5000 10000 20000] )
 
72
    nmplot_simplexhistory ( nm );
 
73
    drawnow();
 
74
    demo_viewCode(filename);
 
75
 
 
76
    // Clean-up
 
77
    deletefile(simplexfn);
 
78
    nm = nmplot_destroy(nm);
 
79
    mprintf("End of demo.\n");
 
80
endfunction
 
81
 
 
82
demo_nmplot_qfixed2();
 
83
clear demo_nmplot_qfixed2;
 
84
 
 
85
 
 
86