File: optimization.rst

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (168 lines) | stat: -rwxr-xr-x 4,969 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Optimization
============


.. function:: fit_praxis


    Syntax:
        ``min = h.fit_praxis(n, "funname", x._ref_x[0])``

        ``min = h.fit_praxis(n, "funname", Vector)``

        ``min = h.fit_praxis(..., ..., ..., "after quad statement")``

        ``min = h.fit_praxis(efun_as_python_callable, neuron_vector)``


    Description:
        This is the principal axis method for minimizing a function. See praxis.c 
        in the scopmath library. 
         


        ``1 <= n < 20`` 
            is the number of parameters to vary (number 
            of arguments to *funname*). 

        *funname* 
            the name of the function to minimize, eg. least square difference between model and data. 
            The funname must take two arguments, the first arg 
            is the number of elements in second arg vector.. 

        *x* 
            is a double :class:`Vector` of at least length *n*. Prior to the call set 
            it to a guess of the parameter values. On return it contains the 
            values of the args that minimize ``funname()``. 

         
        *funname* may be either 
        an interpreted HOC function or a compiled NMODL function. This form of calling
        cannot optimize Python functions directly.
         
        If the variable stoprun is set to 1 during a call to fit_praxis, it will 
        return immediately (when the current call to  funname returns) with 
        a return value and varx values set to the best minimum found so far. Use 
        :func:`stop_praxis` to stop after finishing the current principal axis calculation. 
         
        The fourth argument, if present, specifies a statement to be executed at 
        the end of each principal axis evaluation. 
         
        If the third argument is a Vector, then that style is used to specify 
        the initial starting point and return the final value. However the 
        function is still called with second arg as a pointer into a double array. 
         
        The Python callable form uses a Python Callable as the function to 
        minimize and it must take a single NEURON Vector argument specifying the 
        values of the parameters for use in evaluation the function. On entry to 
        fit_praxis the Vector specifies the number of parameters and the 
        parameter starting values. On return the vector contains the values of 
        parameters which generated the least minimum found so far. 
         
        
        Example: minimize :math:`(x+y - 5)^2 + 5*((x-y) - 15)^2`

        .. code-block::
            python

            from neuron import h 
            v = h.Vector([0, 0]) 
            def efun(v): 
              return (v[0] + v[1] - 5) ** 2 + 5 * (v[0] -v[1] - 15) ** 2 
            h.attr_praxis(1e-5, 0.5, 0) 
            e = h.fit_praxis(efun, v) 
            print("e=%g x=%g y=%g\n"%(e, v[0], v[1]))


    .. warning::
        Up to version 4.0.1, the arguments to *funname* were an explicit 
        list of *n* arguments. ie ``numarg()==n``. 

    .. seealso::
        :func:`attr_praxis`, :func:`stop_praxis`, :func:`pval_praxis`

         

----



.. function:: attr_praxis


    Syntax:
        ``h.attr_praxis(tolerance, maxstepsize, printmode)``

        ``previous_index = h.attr_praxis(mcell_ran4_index)``


    Description:
        Set the attributes of the praxis method. This must be called before 
        the first call to :func:`fit_praxis`. 


        tolerance 
            praxis attempt to return f(x) such that if x0 is the true 
            local minimum then ``norm(x-x0) < tolerance`` 

        maxstepsize 
            should be set to about the maximum distance from 
            initial guess to the minimum. 

        printmode=0 
            	no printing 

        printmode=1,2,3 
            more and more verbose 

        The single argument form causes praxis to pick its random numbers from 
        the the mcellran4 generator beginning at the specified index. This 
        allows reproducible fitting. The return value is the previously picked 
        index. (see :func:`mcell_ran4`) 

         

----



.. function:: pval_praxis


    Syntax:
        ``pval = h.pval_praxis(i)``

        ``pval = h.pval_praxis(i, paxis._ref_x[0])``

        ``pval = h.pval_praxis(i, Vector)``


    Description:
        Return the ith principal value. If the second argument is present, ``pval_praxis`` also fills 
        the :class:`Vector` with the ith principal axis. 

         

----



.. function:: stop_praxis


    Syntax:
        ``h.stop_praxis()``

        ``h.stop_praxis(i)``


    Description:
        Set a flag in the praxis function that will cause it to stop after 
        it finishes the current (or ith subsequent) 
        principal axis calculation. If this function 
        is called before :func:`fit_praxis`, then praxis will do a single 
        (or i) principal axis calculation and then exit.