1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
3 | |
---|
4 | |
---|
5 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
6 | <head> |
---|
7 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
8 | |
---|
9 | <title>park package — SasView 3.0.0 documentation</title> |
---|
10 | |
---|
11 | <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> |
---|
12 | <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
---|
13 | |
---|
14 | <script type="text/javascript"> |
---|
15 | var DOCUMENTATION_OPTIONS = { |
---|
16 | URL_ROOT: '../../', |
---|
17 | VERSION: '3.0.0', |
---|
18 | COLLAPSE_INDEX: false, |
---|
19 | FILE_SUFFIX: '.html', |
---|
20 | HAS_SOURCE: true |
---|
21 | }; |
---|
22 | </script> |
---|
23 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
---|
24 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
---|
25 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
---|
26 | <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> |
---|
27 | <link rel="top" title="SasView 3.0.0 documentation" href="../../index.html" /> |
---|
28 | <link rel="up" title="lib.macosx-10.5-x86_64-2.7" href="modules.html" /> |
---|
29 | <link rel="next" title="sas package" href="sas.html" /> |
---|
30 | <link rel="prev" title="lib.macosx-10.5-x86_64-2.7" href="modules.html" /> |
---|
31 | </head> |
---|
32 | <body> |
---|
33 | <div class="related"> |
---|
34 | <h3>Navigation</h3> |
---|
35 | <ul> |
---|
36 | <li class="right" style="margin-right: 10px"> |
---|
37 | <a href="../../genindex.html" title="General Index" |
---|
38 | accesskey="I">index</a></li> |
---|
39 | <li class="right" > |
---|
40 | <a href="../../py-modindex.html" title="Python Module Index" |
---|
41 | >modules</a> |</li> |
---|
42 | <li class="right" > |
---|
43 | <a href="sas.html" title="sas package" |
---|
44 | accesskey="N">next</a> |</li> |
---|
45 | <li class="right" > |
---|
46 | <a href="modules.html" title="lib.macosx-10.5-x86_64-2.7" |
---|
47 | accesskey="P">previous</a> |</li> |
---|
48 | <li><a href="../../index.html">SasView 3.0.0 documentation</a> »</li> |
---|
49 | <li><a href="../dev.html" >Developer Documentation</a> »</li> |
---|
50 | <li><a href="modules.html" accesskey="U">lib.macosx-10.5-x86_64-2.7</a> »</li> |
---|
51 | </ul> |
---|
52 | </div> |
---|
53 | |
---|
54 | <div class="document"> |
---|
55 | <div class="documentwrapper"> |
---|
56 | <div class="bodywrapper"> |
---|
57 | <div class="body"> |
---|
58 | |
---|
59 | <div class="section" id="park-package"> |
---|
60 | <h1>park package</h1> |
---|
61 | <div class="section" id="submodules"> |
---|
62 | <h2>Submodules</h2> |
---|
63 | </div> |
---|
64 | <div class="section" id="module-park.assembly"> |
---|
65 | <span id="park-assembly-module"></span><h2>park.assembly module</h2> |
---|
66 | <p>An assembly is a collection of fitting functions. This provides |
---|
67 | the model representation that is the basis of the park fitting engine.</p> |
---|
68 | <p>Models can range from very simple one dimensional theory functions |
---|
69 | to complex assemblies of multidimensional datasets from different |
---|
70 | experimental techniques, each with their own theory function and |
---|
71 | a common underlying physical model.</p> |
---|
72 | <div class="section" id="usage"> |
---|
73 | <h3>Usage</h3> |
---|
74 | <p>First define the models you want to work with. In the example |
---|
75 | below we will use an example of a simple multilayer system measured by |
---|
76 | specular reflection of xrays and neutrons. The gold depth is the only |
---|
77 | fitting parameter, ranging from 10-30 A. The interface depths are |
---|
78 | tied together using expressions. In this case the expression is |
---|
79 | a simple copy, but any standard math functions can be used. Some |
---|
80 | model developers may provide additional functions for use with the |
---|
81 | expression.</p> |
---|
82 | <p>Example models:</p> |
---|
83 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">reflectometry.model1d</span> <span class="kn">as</span> <span class="nn">refl</span> |
---|
84 | <span class="n">xray</span> <span class="o">=</span> <span class="n">refl</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="s">'xray'</span><span class="p">)</span> |
---|
85 | <span class="n">xray</span><span class="o">.</span><span class="n">incident</span><span class="p">(</span><span class="s">'Air'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> |
---|
86 | <span class="n">xray</span><span class="o">.</span><span class="n">interface</span><span class="p">(</span><span class="s">'iAu'</span><span class="p">,</span><span class="n">sigma</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> |
---|
87 | <span class="n">xray</span><span class="o">.</span><span class="n">layer</span><span class="p">(</span><span class="s">'Au'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mf">124.68</span><span class="p">,</span><span class="n">depth</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">30</span><span class="p">])</span> |
---|
88 | <span class="n">xray</span><span class="o">.</span><span class="n">interface</span><span class="p">(</span><span class="s">'iSi'</span><span class="p">,</span><span class="n">sigma</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> |
---|
89 | <span class="n">xray</span><span class="o">.</span><span class="n">substrate</span><span class="p">(</span><span class="s">'Si'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mf">20.07</span><span class="p">)</span> |
---|
90 | <span class="n">datax</span> <span class="o">=</span> <span class="n">refl</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="s">'xray.dat'</span><span class="p">)</span> |
---|
91 | |
---|
92 | <span class="n">neutron</span> <span class="o">=</span> <span class="n">refl</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="s">'neutron'</span><span class="p">)</span> |
---|
93 | <span class="n">neutron</span><span class="o">.</span><span class="n">incident</span><span class="p">(</span><span class="s">'Air'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> |
---|
94 | <span class="n">neutron</span><span class="o">.</span><span class="n">interface</span><span class="p">(</span><span class="s">'iAu'</span><span class="p">,</span><span class="n">sigma</span><span class="o">=</span><span class="s">'xray.iAu'</span><span class="p">)</span> |
---|
95 | <span class="n">neutron</span><span class="o">.</span><span class="n">layer</span><span class="p">(</span><span class="s">'Au'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mf">4.66</span><span class="p">,</span><span class="n">depth</span><span class="o">=</span><span class="s">'xray.Au.depth'</span><span class="p">)</span> |
---|
96 | <span class="n">neutron</span><span class="o">.</span><span class="n">interface</span><span class="p">(</span><span class="s">'iSi'</span><span class="p">,</span><span class="n">sigma</span><span class="o">=</span><span class="s">'xray.iSi'</span><span class="p">)</span> |
---|
97 | <span class="n">neutron</span><span class="o">.</span><span class="n">substrate</span><span class="p">(</span><span class="s">'Si'</span><span class="p">,</span><span class="n">rho</span><span class="o">=</span><span class="mf">2.07</span><span class="p">)</span> |
---|
98 | <span class="n">datan</span> <span class="o">=</span> <span class="n">refl</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="s">'neutron.dat'</span><span class="p">)</span> |
---|
99 | </pre></div> |
---|
100 | </div> |
---|
101 | <p>As you can see from the above, parameters can be set to a value if |
---|
102 | the parameter is fixed, to a range if the parametemr is fitted, or |
---|
103 | to a string expression if the parameter is calculated from other |
---|
104 | parameters. See park.Parameter.set for further details.</p> |
---|
105 | <p>Having constructed the models, we can now create an assembly:</p> |
---|
106 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">park</span> |
---|
107 | <span class="n">assembly</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">Assembly</span><span class="p">([(</span><span class="n">xray</span><span class="p">,</span><span class="n">datax</span><span class="p">),</span> <span class="p">(</span><span class="n">neutron</span><span class="p">,</span><span class="n">datan</span><span class="p">)])</span> |
---|
108 | </pre></div> |
---|
109 | </div> |
---|
110 | <p>Note: this would normally be done in the context of a fit |
---|
111 | using fit = park.Fit([(xray,datax), (neutron,datan)]), and later referenced |
---|
112 | using fit.assembly.</p> |
---|
113 | <p>Individual parts of the assembly are accessable using the |
---|
114 | model number 0, 1, 2... or by the model name. In the above, |
---|
115 | assembly[0] and assembly[‘xray’] refer to the same model. |
---|
116 | Assemblies have insert and append functions for adding new |
---|
117 | models, and “del model[idx]” for removing them.</p> |
---|
118 | <p>Once the assembly is created computing the values for the system |
---|
119 | is a matter of calling:</p> |
---|
120 | <div class="highlight-python"><div class="highlight"><pre><span class="n">assembly</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span> |
---|
121 | <span class="k">print</span> <span class="s">"Chi**2"</span><span class="p">,</span><span class="n">assembly</span><span class="o">.</span><span class="n">chisq</span> |
---|
122 | <span class="k">print</span> <span class="s">"Reduced chi**2"</span><span class="p">,</span><span class="n">assembly</span><span class="o">.</span><span class="n">chisq</span><span class="o">/</span><span class="n">assembly</span><span class="o">.</span><span class="n">degrees_of_freedom</span> |
---|
123 | <span class="n">plot</span><span class="p">(</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">assembly</span><span class="o">.</span><span class="n">residuals</span><span class="p">)),</span> <span class="n">assembly</span><span class="o">.</span><span class="n">residuals</span><span class="p">)</span> |
---|
124 | </pre></div> |
---|
125 | </div> |
---|
126 | <p>This defines the attributes residuals, degrees_of_freedom and chisq, |
---|
127 | which is what the optimizer uses as the cost function to minimize.</p> |
---|
128 | <p>assembly.eval uses the current values for the parameters in the |
---|
129 | individual models. These parameters can be changed directly |
---|
130 | in the model. In the reflectometry example above, you could |
---|
131 | set the gold thickness using xray.layer.Au.depth=156, or |
---|
132 | something similar (the details are model specific). Parameters |
---|
133 | can also be changed through the assembly parameter set. In the same |
---|
134 | example, this would be assembly.parameterset[‘xray’][‘Au’][‘depth’]. |
---|
135 | See parameter set for details.</p> |
---|
136 | <p>In the process of modeling data, particularly with multiple |
---|
137 | datasets, you will sometimes want to temporarily ignore |
---|
138 | how well one of the datasets matches so that you |
---|
139 | can more quickly refine the model for the other datasets, |
---|
140 | or see how particular models are influencing the fit. To |
---|
141 | temporarily ignore the xray data in the example above use:</p> |
---|
142 | <div class="highlight-python"><div class="highlight"><pre><span class="n">assembly</span><span class="o">.</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">isfitted</span> <span class="o">=</span> <span class="bp">False</span> |
---|
143 | </pre></div> |
---|
144 | </div> |
---|
145 | <p>The model itself isn’t ignored since its parameters may be |
---|
146 | needed to compute the parameters for other models. To |
---|
147 | reenable checking against the xray data, you would assign |
---|
148 | a True value instead. More subtle weighting of the models |
---|
149 | can be controlled using assembly.parts[idx].weight, but |
---|
150 | see below for a note on model weighting.</p> |
---|
151 | <div class="section" id="a-note-on-model-weighting"> |
---|
152 | <h4>A note on model weighting</h4> |
---|
153 | <p>Changing the weight is equivalent to scaling the error bars |
---|
154 | on the given model by a factor of weight/n where n is the |
---|
155 | number of data points. It is better to set the correct error |
---|
156 | bars on your data in the first place than to adjust the weights. |
---|
157 | If you have the correct error bars, then you should expect |
---|
158 | roughly 2/3 of the data points to lie within one error bar of |
---|
159 | the theory curve. If consecutive data points have largely |
---|
160 | overlapping errorbars, then your uncertainty is overestimated.</p> |
---|
161 | <p>Another case where weights are adjusted (abused?) is to |
---|
162 | compensate for systematic errors in the data by forcing the |
---|
163 | errorbars to be large enough to cover the systematic bias. |
---|
164 | This is a poor approach to the problem. A better strategy |
---|
165 | is to capture the systematic effects in the model, and treat |
---|
166 | the measurement of the independent variable as an additional |
---|
167 | data point in the fit. This is still not statistically sound |
---|
168 | as there is likely to be a large correlation between the |
---|
169 | uncertainty of the measurement and the values of all the |
---|
170 | other variables.</p> |
---|
171 | <p>That said, adjusting the weight on a dataset is a quick way |
---|
172 | of reducing its influence on the entire fit. Please use it |
---|
173 | with care.</p> |
---|
174 | <dl class="class"> |
---|
175 | <dt id="park.assembly.Assembly"> |
---|
176 | <em class="property">class </em><tt class="descclassname">park.assembly.</tt><tt class="descname">Assembly</tt><big>(</big><em>models=[]</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly"><span class="viewcode-link">[source]</span></a></dt> |
---|
177 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
178 | <p>Collection of fit models.</p> |
---|
179 | <p>Assembly implements the <cite>park.fit.Objective</cite> interface.</p> |
---|
180 | <p>See <cite>park.assembly</cite> for usage.</p> |
---|
181 | <p>Instance variables:</p> |
---|
182 | <dl class="docutils"> |
---|
183 | <dt>residuals <span class="classifier-delimiter">:</span> <span class="classifier">array</span></dt> |
---|
184 | <dd>a vector of residuals spanning all models, with model |
---|
185 | weights applied as appropriate.</dd> |
---|
186 | <dt>degrees_of_freedom <span class="classifier-delimiter">:</span> <span class="classifier">integer</span></dt> |
---|
187 | <dd>length of the residuals - number of fitted parameters</dd> |
---|
188 | <dt>chisq <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt> |
---|
189 | <dd>sum squared residuals; this is not the reduced chisq, which |
---|
190 | you can get using chisq/degrees_of_freedom</dd> |
---|
191 | </dl> |
---|
192 | <p>These fields are defined for the individual models as well, with |
---|
193 | degrees of freedom adjusted to the length of the individual data |
---|
194 | set. If the model is not fitted or the weight is zero, the residual |
---|
195 | will not be calculated.</p> |
---|
196 | <p>The residuals fields are available only after the model has been |
---|
197 | evaluated.</p> |
---|
198 | <dl class="method"> |
---|
199 | <dt id="park.assembly.Assembly.abort"> |
---|
200 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
201 | <dd><p>Interrupt the current function evaluation.</p> |
---|
202 | <p>Forward this to the currently executing model if possible.</p> |
---|
203 | </dd></dl> |
---|
204 | |
---|
205 | <dl class="method"> |
---|
206 | <dt id="park.assembly.Assembly.all_results"> |
---|
207 | <tt class="descname">all_results</tt><big>(</big><em>result</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.all_results"><span class="viewcode-link">[source]</span></a></dt> |
---|
208 | <dd><p>Extend result from the fit with the calculated parameters.</p> |
---|
209 | </dd></dl> |
---|
210 | |
---|
211 | <dl class="method"> |
---|
212 | <dt id="park.assembly.Assembly.append"> |
---|
213 | <tt class="descname">append</tt><big>(</big><em>fitness</em>, <em>weight=1.0</em>, <em>isfitted=True</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.append"><span class="viewcode-link">[source]</span></a></dt> |
---|
214 | <dd><p>Add a model to the end of set.</p> |
---|
215 | <table class="docutils field-list" frame="void" rules="none"> |
---|
216 | <col class="field-name" /> |
---|
217 | <col class="field-body" /> |
---|
218 | <tbody valign="top"> |
---|
219 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
---|
220 | <li><strong>fitness</strong> – the fitting model |
---|
221 | The fitting model can be an instance of <cite>park.assembly.Fitness</cite>, |
---|
222 | or a tuple of (<cite>park.model.Model</cite>,`park.data.Data1D`)</li> |
---|
223 | <li><strong>weight</strong> – model weighting (usually 1.0)</li> |
---|
224 | <li><strong>isfitted</strong> – whether model should be fit (equivalent to weight 0.)</li> |
---|
225 | </ul> |
---|
226 | </td> |
---|
227 | </tr> |
---|
228 | </tbody> |
---|
229 | </table> |
---|
230 | </dd></dl> |
---|
231 | |
---|
232 | <dl class="method"> |
---|
233 | <dt id="park.assembly.Assembly.cov"> |
---|
234 | <tt class="descname">cov</tt><big>(</big><em>pvec</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.cov"><span class="viewcode-link">[source]</span></a></dt> |
---|
235 | <dd><p>Return the covariance matrix inv(J’J) at point p.</p> |
---|
236 | </dd></dl> |
---|
237 | |
---|
238 | <dl class="method"> |
---|
239 | <dt id="park.assembly.Assembly.eval"> |
---|
240 | <tt class="descname">eval</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.eval"><span class="viewcode-link">[source]</span></a></dt> |
---|
241 | <dd><p>Recalculate the theory functions, and from them, the |
---|
242 | residuals and chisq.</p> |
---|
243 | <table class="docutils field-list" frame="void" rules="none"> |
---|
244 | <col class="field-name" /> |
---|
245 | <col class="field-body" /> |
---|
246 | <tbody valign="top"> |
---|
247 | <tr class="field-odd field"><th class="field-name">Note:</th><td class="field-body">Call this after the parameters have been updated.</td> |
---|
248 | </tr> |
---|
249 | </tbody> |
---|
250 | </table> |
---|
251 | </dd></dl> |
---|
252 | |
---|
253 | <dl class="method"> |
---|
254 | <dt id="park.assembly.Assembly.fit_parameters"> |
---|
255 | <tt class="descname">fit_parameters</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.fit_parameters"><span class="viewcode-link">[source]</span></a></dt> |
---|
256 | <dd><p>Return an alphabetical list of the fitting parameters.</p> |
---|
257 | <p>This function is called once at the beginning of a fit, |
---|
258 | and serves as a convenient place to precalculate what |
---|
259 | can be precalculated such as the set of fitting parameters |
---|
260 | and the parameter expressions evaluator.</p> |
---|
261 | </dd></dl> |
---|
262 | |
---|
263 | <dl class="method"> |
---|
264 | <dt id="park.assembly.Assembly.fresiduals"> |
---|
265 | <tt class="descname">fresiduals</tt><big>(</big><em>pvec</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.fresiduals"><span class="viewcode-link">[source]</span></a></dt> |
---|
266 | <dd></dd></dl> |
---|
267 | |
---|
268 | <dl class="method"> |
---|
269 | <dt id="park.assembly.Assembly.insert"> |
---|
270 | <tt class="descname">insert</tt><big>(</big><em>idx</em>, <em>fitness</em>, <em>weight=1.0</em>, <em>isfitted=True</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.insert"><span class="viewcode-link">[source]</span></a></dt> |
---|
271 | <dd><p>Add a model to a particular position in the set.</p> |
---|
272 | </dd></dl> |
---|
273 | |
---|
274 | <dl class="method"> |
---|
275 | <dt id="park.assembly.Assembly.isfeasible"> |
---|
276 | <tt class="descname">isfeasible</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.isfeasible"><span class="viewcode-link">[source]</span></a></dt> |
---|
277 | <dd><p>Returns true if the parameter set is in a feasible region of the |
---|
278 | modeling space.</p> |
---|
279 | </dd></dl> |
---|
280 | |
---|
281 | <dl class="method"> |
---|
282 | <dt id="park.assembly.Assembly.isfitted"> |
---|
283 | <tt class="descname">isfitted</tt><big>(</big><em>idx</em>, <em>value=None</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.isfitted"><span class="viewcode-link">[source]</span></a></dt> |
---|
284 | <dd><p>Query if a particular model is fitted.</p> |
---|
285 | <p>Set isfitted to value if value is supplied.</p> |
---|
286 | <table class="docutils field-list" frame="void" rules="none"> |
---|
287 | <col class="field-name" /> |
---|
288 | <col class="field-body" /> |
---|
289 | <tbody valign="top"> |
---|
290 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
---|
291 | <li><strong>idx</strong> (<em>integer</em>) – model number</li> |
---|
292 | <li><strong>value</strong> – </li> |
---|
293 | </ul> |
---|
294 | </td> |
---|
295 | </tr> |
---|
296 | </tbody> |
---|
297 | </table> |
---|
298 | </dd></dl> |
---|
299 | |
---|
300 | <dl class="method"> |
---|
301 | <dt id="park.assembly.Assembly.jacobian"> |
---|
302 | <tt class="descname">jacobian</tt><big>(</big><em>pvec</em>, <em>step=1e-08</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.jacobian"><span class="viewcode-link">[source]</span></a></dt> |
---|
303 | <dd><p>Returns the derivative wrt the fit parameters at point p.</p> |
---|
304 | <p>Numeric derivatives are calculated based on step, where step is |
---|
305 | the portion of the total range for parameter j, or the portion of |
---|
306 | point value p_j if the range on parameter j is infinite.</p> |
---|
307 | </dd></dl> |
---|
308 | |
---|
309 | <dl class="method"> |
---|
310 | <dt id="park.assembly.Assembly.result"> |
---|
311 | <tt class="descname">result</tt><big>(</big><em>status='step'</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.result"><span class="viewcode-link">[source]</span></a></dt> |
---|
312 | <dd><p>Details to send back to the fitting client on an improved fit.</p> |
---|
313 | <p>status is ‘start’, ‘step’ or ‘end’ depending if this is the |
---|
314 | first result to return, an improved result, or the final result.</p> |
---|
315 | <p>[Not implemented]</p> |
---|
316 | </dd></dl> |
---|
317 | |
---|
318 | <dl class="method"> |
---|
319 | <dt id="park.assembly.Assembly.set_result"> |
---|
320 | <tt class="descname">set_result</tt><big>(</big><em>result</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.set_result"><span class="viewcode-link">[source]</span></a></dt> |
---|
321 | <dd><p>Set the parameters resulting from the fit into the parameter set, |
---|
322 | and update the calculated expression.</p> |
---|
323 | <p>The parameter values may be retrieved by walking the assembly.parameterset |
---|
324 | tree, checking each parameter for isfitted, iscomputed, or isfixed. |
---|
325 | For example:</p> |
---|
326 | <div class="highlight-python"><div class="highlight"><pre><span class="n">assembly</span><span class="o">.</span><span class="n">set_result</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> |
---|
327 | <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">assembly</span><span class="o">.</span><span class="n">parameterset</span><span class="o">.</span><span class="n">flatten</span><span class="p">():</span> |
---|
328 | <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">isfitted</span><span class="p">():</span> |
---|
329 | <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> </span><span class="si">%g</span><span class="s"> in [</span><span class="si">%g</span><span class="s">,</span><span class="si">%g</span><span class="s">]"</span><span class="o">%</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">path</span><span class="p">,</span><span class="n">p</span><span class="o">.</span><span class="n">value</span><span class="p">,</span><span class="n">p</span><span class="o">.</span><span class="n">range</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">p</span><span class="o">.</span><span class="n">range</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> |
---|
330 | <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">iscomputed</span><span class="p">():</span> |
---|
331 | <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> computed as </span><span class="si">%g</span><span class="s">"</span><span class="o">%</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> |
---|
332 | </pre></div> |
---|
333 | </div> |
---|
334 | <p>This does not calculate the function or the residuals for these parameters. |
---|
335 | You can call assembly.eval() to do this. The residuals will be set in |
---|
336 | assembly[i].residuals. The theory and data are model specific, and can |
---|
337 | be found in assembly[i].fitness.data.</p> |
---|
338 | </dd></dl> |
---|
339 | |
---|
340 | <dl class="method"> |
---|
341 | <dt id="park.assembly.Assembly.stderr"> |
---|
342 | <tt class="descname">stderr</tt><big>(</big><em>pvec</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.stderr"><span class="viewcode-link">[source]</span></a></dt> |
---|
343 | <dd><p>Return parameter uncertainty.</p> |
---|
344 | <p>This is just the sqrt diagonal of covariance matrix inv(J’J) at point p.</p> |
---|
345 | </dd></dl> |
---|
346 | |
---|
347 | <dl class="method"> |
---|
348 | <dt id="park.assembly.Assembly.weight"> |
---|
349 | <tt class="descname">weight</tt><big>(</big><em>idx</em>, <em>value=None</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Assembly.weight"><span class="viewcode-link">[source]</span></a></dt> |
---|
350 | <dd><p>Query the weight on a particular model.</p> |
---|
351 | <p>Set weight to value if value is supplied.</p> |
---|
352 | <table class="docutils field-list" frame="void" rules="none"> |
---|
353 | <col class="field-name" /> |
---|
354 | <col class="field-body" /> |
---|
355 | <tbody valign="top"> |
---|
356 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><dl class="first docutils"> |
---|
357 | <dt>idx <span class="classifier-delimiter">:</span> <span class="classifier">integer</span></dt> |
---|
358 | <dd><p class="first last">model number</p> |
---|
359 | </dd> |
---|
360 | <dt>value <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt> |
---|
361 | <dd><p class="first last">model weight</p> |
---|
362 | </dd> |
---|
363 | </dl> |
---|
364 | </td> |
---|
365 | </tr> |
---|
366 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">model weight</p> |
---|
367 | </td> |
---|
368 | </tr> |
---|
369 | </tbody> |
---|
370 | </table> |
---|
371 | </dd></dl> |
---|
372 | |
---|
373 | </dd></dl> |
---|
374 | |
---|
375 | <dl class="class"> |
---|
376 | <dt id="park.assembly.Fitness"> |
---|
377 | <em class="property">class </em><tt class="descclassname">park.assembly.</tt><tt class="descname">Fitness</tt><big>(</big><em>model=None</em>, <em>data=None</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Fitness"><span class="viewcode-link">[source]</span></a></dt> |
---|
378 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
379 | <p>Container for theory and data.</p> |
---|
380 | <p>The fit object compares theory with data.</p> |
---|
381 | <p>TODO: what to do with fittable metadata (e.g., footprint correction)?</p> |
---|
382 | <dl class="method"> |
---|
383 | <dt id="park.assembly.Fitness.abort"> |
---|
384 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Fitness.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
385 | <dd></dd></dl> |
---|
386 | |
---|
387 | <dl class="attribute"> |
---|
388 | <dt id="park.assembly.Fitness.data"> |
---|
389 | <tt class="descname">data</tt><em class="property"> = None</em></dt> |
---|
390 | <dd></dd></dl> |
---|
391 | |
---|
392 | <dl class="attribute"> |
---|
393 | <dt id="park.assembly.Fitness.model"> |
---|
394 | <tt class="descname">model</tt><em class="property"> = None</em></dt> |
---|
395 | <dd></dd></dl> |
---|
396 | |
---|
397 | <dl class="attribute"> |
---|
398 | <dt id="park.assembly.Fitness.parameterset"> |
---|
399 | <tt class="descname">parameterset</tt></dt> |
---|
400 | <dd></dd></dl> |
---|
401 | |
---|
402 | <dl class="method"> |
---|
403 | <dt id="park.assembly.Fitness.residuals"> |
---|
404 | <tt class="descname">residuals</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Fitness.residuals"><span class="viewcode-link">[source]</span></a></dt> |
---|
405 | <dd></dd></dl> |
---|
406 | |
---|
407 | <dl class="method"> |
---|
408 | <dt id="park.assembly.Fitness.residuals_deriv"> |
---|
409 | <tt class="descname">residuals_deriv</tt><big>(</big><em>pars=[]</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Fitness.residuals_deriv"><span class="viewcode-link">[source]</span></a></dt> |
---|
410 | <dd></dd></dl> |
---|
411 | |
---|
412 | <dl class="method"> |
---|
413 | <dt id="park.assembly.Fitness.set"> |
---|
414 | <tt class="descname">set</tt><big>(</big><em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/assembly.html#Fitness.set"><span class="viewcode-link">[source]</span></a></dt> |
---|
415 | <dd><p>Set parameters in the model.</p> |
---|
416 | <p>User convenience function. This allows a user with an assembly |
---|
417 | of models in a script to for example set the fit range for |
---|
418 | parameter ‘a’ of the model:</p> |
---|
419 | <div class="highlight-python"><div class="highlight"><pre><span class="n">assembly</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="p">[</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span> |
---|
420 | </pre></div> |
---|
421 | </div> |
---|
422 | <p>Raises KeyError if the parameter is not in parameterset.</p> |
---|
423 | </dd></dl> |
---|
424 | |
---|
425 | </dd></dl> |
---|
426 | |
---|
427 | </div> |
---|
428 | </div> |
---|
429 | </div> |
---|
430 | <div class="section" id="module-park.data"> |
---|
431 | <span id="park-data-module"></span><h2>park.data module</h2> |
---|
432 | <p>Park 1-D data objects.</p> |
---|
433 | <p>The class Data1D represents simple 1-D data objects, along with |
---|
434 | an ascii file loader. This format will work well for many |
---|
435 | uses, but it is likely that more specialized models will have |
---|
436 | their own data file formats.</p> |
---|
437 | <p>The minimal data format for park must supply the following |
---|
438 | methods:</p> |
---|
439 | <blockquote> |
---|
440 | <div><dl class="docutils"> |
---|
441 | <dt>residuals(fn)</dt> |
---|
442 | <dd>returns the residuals vector for the model function.</dd> |
---|
443 | <dt>residuals_deriv(fn_deriv,par)</dt> |
---|
444 | <dd>returns the residuals vector for the model function, and |
---|
445 | for the derivatives with respect to the given parameters.</dd> |
---|
446 | </dl> |
---|
447 | </div></blockquote> |
---|
448 | <p>The function passed is going to be model.eval or in the case |
---|
449 | where derivatives are available, model.eval_deriv. Normally |
---|
450 | this will take a vector of dependent variables and return the |
---|
451 | theory function for that vector but this is only convention. |
---|
452 | The fitting service only uses the parameter set and the residuals |
---|
453 | method from the model.</p> |
---|
454 | <p>The park GUI will make more demands on the interface, but the |
---|
455 | details are not yet resolved.</p> |
---|
456 | <dl class="class"> |
---|
457 | <dt id="park.data.Data1D"> |
---|
458 | <em class="property">class </em><tt class="descclassname">park.data.</tt><tt class="descname">Data1D</tt><big>(</big><em>filename=''</em>, <em>x=None</em>, <em>y=None</em>, <em>dx=0</em>, <em>dy=1</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D"><span class="viewcode-link">[source]</span></a></dt> |
---|
459 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
460 | <p>Data representation for 1-D fitting.</p> |
---|
461 | <p>Attributes</p> |
---|
462 | <dl class="docutils"> |
---|
463 | <dt>filename</dt> |
---|
464 | <dd>The source of the data. This may be the empty string if the |
---|
465 | data is simulation data.</dd> |
---|
466 | <dt>x,y,dy</dt> |
---|
467 | <dd>The data values. |
---|
468 | x is the measurement points of data to be fitted. x must be sorted. |
---|
469 | y is the measured value |
---|
470 | dy is the measurement uncertainty.</dd> |
---|
471 | <dt>dx</dt> |
---|
472 | <dd>Resolution at the the measured points. The resolution may be 0, |
---|
473 | constant, or defined for each data point. dx is the 1-sigma |
---|
474 | width of the Gaussian resolution function at point x. Note that |
---|
475 | dx_FWHM = sqrt(8 ln 2) dx_sigma, so scale dx appropriately.</dd> |
---|
476 | <dt>fit_x,fit_dx,fit_y,fit_dy</dt> |
---|
477 | <dd>The points used in evaluating the residuals.</dd> |
---|
478 | <dt>calc_x</dt> |
---|
479 | <dd>The points at which to evaluate the theory function. This may be |
---|
480 | different from the measured points for a number of reasons, such |
---|
481 | as a resolution function which suggests over or under sampling of |
---|
482 | the points (see below). By default calc_x is x, but it can be set |
---|
483 | explicitly by the user.</dd> |
---|
484 | <dt>calc_y, fx</dt> |
---|
485 | <dd>The value of the function at the theory points, and the value of |
---|
486 | the function after resolution has been applied. These values are |
---|
487 | computed by a call to residuals.</dd> |
---|
488 | </dl> |
---|
489 | <p>Notes on calc_x</p> |
---|
490 | <p>The contribution of Q to a resolution of width dQo at point Qo is:</p> |
---|
491 | <div class="highlight-python"><div class="highlight"><pre>p(Q) = 1/sqrt(2 pi dQo**2) exp ( (Q-Qo)**2/(2 dQo**2) ) |
---|
492 | </pre></div> |
---|
493 | </div> |
---|
494 | <p>We are approximating the convolution at Qo using a numerical |
---|
495 | approximation to the integral over the measured points, with the |
---|
496 | integral is limited to p(Q_i)/p(0)>=0.001.</p> |
---|
497 | <p>Sometimes the function we are convoluting is rapidly changing. |
---|
498 | That means the correct convolution should uniformly sample across |
---|
499 | the entire width of the Gaussian. This is not possible at the |
---|
500 | end points unless you calculate the theory function beyond what is |
---|
501 | strictly needed for the data. For a given dQ and step size, |
---|
502 | you need enough steps that the following is true:</p> |
---|
503 | <div class="highlight-python"><div class="highlight"><pre>(n*step)**2 > -2 dQ**2 * ln 0.001 |
---|
504 | </pre></div> |
---|
505 | </div> |
---|
506 | <p>The choice of sampling density is particularly important near |
---|
507 | critical points where the shape of the function changes. In |
---|
508 | reflectometry, the function goes from flat below the critical |
---|
509 | edge to O(Q**4) above. In one particular model, calculating every |
---|
510 | 0.005 rather than every 0.02 changed a value above the critical |
---|
511 | edge by 15%. In a fitting program, this would lead to a somewhat |
---|
512 | larger estimate of the critical edge for this sample.</p> |
---|
513 | <p>Sometimes the theory function is oscillating more rapidly than |
---|
514 | the instrument can resolve. This happens for example in reflectivity |
---|
515 | measurements involving thick layers. In these systems, the theory |
---|
516 | function should be oversampled around the measured points Q. With |
---|
517 | a single thick layer, oversampling can be limited to just one |
---|
518 | period 2 pi/d. With multiple thick layers, oscillations will |
---|
519 | show interference patterns and it will be necessary to oversample |
---|
520 | uniformly through the entire width of the resolution. If this is |
---|
521 | not accommodated, then aliasing effects make it difficult to |
---|
522 | compute the correct model.</p> |
---|
523 | <dl class="attribute"> |
---|
524 | <dt id="park.data.Data1D.calc_x"> |
---|
525 | <tt class="descname">calc_x</tt><em class="property"> = None</em></dt> |
---|
526 | <dd></dd></dl> |
---|
527 | |
---|
528 | <dl class="attribute"> |
---|
529 | <dt id="park.data.Data1D.calc_y"> |
---|
530 | <tt class="descname">calc_y</tt><em class="property"> = None</em></dt> |
---|
531 | <dd></dd></dl> |
---|
532 | |
---|
533 | <dl class="attribute"> |
---|
534 | <dt id="park.data.Data1D.dx"> |
---|
535 | <tt class="descname">dx</tt><em class="property"> = 0</em></dt> |
---|
536 | <dd></dd></dl> |
---|
537 | |
---|
538 | <dl class="attribute"> |
---|
539 | <dt id="park.data.Data1D.dy"> |
---|
540 | <tt class="descname">dy</tt><em class="property"> = 1</em></dt> |
---|
541 | <dd></dd></dl> |
---|
542 | |
---|
543 | <dl class="attribute"> |
---|
544 | <dt id="park.data.Data1D.filename"> |
---|
545 | <tt class="descname">filename</tt><em class="property"> = ''</em></dt> |
---|
546 | <dd></dd></dl> |
---|
547 | |
---|
548 | <dl class="attribute"> |
---|
549 | <dt id="park.data.Data1D.fit_dx"> |
---|
550 | <tt class="descname">fit_dx</tt><em class="property"> = 0</em></dt> |
---|
551 | <dd></dd></dl> |
---|
552 | |
---|
553 | <dl class="attribute"> |
---|
554 | <dt id="park.data.Data1D.fit_dy"> |
---|
555 | <tt class="descname">fit_dy</tt><em class="property"> = 1</em></dt> |
---|
556 | <dd></dd></dl> |
---|
557 | |
---|
558 | <dl class="attribute"> |
---|
559 | <dt id="park.data.Data1D.fit_x"> |
---|
560 | <tt class="descname">fit_x</tt><em class="property"> = None</em></dt> |
---|
561 | <dd></dd></dl> |
---|
562 | |
---|
563 | <dl class="attribute"> |
---|
564 | <dt id="park.data.Data1D.fit_y"> |
---|
565 | <tt class="descname">fit_y</tt><em class="property"> = None</em></dt> |
---|
566 | <dd></dd></dl> |
---|
567 | |
---|
568 | <dl class="attribute"> |
---|
569 | <dt id="park.data.Data1D.fx"> |
---|
570 | <tt class="descname">fx</tt><em class="property"> = None</em></dt> |
---|
571 | <dd></dd></dl> |
---|
572 | |
---|
573 | <dl class="method"> |
---|
574 | <dt id="park.data.Data1D.load"> |
---|
575 | <tt class="descname">load</tt><big>(</big><em>filename</em>, <em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D.load"><span class="viewcode-link">[source]</span></a></dt> |
---|
576 | <dd><p>Load a multicolumn datafile.</p> |
---|
577 | <p>Data should be in columns, with the following defaults:</p> |
---|
578 | <div class="highlight-python"><div class="highlight"><pre><span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="ow">or</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">dy</span> <span class="ow">or</span> <span class="n">x</span><span class="p">,</span><span class="n">dx</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">dy</span> |
---|
579 | </pre></div> |
---|
580 | </div> |
---|
581 | <p>Note that this resets the selected fitting points calc_x and the |
---|
582 | computed results calc_y and fx.</p> |
---|
583 | <p>Data is sorted after loading.</p> |
---|
584 | <p>Any extra keyword arguments are passed to the numpy loadtxt |
---|
585 | function. This allows you to select the columns you want, |
---|
586 | skip rows, set the column separator, change the comment character, |
---|
587 | amongst other things.</p> |
---|
588 | </dd></dl> |
---|
589 | |
---|
590 | <dl class="method"> |
---|
591 | <dt id="park.data.Data1D.resample"> |
---|
592 | <tt class="descname">resample</tt><big>(</big><em>minstep=None</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D.resample"><span class="viewcode-link">[source]</span></a></dt> |
---|
593 | <dd><p>Over/under sampling support.</p> |
---|
594 | <p>Compute the calc_x points required to adequately sample |
---|
595 | the function y=f(x) so that the value reported for each |
---|
596 | measured point is supported by the resolution. minstep |
---|
597 | is the minimum allowed sampling density that should be |
---|
598 | used.</p> |
---|
599 | </dd></dl> |
---|
600 | |
---|
601 | <dl class="method"> |
---|
602 | <dt id="park.data.Data1D.residuals"> |
---|
603 | <tt class="descname">residuals</tt><big>(</big><em>fn</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D.residuals"><span class="viewcode-link">[source]</span></a></dt> |
---|
604 | <dd><p>Compute the residuals of the data wrt to the given function.</p> |
---|
605 | <p>y = fn(x) should be a callable accepting a list of points at which |
---|
606 | to calculate the function, returning the values at those |
---|
607 | points.</p> |
---|
608 | <p>Any resolution function will be applied after the theory points |
---|
609 | are calculated.</p> |
---|
610 | </dd></dl> |
---|
611 | |
---|
612 | <dl class="method"> |
---|
613 | <dt id="park.data.Data1D.residuals_deriv"> |
---|
614 | <tt class="descname">residuals_deriv</tt><big>(</big><em>fn</em>, <em>pars=[]</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D.residuals_deriv"><span class="viewcode-link">[source]</span></a></dt> |
---|
615 | <dd><p>Compute residuals and derivatives wrt the given parameters.</p> |
---|
616 | <p>fdf = fn(x,pars=pars) should be a callable accepting a list |
---|
617 | of points at which to calculate the function and a keyword |
---|
618 | argument listing the parameters for which the derivative will |
---|
619 | be calculated.</p> |
---|
620 | <p>Returns a list of the residuals and the derivative wrt the |
---|
621 | parameter for each parameter.</p> |
---|
622 | <p>Any resolution function will be applied after the theory points |
---|
623 | and derivatives are calculated.</p> |
---|
624 | </dd></dl> |
---|
625 | |
---|
626 | <dl class="method"> |
---|
627 | <dt id="park.data.Data1D.select"> |
---|
628 | <tt class="descname">select</tt><big>(</big><em>idx</em><big>)</big><a class="reference internal" href="../../_modules/park/data.html#Data1D.select"><span class="viewcode-link">[source]</span></a></dt> |
---|
629 | <dd><p>A selection vector for points to use in the evaluation of the |
---|
630 | residuals, or None if all points are to be used.</p> |
---|
631 | </dd></dl> |
---|
632 | |
---|
633 | <dl class="attribute"> |
---|
634 | <dt id="park.data.Data1D.x"> |
---|
635 | <tt class="descname">x</tt><em class="property"> = None</em></dt> |
---|
636 | <dd></dd></dl> |
---|
637 | |
---|
638 | <dl class="attribute"> |
---|
639 | <dt id="park.data.Data1D.y"> |
---|
640 | <tt class="descname">y</tt><em class="property"> = None</em></dt> |
---|
641 | <dd></dd></dl> |
---|
642 | |
---|
643 | </dd></dl> |
---|
644 | |
---|
645 | </div> |
---|
646 | <div class="section" id="module-park.deps"> |
---|
647 | <span id="park-deps-module"></span><h2>park.deps module</h2> |
---|
648 | <p>Functions for manipulating dependencies.</p> |
---|
649 | <p>Parameter values must be updated in the correct order. If parameter A |
---|
650 | depends on parameter B, then parameter B must be evaluated first.</p> |
---|
651 | <dl class="function"> |
---|
652 | <dt id="park.deps.order_dependencies"> |
---|
653 | <tt class="descclassname">park.deps.</tt><tt class="descname">order_dependencies</tt><big>(</big><em>pairs</em><big>)</big><a class="reference internal" href="../../_modules/park/deps.html#order_dependencies"><span class="viewcode-link">[source]</span></a></dt> |
---|
654 | <dd><p>Order elements from pairs so that b comes before a in the |
---|
655 | ordered list for all pairs (a,b).</p> |
---|
656 | </dd></dl> |
---|
657 | |
---|
658 | <dl class="function"> |
---|
659 | <dt id="park.deps.test"> |
---|
660 | <tt class="descclassname">park.deps.</tt><tt class="descname">test</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/deps.html#test"><span class="viewcode-link">[source]</span></a></dt> |
---|
661 | <dd></dd></dl> |
---|
662 | |
---|
663 | </div> |
---|
664 | <div class="section" id="module-park.diffev"> |
---|
665 | <span id="park-diffev-module"></span><h2>park.diffev module</h2> |
---|
666 | <dl class="class"> |
---|
667 | <dt id="park.diffev.DE"> |
---|
668 | <em class="property">class </em><tt class="descclassname">park.diffev.</tt><tt class="descname">DE</tt><big>(</big><em>F</em>, <em>crossover_rate</em>, <em>func</em>, <em>func_dim</em>, <em>pop</em>, <em>l_bound</em>, <em>u_bound</em>, <em>tol=1e-07</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE"><span class="viewcode-link">[source]</span></a></dt> |
---|
669 | <dd><p>Differential evolution test implementation |
---|
670 | Implements the Scheme_DE_rand_1 variant</p> |
---|
671 | <blockquote> |
---|
672 | <div><dl class="docutils"> |
---|
673 | <dt>F: float</dt> |
---|
674 | <dd>weighting factor which determines the magnitude of perturbation |
---|
675 | occurring in each generation.</dd> |
---|
676 | <dt>crossover_rate: float</dt> |
---|
677 | <dd>In general, 0 < crossover_rate < 1. Usually |
---|
678 | considerably lower than 1. Convergence slows as the value |
---|
679 | increases, but higher crossover rates may be necessary when</dd> |
---|
680 | <dt>func: w = f(p)</dt> |
---|
681 | <dd>The function to be minimized, of the form w = f(p), where p |
---|
682 | is a vector of length func_dim and w is a scalar</dd> |
---|
683 | <dt>func_dim: int</dt> |
---|
684 | <dd>The dimension of the objective function</dd> |
---|
685 | <dt>pop: array</dt> |
---|
686 | <dd>The initial population. This should be an iterable composed of |
---|
687 | Rank-1 numpy arrays. The population size must be at least 4, |
---|
688 | preferably much greater.</dd> |
---|
689 | <dt>l_bound, u_bound: vector</dt> |
---|
690 | <dd>arrays of size func_dim representing the upper and lower bounds |
---|
691 | for the parameters in the solution vectors</dd> |
---|
692 | <dt>tol: float</dt> |
---|
693 | <dd>if (max(pop_values) - min(pop_values) <= conv), the population |
---|
694 | has converged and the evolution will stop</dd> |
---|
695 | </dl> |
---|
696 | </div></blockquote> |
---|
697 | <dl class="method"> |
---|
698 | <dt id="park.diffev.DE.adjust_F"> |
---|
699 | <tt class="descname">adjust_F</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.adjust_F"><span class="viewcode-link">[source]</span></a></dt> |
---|
700 | <dd><p>Adjust F to account for stagnation of the population</p> |
---|
701 | </dd></dl> |
---|
702 | |
---|
703 | <dl class="method"> |
---|
704 | <dt id="park.diffev.DE.crossover"> |
---|
705 | <tt class="descname">crossover</tt><big>(</big><em>candidate</em>, <em>i</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.crossover"><span class="viewcode-link">[source]</span></a></dt> |
---|
706 | <dd><p>Perform a crossover between the candidate and the ith member of |
---|
707 | the previous generation.</p> |
---|
708 | </dd></dl> |
---|
709 | |
---|
710 | <dl class="method"> |
---|
711 | <dt id="park.diffev.DE.evolve"> |
---|
712 | <tt class="descname">evolve</tt><big>(</big><em>numgens=1000</em>, <em>monitor=None</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.evolve"><span class="viewcode-link">[source]</span></a></dt> |
---|
713 | <dd><p>Evolve the population for numgens generations, or until it converges. |
---|
714 | Returns the best vector from the run</p> |
---|
715 | </dd></dl> |
---|
716 | |
---|
717 | <dl class="method"> |
---|
718 | <dt id="park.diffev.DE.get_best_gene"> |
---|
719 | <tt class="descname">get_best_gene</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.get_best_gene"><span class="viewcode-link">[source]</span></a></dt> |
---|
720 | <dd><p>find the most fit gene in the current population</p> |
---|
721 | </dd></dl> |
---|
722 | |
---|
723 | <dl class="method"> |
---|
724 | <dt id="park.diffev.DE.get_random_gene"> |
---|
725 | <tt class="descname">get_random_gene</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.get_random_gene"><span class="viewcode-link">[source]</span></a></dt> |
---|
726 | <dd><p>Generate a random gene within the bounds constraints. |
---|
727 | Used to replace out-of-bounds genes</p> |
---|
728 | </dd></dl> |
---|
729 | |
---|
730 | <dl class="method"> |
---|
731 | <dt id="park.diffev.DE.is_converged"> |
---|
732 | <tt class="descname">is_converged</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.is_converged"><span class="viewcode-link">[source]</span></a></dt> |
---|
733 | <dd><p>check for convergence</p> |
---|
734 | </dd></dl> |
---|
735 | |
---|
736 | <dl class="method"> |
---|
737 | <dt id="park.diffev.DE.is_within_bounds"> |
---|
738 | <tt class="descname">is_within_bounds</tt><big>(</big><em>gene</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.is_within_bounds"><span class="viewcode-link">[source]</span></a></dt> |
---|
739 | <dd><p>Determine whether the gene meets the bounds constraints</p> |
---|
740 | </dd></dl> |
---|
741 | |
---|
742 | <dl class="method"> |
---|
743 | <dt id="park.diffev.DE.select_participants"> |
---|
744 | <tt class="descname">select_participants</tt><big>(</big><em>i</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#DE.select_participants"><span class="viewcode-link">[source]</span></a></dt> |
---|
745 | <dd><p>generate r1, r2, and r3 randomly from the range [0, NP-1] |
---|
746 | such that they are distinct values not equal to i</p> |
---|
747 | </dd></dl> |
---|
748 | |
---|
749 | </dd></dl> |
---|
750 | |
---|
751 | <dl class="function"> |
---|
752 | <dt id="park.diffev.diffev"> |
---|
753 | <tt class="descclassname">park.diffev.</tt><tt class="descname">diffev</tt><big>(</big><em>fn</em>, <em>bounds</em>, <em>x0=None</em>, <em>pop_scale=4</em>, <em>crossover_rate=0.8</em>, <em>Fscale=1</em>, <em>tolerance=1e-05</em>, <em>maxiter=1000</em>, <em>monitor=None</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#diffev"><span class="viewcode-link">[source]</span></a></dt> |
---|
754 | <dd><p>Run differential evolution, returning x,fx,ncalls</p> |
---|
755 | </dd></dl> |
---|
756 | |
---|
757 | <dl class="function"> |
---|
758 | <dt id="park.diffev.gen_pop"> |
---|
759 | <tt class="descclassname">park.diffev.</tt><tt class="descname">gen_pop</tt><big>(</big><em>size</em>, <em>l_bound</em>, <em>u_bound</em>, <em>dimension</em><big>)</big><a class="reference internal" href="../../_modules/park/diffev.html#gen_pop"><span class="viewcode-link">[source]</span></a></dt> |
---|
760 | <dd><p>generate a random population of vectors within the given bounds. dimension |
---|
761 | indicates the length of the vectors. l_bound and u_bound should be vectors |
---|
762 | of length dimension (any iterable container should work)</p> |
---|
763 | </dd></dl> |
---|
764 | |
---|
765 | <dl class="function"> |
---|
766 | <dt id="park.diffev.random"> |
---|
767 | <tt class="descclassname">park.diffev.</tt><tt class="descname">random</tt><big>(</big><big>)</big> → x in the interval [0, 1).</dt> |
---|
768 | <dd></dd></dl> |
---|
769 | |
---|
770 | </div> |
---|
771 | <div class="section" id="module-park.expression"> |
---|
772 | <span id="park-expression-module"></span><h2>park.expression module</h2> |
---|
773 | <p>Functions for manipulating expressions.</p> |
---|
774 | <dl class="function"> |
---|
775 | <dt id="park.expression.build_eval"> |
---|
776 | <tt class="descclassname">park.expression.</tt><tt class="descname">build_eval</tt><big>(</big><em>pars</em>, <em>context={}</em><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#build_eval"><span class="viewcode-link">[source]</span></a></dt> |
---|
777 | <dd><p>Build and return a function to evaluate all parameter expressions in |
---|
778 | the proper order.</p> |
---|
779 | <dl class="docutils"> |
---|
780 | <dt>Inputs:</dt> |
---|
781 | <dd>pars is a list of parameters |
---|
782 | context is a dictionary of additional symbols for the expressions</dd> |
---|
783 | <dt>Output:</dt> |
---|
784 | <dd>updater function</dd> |
---|
785 | <dt>Raises:</dt> |
---|
786 | <dd>AssertionError - model, parameter or function is missing |
---|
787 | SyntaxError - improper expression syntax |
---|
788 | ValueError - expressions have circular dependencies</dd> |
---|
789 | </dl> |
---|
790 | <p>This function is not terribly sophisticated, and it would be easy to |
---|
791 | trick. However it handles the common cases cleanly and generates |
---|
792 | reasonable messages for the common errors.</p> |
---|
793 | <p>This code has not been fully audited for security. While we have |
---|
794 | removed the builtins and the ability to import modules, there may |
---|
795 | be other vectors for users to perform more than simple function |
---|
796 | evaluations. Unauthenticated users should not be running this code.</p> |
---|
797 | <p>Parameter names are assumed to contain only _.a-zA-Z0-9#[]</p> |
---|
798 | <p>The list of parameters is probably something like:</p> |
---|
799 | <div class="highlight-python"><div class="highlight"><pre><span class="n">parset</span><span class="o">.</span><span class="n">setprefix</span><span class="p">()</span> |
---|
800 | <span class="n">pars</span> <span class="o">=</span> <span class="n">parset</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span> |
---|
801 | </pre></div> |
---|
802 | </div> |
---|
803 | <p>Note that math uses acos while numpy uses arccos. To avoid confusion |
---|
804 | we allow both.</p> |
---|
805 | <p>Should try running the function to identify syntax errors before |
---|
806 | running it in a fit.</p> |
---|
807 | <p>Use help(fn) to see the code generated for the returned function fn. |
---|
808 | dis.dis(fn) will show the corresponding python vm instructions.</p> |
---|
809 | </dd></dl> |
---|
810 | |
---|
811 | <dl class="function"> |
---|
812 | <dt id="park.expression.find_dependencies"> |
---|
813 | <tt class="descclassname">park.expression.</tt><tt class="descname">find_dependencies</tt><big>(</big><em>pars</em><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#find_dependencies"><span class="viewcode-link">[source]</span></a></dt> |
---|
814 | <dd><p>Returns a list of pair-wise dependencies from the parameter expressions.</p> |
---|
815 | <p>For example, if p3 = p1+p2, then find_dependencies([p1,p2,p3]) will |
---|
816 | return [(p3,p1),(p3,p2)]. For base expressions without dependencies, |
---|
817 | such as p4 = 2*pi, this should return [(p4, None)]</p> |
---|
818 | </dd></dl> |
---|
819 | |
---|
820 | <dl class="function"> |
---|
821 | <dt id="park.expression.no_constraints"> |
---|
822 | <tt class="descclassname">park.expression.</tt><tt class="descname">no_constraints</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#no_constraints"><span class="viewcode-link">[source]</span></a></dt> |
---|
823 | <dd><p>This parameter set has no constraints between the parameters.</p> |
---|
824 | </dd></dl> |
---|
825 | |
---|
826 | <dl class="function"> |
---|
827 | <dt id="park.expression.parameter_mapping"> |
---|
828 | <tt class="descclassname">park.expression.</tt><tt class="descname">parameter_mapping</tt><big>(</big><em>pairs</em><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#parameter_mapping"><span class="viewcode-link">[source]</span></a></dt> |
---|
829 | <dd><p>Find the parameter substitution we need so that expressions can |
---|
830 | be evaluated without having to traverse a chain of |
---|
831 | model.layer.parameter.value</p> |
---|
832 | </dd></dl> |
---|
833 | |
---|
834 | <dl class="function"> |
---|
835 | <dt id="park.expression.substitute"> |
---|
836 | <tt class="descclassname">park.expression.</tt><tt class="descname">substitute</tt><big>(</big><em>expr</em>, <em>mapping</em><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#substitute"><span class="viewcode-link">[source]</span></a></dt> |
---|
837 | <dd><p>Replace all occurrences of symbol s with mapping[s] for s in mapping.</p> |
---|
838 | </dd></dl> |
---|
839 | |
---|
840 | <dl class="function"> |
---|
841 | <dt id="park.expression.symbols"> |
---|
842 | <tt class="descclassname">park.expression.</tt><tt class="descname">symbols</tt><big>(</big><em>expr</em>, <em>symtab</em><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#symbols"><span class="viewcode-link">[source]</span></a></dt> |
---|
843 | <dd><p>Given an expression string and a symbol table, return the set of symbols |
---|
844 | used in the expression. Symbols are only returned once even if they |
---|
845 | occur multiple times. The return value is a set with the elements in |
---|
846 | no particular order.</p> |
---|
847 | <p>This is the first step in computing a dependency graph.</p> |
---|
848 | </dd></dl> |
---|
849 | |
---|
850 | <dl class="function"> |
---|
851 | <dt id="park.expression.test"> |
---|
852 | <tt class="descclassname">park.expression.</tt><tt class="descname">test</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/expression.html#test"><span class="viewcode-link">[source]</span></a></dt> |
---|
853 | <dd></dd></dl> |
---|
854 | |
---|
855 | </div> |
---|
856 | <div class="section" id="module-park.fit"> |
---|
857 | <span id="park-fit-module"></span><h2>park.fit module</h2> |
---|
858 | <p>Fitting service interface.</p> |
---|
859 | <p>A fit consists of a set of models and a fitting engine. The models are |
---|
860 | collected in an assembly, which manages the parameter set and the |
---|
861 | constraints between them. The models themselves are tightly coupled |
---|
862 | to the data that they are modeling and the data is invisible to the fit.</p> |
---|
863 | <p>The fitting engine can use a variety of methods depending on model.</p> |
---|
864 | <div class="section" id="id1"> |
---|
865 | <h3>Usage</h3> |
---|
866 | <p>The fitter can be run directly on the local machine:</p> |
---|
867 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">park</span> |
---|
868 | <span class="n">M1</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">Peaks</span><span class="p">(</span><span class="n">datafile</span><span class="o">=</span><span class="n">park</span><span class="o">.</span><span class="n">sampledata</span><span class="p">(</span><span class="s">'peak.dat'</span><span class="p">))</span> |
---|
869 | <span class="n">M1</span><span class="o">.</span><span class="n">add_peak</span><span class="p">(</span><span class="s">'P1'</span><span class="p">,</span> <span class="s">'gaussian'</span><span class="p">,</span> <span class="n">A</span><span class="o">=</span><span class="p">[</span><span class="mi">4</span><span class="p">,</span><span class="mi">6</span><span class="p">],</span> <span class="n">mu</span><span class="o">=</span><span class="p">[</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">],</span> <span class="n">sigma</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span> |
---|
870 | <span class="n">result</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">models</span><span class="o">=</span><span class="p">[</span><span class="n">M1</span><span class="p">])</span> |
---|
871 | <span class="k">print</span> <span class="n">result</span> |
---|
872 | </pre></div> |
---|
873 | </div> |
---|
874 | <p>The default settings print results every time the fit improves, and |
---|
875 | print a global result when the fit is complete. This is a suitable |
---|
876 | interface for a fitting script.</p> |
---|
877 | <p>For larger fit jobs you will want to run the fit on a remote server. |
---|
878 | The model setup is identical, but the fit call is different:</p> |
---|
879 | <div class="highlight-python"><div class="highlight"><pre><span class="n">service</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">FitService</span><span class="p">(</span><span class="s">'server:port'</span><span class="p">)</span> |
---|
880 | <span class="n">result</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">models</span><span class="o">=</span><span class="p">[</span><span class="n">M1</span><span class="p">],</span> <span class="n">service</span><span class="o">=</span><span class="n">service</span><span class="p">)</span> |
---|
881 | <span class="k">print</span> <span class="n">result</span> |
---|
882 | </pre></div> |
---|
883 | </div> |
---|
884 | <p>Again, the default settings print results every time the fit improves, |
---|
885 | and print a global result when the fit is complete.</p> |
---|
886 | <p>For long running fit jobs, you want to be able to disconnect from |
---|
887 | the server after submitting the job, and later reconnect to fetch |
---|
888 | the results. An additional email field will send notification by |
---|
889 | email when the fit starts and ends, and daily updates on the status |
---|
890 | of all fits:</p> |
---|
891 | <div class="highlight-python"><div class="highlight"><pre><span class="n">service</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">FitService</span><span class="p">(</span><span class="s">'server:port'</span><span class="p">)</span> |
---|
892 | <span class="n">service</span><span class="o">.</span><span class="n">notify</span><span class="p">(</span><span class="n">email</span><span class="o">=</span><span class="s">'me@my.email.address'</span><span class="p">,</span><span class="n">update</span><span class="o">=</span><span class="s">'daily'</span><span class="p">)</span> |
---|
893 | <span class="n">fit</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">Fit</span><span class="p">(</span><span class="n">models</span><span class="o">=</span><span class="p">[</span><span class="n">M1</span><span class="p">])</span> |
---|
894 | <span class="nb">id</span> <span class="o">=</span> <span class="n">service</span><span class="o">.</span><span class="n">submit_job</span><span class="p">(</span><span class="n">fit</span><span class="p">,</span> <span class="n">jobname</span><span class="o">=</span><span class="s">'peaks'</span><span class="p">)</span> |
---|
895 | <span class="k">print</span> <span class="nb">id</span> |
---|
896 | </pre></div> |
---|
897 | </div> |
---|
898 | <p>The results can be retrieved either by id returned from the server, |
---|
899 | or by the given jobname:</p> |
---|
900 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">park</span> |
---|
901 | <span class="n">service</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">FitService</span><span class="p">(</span><span class="s">'server:port'</span><span class="p">,</span><span class="n">user</span><span class="o">=</span><span class="s">'userid'</span><span class="p">)</span> |
---|
902 | <span class="n">fitlist</span> <span class="o">=</span> <span class="n">service</span><span class="o">.</span><span class="n">retrieve</span><span class="p">(</span><span class="s">'peaks'</span><span class="p">)</span> |
---|
903 | <span class="k">for</span> <span class="n">fit</span> <span class="ow">in</span> <span class="n">fitlist</span><span class="p">:</span> |
---|
904 | <span class="k">print</span> <span class="n">fit</span><span class="o">.</span><span class="n">summary</span><span class="p">()</span> |
---|
905 | </pre></div> |
---|
906 | </div> |
---|
907 | <p>The fit itself is a complicated object, including the model, the |
---|
908 | optimizer, and the type of uncertainty analysis to perform.</p> |
---|
909 | </div> |
---|
910 | <div class="section" id="gui-usage"> |
---|
911 | <h3>GUI Usage</h3> |
---|
912 | <p>When used from a graphical user interface, a different programming |
---|
913 | interface is needed. In this case, the user may want to watch |
---|
914 | the progress of the fit and perhaps stop it. Also, as fits can |
---|
915 | take some time to complete, the user would like to be able to |
---|
916 | set up additional fits and run them at the same time, switching |
---|
917 | between them as necessary to monitor progress.</p> |
---|
918 | <dl class="class"> |
---|
919 | <dt id="park.fit.FitJob"> |
---|
920 | <em class="property">class </em><tt class="descclassname">park.fit.</tt><tt class="descname">FitJob</tt><big>(</big><em>objective=None</em>, <em>fitter=None</em>, <em>handler=None</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#FitJob"><span class="viewcode-link">[source]</span></a></dt> |
---|
921 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
922 | <p>Fit job.</p> |
---|
923 | <p>This implements <cite>park.job.Job</cite>.</p> |
---|
924 | <dl class="method"> |
---|
925 | <dt id="park.fit.FitJob.run"> |
---|
926 | <tt class="descname">run</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#FitJob.run"><span class="viewcode-link">[source]</span></a></dt> |
---|
927 | <dd></dd></dl> |
---|
928 | |
---|
929 | </dd></dl> |
---|
930 | |
---|
931 | <dl class="class"> |
---|
932 | <dt id="park.fit.Fitter"> |
---|
933 | <em class="property">class </em><tt class="descclassname">park.fit.</tt><tt class="descname">Fitter</tt><big>(</big><em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Fitter"><span class="viewcode-link">[source]</span></a></dt> |
---|
934 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
935 | <p>Abstract interface for a fitness optimizer.</p> |
---|
936 | <p>A fitter has a single method, fit, which takes an objective |
---|
937 | function (<cite>park.fit.Objective</cite>) and a handler.</p> |
---|
938 | <p>For a concrete instance see <cite>park.fitmc.FitMC</cite>.</p> |
---|
939 | <dl class="method"> |
---|
940 | <dt id="park.fit.Fitter.fit"> |
---|
941 | <tt class="descname">fit</tt><big>(</big><em>fitness</em>, <em>handler</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Fitter.fit"><span class="viewcode-link">[source]</span></a></dt> |
---|
942 | <dd><p>Global optimizer.</p> |
---|
943 | <p>This function should return immediately</p> |
---|
944 | </dd></dl> |
---|
945 | |
---|
946 | </dd></dl> |
---|
947 | |
---|
948 | <dl class="class"> |
---|
949 | <dt id="park.fit.LocalQueue"> |
---|
950 | <em class="property">class </em><tt class="descclassname">park.fit.</tt><tt class="descname">LocalQueue</tt><a class="reference internal" href="../../_modules/park/fit.html#LocalQueue"><span class="viewcode-link">[source]</span></a></dt> |
---|
951 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
952 | <p>Simple interface to the local job queue. Currently supports start and |
---|
953 | wait. Needs to support stop and status. Also, needs to be a proper queue, |
---|
954 | and needs to allow jobs to run in separate processes according to priority, |
---|
955 | etc. All the essentials of the remote queuing system without the remote |
---|
956 | calls.</p> |
---|
957 | <p>Unlike the remote queue, the local queue need not maintain persistence.</p> |
---|
958 | <dl class="attribute"> |
---|
959 | <dt id="park.fit.LocalQueue.running"> |
---|
960 | <tt class="descname">running</tt><em class="property"> = False</em></dt> |
---|
961 | <dd></dd></dl> |
---|
962 | |
---|
963 | <dl class="method"> |
---|
964 | <dt id="park.fit.LocalQueue.start"> |
---|
965 | <tt class="descname">start</tt><big>(</big><em>job</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#LocalQueue.start"><span class="viewcode-link">[source]</span></a></dt> |
---|
966 | <dd></dd></dl> |
---|
967 | |
---|
968 | <dl class="method"> |
---|
969 | <dt id="park.fit.LocalQueue.wait"> |
---|
970 | <tt class="descname">wait</tt><big>(</big><em>interval=0.1</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#LocalQueue.wait"><span class="viewcode-link">[source]</span></a></dt> |
---|
971 | <dd><p>Wait for the job to complete. This is used in scripts to impose |
---|
972 | a synchronous interface to the fitting service.</p> |
---|
973 | </dd></dl> |
---|
974 | |
---|
975 | </dd></dl> |
---|
976 | |
---|
977 | <dl class="class"> |
---|
978 | <dt id="park.fit.Objective"> |
---|
979 | <em class="property">class </em><tt class="descclassname">park.fit.</tt><tt class="descname">Objective</tt><a class="reference internal" href="../../_modules/park/fit.html#Objective"><span class="viewcode-link">[source]</span></a></dt> |
---|
980 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
981 | <p>Abstract interface to the fitness function for the park minimizer |
---|
982 | classes.</p> |
---|
983 | <p>Park provides a specific implementation <cite>park.assembly.Assembly</cite>.</p> |
---|
984 | <p>TODO: add a results() method to return model specific info to the |
---|
985 | TODO: fit handler.</p> |
---|
986 | <dl class="method"> |
---|
987 | <dt id="park.fit.Objective.abort"> |
---|
988 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Objective.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
989 | <dd><p>Halts the current function evaluation, and has it return inf. |
---|
990 | This will be called from a separate thread. If the function |
---|
991 | contains an expensive calculation, it should reset an abort |
---|
992 | flag before each evaluation and test it periodically.</p> |
---|
993 | <p>This method is optional.</p> |
---|
994 | </dd></dl> |
---|
995 | |
---|
996 | <dl class="method"> |
---|
997 | <dt id="park.fit.Objective.fit_parameters"> |
---|
998 | <tt class="descname">fit_parameters</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Objective.fit_parameters"><span class="viewcode-link">[source]</span></a></dt> |
---|
999 | <dd><p>Returns a list of fit parameters. Each parameter has a name, |
---|
1000 | an initial value and a range.</p> |
---|
1001 | <p>See <cite>park.fitresult.FitParameter</cite> for an example.</p> |
---|
1002 | <p>On each function evaluation a new parameter set will be passed |
---|
1003 | to the fitter, with values in the same order as the list of |
---|
1004 | parameters.</p> |
---|
1005 | </dd></dl> |
---|
1006 | |
---|
1007 | <dl class="method"> |
---|
1008 | <dt id="park.fit.Objective.residuals"> |
---|
1009 | <tt class="descname">residuals</tt><big>(</big><em>p</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Objective.residuals"><span class="viewcode-link">[source]</span></a></dt> |
---|
1010 | <dd><p>Some fitters, notably Levenberg-Marquardt, operate directly on the |
---|
1011 | residuals vector. If the individual residuals are not available, |
---|
1012 | then LM cannot be used.</p> |
---|
1013 | <p>This method is optional.</p> |
---|
1014 | </dd></dl> |
---|
1015 | |
---|
1016 | <dl class="method"> |
---|
1017 | <dt id="park.fit.Objective.residuals_deriv"> |
---|
1018 | <tt class="descname">residuals_deriv</tt><big>(</big><em>p</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#Objective.residuals_deriv"><span class="viewcode-link">[source]</span></a></dt> |
---|
1019 | <dd><p>Returns residuals and derivatives with respect to the given |
---|
1020 | parameters.</p> |
---|
1021 | <p>If these are unavailable in the model, then they can be approximated |
---|
1022 | by numerical derivatives, though it is generally better to use a |
---|
1023 | derivative free optimizer such as coliny or cobyla which can use the |
---|
1024 | function evaluations more efficiently. In any case, your objective |
---|
1025 | function is responsible for calculating these.</p> |
---|
1026 | <p>This method is optional.</p> |
---|
1027 | </dd></dl> |
---|
1028 | |
---|
1029 | </dd></dl> |
---|
1030 | |
---|
1031 | <dl class="function"> |
---|
1032 | <dt id="park.fit.assembly_example"> |
---|
1033 | <tt class="descclassname">park.fit.</tt><tt class="descname">assembly_example</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#assembly_example"><span class="viewcode-link">[source]</span></a></dt> |
---|
1034 | <dd></dd></dl> |
---|
1035 | |
---|
1036 | <dl class="function"> |
---|
1037 | <dt id="park.fit.demo"> |
---|
1038 | <tt class="descclassname">park.fit.</tt><tt class="descname">demo</tt><big>(</big><em>fitter=None</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#demo"><span class="viewcode-link">[source]</span></a></dt> |
---|
1039 | <dd><p>Multiple minima example</p> |
---|
1040 | </dd></dl> |
---|
1041 | |
---|
1042 | <dl class="function"> |
---|
1043 | <dt id="park.fit.demo2"> |
---|
1044 | <tt class="descclassname">park.fit.</tt><tt class="descname">demo2</tt><big>(</big><em>fitter=None</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#demo2"><span class="viewcode-link">[source]</span></a></dt> |
---|
1045 | <dd></dd></dl> |
---|
1046 | |
---|
1047 | <dl class="function"> |
---|
1048 | <dt id="park.fit.fit"> |
---|
1049 | <tt class="descclassname">park.fit.</tt><tt class="descname">fit</tt><big>(</big><em>models=None</em>, <em>fitter=None</em>, <em>service=None</em>, <em>handler=None</em><big>)</big><a class="reference internal" href="../../_modules/park/fit.html#fit"><span class="viewcode-link">[source]</span></a></dt> |
---|
1050 | <dd><p>Start a fit with a set of models. The model set must be |
---|
1051 | in a form accepted by <cite>park.assembly.Assembly</cite>.</p> |
---|
1052 | <p>This is a convenience function which sets up the default |
---|
1053 | optimizer and uses the local fitting engine to do the work. |
---|
1054 | Progress reports are printed as they are received.</p> |
---|
1055 | <p>The choice of fitter, service and handler can be specified |
---|
1056 | by the caller.</p> |
---|
1057 | <p>The default fitter is FitMC, which is a monte carlo Nelder-Mead |
---|
1058 | simplex local optimizer with 100 random start points.</p> |
---|
1059 | <p>The default handler does nothing. Instead, ConsoleUpdate could |
---|
1060 | be used to report progress during the fit.</p> |
---|
1061 | <p>The default service is to run in a separate thread with FitThread. |
---|
1062 | Note that this will change soon to run in a separate process on |
---|
1063 | the local machine so that python’s global interpreter lock does |
---|
1064 | not interfere with parallelism.</p> |
---|
1065 | </dd></dl> |
---|
1066 | |
---|
1067 | </div> |
---|
1068 | </div> |
---|
1069 | <div class="section" id="park-fitmc-module"> |
---|
1070 | <h2>park.fitmc module</h2> |
---|
1071 | <span class="target" id="module-park.fitmc"></span><dl class="function"> |
---|
1072 | <dt id="park.fitmc.fitmc"> |
---|
1073 | <tt class="descclassname">park.fitmc.</tt><tt class="descname">fitmc</tt><big>(</big><em>fitness</em>, <em>x0</em>, <em>bounds</em>, <em>localfit</em>, <em>n</em>, <em>handler</em><big>)</big><a class="reference internal" href="../../_modules/park/fitmc.html#fitmc"><span class="viewcode-link">[source]</span></a></dt> |
---|
1074 | <dd><p>Run a monte carlo fit.</p> |
---|
1075 | <p>This procedure maps a local optimizer across a set of n initial points. |
---|
1076 | The initial parameter value defined by the fitness parameters defines |
---|
1077 | one initial point. The remainder are randomly generated within the |
---|
1078 | bounds of the problem.</p> |
---|
1079 | <p>localfit is the local optimizer to use. It should be a bounded |
---|
1080 | optimizer following the <cite>park.fitmc.LocalFit</cite> interface.</p> |
---|
1081 | <p>handler accepts updates to the current best set of fit parameters. |
---|
1082 | See <cite>park.fitresult.FitHandler</cite> for details.</p> |
---|
1083 | </dd></dl> |
---|
1084 | |
---|
1085 | </div> |
---|
1086 | <div class="section" id="module-park.fitresult"> |
---|
1087 | <span id="park-fitresult-module"></span><h2>park.fitresult module</h2> |
---|
1088 | <dl class="class"> |
---|
1089 | <dt id="park.fitresult.ConsoleUpdate"> |
---|
1090 | <em class="property">class </em><tt class="descclassname">park.fitresult.</tt><tt class="descname">ConsoleUpdate</tt><big>(</big><em>quiet=False</em>, <em>progress_delta=60</em>, <em>improvement_delta=5</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate"><span class="viewcode-link">[source]</span></a></dt> |
---|
1091 | <dd><p>Bases: <a class="reference internal" href="#park.fitresult.FitHandler" title="park.fitresult.FitHandler"><tt class="xref py py-class docutils literal"><span class="pre">park.fitresult.FitHandler</span></tt></a></p> |
---|
1092 | <p>Print progress to the console.</p> |
---|
1093 | <dl class="method"> |
---|
1094 | <dt id="park.fitresult.ConsoleUpdate.abort"> |
---|
1095 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
1096 | <dd></dd></dl> |
---|
1097 | |
---|
1098 | <dl class="method"> |
---|
1099 | <dt id="park.fitresult.ConsoleUpdate.error"> |
---|
1100 | <tt class="descname">error</tt><big>(</big><em>msg</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate.error"><span class="viewcode-link">[source]</span></a></dt> |
---|
1101 | <dd><p>Model had an error; print traceback</p> |
---|
1102 | </dd></dl> |
---|
1103 | |
---|
1104 | <dl class="method"> |
---|
1105 | <dt id="park.fitresult.ConsoleUpdate.finalize"> |
---|
1106 | <tt class="descname">finalize</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate.finalize"><span class="viewcode-link">[source]</span></a></dt> |
---|
1107 | <dd></dd></dl> |
---|
1108 | |
---|
1109 | <dl class="method"> |
---|
1110 | <dt id="park.fitresult.ConsoleUpdate.improvement"> |
---|
1111 | <tt class="descname">improvement</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate.improvement"><span class="viewcode-link">[source]</span></a></dt> |
---|
1112 | <dd><p>Called when a result is observed which is better than previous |
---|
1113 | results from the fit.</p> |
---|
1114 | </dd></dl> |
---|
1115 | |
---|
1116 | <dl class="attribute"> |
---|
1117 | <dt id="park.fitresult.ConsoleUpdate.improvement_delta"> |
---|
1118 | <tt class="descname">improvement_delta</tt><em class="property"> = 5</em></dt> |
---|
1119 | <dd><p>Number of seconds between improvement updates</p> |
---|
1120 | </dd></dl> |
---|
1121 | |
---|
1122 | <dl class="attribute"> |
---|
1123 | <dt id="park.fitresult.ConsoleUpdate.isbetter"> |
---|
1124 | <tt class="descname">isbetter</tt><em class="property"> = False</em></dt> |
---|
1125 | <dd><p>Record whether results improved since last update</p> |
---|
1126 | </dd></dl> |
---|
1127 | |
---|
1128 | <dl class="method"> |
---|
1129 | <dt id="park.fitresult.ConsoleUpdate.progress"> |
---|
1130 | <tt class="descname">progress</tt><big>(</big><em>k</em>, <em>n</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#ConsoleUpdate.progress"><span class="viewcode-link">[source]</span></a></dt> |
---|
1131 | <dd><p>Report on progress.</p> |
---|
1132 | </dd></dl> |
---|
1133 | |
---|
1134 | <dl class="attribute"> |
---|
1135 | <dt id="park.fitresult.ConsoleUpdate.progress_delta"> |
---|
1136 | <tt class="descname">progress_delta</tt><em class="property"> = 60</em></dt> |
---|
1137 | <dd><p>Number of seconds between progress updates</p> |
---|
1138 | </dd></dl> |
---|
1139 | |
---|
1140 | </dd></dl> |
---|
1141 | |
---|
1142 | <dl class="class"> |
---|
1143 | <dt id="park.fitresult.FitHandler"> |
---|
1144 | <em class="property">class </em><tt class="descclassname">park.fitresult.</tt><tt class="descname">FitHandler</tt><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler"><span class="viewcode-link">[source]</span></a></dt> |
---|
1145 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1146 | <p>Abstract interface for fit thread handler.</p> |
---|
1147 | <p>The methods in this class are called by the optimizer as the fit |
---|
1148 | progresses.</p> |
---|
1149 | <p>Note that it is up to the optimizer to call the fit handler correctly, |
---|
1150 | reporting all status changes and maintaining the ‘done’ flag.</p> |
---|
1151 | <dl class="method"> |
---|
1152 | <dt id="park.fitresult.FitHandler.abort"> |
---|
1153 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
1154 | <dd><p>Fit was aborted.</p> |
---|
1155 | </dd></dl> |
---|
1156 | |
---|
1157 | <dl class="attribute"> |
---|
1158 | <dt id="park.fitresult.FitHandler.done"> |
---|
1159 | <tt class="descname">done</tt><em class="property"> = False</em></dt> |
---|
1160 | <dd><p>True when the fit job is complete</p> |
---|
1161 | </dd></dl> |
---|
1162 | |
---|
1163 | <dl class="method"> |
---|
1164 | <dt id="park.fitresult.FitHandler.error"> |
---|
1165 | <tt class="descname">error</tt><big>(</big><em>msg</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler.error"><span class="viewcode-link">[source]</span></a></dt> |
---|
1166 | <dd><p>Model had an error; print traceback</p> |
---|
1167 | </dd></dl> |
---|
1168 | |
---|
1169 | <dl class="method"> |
---|
1170 | <dt id="park.fitresult.FitHandler.finalize"> |
---|
1171 | <tt class="descname">finalize</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler.finalize"><span class="viewcode-link">[source]</span></a></dt> |
---|
1172 | <dd><p>Fit is complete; best results are reported</p> |
---|
1173 | </dd></dl> |
---|
1174 | |
---|
1175 | <dl class="method"> |
---|
1176 | <dt id="park.fitresult.FitHandler.improvement"> |
---|
1177 | <tt class="descname">improvement</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler.improvement"><span class="viewcode-link">[source]</span></a></dt> |
---|
1178 | <dd><p>Called when a result is observed which is better than previous |
---|
1179 | results from the fit.</p> |
---|
1180 | <p>result is a FitResult object, with parameters, #calls and fitness.</p> |
---|
1181 | </dd></dl> |
---|
1182 | |
---|
1183 | <dl class="method"> |
---|
1184 | <dt id="park.fitresult.FitHandler.progress"> |
---|
1185 | <tt class="descname">progress</tt><big>(</big><em>current</em>, <em>expected</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitHandler.progress"><span class="viewcode-link">[source]</span></a></dt> |
---|
1186 | <dd><p>Called each cycle of the fit, reporting the current and the |
---|
1187 | expected amount of work. The meaning of these values is |
---|
1188 | optimizer dependent, but they can be converted into a percent |
---|
1189 | complete using (100*current)//expected.</p> |
---|
1190 | <p>Progress is updated each iteration of the fit, whatever that |
---|
1191 | means for the particular optimization algorithm. It is called |
---|
1192 | after any calls to improvement for the iteration so that the |
---|
1193 | update handler can control I/O bandwidth by suppressing |
---|
1194 | intermediate improvements until the fit is complete.</p> |
---|
1195 | </dd></dl> |
---|
1196 | |
---|
1197 | <dl class="attribute"> |
---|
1198 | <dt id="park.fitresult.FitHandler.result"> |
---|
1199 | <tt class="descname">result</tt><em class="property"> = None</em></dt> |
---|
1200 | <dd><p>The current best result of the fit</p> |
---|
1201 | </dd></dl> |
---|
1202 | |
---|
1203 | </dd></dl> |
---|
1204 | |
---|
1205 | <dl class="class"> |
---|
1206 | <dt id="park.fitresult.FitParameter"> |
---|
1207 | <em class="property">class </em><tt class="descclassname">park.fitresult.</tt><tt class="descname">FitParameter</tt><big>(</big><em>name</em>, <em>range</em>, <em>value</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitParameter"><span class="viewcode-link">[source]</span></a></dt> |
---|
1208 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1209 | <p>Fit result for an individual parameter.</p> |
---|
1210 | <dl class="method"> |
---|
1211 | <dt id="park.fitresult.FitParameter.summarize"> |
---|
1212 | <tt class="descname">summarize</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitParameter.summarize"><span class="viewcode-link">[source]</span></a></dt> |
---|
1213 | <dd><p>Return parameter range string.</p> |
---|
1214 | <p>E.g., ” Gold .....|.... 5.2043 in [2,7]”</p> |
---|
1215 | </dd></dl> |
---|
1216 | |
---|
1217 | </dd></dl> |
---|
1218 | |
---|
1219 | <dl class="class"> |
---|
1220 | <dt id="park.fitresult.FitResult"> |
---|
1221 | <em class="property">class </em><tt class="descclassname">park.fitresult.</tt><tt class="descname">FitResult</tt><big>(</big><em>parameters</em>, <em>calls</em>, <em>fitness</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitResult"><span class="viewcode-link">[source]</span></a></dt> |
---|
1222 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1223 | <p>Container for reporting fit results.</p> |
---|
1224 | <dl class="method"> |
---|
1225 | <dt id="park.fitresult.FitResult.calc_cov"> |
---|
1226 | <tt class="descname">calc_cov</tt><big>(</big><em>fn</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitResult.calc_cov"><span class="viewcode-link">[source]</span></a></dt> |
---|
1227 | <dd><p>Return the covariance matrix inv(J’J) at point p.</p> |
---|
1228 | </dd></dl> |
---|
1229 | |
---|
1230 | <dl class="attribute"> |
---|
1231 | <dt id="park.fitresult.FitResult.calls"> |
---|
1232 | <tt class="descname">calls</tt><em class="property"> = None</em></dt> |
---|
1233 | <dd><p>Number of function calls</p> |
---|
1234 | </dd></dl> |
---|
1235 | |
---|
1236 | <dl class="attribute"> |
---|
1237 | <dt id="park.fitresult.FitResult.cov"> |
---|
1238 | <tt class="descname">cov</tt><em class="property"> = None</em></dt> |
---|
1239 | <dd><p>Covariance matrix</p> |
---|
1240 | </dd></dl> |
---|
1241 | |
---|
1242 | <dl class="attribute"> |
---|
1243 | <dt id="park.fitresult.FitResult.fitness"> |
---|
1244 | <tt class="descname">fitness</tt><em class="property"> = None</em></dt> |
---|
1245 | <dd><p>Value of the goodness of fit metric</p> |
---|
1246 | </dd></dl> |
---|
1247 | |
---|
1248 | <dl class="attribute"> |
---|
1249 | <dt id="park.fitresult.FitResult.parameters"> |
---|
1250 | <tt class="descname">parameters</tt><em class="property"> = None</em></dt> |
---|
1251 | <dd><p>Fit parameter list, each with name, range and value attributes.</p> |
---|
1252 | </dd></dl> |
---|
1253 | |
---|
1254 | <dl class="method"> |
---|
1255 | <dt id="park.fitresult.FitResult.print_summary"> |
---|
1256 | <tt class="descname">print_summary</tt><big>(</big><em>fid=<open file '<stdout>'</em>, <em>mode 'w' at 0x10028e150></em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitResult.print_summary"><span class="viewcode-link">[source]</span></a></dt> |
---|
1257 | <dd></dd></dl> |
---|
1258 | |
---|
1259 | <dl class="attribute"> |
---|
1260 | <dt id="park.fitresult.FitResult.pvec"> |
---|
1261 | <tt class="descname">pvec</tt><em class="property"> = None</em></dt> |
---|
1262 | <dd><p>Parameter vector</p> |
---|
1263 | </dd></dl> |
---|
1264 | |
---|
1265 | <dl class="method"> |
---|
1266 | <dt id="park.fitresult.FitResult.set_cov"> |
---|
1267 | <tt class="descname">set_cov</tt><big>(</big><em>cov</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitResult.set_cov"><span class="viewcode-link">[source]</span></a></dt> |
---|
1268 | <dd><p>Return the covariance matrix inv(J’J) at point p.</p> |
---|
1269 | </dd></dl> |
---|
1270 | |
---|
1271 | <dl class="attribute"> |
---|
1272 | <dt id="park.fitresult.FitResult.stderr"> |
---|
1273 | <tt class="descname">stderr</tt><em class="property"> = None</em></dt> |
---|
1274 | <dd><p>Parameter uncertainties</p> |
---|
1275 | </dd></dl> |
---|
1276 | |
---|
1277 | <dl class="method"> |
---|
1278 | <dt id="park.fitresult.FitResult.update"> |
---|
1279 | <tt class="descname">update</tt><big>(</big><em>pvec</em>, <em>fitness</em>, <em>calls</em><big>)</big><a class="reference internal" href="../../_modules/park/fitresult.html#FitResult.update"><span class="viewcode-link">[source]</span></a></dt> |
---|
1280 | <dd></dd></dl> |
---|
1281 | |
---|
1282 | </dd></dl> |
---|
1283 | |
---|
1284 | </div> |
---|
1285 | <div class="section" id="park-fitservice-module"> |
---|
1286 | <h2>park.fitservice module</h2> |
---|
1287 | </div> |
---|
1288 | <div class="section" id="module-park.formatnum"> |
---|
1289 | <span id="park-formatnum-module"></span><h2>park.formatnum module</h2> |
---|
1290 | <p>Format numbers nicely for printing.</p> |
---|
1291 | <p>Usage:</p> |
---|
1292 | <div class="highlight-python"><div class="highlight"><pre>>> from danse.common.util.formatnum import * |
---|
1293 | >> v,dv = 757.2356,0.01032 |
---|
1294 | >> print format_uncertainty_pm(v,dv) |
---|
1295 | 757.235 +/- 0.010 |
---|
1296 | >> format_uncertainty_compact(v,dv) |
---|
1297 | 757.235(10) |
---|
1298 | >> format_uncertainty(v,dv) |
---|
1299 | 757.235(10) |
---|
1300 | </pre></div> |
---|
1301 | </div> |
---|
1302 | <p>Set format_uncertainty.compact to False to use the +/- |
---|
1303 | format by default, otherwise leave it at True for compact |
---|
1304 | value(##) format.</p> |
---|
1305 | <dl class="function"> |
---|
1306 | <dt id="park.formatnum.format_uncertainty_pm"> |
---|
1307 | <tt class="descclassname">park.formatnum.</tt><tt class="descname">format_uncertainty_pm</tt><big>(</big><em>value</em>, <em>uncertainty=None</em><big>)</big><a class="reference internal" href="../../_modules/park/formatnum.html#format_uncertainty_pm"><span class="viewcode-link">[source]</span></a></dt> |
---|
1308 | <dd><p>Given <em>value</em> v and <em>uncertainty</em> dv, return a string v +/- dv.</p> |
---|
1309 | <p>The returned string uses only the number of digits warranted by |
---|
1310 | the uncertainty in the measurement.</p> |
---|
1311 | <p>If the uncertainty is 0 or not otherwise provided, the simple |
---|
1312 | %g floating point format option is used.</p> |
---|
1313 | <p>Infinite and indefinite numbers are represented as inf and NaN.</p> |
---|
1314 | </dd></dl> |
---|
1315 | |
---|
1316 | <dl class="function"> |
---|
1317 | <dt id="park.formatnum.format_uncertainty_compact"> |
---|
1318 | <tt class="descclassname">park.formatnum.</tt><tt class="descname">format_uncertainty_compact</tt><big>(</big><em>value</em>, <em>uncertainty=None</em><big>)</big><a class="reference internal" href="../../_modules/park/formatnum.html#format_uncertainty_compact"><span class="viewcode-link">[source]</span></a></dt> |
---|
1319 | <dd><p>Given <em>value</em> v and <em>uncertainty</em> dv, return the compact |
---|
1320 | representation v(##), where ## are the first two digits of |
---|
1321 | the uncertainty.</p> |
---|
1322 | <p>The returned string uses only the number of digits warranted by |
---|
1323 | the uncertainty in the measurement.</p> |
---|
1324 | <p>If the uncertainty is 0 or not otherwise provided, the simple |
---|
1325 | %g floating point format option is used.</p> |
---|
1326 | <p>Infinite and indefinite numbers are represented as inf and NaN.</p> |
---|
1327 | </dd></dl> |
---|
1328 | |
---|
1329 | </div> |
---|
1330 | <div class="section" id="module-park.message"> |
---|
1331 | <span id="park-message-module"></span><h2>park.message module</h2> |
---|
1332 | <p>Asynchronous message streams.</p> |
---|
1333 | <p>When you have multiple listeners to a process, some of which can connect and |
---|
1334 | disconnect at different times, you need to dispatch the incoming messages to |
---|
1335 | all the listeners. When a listener joins a running stream, they need to get |
---|
1336 | an immediate status update for the computation. This is stored as the |
---|
1337 | stream header. Then, without dropping any messages, the listeners should |
---|
1338 | receive all subsequent messages in the stream in order.</p> |
---|
1339 | <p>The message stream is multi-channelled, and indexed by a key. Within |
---|
1340 | the service framework the key is likely to be the jobid associated with |
---|
1341 | the message stream.</p> |
---|
1342 | <p>The contents of the message stream are expected to be monitor messages |
---|
1343 | (see <cite>park.monitor</cite> for details), with the stream header being a |
---|
1344 | <cite>park.monitor.Join</cite> message. When a new listener is registered, |
---|
1345 | the header is immediately put on the queue (if there is one), then all |
---|
1346 | subsequent message are sent until the listener calls hangup().</p> |
---|
1347 | <p>To attach to a message stream you need an object which accepts put(). |
---|
1348 | An asynchronous queue object is a good choice since it allows you to |
---|
1349 | buffer the messages in one thread and pull them off as needed in another. |
---|
1350 | You can also use a <cite>park.monitor.Monitor</cite> object to process the messages |
---|
1351 | directly.</p> |
---|
1352 | </div> |
---|
1353 | <div class="section" id="module-park.model"> |
---|
1354 | <span id="park-model-module"></span><h2>park.model module</h2> |
---|
1355 | <p>Define a park fitting model.</p> |
---|
1356 | <div class="section" id="id2"> |
---|
1357 | <h3>Usage</h3> |
---|
1358 | <p>The simplest sort of fitting model is something like the following:</p> |
---|
1359 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">numpy</span> |
---|
1360 | <span class="kn">import</span> <span class="nn">park</span> |
---|
1361 | <span class="k">def</span> <span class="nf">G</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">mu</span><span class="p">,</span><span class="n">sigma</span><span class="p">):</span> |
---|
1362 | <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="n">sigma</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> |
---|
1363 | |
---|
1364 | <span class="k">class</span> <span class="nc">Gauss</span><span class="p">(</span><span class="n">park</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span> |
---|
1365 | <span class="n">parameters</span> <span class="o">=</span> <span class="p">[</span><span class="s">'center'</span><span class="p">,</span><span class="s">'width'</span><span class="p">,</span><span class="s">'scale'</span><span class="p">]</span> |
---|
1366 | <span class="k">def</span> <span class="nf">eval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">):</span> |
---|
1367 | <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span> <span class="n">G</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">width</span><span class="p">)</span> |
---|
1368 | </pre></div> |
---|
1369 | </div> |
---|
1370 | <p>It has a function which is evaluated at a series of x values and |
---|
1371 | a set of adjustable parameters controlling the shape of f(x).</p> |
---|
1372 | <p>You can check your module with something like the following:</p> |
---|
1373 | <div class="highlight-python"><div class="highlight"><pre>$ ipython -pylab |
---|
1374 | |
---|
1375 | from gauss import Gauss |
---|
1376 | |
---|
1377 | g = Gauss(center=5,width=1,scale=10) |
---|
1378 | x = asarray([1,2,3,4,5]) |
---|
1379 | y = g(x) |
---|
1380 | plot(x,y) |
---|
1381 | </pre></div> |
---|
1382 | </div> |
---|
1383 | <p>This should produce a plot of the Gaussian peak.</p> |
---|
1384 | <p>You will then want to try your model with some data. Create a file |
---|
1385 | with some dummy data, such as gauss.dat:</p> |
---|
1386 | <div class="highlight-python"><div class="highlight"><pre># x y |
---|
1387 | 4 2 |
---|
1388 | 5 6 |
---|
1389 | 6 7 |
---|
1390 | 7 3 |
---|
1391 | </pre></div> |
---|
1392 | </div> |
---|
1393 | <p>In order to match the model to data, you need to define a fitness |
---|
1394 | object. This shows the difference between the model and the data, |
---|
1395 | which you can then plot or sum to create a weighted chisq value:</p> |
---|
1396 | <div class="highlight-python"><div class="highlight"><pre><span class="n">f</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">Fitness</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="s">'gauss.dat'</span><span class="p">)</span> |
---|
1397 | <span class="n">plot</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">fit_x</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">residuals</span><span class="p">())</span> |
---|
1398 | </pre></div> |
---|
1399 | </div> |
---|
1400 | <p>The data file can have up to four columns, either x,y or x,y,dy |
---|
1401 | or x,dx,y,dy where x,y are the measurement points and values, |
---|
1402 | dx is the instrument resolution in x and dy is the uncertainty |
---|
1403 | in the measurement value y. You can pass any keyword arguments |
---|
1404 | to data.load that are accepted by numpy.loadtxt. For example, |
---|
1405 | you can reorder columns or skip rows. Additionally, you can modify |
---|
1406 | data attributes directly x,y,dx,dy and calc_x. See help on park.Data1D |
---|
1407 | for details.</p> |
---|
1408 | <p>Once you have your model debugged you can use it in a fit:</p> |
---|
1409 | <div class="highlight-python"><div class="highlight"><pre><span class="n">g</span> <span class="o">=</span> <span class="n">Gauss</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span><span class="n">scale</span><span class="o">=</span><span class="mf">7.2</span><span class="p">,</span><span class="n">width</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span> |
---|
1410 | <span class="n">result</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">fit</span><span class="p">((</span><span class="n">g</span><span class="p">,</span> <span class="s">'gauss.dat'</span><span class="p">))</span> |
---|
1411 | <span class="n">result</span><span class="o">.</span><span class="n">plot</span><span class="p">()</span> |
---|
1412 | </pre></div> |
---|
1413 | </div> |
---|
1414 | <p>In this example, center and width are allowed to vary but scale is fixed.</p> |
---|
1415 | <p>Existing models can be readily adapted to Park:</p> |
---|
1416 | <div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Gauss</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> |
---|
1417 | <span class="s">"Existing model"</span> |
---|
1418 | <span class="n">center</span><span class="p">,</span><span class="n">width</span><span class="p">,</span><span class="n">scale</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span> |
---|
1419 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="o">**</span><span class="n">kw</span><span class="p">):</span> |
---|
1420 | <span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">kw</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="p">)</span> |
---|
1421 | <span class="k">def</span> <span class="nf">eval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">):</span> |
---|
1422 | <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">scale</span> <span class="o">*</span><span class="n">G</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">center</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">width</span><span class="p">)</span> |
---|
1423 | |
---|
1424 | <span class="k">class</span> <span class="nc">GaussAdaptor</span><span class="p">(</span><span class="n">Gauss</span><span class="p">,</span><span class="n">Model</span><span class="p">):</span> |
---|
1425 | <span class="s">"PARK adaptor"</span> |
---|
1426 | <span class="n">parameters</span> <span class="o">=</span> <span class="p">[</span><span class="s">'center'</span><span class="p">,</span><span class="s">'width'</span><span class="p">,</span><span class="s">'scale'</span><span class="p">]</span> |
---|
1427 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">kw</span><span class="p">):</span> |
---|
1428 | <span class="n">Model</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="o">*</span><span class="n">args</span><span class="p">)</span> |
---|
1429 | <span class="n">Gauss</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="o">**</span><span class="n">kw</span><span class="p">)</span> |
---|
1430 | |
---|
1431 | <span class="n">g</span> <span class="o">=</span> <span class="n">GaussAdaptor</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span><span class="n">scale</span><span class="o">=</span><span class="mf">7.2</span><span class="p">,</span><span class="n">width</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span> |
---|
1432 | <span class="n">result</span> <span class="o">=</span> <span class="n">park</span><span class="o">.</span><span class="n">fit</span><span class="p">((</span><span class="n">g</span><span class="p">,</span> <span class="s">'gauss.dat'</span><span class="p">))</span> |
---|
1433 | <span class="n">result</span><span class="o">.</span><span class="n">plot</span><span class="p">()</span> |
---|
1434 | </pre></div> |
---|
1435 | </div> |
---|
1436 | <p>Models can become much more complex than the ones described above, |
---|
1437 | including multilevel models where fitting parameters can be added |
---|
1438 | and removed dynamically.</p> |
---|
1439 | <p>In many cases the park optimizer will need an adaptor for pre-existing |
---|
1440 | models. The adaptor above relies on python properties to translate |
---|
1441 | model.par access into model._par.get() and model._par.set() where _par |
---|
1442 | is the internal name for par. This technique works for simple static |
---|
1443 | models, but will not work well for sophisticated models which have, |
---|
1444 | for example, a dynamic parameter set where the model parameters cannot |
---|
1445 | be set as properties. A solution to this problem is to subclass the |
---|
1446 | park.Parameter and override the value attribute as a property.</p> |
---|
1447 | <p>Once models are defined they can be used in a variety of contexts, such |
---|
1448 | as simultaneous fitting with constraints between the parameters. With |
---|
1449 | some care in defining the model, computationally intensive fits can |
---|
1450 | be distributed across multiple processors. We provide a simple user |
---|
1451 | interface for interacting with the model parameters and managing fits. |
---|
1452 | This can be extended with model specialized model editors which format |
---|
1453 | the parameters in a sensible way for the model, or allow direct manipulation |
---|
1454 | of the model structure. The underlying fitting engine can also be |
---|
1455 | used directly from your own user interface.</p> |
---|
1456 | <dl class="class"> |
---|
1457 | <dt id="park.model.Model"> |
---|
1458 | <em class="property">class </em><tt class="descclassname">park.model.</tt><tt class="descname">Model</tt><big>(</big><em>*args</em>, <em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/model.html#Model"><span class="viewcode-link">[source]</span></a></dt> |
---|
1459 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1460 | <p>Model definition.</p> |
---|
1461 | <p>The model manages attribute access to the fitting parameters and |
---|
1462 | also manages the dataset.</p> |
---|
1463 | <dl class="docutils"> |
---|
1464 | <dt>derivatives [‘p1’,’p2’,...]</dt> |
---|
1465 | <dd><p class="first">List of parameters for which the model can calculate |
---|
1466 | derivatives. The derivs |
---|
1467 | The model function can compute the derivative with respect |
---|
1468 | to this parameter. The function model.derivs(x,[p1,p2,...]) |
---|
1469 | will return (f(x),df/dp1(x), ...). The parameters and their |
---|
1470 | order are determined by the fitting engine.</p> |
---|
1471 | <p class="last">Note: This is a property of the model, not the fit. |
---|
1472 | Numerical derivatives will be used if the parameter is |
---|
1473 | used in an expression or if no analytic derivative is |
---|
1474 | available for the parameter. Automatic differentiation |
---|
1475 | on parameter expressions is possible, but beyond the scope |
---|
1476 | of this project.</p> |
---|
1477 | </dd> |
---|
1478 | <dt>eval(x)</dt> |
---|
1479 | <dd>Evaluate the model at x. This must be defined by the subclass.</dd> |
---|
1480 | <dt>eval_deriv(x,pars=[])</dt> |
---|
1481 | <dd>Evaluate the model and the derivatives at x. This must be |
---|
1482 | defined by the subclass.</dd> |
---|
1483 | <dt>parameters</dt> |
---|
1484 | <dd>The names of the model parameters. If this is not provided, then |
---|
1485 | the model will search the subclass for park.Parameter attributes |
---|
1486 | and construct the list of names from that. Any parameters in the |
---|
1487 | list not already defined as park.Parameter attributes will be |
---|
1488 | defined as parameters with a default of 0.</dd> |
---|
1489 | <dt>parameterset</dt> |
---|
1490 | <dd>The set of parameters defined by the model. These are the |
---|
1491 | parameters themselves, gathered into a park.ParameterSet.</dd> |
---|
1492 | </dl> |
---|
1493 | <p>The minimum fittng model if you choose not to subclass park.Model |
---|
1494 | requires parameterset and a residuals() method.</p> |
---|
1495 | <dl class="attribute"> |
---|
1496 | <dt id="park.model.Model.derivatives"> |
---|
1497 | <tt class="descname">derivatives</tt><em class="property"> = []</em></dt> |
---|
1498 | <dd></dd></dl> |
---|
1499 | |
---|
1500 | <dl class="method"> |
---|
1501 | <dt id="park.model.Model.eval"> |
---|
1502 | <tt class="descname">eval</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/model.html#Model.eval"><span class="viewcode-link">[source]</span></a></dt> |
---|
1503 | <dd><p>Evaluate the model at x.</p> |
---|
1504 | <p>This method needs to be specialized in the model to evaluate the |
---|
1505 | model function. Alternatively, the model can implement is own |
---|
1506 | version of residuals which calculates the residuals directly |
---|
1507 | instead of calling eval.</p> |
---|
1508 | </dd></dl> |
---|
1509 | |
---|
1510 | <dl class="method"> |
---|
1511 | <dt id="park.model.Model.eval_derivs"> |
---|
1512 | <tt class="descname">eval_derivs</tt><big>(</big><em>x</em>, <em>pars=[]</em><big>)</big><a class="reference internal" href="../../_modules/park/model.html#Model.eval_derivs"><span class="viewcode-link">[source]</span></a></dt> |
---|
1513 | <dd><p>Evaluate the model and derivatives wrt pars at x.</p> |
---|
1514 | <p>pars is a list of the names of the parameters for which derivatives |
---|
1515 | are desired.</p> |
---|
1516 | <p>This method needs to be specialized in the model to evaluate the |
---|
1517 | model function. Alternatively, the model can implement is own |
---|
1518 | version of residuals which calculates the residuals directly |
---|
1519 | instead of calling eval.</p> |
---|
1520 | </dd></dl> |
---|
1521 | |
---|
1522 | <dl class="attribute"> |
---|
1523 | <dt id="park.model.Model.parameters"> |
---|
1524 | <tt class="descname">parameters</tt><em class="property"> = []</em></dt> |
---|
1525 | <dd></dd></dl> |
---|
1526 | |
---|
1527 | <dl class="attribute"> |
---|
1528 | <dt id="park.model.Model.parameterset"> |
---|
1529 | <tt class="descname">parameterset</tt><em class="property"> = []</em></dt> |
---|
1530 | <dd></dd></dl> |
---|
1531 | |
---|
1532 | <dl class="method"> |
---|
1533 | <dt id="park.model.Model.set"> |
---|
1534 | <tt class="descname">set</tt><big>(</big><em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/model.html#Model.set"><span class="viewcode-link">[source]</span></a></dt> |
---|
1535 | <dd><p>Set the initial value for a set of parameters.</p> |
---|
1536 | <p>E.g., model.set(width=3,center=5)</p> |
---|
1537 | </dd></dl> |
---|
1538 | |
---|
1539 | </dd></dl> |
---|
1540 | |
---|
1541 | </div> |
---|
1542 | </div> |
---|
1543 | <div class="section" id="module-park.monitor"> |
---|
1544 | <span id="park-monitor-module"></span><h2>park.monitor module</h2> |
---|
1545 | <p>Asychronous execution monitoring service.</p> |
---|
1546 | <p>Long running computations need to convey status information to the user. |
---|
1547 | This status can take multiple forms, such as output to the console or |
---|
1548 | activity on a GUI, or even mail to your inbox.</p> |
---|
1549 | <p>park.monitor defines several standard message types:</p> |
---|
1550 | <div class="highlight-python"><div class="highlight"><pre>`Start` for job start |
---|
1551 | `Join` first message when joining an already running job |
---|
1552 | `Progress` for job activity |
---|
1553 | `Improvement` for partial results |
---|
1554 | `Complete` for final result |
---|
1555 | `Abort` when job is killed |
---|
1556 | `Error` when job has an error |
---|
1557 | `Log` for various debugging messages |
---|
1558 | </pre></div> |
---|
1559 | </div> |
---|
1560 | <p>Individual services may have specialized message types.</p> |
---|
1561 | <p>park.monitor also defines <cite>Monitor</cite> to process the various kinds of messages, |
---|
1562 | and dispatch them to the various user defined handlers.</p> |
---|
1563 | <p>For each message type, the Monitor dispatcher will look for a function |
---|
1564 | named onMonitorQQQ where QQQ is the message type. For example, |
---|
1565 | onMonitorStart(self, message) will be called in response to a Start message. |
---|
1566 | If onMonitorQQQ is not defined, then onMonitorMessage will be called. The |
---|
1567 | default behaviour of onMonitorMessage is to print the message on the console.</p> |
---|
1568 | <p>Log messages are sent to the standard system logger. See logging in the |
---|
1569 | python standard library for details.</p> |
---|
1570 | <p>The Monitor class has methods for onMonitorStart(message), etc. |
---|
1571 | In panel, be sure to have methods for onMonitorStart(message), |
---|
1572 | onMonitorProgress(message), etc., for the kinds of monitor messages |
---|
1573 | the application will send. The catch-all method is onMonitorMessage.</p> |
---|
1574 | <p>See <cite>park.monitor</cite> for details on the message types. Individual services |
---|
1575 | may have additional message types.</p> |
---|
1576 | <dl class="class"> |
---|
1577 | <dt id="park.monitor.Monitor"> |
---|
1578 | <em class="property">class </em><tt class="descclassname">park.monitor.</tt><tt class="descname">Monitor</tt><a class="reference internal" href="../../_modules/park/monitor.html#Monitor"><span class="viewcode-link">[source]</span></a></dt> |
---|
1579 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1580 | <p>Messages that are received during the processing of the job.</p> |
---|
1581 | <p>Standard message types:</p> |
---|
1582 | <div class="highlight-python"><div class="highlight"><pre><span class="sb">`Start`</span><span class="p">,</span> <span class="sb">`Progress`</span><span class="p">,</span> <span class="sb">`Improvement`</span><span class="p">,</span> <span class="sb">`Complete`</span><span class="p">,</span> <span class="sb">`Error`</span><span class="p">,</span> <span class="sb">`Abort`</span><span class="p">,</span> <span class="sb">`Log`</span> |
---|
1583 | </pre></div> |
---|
1584 | </div> |
---|
1585 | <p>Specific job types may have their own monitor messages.</p> |
---|
1586 | <p>The messages themselves should all produce nicely formatted results |
---|
1587 | in response to str(message).</p> |
---|
1588 | <p>The message dispatch calls on<Class>(message) if the on<Class> |
---|
1589 | method exists for the message type. If not, then dispatch |
---|
1590 | calls otherwise(message). By default onLog(message) submits the |
---|
1591 | log record to the logger.</p> |
---|
1592 | <p>Subclass Monitor to define your own behaviours.</p> |
---|
1593 | <dl class="method"> |
---|
1594 | <dt id="park.monitor.Monitor.onMonitorLog"> |
---|
1595 | <tt class="descname">onMonitorLog</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/monitor.html#Monitor.onMonitorLog"><span class="viewcode-link">[source]</span></a></dt> |
---|
1596 | <dd><p>Called when the job sends a logging record.</p> |
---|
1597 | <p>The logging record contains a normal python logging record.</p> |
---|
1598 | <p>The default behaviour is to tie into the application logging |
---|
1599 | system using:</p> |
---|
1600 | <div class="highlight-python"><div class="highlight"><pre><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> |
---|
1601 | <span class="n">logger</span><span class="o">.</span><span class="n">handle</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">record</span><span class="p">)</span> |
---|
1602 | </pre></div> |
---|
1603 | </div> |
---|
1604 | <p>Logging levels are set in the job controller.</p> |
---|
1605 | </dd></dl> |
---|
1606 | |
---|
1607 | <dl class="method"> |
---|
1608 | <dt id="park.monitor.Monitor.onMonitorMessage"> |
---|
1609 | <tt class="descname">onMonitorMessage</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/monitor.html#Monitor.onMonitorMessage"><span class="viewcode-link">[source]</span></a></dt> |
---|
1610 | <dd><p>What to do if the message handler is not found.</p> |
---|
1611 | <p>Default is to ignore the message.</p> |
---|
1612 | </dd></dl> |
---|
1613 | |
---|
1614 | <dl class="method"> |
---|
1615 | <dt id="park.monitor.Monitor.put"> |
---|
1616 | <tt class="descname">put</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/monitor.html#Monitor.put"><span class="viewcode-link">[source]</span></a></dt> |
---|
1617 | <dd><p>Called from thread when new message has arrived.</p> |
---|
1618 | </dd></dl> |
---|
1619 | |
---|
1620 | </dd></dl> |
---|
1621 | |
---|
1622 | </div> |
---|
1623 | <div class="section" id="module-park.parameter"> |
---|
1624 | <span id="park-parameter-module"></span><h2>park.parameter module</h2> |
---|
1625 | <p>Parameters and parameter sets.</p> |
---|
1626 | <p>Parameter defines an individual parameter, and ParameterSet groups them |
---|
1627 | into a hierarchy.</p> |
---|
1628 | <p>Individual models need to provide a parameter set with the correct |
---|
1629 | properties, either by using park.ParameterSet in their model definition, |
---|
1630 | or by providing a wrapper which can translate assignment to parameter.value |
---|
1631 | into the appropriate change in the wrapped model. See wrapper.py for |
---|
1632 | an example.</p> |
---|
1633 | <dl class="class"> |
---|
1634 | <dt id="park.parameter.Parameter"> |
---|
1635 | <em class="property">class </em><tt class="descclassname">park.parameter.</tt><tt class="descname">Parameter</tt><big>(</big><em>name='unknown'</em>, <em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter"><span class="viewcode-link">[source]</span></a></dt> |
---|
1636 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
1637 | <p>A parameter is a box for communicating with the fitting service. |
---|
1638 | Parameters can have a number of properties,</p> |
---|
1639 | <p>Parameters have a number of properties:</p> |
---|
1640 | <dl class="docutils"> |
---|
1641 | <dt>name “string”</dt> |
---|
1642 | <dd><p class="first">name of the parameter within the parameter set.</p> |
---|
1643 | <p class="last">The name is read only. You can rename a parameter but only |
---|
1644 | in the context of the parameter set which contains it, using |
---|
1645 | parameterset.rename(par,name). This will change all expressions |
---|
1646 | containing the named parameter.</p> |
---|
1647 | </dd> |
---|
1648 | <dt>path</dt> |
---|
1649 | <dd>dotted name of the parameter within the set of models. The |
---|
1650 | dotted name is automatically generated by the parameter set |
---|
1651 | before expressions are parsed and evaluated. There are |
---|
1652 | some operations on parameter sets (such as renaming the |
---|
1653 | layer containing a parameter) which will force an adjustment |
---|
1654 | of all the underlying parameter names, as well as any |
---|
1655 | expressions in which they are referenced.</dd> |
---|
1656 | <dt>limits (low, high)</dt> |
---|
1657 | <dd>hard limits on the range of allowed parameter values, dictated |
---|
1658 | by physics rather than by knowledge of the particular system. |
---|
1659 | For example, thickness parameters would have limits (0,inf) |
---|
1660 | because negative thicknesses are unphysical. These limits |
---|
1661 | are enforced when setting range for the fit.</dd> |
---|
1662 | <dt>units “string”</dt> |
---|
1663 | <dd>units for the parameter. This should be a string, but |
---|
1664 | be parsable by whatever units package your application |
---|
1665 | supports.</dd> |
---|
1666 | <dt>tip “string”</dt> |
---|
1667 | <dd>parameter description, suitable for use in a tooltip</dd> |
---|
1668 | <dt>value double</dt> |
---|
1669 | <dd>current value of the parameter, either fixed, fitted or computed</dd> |
---|
1670 | <dt>range (low, high)</dt> |
---|
1671 | <dd>range of expected values for the parameter in the model</dd> |
---|
1672 | <dt>expression “string”</dt> |
---|
1673 | <dd><p class="first">expression for the parameter in the model. This is a string |
---|
1674 | containing a formula for updating the parameter value based |
---|
1675 | on the values of other parameters in the system. The expression |
---|
1676 | is ignored if ‘calculated’ is False.</p> |
---|
1677 | <p class="last">Note: the list of symbols available to the expression evaluator |
---|
1678 | defaults to the contents of the math module. The caller will be |
---|
1679 | able to override this within the fitting fitting class.</p> |
---|
1680 | </dd> |
---|
1681 | <dt>status ‘fixed’|’computed’|’fitted’</dt> |
---|
1682 | <dd>the parameter type. Choose ‘fixed’ if the values is to |
---|
1683 | remain fixed throughout the fit, even if a range and an |
---|
1684 | expression have been specified. Choose ‘computed’ if the |
---|
1685 | value of the parameter is to be computed each time the |
---|
1686 | parameters are updated. Choose ‘fitted’ if an optimization |
---|
1687 | algorithm is supposed to search the parameter space.</dd> |
---|
1688 | <dt>likelihood</dt> |
---|
1689 | <dd><p class="first">function to return the negative log likelihood of seeing a |
---|
1690 | particular parameter value. 2*likelihood(value) will be added |
---|
1691 | to the total cost function for the particular parameter set |
---|
1692 | during the fit. This will be on par with the probabilty |
---|
1693 | of seeing the particular theory function given the observed |
---|
1694 | datapoints when performing the fit (the residual term is |
---|
1695 | closely related to the log likelihood of the normal distribution).</p> |
---|
1696 | <p class="last">Note: we are minimizing chi^2 = sum [ ((y-f(x;p))/dy)^2 ] rather |
---|
1697 | than -log P = sum [ ((y-f(x;p))/dy)^2/2 + log(2 pi dy^2) ], |
---|
1698 | where P is the probability of seeing f(x;p) given y,dy as the |
---|
1699 | mean and standard deviation of a normal distribution. Because |
---|
1700 | chi^2_p = - 2 * log P_p + constant, the minima of p are the same |
---|
1701 | for chi^2 and negative log likelihood. However, to weight the |
---|
1702 | likelihood properly when adding likelihood values to chisq, we |
---|
1703 | need the extra factor of 2 mentioned above. The usual statistical |
---|
1704 | implications of normalized chi^2 will of course be suspect, both |
---|
1705 | because the assumption of independence between the points in |
---|
1706 | chi^2 (which definitely do not hold for the new ‘point’ p_k), and |
---|
1707 | because of the additional 2 log(2 pi dp_k^2) constant, but given |
---|
1708 | the uncertainty in the estimate of the distribution parameters, |
---|
1709 | this is likely a minor point.</p> |
---|
1710 | </dd> |
---|
1711 | </dl> |
---|
1712 | <dl class="attribute"> |
---|
1713 | <dt id="park.parameter.Parameter.deriv"> |
---|
1714 | <tt class="descname">deriv</tt><em class="property"> = False</em></dt> |
---|
1715 | <dd></dd></dl> |
---|
1716 | |
---|
1717 | <dl class="attribute"> |
---|
1718 | <dt id="park.parameter.Parameter.expression"> |
---|
1719 | <tt class="descname">expression</tt><em class="property"> = ''</em></dt> |
---|
1720 | <dd></dd></dl> |
---|
1721 | |
---|
1722 | <dl class="method"> |
---|
1723 | <dt id="park.parameter.Parameter.get"> |
---|
1724 | <tt class="descname">get</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.get"><span class="viewcode-link">[source]</span></a></dt> |
---|
1725 | <dd><p>Return the current value for a parameter.</p> |
---|
1726 | </dd></dl> |
---|
1727 | |
---|
1728 | <dl class="method"> |
---|
1729 | <dt id="park.parameter.Parameter.iscomputed"> |
---|
1730 | <tt class="descname">iscomputed</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.iscomputed"><span class="viewcode-link">[source]</span></a></dt> |
---|
1731 | <dd></dd></dl> |
---|
1732 | |
---|
1733 | <dl class="method"> |
---|
1734 | <dt id="park.parameter.Parameter.isfeasible"> |
---|
1735 | <tt class="descname">isfeasible</tt><big>(</big><em>value</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.isfeasible"><span class="viewcode-link">[source]</span></a></dt> |
---|
1736 | <dd><p>Return true if the value is in the range</p> |
---|
1737 | </dd></dl> |
---|
1738 | |
---|
1739 | <dl class="method"> |
---|
1740 | <dt id="park.parameter.Parameter.isfitted"> |
---|
1741 | <tt class="descname">isfitted</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.isfitted"><span class="viewcode-link">[source]</span></a></dt> |
---|
1742 | <dd></dd></dl> |
---|
1743 | |
---|
1744 | <dl class="method"> |
---|
1745 | <dt id="park.parameter.Parameter.isfixed"> |
---|
1746 | <tt class="descname">isfixed</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.isfixed"><span class="viewcode-link">[source]</span></a></dt> |
---|
1747 | <dd></dd></dl> |
---|
1748 | |
---|
1749 | <dl class="method"> |
---|
1750 | <dt id="park.parameter.Parameter.isrestrained"> |
---|
1751 | <tt class="descname">isrestrained</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.isrestrained"><span class="viewcode-link">[source]</span></a></dt> |
---|
1752 | <dd></dd></dl> |
---|
1753 | |
---|
1754 | <dl class="attribute"> |
---|
1755 | <dt id="park.parameter.Parameter.likelihood"> |
---|
1756 | <tt class="descname">likelihood</tt><em class="property"> = None</em></dt> |
---|
1757 | <dd></dd></dl> |
---|
1758 | |
---|
1759 | <dl class="attribute"> |
---|
1760 | <dt id="park.parameter.Parameter.limits"> |
---|
1761 | <tt class="descname">limits</tt><em class="property"> = (-inf, inf)</em></dt> |
---|
1762 | <dd></dd></dl> |
---|
1763 | |
---|
1764 | <dl class="attribute"> |
---|
1765 | <dt id="park.parameter.Parameter.name"> |
---|
1766 | <tt class="descname">name</tt></dt> |
---|
1767 | <dd><p>parameter name</p> |
---|
1768 | </dd></dl> |
---|
1769 | |
---|
1770 | <dl class="attribute"> |
---|
1771 | <dt id="park.parameter.Parameter.path"> |
---|
1772 | <tt class="descname">path</tt><em class="property"> = ''</em></dt> |
---|
1773 | <dd></dd></dl> |
---|
1774 | |
---|
1775 | <dl class="attribute"> |
---|
1776 | <dt id="park.parameter.Parameter.range"> |
---|
1777 | <tt class="descname">range</tt></dt> |
---|
1778 | <dd><p>parameter range</p> |
---|
1779 | </dd></dl> |
---|
1780 | |
---|
1781 | <dl class="method"> |
---|
1782 | <dt id="park.parameter.Parameter.set"> |
---|
1783 | <tt class="descname">set</tt><big>(</big><em>value</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.set"><span class="viewcode-link">[source]</span></a></dt> |
---|
1784 | <dd><p>Set a parameter to a value, a range or an expression. If it is a value, |
---|
1785 | the parameter will be fixed for the fit. If it is a range, the value |
---|
1786 | will be varying for the fit. If it is an expression, the parameter will |
---|
1787 | be calculated from the values of other parameters in the fit.</p> |
---|
1788 | <p>Raises ValueError if the value could not be interpreted.</p> |
---|
1789 | </dd></dl> |
---|
1790 | |
---|
1791 | <dl class="method"> |
---|
1792 | <dt id="park.parameter.Parameter.setprefix"> |
---|
1793 | <tt class="descname">setprefix</tt><big>(</big><em>prefix</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.setprefix"><span class="viewcode-link">[source]</span></a></dt> |
---|
1794 | <dd><p>Set the full path to the parameter as used in expressions involving |
---|
1795 | the parameter name.</p> |
---|
1796 | </dd></dl> |
---|
1797 | |
---|
1798 | <dl class="attribute"> |
---|
1799 | <dt id="park.parameter.Parameter.status"> |
---|
1800 | <tt class="descname">status</tt><em class="property"> = 'fixed'</em></dt> |
---|
1801 | <dd></dd></dl> |
---|
1802 | |
---|
1803 | <dl class="method"> |
---|
1804 | <dt id="park.parameter.Parameter.summarize"> |
---|
1805 | <tt class="descname">summarize</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#Parameter.summarize"><span class="viewcode-link">[source]</span></a></dt> |
---|
1806 | <dd><p>Return parameter range string.</p> |
---|
1807 | <p>E.g., ” Gold .....|.... 5.2043 in [2,7]”</p> |
---|
1808 | </dd></dl> |
---|
1809 | |
---|
1810 | <dl class="attribute"> |
---|
1811 | <dt id="park.parameter.Parameter.tip"> |
---|
1812 | <tt class="descname">tip</tt><em class="property"> = 'Fitting parameter'</em></dt> |
---|
1813 | <dd></dd></dl> |
---|
1814 | |
---|
1815 | <dl class="attribute"> |
---|
1816 | <dt id="park.parameter.Parameter.units"> |
---|
1817 | <tt class="descname">units</tt><em class="property"> = ''</em></dt> |
---|
1818 | <dd></dd></dl> |
---|
1819 | |
---|
1820 | <dl class="attribute"> |
---|
1821 | <dt id="park.parameter.Parameter.value"> |
---|
1822 | <tt class="descname">value</tt><em class="property"> = 0.0</em></dt> |
---|
1823 | <dd></dd></dl> |
---|
1824 | |
---|
1825 | </dd></dl> |
---|
1826 | |
---|
1827 | <dl class="class"> |
---|
1828 | <dt id="park.parameter.ParameterSet"> |
---|
1829 | <em class="property">class </em><tt class="descclassname">park.parameter.</tt><tt class="descname">ParameterSet</tt><big>(</big><em>name='unknown'</em>, <em>pars=[]</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet"><span class="viewcode-link">[source]</span></a></dt> |
---|
1830 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></p> |
---|
1831 | <p>The set of parameters used to fit theory to data.</p> |
---|
1832 | <p>ParameterSet forms a hierarchy of parameters. The parameters themselves |
---|
1833 | are referred to by the path through the hierarchy, usually:</p> |
---|
1834 | <div class="highlight-python"><div class="highlight"><pre><span class="n">fitname</span><span class="o">.</span><span class="n">component</span><span class="o">.</span><span class="n">parameter</span> |
---|
1835 | </pre></div> |
---|
1836 | </div> |
---|
1837 | <p>Though more or fewer levels are permitted. Parameters are assumed to |
---|
1838 | have a unique label throughout the fit. This is required so that |
---|
1839 | expressions tying the results of one fit to another can uniquely |
---|
1840 | reference a parameter.</p> |
---|
1841 | <p>Attributes:</p> |
---|
1842 | <dl class="docutils"> |
---|
1843 | <dt>name</dt> |
---|
1844 | <dd>the name of the parameter set</dd> |
---|
1845 | <dt>path</dt> |
---|
1846 | <dd>the full dotted name of the parameter set</dd> |
---|
1847 | <dt>context</dt> |
---|
1848 | <dd>a dictionary providing additional context for evaluating parameters; |
---|
1849 | Note that this namespace is shared with other theory functions, so |
---|
1850 | populate it carefully.</dd> |
---|
1851 | </dl> |
---|
1852 | <dl class="method"> |
---|
1853 | <dt id="park.parameter.ParameterSet.byname"> |
---|
1854 | <tt class="descname">byname</tt><big>(</big><em>name</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet.byname"><span class="viewcode-link">[source]</span></a></dt> |
---|
1855 | <dd><p>Lookup parameter from dotted path</p> |
---|
1856 | </dd></dl> |
---|
1857 | |
---|
1858 | <dl class="attribute"> |
---|
1859 | <dt id="park.parameter.ParameterSet.computed"> |
---|
1860 | <tt class="descname">computed</tt></dt> |
---|
1861 | <dd><p>Return the subset of the parameters which are calculated</p> |
---|
1862 | </dd></dl> |
---|
1863 | |
---|
1864 | <dl class="attribute"> |
---|
1865 | <dt id="park.parameter.ParameterSet.fitted"> |
---|
1866 | <tt class="descname">fitted</tt></dt> |
---|
1867 | <dd><p>Return the subset of the paramters which are varying</p> |
---|
1868 | </dd></dl> |
---|
1869 | |
---|
1870 | <dl class="attribute"> |
---|
1871 | <dt id="park.parameter.ParameterSet.fixed"> |
---|
1872 | <tt class="descname">fixed</tt></dt> |
---|
1873 | <dd><p>Return the subset of the parameters which are fixed</p> |
---|
1874 | </dd></dl> |
---|
1875 | |
---|
1876 | <dl class="method"> |
---|
1877 | <dt id="park.parameter.ParameterSet.flatten"> |
---|
1878 | <tt class="descname">flatten</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet.flatten"><span class="viewcode-link">[source]</span></a></dt> |
---|
1879 | <dd><p>Iterate over the elements in depth first order.</p> |
---|
1880 | </dd></dl> |
---|
1881 | |
---|
1882 | <dl class="method"> |
---|
1883 | <dt id="park.parameter.ParameterSet.gather_context"> |
---|
1884 | <tt class="descname">gather_context</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet.gather_context"><span class="viewcode-link">[source]</span></a></dt> |
---|
1885 | <dd><p>Gather all additional symbols that can be used in expressions.</p> |
---|
1886 | <p>For example, if reflectometry provides a volume fraction |
---|
1887 | function volfrac(rho1,rho2,frac) to compute densities, then |
---|
1888 | this function can be added as a context dictionary to the |
---|
1889 | reflectometry parameter set. Note that there is no guarantee |
---|
1890 | which function will be used if the same function exists in |
---|
1891 | two separate contexts.</p> |
---|
1892 | </dd></dl> |
---|
1893 | |
---|
1894 | <dl class="attribute"> |
---|
1895 | <dt id="park.parameter.ParameterSet.name"> |
---|
1896 | <tt class="descname">name</tt></dt> |
---|
1897 | <dd><p>parameter name</p> |
---|
1898 | </dd></dl> |
---|
1899 | |
---|
1900 | <dl class="attribute"> |
---|
1901 | <dt id="park.parameter.ParameterSet.path"> |
---|
1902 | <tt class="descname">path</tt><em class="property"> = ''</em></dt> |
---|
1903 | <dd></dd></dl> |
---|
1904 | |
---|
1905 | <dl class="method"> |
---|
1906 | <dt id="park.parameter.ParameterSet.rename"> |
---|
1907 | <tt class="descname">rename</tt><big>(</big><em>par</em>, <em>name</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet.rename"><span class="viewcode-link">[source]</span></a></dt> |
---|
1908 | <dd><p>Rename the parameter to something new. |
---|
1909 | Called from root of the parameter hierarchy, rename the particular |
---|
1910 | parameter object to something else.</p> |
---|
1911 | <p>This changes the internal name of the parameter, as well as all |
---|
1912 | expressions in which it occurs. If the parameter is actually |
---|
1913 | a parameter set, then it renames all parameters in the set.</p> |
---|
1914 | </dd></dl> |
---|
1915 | |
---|
1916 | <dl class="attribute"> |
---|
1917 | <dt id="park.parameter.ParameterSet.restrained"> |
---|
1918 | <tt class="descname">restrained</tt></dt> |
---|
1919 | <dd><p>Return the subset of the parameters which have a likelihood |
---|
1920 | function associated with them.</p> |
---|
1921 | </dd></dl> |
---|
1922 | |
---|
1923 | <dl class="method"> |
---|
1924 | <dt id="park.parameter.ParameterSet.setprefix"> |
---|
1925 | <tt class="descname">setprefix</tt><big>(</big><em>prefix=None</em><big>)</big><a class="reference internal" href="../../_modules/park/parameter.html#ParameterSet.setprefix"><span class="viewcode-link">[source]</span></a></dt> |
---|
1926 | <dd><p>Fill in the full path name for all the parameters in the tree.</p> |
---|
1927 | <p>Note: this function must be called from the root parameter set |
---|
1928 | to build proper path names.</p> |
---|
1929 | <p>This is required before converting parameter expressions into |
---|
1930 | function calls.</p> |
---|
1931 | </dd></dl> |
---|
1932 | |
---|
1933 | </dd></dl> |
---|
1934 | |
---|
1935 | </div> |
---|
1936 | <div class="section" id="module-park.parkde"> |
---|
1937 | <span id="park-parkde-module"></span><h2>park.parkde module</h2> |
---|
1938 | <dl class="class"> |
---|
1939 | <dt id="park.parkde.DiffEv"> |
---|
1940 | <em class="property">class </em><tt class="descclassname">park.parkde.</tt><tt class="descname">DiffEv</tt><big>(</big><em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/parkde.html#DiffEv"><span class="viewcode-link">[source]</span></a></dt> |
---|
1941 | <dd><p>Bases: <a class="reference internal" href="#park.fit.Fitter" title="park.fit.Fitter"><tt class="xref py py-class docutils literal"><span class="pre">park.fit.Fitter</span></tt></a></p> |
---|
1942 | <p>Differential evolution optimizer</p> |
---|
1943 | <p>This implements <cite>park.fit.Fitter</cite>.</p> |
---|
1944 | <dl class="attribute"> |
---|
1945 | <dt id="park.parkde.DiffEv.Fscale"> |
---|
1946 | <tt class="descname">Fscale</tt><em class="property"> = 0.5</em></dt> |
---|
1947 | <dd><p>Step size along difference vector</p> |
---|
1948 | </dd></dl> |
---|
1949 | |
---|
1950 | <dl class="attribute"> |
---|
1951 | <dt id="park.parkde.DiffEv.crossover_rate"> |
---|
1952 | <tt class="descname">crossover_rate</tt><em class="property"> = 0.9</em></dt> |
---|
1953 | <dd><p>Amount of mixing in population</p> |
---|
1954 | </dd></dl> |
---|
1955 | |
---|
1956 | <dl class="method"> |
---|
1957 | <dt id="park.parkde.DiffEv.improvement"> |
---|
1958 | <tt class="descname">improvement</tt><big>(</big><em>x</em>, <em>fx</em>, <em>ncalls=-1</em><big>)</big><a class="reference internal" href="../../_modules/park/parkde.html#DiffEv.improvement"><span class="viewcode-link">[source]</span></a></dt> |
---|
1959 | <dd></dd></dl> |
---|
1960 | |
---|
1961 | <dl class="attribute"> |
---|
1962 | <dt id="park.parkde.DiffEv.maxiter"> |
---|
1963 | <tt class="descname">maxiter</tt><em class="property"> = 1000</em></dt> |
---|
1964 | <dd><p>Maximum number of iterations</p> |
---|
1965 | </dd></dl> |
---|
1966 | |
---|
1967 | <dl class="attribute"> |
---|
1968 | <dt id="park.parkde.DiffEv.pop_scale"> |
---|
1969 | <tt class="descname">pop_scale</tt><em class="property"> = 4</em></dt> |
---|
1970 | <dd><p>Number of active points per dimension</p> |
---|
1971 | </dd></dl> |
---|
1972 | |
---|
1973 | <dl class="method"> |
---|
1974 | <dt id="park.parkde.DiffEv.progress"> |
---|
1975 | <tt class="descname">progress</tt><big>(</big><em>k</em>, <em>n</em><big>)</big><a class="reference internal" href="../../_modules/park/parkde.html#DiffEv.progress"><span class="viewcode-link">[source]</span></a></dt> |
---|
1976 | <dd></dd></dl> |
---|
1977 | |
---|
1978 | <dl class="attribute"> |
---|
1979 | <dt id="park.parkde.DiffEv.tolerance"> |
---|
1980 | <tt class="descname">tolerance</tt><em class="property"> = 1e-05</em></dt> |
---|
1981 | <dd><p>Fit tolerance</p> |
---|
1982 | </dd></dl> |
---|
1983 | |
---|
1984 | </dd></dl> |
---|
1985 | |
---|
1986 | </div> |
---|
1987 | <div class="section" id="park-parksnob-module"> |
---|
1988 | <h2>park.parksnob module</h2> |
---|
1989 | </div> |
---|
1990 | <div class="section" id="module-park.peaks"> |
---|
1991 | <span id="park-peaks-module"></span><h2>park.peaks module</h2> |
---|
1992 | <p>A park model implementing a multipeak fitter.</p> |
---|
1993 | <p><strong>* WARNING *</strong> this example was used to inform the design process, |
---|
1994 | and has not yet been updated to correspond to the current implementation. |
---|
1995 | Do not use this as a tutorial.</p> |
---|
1996 | <p>This is an example model showing how to put together a multi-part |
---|
1997 | fit objective function.</p> |
---|
1998 | <table class="docutils field-list" frame="void" rules="none"> |
---|
1999 | <col class="field-name" /> |
---|
2000 | <col class="field-body" /> |
---|
2001 | <tbody valign="top"> |
---|
2002 | <tr class="field-odd field"><th class="field-name">group main:</th><td class="field-body">Peaks</td> |
---|
2003 | </tr> |
---|
2004 | <tr class="field-even field"><th class="field-name">group peaks:</th><td class="field-body">Gaussian, Lorentzian, Voigt</td> |
---|
2005 | </tr> |
---|
2006 | <tr class="field-odd field"><th class="field-name" colspan="2">group backgrounds:</th></tr> |
---|
2007 | <tr class="field-odd field"><td> </td><td class="field-body">Constant, Quadratic, Linear</td> |
---|
2008 | </tr> |
---|
2009 | </tbody> |
---|
2010 | </table> |
---|
2011 | <dl class="class"> |
---|
2012 | <dt id="park.peaks.Constant"> |
---|
2013 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Constant</tt><big>(</big><em>name</em>, <em>C=0</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Constant"><span class="viewcode-link">[source]</span></a></dt> |
---|
2014 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2015 | <p>Constant background: C</p> |
---|
2016 | <dl class="method"> |
---|
2017 | <dt id="park.peaks.Constant.dC"> |
---|
2018 | <tt class="descname">dC</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Constant.dC"><span class="viewcode-link">[source]</span></a></dt> |
---|
2019 | <dd></dd></dl> |
---|
2020 | |
---|
2021 | <dl class="attribute"> |
---|
2022 | <dt id="park.peaks.Constant.name"> |
---|
2023 | <tt class="descname">name</tt><em class="property"> = 'Background: constant'</em></dt> |
---|
2024 | <dd></dd></dl> |
---|
2025 | |
---|
2026 | </dd></dl> |
---|
2027 | |
---|
2028 | <dl class="class"> |
---|
2029 | <dt id="park.peaks.Gaussian"> |
---|
2030 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Gaussian</tt><big>(</big><em>name</em>, <em>scale=1.0</em>, <em>center=0</em>, <em>sigma=1</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Gaussian"><span class="viewcode-link">[source]</span></a></dt> |
---|
2031 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2032 | <p>Gaussian peak: scale exp ( -0.5 (x-center)**2 / sigma**2 )</p> |
---|
2033 | <dl class="method"> |
---|
2034 | <dt id="park.peaks.Gaussian.dcenter"> |
---|
2035 | <tt class="descname">dcenter</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Gaussian.dcenter"><span class="viewcode-link">[source]</span></a></dt> |
---|
2036 | <dd></dd></dl> |
---|
2037 | |
---|
2038 | <dl class="method"> |
---|
2039 | <dt id="park.peaks.Gaussian.dscale"> |
---|
2040 | <tt class="descname">dscale</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Gaussian.dscale"><span class="viewcode-link">[source]</span></a></dt> |
---|
2041 | <dd></dd></dl> |
---|
2042 | |
---|
2043 | <dl class="method"> |
---|
2044 | <dt id="park.peaks.Gaussian.dsigma"> |
---|
2045 | <tt class="descname">dsigma</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Gaussian.dsigma"><span class="viewcode-link">[source]</span></a></dt> |
---|
2046 | <dd></dd></dl> |
---|
2047 | |
---|
2048 | </dd></dl> |
---|
2049 | |
---|
2050 | <dl class="class"> |
---|
2051 | <dt id="park.peaks.Linear"> |
---|
2052 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Linear</tt><big>(</big><em>name</em>, <em>B=0</em>, <em>C=0</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Linear"><span class="viewcode-link">[source]</span></a></dt> |
---|
2053 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2054 | <p>Linear background: B x**2 + C</p> |
---|
2055 | <dl class="method"> |
---|
2056 | <dt id="park.peaks.Linear.dB"> |
---|
2057 | <tt class="descname">dB</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Linear.dB"><span class="viewcode-link">[source]</span></a></dt> |
---|
2058 | <dd></dd></dl> |
---|
2059 | |
---|
2060 | <dl class="method"> |
---|
2061 | <dt id="park.peaks.Linear.dC"> |
---|
2062 | <tt class="descname">dC</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Linear.dC"><span class="viewcode-link">[source]</span></a></dt> |
---|
2063 | <dd></dd></dl> |
---|
2064 | |
---|
2065 | <dl class="attribute"> |
---|
2066 | <dt id="park.peaks.Linear.name"> |
---|
2067 | <tt class="descname">name</tt><em class="property"> = 'Background: linear'</em></dt> |
---|
2068 | <dd></dd></dl> |
---|
2069 | |
---|
2070 | </dd></dl> |
---|
2071 | |
---|
2072 | <dl class="class"> |
---|
2073 | <dt id="park.peaks.Lorentzian"> |
---|
2074 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Lorentzian</tt><big>(</big><em>name</em>, <em>scale=1.0</em>, <em>center=0</em>, <em>gamma=1</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Lorentzian"><span class="viewcode-link">[source]</span></a></dt> |
---|
2075 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2076 | <p>Lorentzian peak (HWHM): scale/pi gamma/((x-center)**2 + gamma**2)</p> |
---|
2077 | <dl class="method"> |
---|
2078 | <dt id="park.peaks.Lorentzian.dcenter"> |
---|
2079 | <tt class="descname">dcenter</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Lorentzian.dcenter"><span class="viewcode-link">[source]</span></a></dt> |
---|
2080 | <dd></dd></dl> |
---|
2081 | |
---|
2082 | <dl class="method"> |
---|
2083 | <dt id="park.peaks.Lorentzian.dgamma"> |
---|
2084 | <tt class="descname">dgamma</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Lorentzian.dgamma"><span class="viewcode-link">[source]</span></a></dt> |
---|
2085 | <dd></dd></dl> |
---|
2086 | |
---|
2087 | <dl class="method"> |
---|
2088 | <dt id="park.peaks.Lorentzian.dscale"> |
---|
2089 | <tt class="descname">dscale</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Lorentzian.dscale"><span class="viewcode-link">[source]</span></a></dt> |
---|
2090 | <dd></dd></dl> |
---|
2091 | |
---|
2092 | </dd></dl> |
---|
2093 | |
---|
2094 | <dl class="class"> |
---|
2095 | <dt id="park.peaks.Peaks"> |
---|
2096 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Peaks</tt><big>(</big><em>datafile=None</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Peaks"><span class="viewcode-link">[source]</span></a></dt> |
---|
2097 | <dd><p>Bases: <a class="reference internal" href="#park.model.Model" title="park.model.Model"><tt class="xref py py-class docutils literal"><span class="pre">park.model.Model</span></tt></a></p> |
---|
2098 | <p>Peak fitter</p> |
---|
2099 | <dl class="method"> |
---|
2100 | <dt id="park.peaks.Peaks.add_peak"> |
---|
2101 | <tt class="descname">add_peak</tt><big>(</big><em>type</em>, <em>name=None</em>, <em>**kw</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Peaks.add_peak"><span class="viewcode-link">[source]</span></a></dt> |
---|
2102 | <dd><p>Add a peak to the model.</p> |
---|
2103 | <p>The name of the peak is used to distinguish it from other peaks |
---|
2104 | in the model, and appears as part of the parameter name in |
---|
2105 | constraint expressions. For example, if name is ‘P3’ and this |
---|
2106 | is part of model ‘M1’ then the sigma parameter of a gaussian |
---|
2107 | peak would be ‘M1.P3.sigma’.</p> |
---|
2108 | <p>The peak can be specified either by peak type and initial arguments |
---|
2109 | or by the peak itself, which is a function of x with a parameters |
---|
2110 | attribute.</p> |
---|
2111 | <dl class="docutils"> |
---|
2112 | <dt>Available peak types include:</dt> |
---|
2113 | <dd><dl class="first last docutils"> |
---|
2114 | <dt>gaussian(scale=1, center=0, sigma=1) </dt> |
---|
2115 | <dd>= scale exp ( -0.5 (x-center)**2 / sigma**2 )</dd> |
---|
2116 | <dt>lorentzian(scale=1, center=0, gamma=1) </dt> |
---|
2117 | <dd>= scale/pi gamma / ((x-center)**2 + gamma**2))</dd> |
---|
2118 | <dt>voigt(scale=1, center=0, sigma=1, gamma=1)</dt> |
---|
2119 | <dd>= scale (lorentzian(mu,gamma) * gaussian(mu,sigma))(x-center) |
---|
2120 | where * represents convolution</dd> |
---|
2121 | </dl> |
---|
2122 | </dd> |
---|
2123 | <dt>Available background functions include:</dt> |
---|
2124 | <dd><dl class="first last docutils"> |
---|
2125 | <dt>constant(C=0)</dt> |
---|
2126 | <dd>= C</dd> |
---|
2127 | <dt>slope(C=0, B=1)</dt> |
---|
2128 | <dd>= B x + C</dd> |
---|
2129 | <dt>quadratic(A=1, B=0, C=0)</dt> |
---|
2130 | <dd>= A x**2 + B x + C</dd> |
---|
2131 | </dl> |
---|
2132 | </dd> |
---|
2133 | </dl> |
---|
2134 | <p>Additional peak types can be registered. The complete dictionary |
---|
2135 | of available types is in Peaks.peak_types.</p> |
---|
2136 | </dd></dl> |
---|
2137 | |
---|
2138 | <dl class="method"> |
---|
2139 | <dt id="park.peaks.Peaks.eval"> |
---|
2140 | <tt class="descname">eval</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Peaks.eval"><span class="viewcode-link">[source]</span></a></dt> |
---|
2141 | <dd><p>Returns the raw theory value at x, unconvoluted and unweighted.</p> |
---|
2142 | <p>The residuals will be calculated by park.Model.residuals by |
---|
2143 | calling</p> |
---|
2144 | </dd></dl> |
---|
2145 | |
---|
2146 | <dl class="attribute"> |
---|
2147 | <dt id="park.peaks.Peaks.parameters"> |
---|
2148 | <tt class="descname">parameters</tt><em class="property"> = []</em></dt> |
---|
2149 | <dd></dd></dl> |
---|
2150 | |
---|
2151 | <dl class="attribute"> |
---|
2152 | <dt id="park.peaks.Peaks.parameterset"> |
---|
2153 | <tt class="descname">parameterset</tt><em class="property"> = []</em></dt> |
---|
2154 | <dd></dd></dl> |
---|
2155 | |
---|
2156 | <dl class="attribute"> |
---|
2157 | <dt id="park.peaks.Peaks.peak_types"> |
---|
2158 | <tt class="descname">peak_types</tt><em class="property"> = {'Constant': <class 'park.peaks.Constant'>, 'Linear': <class 'park.peaks.Linear'>, 'Gaussian': <class 'park.peaks.Gaussian'>, 'Quadratic': <class 'park.peaks.Quadratic'>, 'Voigt': <class 'park.peaks.Voigt'>, 'Lorentzian': <class 'park.peaks.Lorentzian'>}</em></dt> |
---|
2159 | <dd></dd></dl> |
---|
2160 | |
---|
2161 | <dl class="classmethod"> |
---|
2162 | <dt id="park.peaks.Peaks.register_peak_generator"> |
---|
2163 | <em class="property">classmethod </em><tt class="descname">register_peak_generator</tt><big>(</big><em>type</em>, <em>factory</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Peaks.register_peak_generator"><span class="viewcode-link">[source]</span></a></dt> |
---|
2164 | <dd><p>Register a new peak generator. This will return a callable |
---|
2165 | object with a parameter set that can be used in the peak |
---|
2166 | fitting class.</p> |
---|
2167 | <p>The individual peak functions a number of attributes:</p> |
---|
2168 | <dl class="docutils"> |
---|
2169 | <dt>__name__</dt> |
---|
2170 | <dd>the name to be displayed in the list of peaks; the |
---|
2171 | default is __class__.__name__</dd> |
---|
2172 | <dt>__factory__</dt> |
---|
2173 | <dd>the name of a factory function in the python |
---|
2174 | namespace which returns a new peak. These parameters |
---|
2175 | will be set from the stored parameter list when the |
---|
2176 | peak model is reloaded. This can be omitted if it |
---|
2177 | is simply the module and name of the class.</dd> |
---|
2178 | <dt>__doc__</dt> |
---|
2179 | <dd>the tool tip to be displayed with the peak</dd> |
---|
2180 | <dt>__call__(x)</dt> |
---|
2181 | <dd>evaluate the peak function at x</dd> |
---|
2182 | </dl> |
---|
2183 | </dd></dl> |
---|
2184 | |
---|
2185 | <dl class="method"> |
---|
2186 | <dt id="park.peaks.Peaks.remove_peak"> |
---|
2187 | <tt class="descname">remove_peak</tt><big>(</big><em>name</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Peaks.remove_peak"><span class="viewcode-link">[source]</span></a></dt> |
---|
2188 | <dd><p>Remove the named peak from the model.</p> |
---|
2189 | </dd></dl> |
---|
2190 | |
---|
2191 | </dd></dl> |
---|
2192 | |
---|
2193 | <dl class="class"> |
---|
2194 | <dt id="park.peaks.Quadratic"> |
---|
2195 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Quadratic</tt><big>(</big><em>name</em>, <em>A=1</em>, <em>B=0</em>, <em>C=0</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Quadratic"><span class="viewcode-link">[source]</span></a></dt> |
---|
2196 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2197 | <p>Quadratic background: A x**2 + B x + C</p> |
---|
2198 | <dl class="method"> |
---|
2199 | <dt id="park.peaks.Quadratic.dA"> |
---|
2200 | <tt class="descname">dA</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Quadratic.dA"><span class="viewcode-link">[source]</span></a></dt> |
---|
2201 | <dd></dd></dl> |
---|
2202 | |
---|
2203 | <dl class="method"> |
---|
2204 | <dt id="park.peaks.Quadratic.dB"> |
---|
2205 | <tt class="descname">dB</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Quadratic.dB"><span class="viewcode-link">[source]</span></a></dt> |
---|
2206 | <dd></dd></dl> |
---|
2207 | |
---|
2208 | <dl class="method"> |
---|
2209 | <dt id="park.peaks.Quadratic.dC"> |
---|
2210 | <tt class="descname">dC</tt><big>(</big><em>x</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Quadratic.dC"><span class="viewcode-link">[source]</span></a></dt> |
---|
2211 | <dd></dd></dl> |
---|
2212 | |
---|
2213 | <dl class="attribute"> |
---|
2214 | <dt id="park.peaks.Quadratic.name"> |
---|
2215 | <tt class="descname">name</tt><em class="property"> = 'Background: quadratic'</em></dt> |
---|
2216 | <dd></dd></dl> |
---|
2217 | |
---|
2218 | </dd></dl> |
---|
2219 | |
---|
2220 | <dl class="class"> |
---|
2221 | <dt id="park.peaks.Voigt"> |
---|
2222 | <em class="property">class </em><tt class="descclassname">park.peaks.</tt><tt class="descname">Voigt</tt><big>(</big><em>name</em>, <em>scale=1</em>, <em>center=0</em>, <em>sigma=1</em>, <em>gamma=1</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#Voigt"><span class="viewcode-link">[source]</span></a></dt> |
---|
2223 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2224 | <p>Voigt peak (HWHM,sigma): A [G(sigma) * L(gamma)](x-center)</p> |
---|
2225 | </dd></dl> |
---|
2226 | |
---|
2227 | <dl class="function"> |
---|
2228 | <dt id="park.peaks.init"> |
---|
2229 | <tt class="descclassname">park.peaks.</tt><tt class="descname">init</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#init"><span class="viewcode-link">[source]</span></a></dt> |
---|
2230 | <dd><p>Register peak types with the Peaks model.</p> |
---|
2231 | </dd></dl> |
---|
2232 | |
---|
2233 | <dl class="function"> |
---|
2234 | <dt id="park.peaks.test"> |
---|
2235 | <tt class="descclassname">park.peaks.</tt><tt class="descname">test</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#test"><span class="viewcode-link">[source]</span></a></dt> |
---|
2236 | <dd></dd></dl> |
---|
2237 | |
---|
2238 | <dl class="function"> |
---|
2239 | <dt id="park.peaks.voigt"> |
---|
2240 | <tt class="descclassname">park.peaks.</tt><tt class="descname">voigt</tt><big>(</big><em>x</em>, <em>sigma</em>, <em>gamma</em><big>)</big><a class="reference internal" href="../../_modules/park/peaks.html#voigt"><span class="viewcode-link">[source]</span></a></dt> |
---|
2241 | <dd><p>Return the voigt function, which is the convolution of a Lorentz |
---|
2242 | function with a Gaussian.</p> |
---|
2243 | <table class="docutils field-list" frame="void" rules="none"> |
---|
2244 | <col class="field-name" /> |
---|
2245 | <col class="field-body" /> |
---|
2246 | <tbody valign="top"> |
---|
2247 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><dl class="first last docutils"> |
---|
2248 | <dt>gamma <span class="classifier-delimiter">:</span> <span class="classifier">real</span></dt> |
---|
2249 | <dd><p class="first last">The half-width half-maximum of the Lorentzian</p> |
---|
2250 | </dd> |
---|
2251 | <dt>sigma <span class="classifier-delimiter">:</span> <span class="classifier">real</span></dt> |
---|
2252 | <dd><p class="first last">The 1-sigma width of the Gaussian, which is one standard deviation.</p> |
---|
2253 | </dd> |
---|
2254 | </dl> |
---|
2255 | </td> |
---|
2256 | </tr> |
---|
2257 | </tbody> |
---|
2258 | </table> |
---|
2259 | <p>Ref: W.I.F. David, J. Appl. Cryst. (1986). 19, 63-64</p> |
---|
2260 | <p>Note: adjusted to use stddev and HWHM rather than FWHM parameters</p> |
---|
2261 | </dd></dl> |
---|
2262 | |
---|
2263 | </div> |
---|
2264 | <div class="section" id="module-park.pmap"> |
---|
2265 | <span id="park-pmap-module"></span><h2>park.pmap module</h2> |
---|
2266 | <p>Parallel map-reduce implementation using threads.</p> |
---|
2267 | <dl class="class"> |
---|
2268 | <dt id="park.pmap.Collector"> |
---|
2269 | <em class="property">class </em><tt class="descclassname">park.pmap.</tt><tt class="descname">Collector</tt><a class="reference internal" href="../../_modules/park/pmap.html#Collector"><span class="viewcode-link">[source]</span></a></dt> |
---|
2270 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2271 | <p>Abstract interface to map-reduce accumulator function.</p> |
---|
2272 | <dl class="method"> |
---|
2273 | <dt id="park.pmap.Collector.error"> |
---|
2274 | <tt class="descname">error</tt><big>(</big><em>part</em>, <em>msg</em><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#Collector.error"><span class="viewcode-link">[source]</span></a></dt> |
---|
2275 | <dd><p>Exception seen on executing map or reduce. The collector |
---|
2276 | can adjust the accumulated result appropriately to reflect |
---|
2277 | the error.</p> |
---|
2278 | </dd></dl> |
---|
2279 | |
---|
2280 | <dl class="method"> |
---|
2281 | <dt id="park.pmap.Collector.finalize"> |
---|
2282 | <tt class="descname">finalize</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#Collector.finalize"><span class="viewcode-link">[source]</span></a></dt> |
---|
2283 | <dd><p>Called when all parts have been accumulated</p> |
---|
2284 | </dd></dl> |
---|
2285 | |
---|
2286 | </dd></dl> |
---|
2287 | |
---|
2288 | <dl class="class"> |
---|
2289 | <dt id="park.pmap.Mapper"> |
---|
2290 | <em class="property">class </em><tt class="descclassname">park.pmap.</tt><tt class="descname">Mapper</tt><a class="reference internal" href="../../_modules/park/pmap.html#Mapper"><span class="viewcode-link">[source]</span></a></dt> |
---|
2291 | <dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p> |
---|
2292 | <p>Abstract interface to map-reduce mapper function.</p> |
---|
2293 | <dl class="method"> |
---|
2294 | <dt id="park.pmap.Mapper.abort"> |
---|
2295 | <tt class="descname">abort</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#Mapper.abort"><span class="viewcode-link">[source]</span></a></dt> |
---|
2296 | <dd><p>Stop the mapper</p> |
---|
2297 | </dd></dl> |
---|
2298 | |
---|
2299 | </dd></dl> |
---|
2300 | |
---|
2301 | <dl class="function"> |
---|
2302 | <dt id="park.pmap.main"> |
---|
2303 | <tt class="descclassname">park.pmap.</tt><tt class="descname">main</tt><big>(</big><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#main"><span class="viewcode-link">[source]</span></a></dt> |
---|
2304 | <dd></dd></dl> |
---|
2305 | |
---|
2306 | <dl class="function"> |
---|
2307 | <dt id="park.pmap.pmap"> |
---|
2308 | <tt class="descclassname">park.pmap.</tt><tt class="descname">pmap</tt><big>(</big><em>mapper</em>, <em>inputs</em><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#pmap"><span class="viewcode-link">[source]</span></a></dt> |
---|
2309 | <dd><p>Apply function mapper to all inputs.</p> |
---|
2310 | <p>This is the serial version of a parallel iterator, yielding the next |
---|
2311 | sequence value as soon as it is available. There is no guarantee |
---|
2312 | that the order of the inputs will be preserved in the parallel |
---|
2313 | version, so don’t depend on it!</p> |
---|
2314 | </dd></dl> |
---|
2315 | |
---|
2316 | <dl class="function"> |
---|
2317 | <dt id="park.pmap.pmapreduce"> |
---|
2318 | <tt class="descclassname">park.pmap.</tt><tt class="descname">pmapreduce</tt><big>(</big><em>mapper</em>, <em>collector</em>, <em>inputs</em><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#pmapreduce"><span class="viewcode-link">[source]</span></a></dt> |
---|
2319 | <dd><p>Apply function mapper to inputs, accumulating the results in collector.</p> |
---|
2320 | <p>Collector is a function which accepts the result of mapper(item) for |
---|
2321 | each item of inputs. There is no guarantee that the outputs will be |
---|
2322 | received in order.</p> |
---|
2323 | <p>The map is executed in a separate thread so the function returns |
---|
2324 | to the caller immediately.</p> |
---|
2325 | </dd></dl> |
---|
2326 | |
---|
2327 | <dl class="function"> |
---|
2328 | <dt id="park.pmap.preduce"> |
---|
2329 | <tt class="descclassname">park.pmap.</tt><tt class="descname">preduce</tt><big>(</big><em>collector</em>, <em>outputs</em><big>)</big><a class="reference internal" href="../../_modules/park/pmap.html#preduce"><span class="viewcode-link">[source]</span></a></dt> |
---|
2330 | <dd><p>Collect all outputs, calling collector(item) for each item in the sequence.</p> |
---|
2331 | </dd></dl> |
---|
2332 | |
---|
2333 | <dl class="data"> |
---|
2334 | <dt id="park.pmap.profile_mapper"> |
---|
2335 | <tt class="descclassname">park.pmap.</tt><tt class="descname">profile_mapper</tt><em class="property"> = False</em></dt> |
---|
2336 | <dd><p>True if the mapper cost should be profiled.</p> |
---|
2337 | </dd></dl> |
---|
2338 | |
---|
2339 | </div> |
---|
2340 | <div class="section" id="park-rangemap-module"> |
---|
2341 | <h2>park.rangemap module</h2> |
---|
2342 | </div> |
---|
2343 | <div class="section" id="park-serial-module"> |
---|
2344 | <h2>park.serial module</h2> |
---|
2345 | </div> |
---|
2346 | <div class="section" id="module-park.setup"> |
---|
2347 | <span id="park-setup-module"></span><h2>park.setup module</h2> |
---|
2348 | <dl class="function"> |
---|
2349 | <dt id="park.setup.configuration"> |
---|
2350 | <tt class="descclassname">park.setup.</tt><tt class="descname">configuration</tt><big>(</big><em>parent_package=''</em>, <em>top_path=None</em><big>)</big><a class="reference internal" href="../../_modules/park/setup.html#configuration"><span class="viewcode-link">[source]</span></a></dt> |
---|
2351 | <dd></dd></dl> |
---|
2352 | |
---|
2353 | </div> |
---|
2354 | <div class="section" id="module-park.simplex"> |
---|
2355 | <span id="park-simplex-module"></span><h2>park.simplex module</h2> |
---|
2356 | <p>Downhill simplex optimizer.</p> |
---|
2357 | <dl class="function"> |
---|
2358 | <dt id="park.simplex.simplex"> |
---|
2359 | <tt class="descclassname">park.simplex.</tt><tt class="descname">simplex</tt><big>(</big><em>f</em>, <em>x0=None</em>, <em>bounds=None</em>, <em>radius=0.05</em>, <em>xtol=0.0001</em>, <em>ftol=0.0001</em>, <em>maxiter=None</em>, <em>update_handler=None</em>, <em>abort_test=<function dont_abort at 0x105341500></em><big>)</big><a class="reference internal" href="../../_modules/park/simplex.html#simplex"><span class="viewcode-link">[source]</span></a></dt> |
---|
2360 | <dd><p>Minimize a function using Nelder-Mead downhill simplex algorithm.</p> |
---|
2361 | <p>This optimizer is also known as Amoeba (from Numerical Recipes) and |
---|
2362 | the Nealder-Mead simplex algorithm. This is not the simplex algorithm |
---|
2363 | for solving constrained linear systems.</p> |
---|
2364 | <p>Downhill simplex is a robust derivative free algorithm for finding |
---|
2365 | minima. It proceeds by choosing a set of points (the simplex) forming |
---|
2366 | an n-dimensional triangle, and transforming that triangle so that the |
---|
2367 | worst vertex is improved, either by stretching, shrinking or reflecting |
---|
2368 | it about the center of the triangle. This algorithm is not known for |
---|
2369 | its speed, but for its simplicity and robustness, and is a good algorithm |
---|
2370 | to start your problem with.</p> |
---|
2371 | <p><em>Parameters</em>:</p> |
---|
2372 | <blockquote> |
---|
2373 | <div><dl class="docutils"> |
---|
2374 | <dt>f <span class="classifier-delimiter">:</span> <span class="classifier">callable f(x,*args)</span></dt> |
---|
2375 | <dd>The objective function to be minimized.</dd> |
---|
2376 | <dt>x0 <span class="classifier-delimiter">:</span> <span class="classifier">ndarray</span></dt> |
---|
2377 | <dd>Initial guess.</dd> |
---|
2378 | <dt>bounds <span class="classifier-delimiter">:</span> <span class="classifier">(ndarray,ndarray) or None</span></dt> |
---|
2379 | <dd>Bounds on the parameter values for the function.</dd> |
---|
2380 | <dt>radius: float</dt> |
---|
2381 | <dd>Size of the initial simplex. For bounded parameters (those |
---|
2382 | which have finite lower and upper bounds), radius is clipped |
---|
2383 | to a value in (0,0.5] representing the portion of the |
---|
2384 | range to use as the size of the initial simplex.</dd> |
---|
2385 | </dl> |
---|
2386 | </div></blockquote> |
---|
2387 | <p><em>Returns</em>: Result (<cite>park.simplex.Result</cite>)</p> |
---|
2388 | <blockquote> |
---|
2389 | <div><dl class="docutils"> |
---|
2390 | <dt>x <span class="classifier-delimiter">:</span> <span class="classifier">ndarray</span></dt> |
---|
2391 | <dd>Parameter that minimizes function.</dd> |
---|
2392 | <dt>fx <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt> |
---|
2393 | <dd>Value of function at minimum: <tt class="docutils literal"><span class="pre">fopt</span> <span class="pre">=</span> <span class="pre">func(xopt)</span></tt>.</dd> |
---|
2394 | <dt>iters <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt> |
---|
2395 | <dd>Number of iterations performed.</dd> |
---|
2396 | <dt>calls <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt> |
---|
2397 | <dd>Number of function calls made.</dd> |
---|
2398 | <dt>success <span class="classifier-delimiter">:</span> <span class="classifier">boolean</span></dt> |
---|
2399 | <dd>True if fit completed successfully.</dd> |
---|
2400 | </dl> |
---|
2401 | </div></blockquote> |
---|
2402 | <p><em>Other Parameters</em>:</p> |
---|
2403 | <blockquote> |
---|
2404 | <div><dl class="docutils"> |
---|
2405 | <dt>xtol <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt> |
---|
2406 | <dd>Relative error in xopt acceptable for convergence.</dd> |
---|
2407 | <dt>ftol <span class="classifier-delimiter">:</span> <span class="classifier">number</span></dt> |
---|
2408 | <dd>Relative error in func(xopt) acceptable for convergence.</dd> |
---|
2409 | <dt>maxiter <span class="classifier-delimiter">:</span> <span class="classifier">int=200*N</span></dt> |
---|
2410 | <dd>Maximum number of iterations to perform. Defaults</dd> |
---|
2411 | <dt>update_handler <span class="classifier-delimiter">:</span> <span class="classifier">callable</span></dt> |
---|
2412 | <dd>Called after each iteration, as callback(xk,fxk), where xk |
---|
2413 | is the current parameter vector and fxk is the function value. |
---|
2414 | Returns True if the fit should continue.</dd> |
---|
2415 | </dl> |
---|
2416 | </div></blockquote> |
---|
2417 | <p><em>Notes</em></p> |
---|
2418 | <blockquote> |
---|
2419 | <div>Uses a Nelder-Mead simplex algorithm to find the minimum of |
---|
2420 | function of one or more variables.</div></blockquote> |
---|
2421 | </dd></dl> |
---|
2422 | |
---|
2423 | </div> |
---|
2424 | <div class="section" id="module-park.version"> |
---|
2425 | <span id="park-version-module"></span><h2>park.version module</h2> |
---|
2426 | <p>version and package information about PARK.</p> |
---|
2427 | </div> |
---|
2428 | <div class="section" id="module-park.wxmonitor"> |
---|
2429 | <span id="park-wxmonitor-module"></span><h2>park.wxmonitor module</h2> |
---|
2430 | <p>Asynchronous monitoring service for wx applications.</p> |
---|
2431 | <p>Define a monitor using park.wxmonitor.wxMonitor(panel) where panel is |
---|
2432 | the window which will receive the monitor updates.</p> |
---|
2433 | <p>In panel, be sure to have methods for onMonitorStart(message), |
---|
2434 | onMonitorProgress(message), etc., for the kinds of monitor messages |
---|
2435 | the application will send. The catch-all method is onMonitorMessage, |
---|
2436 | which by default will print the messages on the console. If you |
---|
2437 | don’t catch onMonitorLog messages then the log messages will be |
---|
2438 | sent to the standard python logger.</p> |
---|
2439 | <p>See <cite>park.monitor</cite> for details on the message types.</p> |
---|
2440 | <div class="section" id="example"> |
---|
2441 | <h3>Example</h3> |
---|
2442 | <p>The following defines a panel which responds to monitor messages:</p> |
---|
2443 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">wx</span> |
---|
2444 | |
---|
2445 | <span class="k">class</span> <span class="nc">Panel</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">Panel</span><span class="p">):</span> |
---|
2446 | <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span> |
---|
2447 | <span class="n">wx</span><span class="o">.</span><span class="n">Panel</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span> |
---|
2448 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">TextCtrl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span><span class="mi">100</span><span class="p">),</span> <span class="n">style</span><span class="o">=</span><span class="n">wx</span><span class="o">.</span><span class="n">TE_MULTILINE</span><span class="p">)</span> |
---|
2449 | <span class="bp">self</span><span class="o">.</span><span class="n">gauge</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Gauge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">range</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> |
---|
2450 | <span class="n">sizer</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">BoxSizer</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">VERTICAL</span><span class="p">)</span> |
---|
2451 | <span class="n">sizer</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">wx</span><span class="o">.</span><span class="n">LEFT</span> <span class="o">|</span> <span class="n">wx</span><span class="o">.</span><span class="n">EXPAND</span><span class="p">)</span> |
---|
2452 | <span class="n">sizer</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gauge</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">wx</span><span class="o">.</span><span class="n">LEFT</span> <span class="o">|</span> <span class="n">wx</span><span class="o">.</span><span class="n">EXPAND</span><span class="p">)</span> |
---|
2453 | <span class="bp">self</span><span class="o">.</span><span class="n">SetSizer</span><span class="p">(</span><span class="n">sizer</span><span class="p">)</span> |
---|
2454 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="s">'starting value'</span><span class="p">)</span> |
---|
2455 | <span class="k">def</span> <span class="nf">onMonitorMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span> |
---|
2456 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">))</span> |
---|
2457 | <span class="k">def</span> <span class="nf">onMonitorStart</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span> |
---|
2458 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">))</span> |
---|
2459 | <span class="bp">self</span><span class="o">.</span><span class="n">gauge</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> |
---|
2460 | <span class="k">def</span> <span class="nf">onMonitorProgress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span> |
---|
2461 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">))</span> |
---|
2462 | <span class="bp">self</span><span class="o">.</span><span class="n">gauge</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="n">message</span><span class="o">.</span><span class="n">complete</span><span class="o">/</span><span class="n">message</span><span class="o">.</span><span class="n">total</span><span class="p">))</span> |
---|
2463 | <span class="k">def</span> <span class="nf">onMonitorComplete</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span> |
---|
2464 | <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">))</span> |
---|
2465 | <span class="bp">self</span><span class="o">.</span><span class="n">gauge</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span> |
---|
2466 | </pre></div> |
---|
2467 | </div> |
---|
2468 | <p>We can put this panel in a simple app:</p> |
---|
2469 | <div class="highlight-python"><div class="highlight"><pre><span class="n">app</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">PySimpleApp</span><span class="p">()</span> |
---|
2470 | <span class="n">frame</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s">'Test Monitor'</span><span class="p">)</span> |
---|
2471 | <span class="n">panel</span> <span class="o">=</span> <span class="n">Panel</span><span class="p">(</span><span class="n">frame</span><span class="p">)</span> |
---|
2472 | <span class="n">frame</span><span class="o">.</span><span class="n">Show</span><span class="p">()</span> |
---|
2473 | </pre></div> |
---|
2474 | </div> |
---|
2475 | <p>Next we attach attach the monitor to this panel and feed some messages from |
---|
2476 | another thread:</p> |
---|
2477 | <div class="highlight-python"><div class="highlight"><pre>import time,thread |
---|
2478 | import park.wxmonitor, park.monitor |
---|
2479 | from park.monitor import Start, Progress, Improvement, Complete |
---|
2480 | monitor = park.wxmonitor.wxMonitor(panel) |
---|
2481 | msgs = [Start(), Progress(1,10), Progress(3,10), |
---|
2482 | Improvement('Better!'), Progerss(6,10), Complete('Best!')]: |
---|
2483 | def message_stream(monitor,msgs): |
---|
2484 | time.sleep(1) |
---|
2485 | for message in msgs: |
---|
2486 | monitor.put(message) |
---|
2487 | time.sleep(1) |
---|
2488 | thread.start_new_thread(message_stream, (monitor,msgs)) |
---|
2489 | app.MainLoop() |
---|
2490 | </pre></div> |
---|
2491 | </div> |
---|
2492 | <p>You should see the progress bar jump from 10% to 30% to 60% then all the way |
---|
2493 | to the end.</p> |
---|
2494 | <dl class="function"> |
---|
2495 | <dt id="park.wxmonitor.demo"> |
---|
2496 | <tt class="descclassname">park.wxmonitor.</tt><tt class="descname">demo</tt><big>(</big><em>rate=0</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#demo"><span class="viewcode-link">[source]</span></a></dt> |
---|
2497 | <dd></dd></dl> |
---|
2498 | |
---|
2499 | <dl class="class"> |
---|
2500 | <dt id="park.wxmonitor.wxMonitor"> |
---|
2501 | <em class="property">class </em><tt class="descclassname">park.wxmonitor.</tt><tt class="descname">wxMonitor</tt><big>(</big><em>win</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#wxMonitor"><span class="viewcode-link">[source]</span></a></dt> |
---|
2502 | <dd><p>Bases: <a class="reference internal" href="#park.monitor.Monitor" title="park.monitor.Monitor"><tt class="xref py py-class docutils literal"><span class="pre">park.monitor.Monitor</span></tt></a></p> |
---|
2503 | <p>Attach a job monitor to a panel.</p> |
---|
2504 | <p>The monitor will perform callbacks to onMonitorStart(message), |
---|
2505 | onMonitorProgress(message), etc. if the associated method is |
---|
2506 | defined. If the type specific method is not defined, then the |
---|
2507 | monitor will call onMonitorMessage(message). Otherwise the |
---|
2508 | message is dropped.</p> |
---|
2509 | <p>See <cite>park.monitor</cite> for a description of the usual messages.</p> |
---|
2510 | <dl class="method"> |
---|
2511 | <dt id="park.wxmonitor.wxMonitor.dispatch"> |
---|
2512 | <tt class="descname">dispatch</tt><big>(</big><em>event</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#wxMonitor.dispatch"><span class="viewcode-link">[source]</span></a></dt> |
---|
2513 | <dd><p>Dispatch the event from the asynchronous monitor. This is running |
---|
2514 | in the GUI thread.</p> |
---|
2515 | </dd></dl> |
---|
2516 | |
---|
2517 | <dl class="method"> |
---|
2518 | <dt id="park.wxmonitor.wxMonitor.onMonitorLog"> |
---|
2519 | <tt class="descname">onMonitorLog</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#wxMonitor.onMonitorLog"><span class="viewcode-link">[source]</span></a></dt> |
---|
2520 | <dd><p>Called when the job sends a logging record.</p> |
---|
2521 | <p>The logging record contains a normal python logging record.</p> |
---|
2522 | <p>The default behaviour is to tie into the application logging |
---|
2523 | system using:</p> |
---|
2524 | <div class="highlight-python"><div class="highlight"><pre><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> |
---|
2525 | <span class="n">logger</span><span class="o">.</span><span class="n">handle</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">record</span><span class="p">)</span> |
---|
2526 | </pre></div> |
---|
2527 | </div> |
---|
2528 | <p>Logging levels are set in the job controller.</p> |
---|
2529 | </dd></dl> |
---|
2530 | |
---|
2531 | <dl class="method"> |
---|
2532 | <dt id="park.wxmonitor.wxMonitor.onMonitorMessage"> |
---|
2533 | <tt class="descname">onMonitorMessage</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#wxMonitor.onMonitorMessage"><span class="viewcode-link">[source]</span></a></dt> |
---|
2534 | <dd><p>Generic message handler: do nothing.</p> |
---|
2535 | </dd></dl> |
---|
2536 | |
---|
2537 | <dl class="method"> |
---|
2538 | <dt id="park.wxmonitor.wxMonitor.put"> |
---|
2539 | <tt class="descname">put</tt><big>(</big><em>message</em><big>)</big><a class="reference internal" href="../../_modules/park/wxmonitor.html#wxMonitor.put"><span class="viewcode-link">[source]</span></a></dt> |
---|
2540 | <dd><p>Intercept an event received from an asynchronous monitor. This is |
---|
2541 | running in the asynchronous thread.</p> |
---|
2542 | </dd></dl> |
---|
2543 | |
---|
2544 | </dd></dl> |
---|
2545 | |
---|
2546 | </div> |
---|
2547 | </div> |
---|
2548 | <div class="section" id="module-park"> |
---|
2549 | <span id="module-contents"></span><h2>Module contents</h2> |
---|
2550 | <p>PARK fitting service.</p> |
---|
2551 | <p>The PARK fitting service is a set of python packages to support |
---|
2552 | fitting in datasets. Using common python infrastructure such |
---|
2553 | as scipy optimizers, numpy arrays, and matplotlib plotting, park |
---|
2554 | allows you to define models, associate them with datasets and |
---|
2555 | simultaneously fit them. Park provides a simple job queue to |
---|
2556 | manage multiple fits using separate processes or running across |
---|
2557 | the network on separate machines.</p> |
---|
2558 | <div class="section" id="installation"> |
---|
2559 | <h3>Installation</h3> |
---|
2560 | <p>The latest version of Park is available from |
---|
2561 | <a class="reference external" href="http://www.reflectometry.org/danse/park">http://www.reflectometry.org/danse/park</a>.</p> |
---|
2562 | <p>Currently this is supplied as source from a zip file. You can |
---|
2563 | also retrieve the latest version from svn:</p> |
---|
2564 | <div class="highlight-python"><div class="highlight"><pre>svn co svn://danse.us/park/branches/park-1.2 |
---|
2565 | </pre></div> |
---|
2566 | </div> |
---|
2567 | <p>If you are installing from source, you will need a python |
---|
2568 | environment with numpy and scipy. For the GUI version, you |
---|
2569 | will also need matplotlib and wx.</p> |
---|
2570 | <p>You will need a C compiler to build the resolution convolution |
---|
2571 | function. On Windows this may require installing MinGW and |
---|
2572 | adding distutils.cfg to your distutils directory:</p> |
---|
2573 | <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">build</span><span class="p">]</span> |
---|
2574 | <span class="n">compiler</span> <span class="o">=</span> <span class="n">mingw</span> |
---|
2575 | </pre></div> |
---|
2576 | </div> |
---|
2577 | <p>Once you have the required supporting packages, use the following |
---|
2578 | to build and install:</p> |
---|
2579 | <div class="highlight-python"><div class="highlight"><pre>python setup.py install |
---|
2580 | </pre></div> |
---|
2581 | </div> |
---|
2582 | </div> |
---|
2583 | <div class="section" id="id3"> |
---|
2584 | <h3>Usage</h3> |
---|
2585 | <p>To get started with park, you will need to first define the |
---|
2586 | models that you are using. These can be very basic models, |
---|
2587 | listing all possible fitting parameters. When setting up the |
---|
2588 | fit later, you will be able to combine models, using |
---|
2589 | parameter expressions to relate the values in one model with |
---|
2590 | those in another. See <cite>park.model</cite> for details.</p> |
---|
2591 | <p>Once your models are constructed you can use them in a fit. |
---|
2592 | See <cite>park.fit</cite> for details.</p> |
---|
2593 | <p>Important classes and functions: |
---|
2594 | <cite>park.model.Model</cite>, <cite>park.parameter.ParameterSet</cite>, <cite>park.fit.Fit</cite></p> |
---|
2595 | <table class="docutils field-list" frame="void" rules="none"> |
---|
2596 | <col class="field-name" /> |
---|
2597 | <col class="field-body" /> |
---|
2598 | <tbody valign="top"> |
---|
2599 | <tr class="field-odd field"><th class="field-name">group models:</th><td class="field-body">model, assembly, parameter, data</td> |
---|
2600 | </tr> |
---|
2601 | <tr class="field-even field"><th class="field-name">group examples:</th><td class="field-body">peaks</td> |
---|
2602 | </tr> |
---|
2603 | <tr class="field-odd field"><th class="field-name" colspan="2">group optimizer:</th></tr> |
---|
2604 | <tr class="field-odd field"><td> </td><td class="field-body">fit, fitresult, fitmc, simplex</td> |
---|
2605 | </tr> |
---|
2606 | <tr class="field-even field"><th class="field-name">group support:</th><td class="field-body">expression, deps, version, setup, serial</td> |
---|
2607 | </tr> |
---|
2608 | <tr class="field-odd field"><th class="field-name">group server:</th><td class="field-body">fitservice</td> |
---|
2609 | </tr> |
---|
2610 | </tbody> |
---|
2611 | </table> |
---|
2612 | </div> |
---|
2613 | </div> |
---|
2614 | </div> |
---|
2615 | |
---|
2616 | |
---|
2617 | </div> |
---|
2618 | </div> |
---|
2619 | </div> |
---|
2620 | <div class="sphinxsidebar"> |
---|
2621 | <div class="sphinxsidebarwrapper"> |
---|
2622 | <h3><a href="../../index.html">Table Of Contents</a></h3> |
---|
2623 | <ul> |
---|
2624 | <li><a class="reference internal" href="#">park package</a><ul> |
---|
2625 | <li><a class="reference internal" href="#submodules">Submodules</a></li> |
---|
2626 | <li><a class="reference internal" href="#module-park.assembly">park.assembly module</a><ul> |
---|
2627 | <li><a class="reference internal" href="#usage">Usage</a><ul> |
---|
2628 | <li><a class="reference internal" href="#a-note-on-model-weighting">A note on model weighting</a></li> |
---|
2629 | </ul> |
---|
2630 | </li> |
---|
2631 | </ul> |
---|
2632 | </li> |
---|
2633 | <li><a class="reference internal" href="#module-park.data">park.data module</a></li> |
---|
2634 | <li><a class="reference internal" href="#module-park.deps">park.deps module</a></li> |
---|
2635 | <li><a class="reference internal" href="#module-park.diffev">park.diffev module</a></li> |
---|
2636 | <li><a class="reference internal" href="#module-park.expression">park.expression module</a></li> |
---|
2637 | <li><a class="reference internal" href="#module-park.fit">park.fit module</a><ul> |
---|
2638 | <li><a class="reference internal" href="#id1">Usage</a></li> |
---|
2639 | <li><a class="reference internal" href="#gui-usage">GUI Usage</a></li> |
---|
2640 | </ul> |
---|
2641 | </li> |
---|
2642 | <li><a class="reference internal" href="#park-fitmc-module">park.fitmc module</a></li> |
---|
2643 | <li><a class="reference internal" href="#module-park.fitresult">park.fitresult module</a></li> |
---|
2644 | <li><a class="reference internal" href="#park-fitservice-module">park.fitservice module</a></li> |
---|
2645 | <li><a class="reference internal" href="#module-park.formatnum">park.formatnum module</a></li> |
---|
2646 | <li><a class="reference internal" href="#module-park.message">park.message module</a></li> |
---|
2647 | <li><a class="reference internal" href="#module-park.model">park.model module</a><ul> |
---|
2648 | <li><a class="reference internal" href="#id2">Usage</a></li> |
---|
2649 | </ul> |
---|
2650 | </li> |
---|
2651 | <li><a class="reference internal" href="#module-park.monitor">park.monitor module</a></li> |
---|
2652 | <li><a class="reference internal" href="#module-park.parameter">park.parameter module</a></li> |
---|
2653 | <li><a class="reference internal" href="#module-park.parkde">park.parkde module</a></li> |
---|
2654 | <li><a class="reference internal" href="#park-parksnob-module">park.parksnob module</a></li> |
---|
2655 | <li><a class="reference internal" href="#module-park.peaks">park.peaks module</a></li> |
---|
2656 | <li><a class="reference internal" href="#module-park.pmap">park.pmap module</a></li> |
---|
2657 | <li><a class="reference internal" href="#park-rangemap-module">park.rangemap module</a></li> |
---|
2658 | <li><a class="reference internal" href="#park-serial-module">park.serial module</a></li> |
---|
2659 | <li><a class="reference internal" href="#module-park.setup">park.setup module</a></li> |
---|
2660 | <li><a class="reference internal" href="#module-park.simplex">park.simplex module</a></li> |
---|
2661 | <li><a class="reference internal" href="#module-park.version">park.version module</a></li> |
---|
2662 | <li><a class="reference internal" href="#module-park.wxmonitor">park.wxmonitor module</a><ul> |
---|
2663 | <li><a class="reference internal" href="#example">Example</a></li> |
---|
2664 | </ul> |
---|
2665 | </li> |
---|
2666 | <li><a class="reference internal" href="#module-park">Module contents</a><ul> |
---|
2667 | <li><a class="reference internal" href="#installation">Installation</a></li> |
---|
2668 | <li><a class="reference internal" href="#id3">Usage</a></li> |
---|
2669 | </ul> |
---|
2670 | </li> |
---|
2671 | </ul> |
---|
2672 | </li> |
---|
2673 | </ul> |
---|
2674 | |
---|
2675 | <h4>Previous topic</h4> |
---|
2676 | <p class="topless"><a href="modules.html" |
---|
2677 | title="previous chapter">lib.macosx-10.5-x86_64-2.7</a></p> |
---|
2678 | <h4>Next topic</h4> |
---|
2679 | <p class="topless"><a href="sas.html" |
---|
2680 | title="next chapter">sas package</a></p> |
---|
2681 | <h3>This Page</h3> |
---|
2682 | <ul class="this-page-menu"> |
---|
2683 | <li><a href="../../_sources/dev/api/park.txt" |
---|
2684 | rel="nofollow">Show Source</a></li> |
---|
2685 | </ul> |
---|
2686 | <div id="searchbox" style="display: none"> |
---|
2687 | <h3>Quick search</h3> |
---|
2688 | <form class="search" action="../../search.html" method="get"> |
---|
2689 | <input type="text" name="q" /> |
---|
2690 | <input type="submit" value="Go" /> |
---|
2691 | <input type="hidden" name="check_keywords" value="yes" /> |
---|
2692 | <input type="hidden" name="area" value="default" /> |
---|
2693 | </form> |
---|
2694 | <p class="searchtip" style="font-size: 90%"> |
---|
2695 | Enter search terms or a module, class or function name. |
---|
2696 | </p> |
---|
2697 | </div> |
---|
2698 | <script type="text/javascript">$('#searchbox').show(0);</script> |
---|
2699 | </div> |
---|
2700 | </div> |
---|
2701 | <div class="clearer"></div> |
---|
2702 | </div> |
---|
2703 | <div class="related"> |
---|
2704 | <h3>Navigation</h3> |
---|
2705 | <ul> |
---|
2706 | <li class="right" style="margin-right: 10px"> |
---|
2707 | <a href="../../genindex.html" title="General Index" |
---|
2708 | >index</a></li> |
---|
2709 | <li class="right" > |
---|
2710 | <a href="../../py-modindex.html" title="Python Module Index" |
---|
2711 | >modules</a> |</li> |
---|
2712 | <li class="right" > |
---|
2713 | <a href="sas.html" title="sas package" |
---|
2714 | >next</a> |</li> |
---|
2715 | <li class="right" > |
---|
2716 | <a href="modules.html" title="lib.macosx-10.5-x86_64-2.7" |
---|
2717 | >previous</a> |</li> |
---|
2718 | <li><a href="../../index.html">SasView 3.0.0 documentation</a> »</li> |
---|
2719 | <li><a href="../dev.html" >Developer Documentation</a> »</li> |
---|
2720 | <li><a href="modules.html" >lib.macosx-10.5-x86_64-2.7</a> »</li> |
---|
2721 | </ul> |
---|
2722 | </div> |
---|
2723 | <div class="footer"> |
---|
2724 | © Copyright 2013, The SasView Project. |
---|
2725 | Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3. |
---|
2726 | </div> |
---|
2727 | </body> |
---|
2728 | </html> |
---|