-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules.html
532 lines (481 loc) · 39 KB
/
modules.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>API reference — cdsaxs v0.0.1 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css" />
<script src="_static/jquery.js"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/sphinx_highlight.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="cdsaxs.simulations package" href="cdsaxs.simulations.html" />
<link rel="prev" title="Tutorial for Strong castle model" href="Tutorials/strong_castle_simulation.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home">
cdsaxs
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">User Guide:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="introduction.html#installation">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="introduction.html#background">Background</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials.html">Tutorials</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">API reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#submodules">Submodules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#module-cdsaxs.fitter">fitter</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#cdsaxs.fitter.Fitter"><code class="docutils literal notranslate"><span class="pre">Fitter</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#module-cdsaxs.residual">residual</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#cdsaxs.residual.Residual"><code class="docutils literal notranslate"><span class="pre">Residual</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="cdsaxs.simulations.html">cdsaxs.simulations package</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">For Developers:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="for_developpers.html">Setting Up a Development Environment</a></li>
<li class="toctree-l1"><a class="reference internal" href="for_developpers.html#project-structure">Project Structure</a></li>
<li class="toctree-l1"><a class="reference internal" href="for_developpers.html#creating-a-new-simulation-model">Creating a New Simulation Model</a></li>
<li class="toctree-l1"><a class="reference internal" href="for_developpers.html#testing">Testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="for_developpers.html#modifying-and-building-the-documentation">Modifying and building the documentation</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">cdsaxs</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">API reference</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/modules.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="api-reference">
<h1>API reference<a class="headerlink" href="#api-reference" title="Permalink to this heading"></a></h1>
<section id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this heading"></a></h2>
<section id="module-cdsaxs.fitter">
<span id="fitter"></span><h3>fitter<a class="headerlink" href="#module-cdsaxs.fitter" title="Permalink to this heading"></a></h3>
<p>This module contains the Fitter class, which is designed to fit the cdsaxs experimental data using the CMA-ES (Covariance Matrix Adaptation Evolution Strategy)
and then do a statstical analysis of the best fit parameters using the MCMC (Markov Chain Monte Carlo) algorithm.</p>
<dl class="simple">
<dt>Classes:</dt><dd><p>Fitter: A class that fits the cdsaxs experimental data using the CMA-ES and MCMC algorithms.</p>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cdsaxs.fitter.</span></span><span class="sig-name descname"><span class="pre">Fitter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">Simulation</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="cdsaxs.simulations.html#cdsaxs.simulations.base.Simulation" title="cdsaxs.simulations.base.Simulation"><span class="pre">Simulation</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">exp_data</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>This class is designed to fit the cdsaxs experimental data using the CMA-ES (Covariance Matrix Adaptation Evolution Strategy) and then do a statstical analysis
of the best fit parameters using the MCMC (Markov Chain Monte Carlo) algorithm. It takes an instance of the Simulation class and fits this simulated data to the
experimental data.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.Simulation">
<span class="sig-name descname"><span class="pre">Simulation</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.Simulation" title="Permalink to this definition"></a></dt>
<dd><p>An instance of the Simulation class representing the simulated diffraction pattern.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p><a class="reference internal" href="cdsaxs.simulations.html#cdsaxs.simulations.base.Simulation" title="cdsaxs.simulations.base.Simulation">Simulation</a></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.exp_data">
<span class="sig-name descname"><span class="pre">exp_data</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.exp_data" title="Permalink to this definition"></a></dt>
<dd><p>Experimental diffraction data.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>numpy.ndarray</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.np">
<span class="sig-name descname"><span class="pre">np</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.np" title="Permalink to this definition"></a></dt>
<dd><p>NumPy or CuPy module, depending on whether GPU acceleration is used.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>module</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.best_fit_cmaes">
<span class="sig-name descname"><span class="pre">best_fit_cmaes</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.best_fit_cmaes" title="Permalink to this definition"></a></dt>
<dd><p>List containing the best fit parameters obtained using the CMA-ES algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>list or None</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.cmaes">
<span class="sig-name descname"><span class="pre">cmaes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.cmaes"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.cmaes" title="Permalink to this definition"></a></dt>
<dd><p>Perform fitting using the CMA-ES (Covariance Matrix Adaptation Evolution Strategy) algorithm.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.mcmc">
<span class="sig-name descname"><span class="pre">mcmc</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cdsaxs.fitter.Fitter.mcmc" title="Permalink to this definition"></a></dt>
<dd><p>Give a set of statstical data on the best fit parameters using the MCMC (Markov Chain Monte Carlo) algorithm.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="id0">
<span class="sig-name descname"><span class="pre">cmaes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ngen</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">popsize</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mu</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_default</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">restarts</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tolhistfun</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ftarget</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">restart_from_best</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_save</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.cmaes"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id0" title="Permalink to this definition"></a></dt>
<dd><p>Fit experimental data using the Covariance Matrix Adaptation Evolution Strategy (CMA-ES) algorithm.</p>
<p>This method utilizes a modified version of the CMA-ES algorithm to fit experimental data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>sigma</strong> (<em>float</em>) – The initial standard deviation for each parameter.</p></li>
<li><p><strong>ngen</strong> (<em>int</em>) – The number of generations to run the algorithm.</p></li>
<li><p><strong>popsize</strong> (<em>int</em>) – The size of the population (number of candidate solutions) in each generation.</p></li>
<li><p><strong>mu</strong> (<em>int</em>) – The number of parents/points for recombination.</p></li>
<li><p><strong>n_default</strong> (<em>int</em>) – The number of parameters to be optimized.</p></li>
<li><p><strong>restarts</strong> (<em>int</em>) – The number of restarts allowed during the optimization process.</p></li>
<li><p><strong>tolhistfun</strong> (<em>float</em>) – The tolerance for the history of the best fitness value.</p></li>
<li><p><strong>ftarget</strong> (<em>float</em>) – The target fitness value.</p></li>
<li><p><strong>restart_from_best</strong> (<em>bool</em><em>, </em><em>optional</em>) – Determines whether to restart from the best individual found so far. Default is True.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em><em>, </em><em>optional</em>) – Controls whether to print progress information during optimization. Default is True.</p></li>
<li><p><strong>dir_save</strong> (<em>str</em><em>, </em><em>optional</em>) – The directory to save the output. Default is None.</p></li>
<li><p><strong>test</strong> (<em>bool</em><em>, </em><em>optional</em>) – Controls whether to test the function and return best value instead of performing the full optimization process. If True, the function returns best value. Default is False.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>A tuple containing the best fit parameters and the corresponding fitness value.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>tuple</p>
</dd>
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="id1">
<span class="sig-name descname"><span class="pre">best_fit_cmaes</span></span><a class="headerlink" href="#id1" title="Permalink to this definition"></a></dt>
<dd><p>List containing the best fit parameters obtained using the CMA-ES algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>list or None</p>
</dd>
</dl>
</dd></dl>
<p class="rubric">Notes</p>
<p>This method is modified from deap/algorithms.py to return a list of populations instead of the final population and to incorporate additional termination criteria based on neuromorphic algorithms. The function was originally extracted from XiCam and has been modified for specific use cases.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.do_stats">
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">do_stats</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">df</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ci</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.95</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.do_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.do_stats" title="Permalink to this definition"></a></dt>
<dd><p>This method generates a set of statistical data on the best fit parameters obtained from the MCMC fitting process.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>df</strong> (<em>pandas.DataFrame</em>) – The DataFrame containing the best fit parameters.</p></li>
<li><p><strong>ci</strong> (<em>float</em><em>, </em><em>optional</em>) – The confidence interval. Default is 0.95.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>A DataFrame containing the statistical data on the best fit parameters.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>pandas.DataFrame</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.mcmc_bestfit_stats">
<span class="sig-name descname"><span class="pre">mcmc_bestfit_stats</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">N</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nsteps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nwalkers</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gaussian_move</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_save</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tau</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-05</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.mcmc_bestfit_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.mcmc_bestfit_stats" title="Permalink to this definition"></a></dt>
<dd><p>Generate a set of statstical data on the best fit parameters using the MCMC (Markov Chain Monte Carlo) algorithm. Two kinds of options for moves to explore solution space are provided gaussian and stretch move. Default is strech move and recommended.</p>
<p>This method utilizes the emcee package’s implementation of the MCMC algorithm and generates a csv file with the statistical data of the best fit parameters.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>N</strong> (<em>int</em>) – The number of parameters to be optimized.</p></li>
<li><p><strong>sigma</strong> (<em>float</em><em> or </em><em>list</em>) – The initial standard deviation for each parameter. If a float is provided, it is applied to all parameters. If a list is provided, each parameter is initialized with the corresponding value.</p></li>
<li><p><strong>nsteps</strong> (<em>int</em>) – The number of MCMC steps to perform.</p></li>
<li><p><strong>nwalkers</strong> (<em>int</em>) – The number of MCMC walkers to use.</p></li>
<li><p><strong>gaussian_move</strong> (<em>bool</em><em>, </em><em>optional</em>) – Determines whether to use Gaussian moves for proposal distribution. If True, Gaussian moves are used. If False, stretch moves are used. Default is False.</p></li>
<li><p><strong>seed</strong> (<em>int</em><em>, </em><em>optional</em>) – The seed for the random number generator. If None, a random seed is generated. Default is None.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em><em>, </em><em>optional</em>) – Controls whether to print progress information during fitting. If True, progress information is printed. Default is False.</p></li>
<li><p><strong>test</strong> (<em>bool</em><em>, </em><em>optional</em>) – Controls whether to test the function and return mean values instead of performing the full fitting process. If True, the function returns mean values. Default is True.</p></li>
<li><p><strong>tau</strong> (<em>float</em><em>, </em><em>optional</em>) – The autocorrelation time to find burnin steps. If None, is provided emcee package is used to estimate the autocorrelation time. If emcee fails to do so 1/3 of the first nsteps are discarded. Default is None.</p></li>
<li><p><strong>c</strong> (<em>float</em><em>, </em><em>optional</em>) – Empirical factor to modify the MCMC acceptance rate. Default is 1e-5.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.best_uncorr">
<span class="sig-name descname"><span class="pre">best_uncorr</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.best_uncorr" title="Permalink to this definition"></a></dt>
<dd><p>The best uncorrected individual obtained from the MCMC fitting process.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>numpy.ndarray</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.best_fitness">
<span class="sig-name descname"><span class="pre">best_fitness</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.best_fitness" title="Permalink to this definition"></a></dt>
<dd><p>The fitness value of the best individual obtained from the MCMC fitting process.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.minfitness_each_gen">
<span class="sig-name descname"><span class="pre">minfitness_each_gen</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.minfitness_each_gen" title="Permalink to this definition"></a></dt>
<dd><p>The minimum fitness value at each generation during the MCMC fitting process.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>numpy.ndarray</p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.Sampler">
<span class="sig-name descname"><span class="pre">Sampler</span></span><a class="headerlink" href="#cdsaxs.fitter.Fitter.Sampler" title="Permalink to this definition"></a></dt>
<dd><p>An instance of emcee.EnsembleSampler with detailed output of the MCMC algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>emcee.EnsembleSampler</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.plot_correlation">
<span class="sig-name descname"><span class="pre">plot_correlation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_save</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.plot_correlation"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.plot_correlation" title="Permalink to this definition"></a></dt>
<dd><p>Generate a corner plot of the best fit parameters obtained from the MCMC fitting process.</p>
<p>This method utilizes the corner package to generate a corner plot of the best fit parameters obtained from the MCMC fitting process.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>file</strong> (<em>str</em>) – The path to the file containing the data.</p></li>
<li><p><strong>dir_save</strong> (<em>str</em><em>, </em><em>optional</em>) – The directory to save the output. If not provided, the plot will be displayed instead of being saved.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.save_population">
<span class="sig-name descname"><span class="pre">save_population</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">population_arr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fitness_arr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_save</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fit_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'cmaes'</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.save_population"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.save_population" title="Permalink to this definition"></a></dt>
<dd><p>Save the population array to a csv file.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>population</strong> (<em>numpy.ndarray</em>) – The population array to save.</p></li>
<li><p><strong>dir_save</strong> (<em>str</em>) – The directory to save the output.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.fitter.Fitter.set_best_fit_cmaes">
<span class="sig-name descname"><span class="pre">set_best_fit_cmaes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">best_fit</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/fitter.html#Fitter.set_best_fit_cmaes"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.fitter.Fitter.set_best_fit_cmaes" title="Permalink to this definition"></a></dt>
<dd><p>Set the best fit parameters obtained using the CMA-ES algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>best_fit</strong> (<em>pandas.DataFrame</em>) – The best fit parameters obtained using the CMA-ES algorithm.</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="module-cdsaxs.residual">
<span id="residual"></span><h3>residual<a class="headerlink" href="#module-cdsaxs.residual" title="Permalink to this heading"></a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cdsaxs.residual.</span></span><span class="sig-name descname"><span class="pre">Residual</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fit_mode='cmaes'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xp=<module</span> <span class="pre">'numpy'</span> <span class="pre">from</span> <span class="pre">'/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/numpy/__init__.py'></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Simulation:</span> <span class="pre">Simulation</span> <span class="pre">|</span> <span class="pre">None</span> <span class="pre">=</span> <span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c=1e-05</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">best_fit=None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.residual.Residual" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>A class to calculate the residual between experimental and simulated data, used for fitness evaluation in optimization algorithms.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.mdata">
<span class="sig-name descname"><span class="pre">mdata</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.mdata" title="Permalink to this definition"></a></dt>
<dd><p>numpy.ndarray
Experimental intensity data.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.mfit_mode">
<span class="sig-name descname"><span class="pre">mfit_mode</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.mfit_mode" title="Permalink to this definition"></a></dt>
<dd><p>str
Method to calculate fitness, differentiating between ‘cmaes’ and ‘mcmc’.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.xp">
<span class="sig-name descname"><span class="pre">xp</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.xp" title="Permalink to this definition"></a></dt>
<dd><p>module
NumPy or CuPy module.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.Simulation">
<span class="sig-name descname"><span class="pre">Simulation</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.Simulation" title="Permalink to this definition"></a></dt>
<dd><p>Optional[‘Simulation’]
Class to simulate the diffraction pattern (for now only StackedTrapezoidSimulation).</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.c">
<span class="sig-name descname"><span class="pre">c</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.c" title="Permalink to this definition"></a></dt>
<dd><p>float
Empirical factor to modify the MCMC acceptance rate.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.best_fit">
<span class="sig-name descname"><span class="pre">best_fit</span></span><a class="headerlink" href="#cdsaxs.residual.Residual.best_fit" title="Permalink to this definition"></a></dt>
<dd><p>list or None
List containing the best fit parameters obtained from the optimization algorithm (optional).</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.__call__">
<span class="sig-name descname"><span class="pre">__call__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual.__call__"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.residual.Residual.__call__" title="Permalink to this definition"></a></dt>
<dd><p>Calculate the residual between experimental and simulated data.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.log_error">
<span class="sig-name descname"><span class="pre">log_error</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual.log_error"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.residual.Residual.log_error" title="Permalink to this definition"></a></dt>
<dd><p>Return the difference between experimental and simulated data using the log error.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="cdsaxs.residual.Residual.fix_fitness_mcmc">
<span class="sig-name descname"><span class="pre">fix_fitness_mcmc</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual.fix_fitness_mcmc"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cdsaxs.residual.Residual.fix_fitness_mcmc" title="Permalink to this definition"></a></dt>
<dd><p>Fix the fitness for the MCMC algorithm using the Metropolis-Hastings criterion.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="id2">
<span class="sig-name descname"><span class="pre">fix_fitness_mcmc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fitness</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual.fix_fitness_mcmc"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id2" title="Permalink to this definition"></a></dt>
<dd><p>Metropolis-Hastings criterion: acceptance probability equal to ratio between P(new)/P(old)
where P is proportional to probability distribution we want to find
for our case we assume that probability of our parameters being the best is proportional to a Gaussian centered at fitness=0
where fitness can be log, abs, squared error, etc.
emcee expects the fitness function to return ln(P(new)), P(old) is auto-calculated</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>fitness</strong> – float
Fitness value to be fixed.</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><dl class="simple">
<dt>float</dt><dd><p>Fixed fitness value.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="id3">
<span class="sig-name descname"><span class="pre">log_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exp_i_array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sim_i_array</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdsaxs/residual.html#Residual.log_error"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id3" title="Permalink to this definition"></a></dt>
<dd><p>Return the difference between two set of values (experimental and
simulated data), using the log error</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>exp_i_array</strong> (<em>numpy.ndarray</em><em>(</em><em>(</em><em>n</em><em>)</em><em>)</em>) – Experimental intensities data</p></li>
<li><p><strong>sim_i_array</strong> (<em>numpy.ndarray</em><em>(</em><em>(</em><em>n</em><em>)</em><em>)</em>) – Simulated intensities data</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><dl class="simple">
<dt>numpy.ndarray</dt><dd><p>Difference between experimental and simulated data using the log error.</p>
</dd>
</dl>
</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>Returns</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
</section>
<section id="subpackages">
<h2>Subpackages<a class="headerlink" href="#subpackages" title="Permalink to this heading"></a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="cdsaxs.simulations.html">cdsaxs.simulations package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="cdsaxs.simulations.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="cdsaxs.simulations.html#module-cdsaxs.simulations.base">cdsaxs.simulations.base module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cdsaxs.simulations.html#module-cdsaxs.simulations.stacked_trapezoid">cdsaxs.simulations.stacked_trapezoid module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cdsaxs.simulations.html#module-cdsaxs.simulations.strong_castle">cdsaxs.simulations.strong_castle module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cdsaxs.simulations.html#module-cdsaxs.simulations">Module contents</a></li>
</ul>
</li>
</ul>
</div>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="Tutorials/strong_castle_simulation.html" class="btn btn-neutral float-left" title="Tutorial for Strong castle model" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="cdsaxs.simulations.html" class="btn btn-neutral float-right" title="cdsaxs.simulations package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2024, Nischal Dhungana.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>