microeye 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. microEye/__init__.py +47 -0
  2. microEye/_version.py +2 -0
  3. microEye/analysis/__init__.py +1 -0
  4. microEye/analysis/checklist_dialog.py +143 -0
  5. microEye/analysis/cmosMaps.py +228 -0
  6. microEye/analysis/filters/__init__.py +9 -0
  7. microEye/analysis/filters/base.py +21 -0
  8. microEye/analysis/filters/spatial.py +338 -0
  9. microEye/analysis/filters/temporal.py +76 -0
  10. microEye/analysis/fitting/__init__.py +0 -0
  11. microEye/analysis/fitting/fit.py +680 -0
  12. microEye/analysis/fitting/nena.py +375 -0
  13. microEye/analysis/fitting/phasor_fit.py +90 -0
  14. microEye/analysis/fitting/processing.py +317 -0
  15. microEye/analysis/fitting/psf/__init__.py +6 -0
  16. microEye/analysis/fitting/psf/extract.py +1129 -0
  17. microEye/analysis/fitting/psf/rubost_mean.py +150 -0
  18. microEye/analysis/fitting/psf/spline.py +167 -0
  19. microEye/analysis/fitting/psf/stats/__init__.py +12 -0
  20. microEye/analysis/fitting/psf/stats/core.py +295 -0
  21. microEye/analysis/fitting/psf/stats/curve_fit.py +708 -0
  22. microEye/analysis/fitting/psf/stats/io.py +104 -0
  23. microEye/analysis/fitting/psf/stats/slope_fit.py +171 -0
  24. microEye/analysis/fitting/psf/temp.py +147 -0
  25. microEye/analysis/fitting/psf/test.py +47 -0
  26. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUfunctions.py +657 -0
  27. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUmleFit_LM.py +1336 -0
  28. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUsplineLib.py +270 -0
  29. microEye/analysis/fitting/pyfit3Dcspline/CPU/__init__.py +1 -0
  30. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUfunctions.py +609 -0
  31. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_EMCCD.py +1396 -0
  32. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_sCMOS.py +1426 -0
  33. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUsplineLib.py +231 -0
  34. microEye/analysis/fitting/pyfit3Dcspline/GPU/__init__.py +2 -0
  35. microEye/analysis/fitting/pyfit3Dcspline/__init__.py +10 -0
  36. microEye/analysis/fitting/pyfit3Dcspline/constants.py +27 -0
  37. microEye/analysis/fitting/pyfit3Dcspline/mainfunctions.py +903 -0
  38. microEye/analysis/fitting/results.py +917 -0
  39. microEye/analysis/fitting/results_stats.py +251 -0
  40. microEye/analysis/fitting/tardis.py +209 -0
  41. microEye/analysis/multi_viewer.py +568 -0
  42. microEye/analysis/processing/__init__.py +1 -0
  43. microEye/analysis/processing/frc.py +120 -0
  44. microEye/analysis/rendering/__init__.py +3 -0
  45. microEye/analysis/rendering/base.py +452 -0
  46. microEye/analysis/rendering/cloud.py +215 -0
  47. microEye/analysis/rendering/core.py +47 -0
  48. microEye/analysis/rendering/volumetric.py +198 -0
  49. microEye/analysis/tools/__init__.py +0 -0
  50. microEye/analysis/tools/kymograms.py +1079 -0
  51. microEye/analysis/tools/roi_selectors.py +556 -0
  52. microEye/analysis/utils/__init__.py +3 -0
  53. microEye/analysis/utils/coordinates.py +18 -0
  54. microEye/analysis/utils/images.py +68 -0
  55. microEye/analysis/utils/windows.py +19 -0
  56. microEye/analysis/viewer/__init__.py +3 -0
  57. microEye/analysis/viewer/image_options_widget.py +615 -0
  58. microEye/analysis/viewer/images.py +1225 -0
  59. microEye/analysis/viewer/layers_widget.py +415 -0
  60. microEye/analysis/viewer/localizations.py +1304 -0
  61. microEye/analysis/viewer/psf.py +1003 -0
  62. microEye/analysis/viewer/volume.py +456 -0
  63. microEye/hardware/__init__.py +3 -0
  64. microEye/hardware/cams/__init__.py +29 -0
  65. microEye/hardware/cams/camera_calibration.py +99 -0
  66. microEye/hardware/cams/camera_list.py +528 -0
  67. microEye/hardware/cams/camera_options.py +694 -0
  68. microEye/hardware/cams/camera_panel.py +941 -0
  69. microEye/hardware/cams/dummy/__init__.py +1 -0
  70. microEye/hardware/cams/dummy/dummy_panel.py +759 -0
  71. microEye/hardware/cams/jobs.py +497 -0
  72. microEye/hardware/cams/line_profiler.py +99 -0
  73. microEye/hardware/cams/linescan/IR_Cam.py +474 -0
  74. microEye/hardware/cams/linescan/__init__.py +1 -0
  75. microEye/hardware/cams/micam.py +524 -0
  76. microEye/hardware/cams/pco/__init__.py +58 -0
  77. microEye/hardware/cams/pco/enums.py +382 -0
  78. microEye/hardware/cams/pco/pco_cam.py +761 -0
  79. microEye/hardware/cams/pco/pco_panel.py +477 -0
  80. microEye/hardware/cams/shortcuts.py +312 -0
  81. microEye/hardware/cams/thorlabs/__init__.py +1 -0
  82. microEye/hardware/cams/thorlabs/thorlabs.py +1508 -0
  83. microEye/hardware/cams/thorlabs/thorlabs_panel.py +850 -0
  84. microEye/hardware/cams/ueye/__init__.py +1 -0
  85. microEye/hardware/cams/ueye/ueye_camera.py +1023 -0
  86. microEye/hardware/cams/ueye/ueye_panel.py +861 -0
  87. microEye/hardware/cams/vimba/__init__.py +1 -0
  88. microEye/hardware/cams/vimba/vimba_cam.py +1000 -0
  89. microEye/hardware/cams/vimba/vimba_panel.py +813 -0
  90. microEye/hardware/device.py +60 -0
  91. microEye/hardware/lasers/__init__.py +13 -0
  92. microEye/hardware/lasers/io_matchbox.py +791 -0
  93. microEye/hardware/lasers/io_params.py +85 -0
  94. microEye/hardware/lasers/io_single_laser.py +742 -0
  95. microEye/hardware/lasers/laser_relay.py +594 -0
  96. microEye/hardware/mieye/__init__.py +1 -0
  97. microEye/hardware/mieye/acquisition_manager.py +467 -0
  98. microEye/hardware/mieye/devices_manager.py +533 -0
  99. microEye/hardware/mieye/miEye.py +659 -0
  100. microEye/hardware/misc/__init__.py +0 -0
  101. microEye/hardware/misc/acquisition_view.py +71 -0
  102. microEye/hardware/misc/reglo.py +761 -0
  103. microEye/hardware/misc/temp.py +188 -0
  104. microEye/hardware/port_config.py +59 -0
  105. microEye/hardware/protocols/__init__.py +2 -0
  106. microEye/hardware/protocols/actions.py +402 -0
  107. microEye/hardware/protocols/actions_items.py +703 -0
  108. microEye/hardware/protocols/designer.py +244 -0
  109. microEye/hardware/protocols/scene_manager.py +191 -0
  110. microEye/hardware/protocols/serialization.py +97 -0
  111. microEye/hardware/pycromanager/__init__.py +16 -0
  112. microEye/hardware/pycromanager/core.py +1433 -0
  113. microEye/hardware/pycromanager/devices.py +461 -0
  114. microEye/hardware/pycromanager/enums.py +107 -0
  115. microEye/hardware/pycromanager/headless.py +153 -0
  116. microEye/hardware/pycromanager/utils.py +34 -0
  117. microEye/hardware/pycromanager/widgets/__init__.py +5 -0
  118. microEye/hardware/pycromanager/widgets/bridges.py +407 -0
  119. microEye/hardware/pycromanager/widgets/headless_manager.py +258 -0
  120. microEye/hardware/pycromanager/widgets/headless_options.py +224 -0
  121. microEye/hardware/pycromanager/widgets/pycro_panel.py +455 -0
  122. microEye/hardware/stages/__init__.py +18 -0
  123. microEye/hardware/stages/elliptec/__init__.py +5 -0
  124. microEye/hardware/stages/elliptec/baseDevice.py +314 -0
  125. microEye/hardware/stages/elliptec/device.py +384 -0
  126. microEye/hardware/stages/elliptec/deviceID.py +212 -0
  127. microEye/hardware/stages/elliptec/devicePort.py +379 -0
  128. microEye/hardware/stages/elliptec/deviceStatus.py +65 -0
  129. microEye/hardware/stages/elliptec/devicesView.py +706 -0
  130. microEye/hardware/stages/elliptec/ellDevices.py +134 -0
  131. microEye/hardware/stages/elliptec/messageUpdater.py +34 -0
  132. microEye/hardware/stages/elliptec/motorInfo.py +153 -0
  133. microEye/hardware/stages/elliptec/stage.py +62 -0
  134. microEye/hardware/stages/elliptec/test.py +139 -0
  135. microEye/hardware/stages/kinesis/__init__.py +1 -0
  136. microEye/hardware/stages/kinesis/kdc101/__init__.py +1 -0
  137. microEye/hardware/stages/kinesis/kdc101/enums.py +1002 -0
  138. microEye/hardware/stages/kinesis/kdc101/factory.py +171 -0
  139. microEye/hardware/stages/kinesis/kdc101/kdc101.py +718 -0
  140. microEye/hardware/stages/kinesis/kinesis.py +776 -0
  141. microEye/hardware/stages/piezo_concept.py +607 -0
  142. microEye/hardware/stages/stabilizer.py +785 -0
  143. microEye/hardware/stages/stage.py +89 -0
  144. microEye/hardware/widgets/__init__.py +10 -0
  145. microEye/hardware/widgets/controller.py +246 -0
  146. microEye/hardware/widgets/devices.py +133 -0
  147. microEye/hardware/widgets/focusWidget.py +264 -0
  148. microEye/hardware/widgets/qlist_slider.py +113 -0
  149. microEye/hardware/widgets/scan_acquisition.py +424 -0
  150. microEye/icons/1024.png +0 -0
  151. microEye/icons/128.png +0 -0
  152. microEye/icons/16.png +0 -0
  153. microEye/icons/24.png +0 -0
  154. microEye/icons/256.png +0 -0
  155. microEye/icons/32.png +0 -0
  156. microEye/icons/48.png +0 -0
  157. microEye/icons/512.png +0 -0
  158. microEye/icons/64.png +0 -0
  159. microEye/icons/__init__.py +0 -0
  160. microEye/icons/close.svg +88 -0
  161. microEye/icons/mieye.png +0 -0
  162. microEye/icons/min.svg +83 -0
  163. microEye/icons/viewer.png +0 -0
  164. microEye/launcher.py +42 -0
  165. microEye/qt.py +181 -0
  166. microEye/utils/__init__.py +2 -0
  167. microEye/utils/enum_encoder.py +10 -0
  168. microEye/utils/expandable_groupbox.py +93 -0
  169. microEye/utils/gui_helper.py +457 -0
  170. microEye/utils/hid/__init__.py +8 -0
  171. microEye/utils/hid/controller.py +153 -0
  172. microEye/utils/hid/device.py +63 -0
  173. microEye/utils/hid/enums.py +140 -0
  174. microEye/utils/hid/utils.py +58 -0
  175. microEye/utils/labelled_slider.py +134 -0
  176. microEye/utils/metadata.py +599 -0
  177. microEye/utils/metadata_tree.py +718 -0
  178. microEye/utils/micro_launcher.py +245 -0
  179. microEye/utils/parameter_tree.py +325 -0
  180. microEye/utils/pyscripting.py +444 -0
  181. microEye/utils/retry_exec.py +35 -0
  182. microEye/utils/start_gui.py +112 -0
  183. microEye/utils/thread_worker.py +115 -0
  184. microEye/utils/uImage.py +1512 -0
  185. microeye-2.3.2.dist-info/METADATA +401 -0
  186. microeye-2.3.2.dist-info/RECORD +190 -0
  187. microeye-2.3.2.dist-info/WHEEL +5 -0
  188. microeye-2.3.2.dist-info/entry_points.txt +2 -0
  189. microeye-2.3.2.dist-info/licenses/LICENSE +674 -0
  190. microeye-2.3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1426 @@
1
+
2
+ import numba as nb
3
+ from numba import cuda
4
+
5
+ from microEye.analysis.fitting.pyfit3Dcspline.constants import *
6
+ from microEye.analysis.fitting.pyfit3Dcspline.GPU.GPUfunctions import *
7
+ from microEye.analysis.fitting.pyfit3Dcspline.GPU.GPUsplineLib import *
8
+
9
+
10
+ @cuda.jit
11
+ def kernel_MLEFit_LM_sCMOS(
12
+ d_data, PSFSigma, sz, iterations, d_Parameters, d_CRLBs,
13
+ d_LogLikelihood, Nfits, d_varim):
14
+ '''
15
+ brief basic MLE fitting kernel. No additional parameters are computed.
16
+
17
+ Parameters
18
+ ----------
19
+ d_data : _type_
20
+ d_data array of subregions to fit copied to GPU
21
+ PSFSigma : _type_
22
+ PSFSigma sigma of the point spread function
23
+ sz : _type_
24
+ sz nxn size of the subregion to fit
25
+ iterations : _type_
26
+ iterations number of iterations for solution to converge
27
+ d_Parameters : _type_
28
+ d_Parameters array of fitting parameters to return for each subregion
29
+ d_CRLBs : _type_
30
+ d_CRLBs array of Cramer-Rao lower bound estimates to return for
31
+ each subregion
32
+ d_LogLikelihood : _type_
33
+ d_LogLikelihood array of loglikelihood estimates to return for
34
+ each subregion
35
+ Nfits : _type_
36
+ Nfits number of subregions to fit
37
+ d_varim : _type_
38
+ variance map of scmos
39
+ '''
40
+ NV = NV_P
41
+ NV_NV = NV_P_squared
42
+
43
+ M = cuda.local.array(NV_NV, nb.float32)
44
+ Diag = cuda.local.array(NV, nb.float32)
45
+ Minv = cuda.local.array(NV_NV, nb.float32)
46
+
47
+ tx = cuda.threadIdx.x
48
+ bx = cuda.blockIdx.x
49
+ BlockSize = cuda.blockDim.x
50
+
51
+ model = 0
52
+ data = 0
53
+ Div = 0
54
+
55
+ newTheta = cuda.local.array(NV, nb.float32)
56
+ oldTheta = cuda.local.array(NV, nb.float32)
57
+ newLambda = INIT_LAMBDA
58
+ oldLambda = INIT_LAMBDA
59
+ mu = 0
60
+
61
+ newUpdate = cuda.local.array(NV, nb.float32)
62
+ oldUpdate = cuda.local.array(NV, nb.float32)
63
+ newDudt = cuda.local.array(NV, nb.float32)
64
+ for i in range(NV):
65
+ newUpdate[i] = 1e13
66
+ oldUpdate[i] = 1e13
67
+ newDudt[i] = 0
68
+ maxJump = cuda.local.array(4, nb.float32)
69
+ maxJump[0] = 1.0
70
+ maxJump[1] = 1.0
71
+ maxJump[2] = 100.0
72
+ maxJump[3] = 20.0
73
+
74
+ newErr = 1e12
75
+ oldErr = 1e13
76
+
77
+ jacobian = cuda.local.array(NV, nb.float32)
78
+ hessian = cuda.local.array(NV_NV, nb.float32)
79
+ t1 = 0
80
+ t2 = 0
81
+
82
+ Nmax = 0
83
+ errFlag = 0
84
+ L = cuda.local.array(NV_NV, nb.float32)
85
+ U = cuda.local.array(NV_NV, nb.float32)
86
+
87
+ # Prevent read/write past end of array
88
+ if ((bx*BlockSize+tx) >= Nfits):
89
+ return
90
+
91
+ for ii in range(NV_NV):
92
+ M[ii] = 0
93
+ Minv[ii] = 0
94
+ hessian[ii] = 0
95
+ L[ii] = 0
96
+ U[ii] = 0
97
+
98
+ # Requires Checking
99
+ idx = sz*sz*bx*BlockSize + sz*sz*tx
100
+ s_data = d_data[idx:idx + sz*sz]
101
+ s_varim = d_varim[idx:idx + sz*sz]
102
+
103
+ # initial values
104
+ newTheta[0], newTheta[1] = kernel_CenterofMass2D(sz, s_data)
105
+ Nmax, newTheta[3] = kernel_GaussFMaxMin2D(sz, PSFSigma, s_data)
106
+ newTheta[2] = max(0.0, (Nmax-newTheta[3])*2*pi*PSFSigma*PSFSigma)
107
+ newTheta[3] = max(newTheta[3], 0.01)
108
+
109
+ maxJump[2] = max(newTheta[2], maxJump[2])
110
+
111
+ maxJump[3] = max(newTheta[3], maxJump[3])
112
+
113
+ for ii in range(NV):
114
+ oldTheta[ii] = newTheta[ii]
115
+ jacobian[ii] = 0
116
+
117
+ # updateFitValues
118
+ newErr = 0
119
+ for ii in range(sz):
120
+ for jj in range(sz):
121
+ newDudt, model = kernel_DerivativeGauss2D(
122
+ ii, jj, PSFSigma, newTheta, newDudt)
123
+ model += s_varim[sz*jj+ii]
124
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
125
+
126
+ if (data > 0):
127
+ newErr = newErr + 2*((model-data)-data*math.log(model/data))
128
+ else:
129
+ newErr = newErr + 2*model
130
+ data = 0
131
+
132
+ t1 = 1 - data/model
133
+ for ll in range(NV):
134
+ jacobian[ll] += t1 * newDudt[ll]
135
+
136
+ t2 = data/math.pow(model, 2)
137
+ for ll in range(NV):
138
+ for mm in range(ll, NV, 1):
139
+ hessian[ll*NV + mm] += t2 * newDudt[ll] * newDudt[mm]
140
+ hessian[mm*NV + ll] = hessian[ll*NV + mm]
141
+
142
+ for kk in range(iterations): # main iterative loop # noqa: B007
143
+ if(abs((newErr-oldErr)/newErr) < TOLERANCE):
144
+ break # CONVERGED
145
+ else:
146
+ if(newErr > ACCEPTANCE * oldErr):
147
+ # copy Fitdata
148
+
149
+ for i in range(NV):
150
+ newTheta[i] = oldTheta[i]
151
+ newUpdate[i] = oldUpdate[i]
152
+ newLambda = oldLambda
153
+ newErr = oldErr
154
+ mu = max((1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
155
+ newLambda = SCALE_UP * newLambda
156
+ elif(newErr < oldErr and errFlag == 0):
157
+ newLambda = SCALE_DOWN * newLambda
158
+ mu = 1 + newLambda
159
+
160
+ for i in range(NV):
161
+ hessian[i*NV + i] = hessian[i*NV + i] * mu
162
+
163
+ for ii in range(NV_NV):
164
+ L[ii] = 0
165
+ U[ii] = 0
166
+
167
+ errFlag = kernel_cholesky(hessian, NV, L, U)
168
+ if (errFlag == 0):
169
+ for i in range(NV):
170
+ oldTheta[i] = newTheta[i]
171
+ oldUpdate[i] = newUpdate[i]
172
+ oldLambda = newLambda
173
+ oldErr = newErr
174
+
175
+ newUpdate = kernel_luEvaluate(L, U, jacobian, NV, newUpdate)
176
+
177
+ # updateFitParameters
178
+ for ll in range(NV):
179
+ if (newUpdate[ll]/oldUpdate[ll] < -0.5):
180
+ maxJump[ll] = maxJump[ll] * 0.5
181
+
182
+ newUpdate[ll] = (
183
+ newUpdate[ll] /
184
+ (1+math.fabs(newUpdate[ll]/maxJump[ll])))
185
+ newTheta[ll] = newTheta[ll] - newUpdate[ll]
186
+
187
+ # restrict range
188
+ newTheta[0] = max(newTheta[0], (float(sz)-1)/2-sz/4.0)
189
+ newTheta[0] = min(newTheta[0], (float(sz)-1)/2+sz/4.0)
190
+ newTheta[1] = max(newTheta[1], (float(sz)-1)/2-sz/4.0)
191
+ newTheta[1] = min(newTheta[1], (float(sz)-1)/2+sz/4.0)
192
+ newTheta[2] = max(newTheta[2], 1.0)
193
+ newTheta[3] = max(newTheta[3], 0.01)
194
+
195
+ newErr = 0
196
+ for hh in range(NV):
197
+ jacobian[hh] = 0
198
+ for hh in range(NV_NV):
199
+ hessian[hh] = 0
200
+ for ii in range(sz):
201
+ for jj in range(sz):
202
+ # calculating derivatives
203
+ newDudt, model = kernel_DerivativeGauss2D(
204
+ ii, jj, PSFSigma, newTheta, newDudt)
205
+ model += s_varim[sz*jj+ii]
206
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
207
+
208
+ if (data > 0):
209
+ newErr = newErr + \
210
+ 2*((model-data)-data*math.log(model/data))
211
+ else:
212
+ newErr = newErr + 2 * model
213
+ data = 0
214
+
215
+ t1 = 1 - data/model
216
+ for ll in range(NV):
217
+ jacobian[ll] += t1 * newDudt[ll]
218
+
219
+ t2 = data/math.pow(model, 2)
220
+ for ll in range(NV):
221
+ for mm in range(ll, NV, 1):
222
+ hessian[ll*NV+mm] += \
223
+ t2 * newDudt[ll] * newDudt[mm]
224
+ hessian[mm*NV+ll] = hessian[ll*NV+mm]
225
+ else:
226
+ mu = max(
227
+ (1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
228
+ newLambda = SCALE_UP * newLambda
229
+
230
+ # output iteration
231
+ d_Parameters[(NV + 1)*(1+BlockSize*bx+tx) - 1] = kk
232
+ # Calculating the CRLB and LogLikelihood
233
+ Div = 0.0
234
+ for ii in range(sz):
235
+ for jj in range(sz):
236
+ newDudt, model = kernel_DerivativeGauss2D(
237
+ ii, jj, PSFSigma, newTheta, newDudt)
238
+ model += s_varim[sz*jj+ii]
239
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
240
+
241
+ # Building the Fisher Information Matrix
242
+ for kk in range(NV):
243
+ for ll in range(kk, NV, 1):
244
+ M[kk*NV+ll] += newDudt[ll] * newDudt[kk] / model
245
+ M[ll*NV+kk] = M[kk*NV+ll]
246
+
247
+ # LogLikelyhood
248
+ if (model > 0):
249
+ if (data > 0):
250
+ Div += \
251
+ data*math.log(model) - \
252
+ model-data*math.log(data) + data
253
+ else:
254
+ Div += - model
255
+
256
+ # Matrix inverse (CRLB=F^-1) and output assigments
257
+ kernel_MatInvN(M, Minv, Diag, NV)
258
+ # Write to global arrays
259
+ for kk in range(NV):
260
+ d_Parameters[kk + (NV + 1)*(BlockSize*bx+tx)] = newTheta[kk]
261
+ d_CRLBs[kk + NV*(BlockSize*bx+tx)] = Diag[kk]
262
+ d_LogLikelihood[BlockSize*bx+tx] = Div
263
+
264
+ return
265
+
266
+
267
+ @cuda.jit
268
+ def kernel_MLEFit_LM_Sigma_sCMOS(
269
+ d_data, PSFSigma, sz, iterations, d_Parameters,
270
+ d_CRLBs, d_LogLikelihood, Nfits, d_varim):
271
+ '''
272
+ basic MLE fitting kernel. No additional parameters are computed.
273
+
274
+ Parameters
275
+ ----------
276
+ d_data : float[]
277
+ d_data array of subregions to fit copied to GPU
278
+ PSFSigma : float
279
+ PSFSigma sigma of the point spread function
280
+ sz : int
281
+ sz nxn size of the subregion to fit
282
+ iterations : int
283
+ iterations number of iterations for solution to converge
284
+ d_Parameters : float[]
285
+ d_Parameters array of fitting parameters to return for each subregion
286
+ d_CRLBs : float[]
287
+ d_CRLBs array of Cramer-Rao lower bound estimates to return for
288
+ each subregion
289
+ d_LogLikelihood : float[]
290
+ d_LogLikelihood array of loglikelihood estimates to return for
291
+ each subregion
292
+ Nfits : int
293
+ Nfits number of subregions to fit
294
+ d_varim : float[]
295
+ variance map of scmos
296
+ '''
297
+ NV = NV_PS
298
+ NV_NV = NV_PS_squared
299
+
300
+ M = cuda.local.array(NV_NV, nb.float32)
301
+ Diag = cuda.local.array(NV, nb.float32)
302
+ Minv = cuda.local.array(NV_NV, nb.float32)
303
+
304
+ tx = cuda.threadIdx.x
305
+ bx = cuda.blockIdx.x
306
+ BlockSize = cuda.blockDim.x
307
+
308
+ model = 0
309
+ data = 0
310
+ Div = 0
311
+
312
+ newTheta = cuda.local.array(NV, nb.float32)
313
+ oldTheta = cuda.local.array(NV, nb.float32)
314
+ newLambda = INIT_LAMBDA
315
+ oldLambda = INIT_LAMBDA
316
+ mu = 0
317
+
318
+ newUpdate = cuda.local.array(NV, nb.float32)
319
+ oldUpdate = cuda.local.array(NV, nb.float32)
320
+ newDudt = cuda.local.array(NV, nb.float32)
321
+ for i in range(NV):
322
+ newUpdate[i] = 1e13
323
+ oldUpdate[i] = 1e13
324
+ newDudt[i] = 0
325
+ maxJump = cuda.local.array(NV, nb.float32)
326
+ maxJump[0] = 1.0
327
+ maxJump[1] = 1.0
328
+ maxJump[2] = 100.0
329
+ maxJump[3] = 20.0
330
+ maxJump[4] = 0.5
331
+
332
+ newErr = 1e12
333
+ oldErr = 1e13
334
+
335
+ jacobian = cuda.local.array(NV, nb.float32)
336
+ hessian = cuda.local.array(NV_NV, nb.float32)
337
+ t1 = 0
338
+ t2 = 0
339
+
340
+ Nmax = 0
341
+ errFlag = 0
342
+ L = cuda.local.array(NV_NV, nb.float32)
343
+ U = cuda.local.array(NV_NV, nb.float32)
344
+
345
+ # Prevent read/write past end of array
346
+ if ((bx*BlockSize+tx) >= Nfits):
347
+ return
348
+
349
+ for ii in range(NV_NV):
350
+ M[ii] = 0
351
+ Minv[ii] = 0
352
+ hessian[ii] = 0
353
+ L[ii] = 0
354
+ U[ii] = 0
355
+
356
+ # Requires Checking
357
+ idx = sz*sz*bx*BlockSize + sz*sz*tx
358
+ s_data = d_data[idx:idx + sz*sz]
359
+ s_varim = d_varim[idx:idx + sz*sz]
360
+
361
+ # initial values
362
+ newTheta[0], newTheta[1] = kernel_CenterofMass2D(sz, s_data)
363
+ Nmax, newTheta[3] = kernel_GaussFMaxMin2D(sz, PSFSigma, s_data)
364
+ newTheta[2] = max(0.0, (Nmax-newTheta[3])*2*pi*PSFSigma*PSFSigma)
365
+ newTheta[3] = max(newTheta[3], 0.01)
366
+ newTheta[4] = PSFSigma
367
+
368
+ maxJump[2] = max(newTheta[2], maxJump[2])
369
+
370
+ maxJump[3] = max(newTheta[3], maxJump[3])
371
+
372
+ for ii in range(NV):
373
+ oldTheta[ii] = newTheta[ii]
374
+ jacobian[ii] = 0
375
+
376
+ # updateFitValues
377
+ newErr = 0
378
+ for ii in range(sz):
379
+ for jj in range(sz):
380
+ newDudt, model = kernel_DerivativeGauss2D_sigma(
381
+ ii, jj, newTheta, newDudt)
382
+ model += s_varim[sz*jj+ii]
383
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
384
+
385
+ if (data > 0):
386
+ newErr = newErr + 2*((model-data)-data*math.log(model/data))
387
+ else:
388
+ newErr = newErr + 2*model
389
+ data = 0
390
+
391
+ t1 = 1 - data/model
392
+ for ll in range(NV):
393
+ jacobian[ll] += t1 * newDudt[ll]
394
+
395
+ t2 = data/math.pow(model, 2)
396
+ for ll in range(NV):
397
+ for mm in range(ll, NV, 1):
398
+ hessian[ll*NV + mm] += t2 * newDudt[ll] * newDudt[mm]
399
+ hessian[mm*NV + ll] = hessian[ll*NV + mm]
400
+
401
+ for kk in range(iterations): # main iterative loop # noqa: B007
402
+ if(abs((newErr-oldErr)/newErr) < TOLERANCE):
403
+ break # CONVERGED
404
+ else:
405
+ if(newErr > ACCEPTANCE * oldErr):
406
+ # copy Fitdata
407
+
408
+ for i in range(NV):
409
+ newTheta[i] = oldTheta[i]
410
+ newUpdate[i] = oldUpdate[i]
411
+ newLambda = oldLambda
412
+ newErr = oldErr
413
+ mu = max((1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
414
+ newLambda = SCALE_UP * newLambda
415
+ elif(newErr < oldErr and errFlag == 0):
416
+ newLambda = SCALE_DOWN * newLambda
417
+ mu = 1 + newLambda
418
+
419
+ for i in range(NV):
420
+ hessian[i*NV + i] = hessian[i*NV + i] * mu
421
+
422
+ for ii in range(NV_NV):
423
+ L[ii] = 0
424
+ U[ii] = 0
425
+
426
+ errFlag = kernel_cholesky(hessian, NV, L, U)
427
+ if (errFlag == 0):
428
+ for i in range(NV):
429
+ oldTheta[i] = newTheta[i]
430
+ oldUpdate[i] = newUpdate[i]
431
+ oldLambda = newLambda
432
+ oldErr = newErr
433
+
434
+ newUpdate = kernel_luEvaluate(L, U, jacobian, NV, newUpdate)
435
+
436
+ # updateFitParameters
437
+ for ll in range(NV):
438
+ if (newUpdate[ll]/oldUpdate[ll] < -0.5):
439
+ maxJump[ll] = maxJump[ll] * 0.5
440
+
441
+ newUpdate[ll] = (
442
+ newUpdate[ll] /
443
+ (1+math.fabs(newUpdate[ll]/maxJump[ll])))
444
+ newTheta[ll] = newTheta[ll] - newUpdate[ll]
445
+ # restrict range
446
+ newTheta[0] = max(newTheta[0], (float(sz)-1)/2-sz/4.0)
447
+ newTheta[0] = min(newTheta[0], (float(sz)-1)/2+sz/4.0)
448
+ newTheta[1] = max(newTheta[1], (float(sz)-1)/2-sz/4.0)
449
+ newTheta[1] = min(newTheta[1], (float(sz)-1)/2+sz/4.0)
450
+ newTheta[2] = max(newTheta[2], 1.0)
451
+ newTheta[3] = max(newTheta[3], 0.01)
452
+ newTheta[4] = max(newTheta[4], 0.0)
453
+ newTheta[4] = min(newTheta[4], sz/2.0)
454
+
455
+ newErr = 0
456
+ for hh in range(NV):
457
+ jacobian[hh] = 0
458
+ for hh in range(NV_NV):
459
+ hessian[hh] = 0
460
+ for ii in range(sz):
461
+ for jj in range(sz):
462
+ # calculating derivatives
463
+ newDudt, model = kernel_DerivativeGauss2D_sigma(
464
+ ii, jj, newTheta, newDudt)
465
+ model += s_varim[sz*jj+ii]
466
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
467
+
468
+ if (data > 0):
469
+ newErr = newErr + \
470
+ 2*((model-data)-data*math.log(model/data))
471
+ else:
472
+ newErr = newErr + 2 * model
473
+ data = 0
474
+
475
+ t1 = 1 - data/model
476
+ for ll in range(NV):
477
+ jacobian[ll] += t1 * newDudt[ll]
478
+
479
+ t2 = data/math.pow(model, 2)
480
+ for ll in range(NV):
481
+ for mm in range(ll, NV, 1):
482
+ hessian[ll*NV+mm] += \
483
+ t2 * newDudt[ll] * newDudt[mm]
484
+ hessian[mm*NV+ll] = hessian[ll*NV+mm]
485
+ else:
486
+ mu = max(
487
+ (1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
488
+ newLambda = SCALE_UP * newLambda
489
+
490
+ # output iteration
491
+ d_Parameters[(NV + 1)*(1+BlockSize*bx+tx) - 1] = kk
492
+
493
+ # Calculating the CRLB and LogLikelihood
494
+ Div = 0.0
495
+ for ii in range(sz):
496
+ for jj in range(sz):
497
+ newDudt, model = kernel_DerivativeGauss2D_sigma(
498
+ ii, jj, newTheta, newDudt)
499
+ model += s_varim[sz*jj+ii]
500
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
501
+
502
+ # Building the Fisher Information Matrix
503
+ for kk in range(NV):
504
+ for ll in range(kk, NV, 1):
505
+ M[kk*NV+ll] += newDudt[ll] * newDudt[kk] / model
506
+ M[ll*NV+kk] = M[kk*NV+ll]
507
+
508
+ # LogLikelyhood
509
+ if (model > 0):
510
+ if (data > 0):
511
+ Div += \
512
+ data*math.log(model) - \
513
+ model-data*math.log(data) + data
514
+ else:
515
+ Div += - model
516
+
517
+ # Matrix inverse (CRLB=F^-1) and output assigments
518
+ kernel_MatInvN(M, Minv, Diag, NV)
519
+ # Write to global arrays
520
+ for kk in range(NV):
521
+ d_Parameters[kk + (NV + 1)*(BlockSize*bx+tx)] = newTheta[kk]
522
+ d_CRLBs[kk + NV*(BlockSize*bx+tx)] = Diag[kk]
523
+ d_LogLikelihood[BlockSize*bx+tx] = Div
524
+
525
+ return
526
+
527
+
528
+ @cuda.jit
529
+ def kernel_MLEFit_LM_z_sCMOS(
530
+ d_data, PSFSigma_x, Ax, Ay, Bx, By, gamma, d,
531
+ PSFSigma_y, sz, iterations, d_Parameters, d_CRLBs,
532
+ d_LogLikelihood, Nfits, d_varim):
533
+ '''
534
+ basic MLE fitting kernel. No additional parameters are computed.
535
+
536
+ Parameters
537
+ ----------
538
+ d_data : float[]
539
+ array of subregions to fit copied to GPU
540
+ PSFSigma_x : float
541
+ sigma of the point spread function on the x axis
542
+ Ax : float
543
+ ???
544
+ Ay : float
545
+ ???
546
+ Bx : float
547
+ ???
548
+ By : float
549
+ ???
550
+ gamma : float
551
+ ???
552
+ d : float
553
+ ???
554
+ PSFSigma_y : float
555
+ sigma of the point spread function on the y axis
556
+ sz : int
557
+ nxn size of the subregion to fit
558
+ iterations : int
559
+ number of iterations for solution to converge
560
+ d_Parameters : float[]
561
+ array of fitting parameters to return for each subregion
562
+ d_CRLBs : float[]
563
+ array of Cramer-Rao lower bound estimates to return for each subregion
564
+ d_LogLikelihood : float[]
565
+ array of loglikelihood estimates to return for each subregion
566
+ Nfits : int
567
+ number of subregions to fit
568
+ d_varim : float[]
569
+ variance map of scmos
570
+ '''
571
+ NV = NV_PS
572
+ NV_NV = NV_PS_squared
573
+
574
+ M = cuda.local.array(NV_NV, nb.float32)
575
+ Diag = cuda.local.array(NV, nb.float32)
576
+ Minv = cuda.local.array(NV_NV, nb.float32)
577
+
578
+ tx = cuda.threadIdx.x
579
+ bx = cuda.blockIdx.x
580
+ BlockSize = cuda.blockDim.x
581
+
582
+ model = 0
583
+ data = 0
584
+ Div = 0
585
+ PSFy = PSFx = 0
586
+
587
+ newTheta = cuda.local.array(NV, nb.float32)
588
+ oldTheta = cuda.local.array(NV, nb.float32)
589
+ newLambda = INIT_LAMBDA
590
+ oldLambda = INIT_LAMBDA
591
+ mu = 0
592
+
593
+ newUpdate = cuda.local.array(NV, nb.float32)
594
+ oldUpdate = cuda.local.array(NV, nb.float32)
595
+ newDudt = cuda.local.array(NV, nb.float32)
596
+ for i in range(NV):
597
+ newUpdate[i] = 1e13
598
+ oldUpdate[i] = 1e13
599
+ newDudt[i] = 0
600
+ maxJump = cuda.local.array(NV, nb.float32)
601
+ maxJump[0] = 1.0
602
+ maxJump[1] = 1.0
603
+ maxJump[2] = 100.0
604
+ maxJump[3] = 20.0
605
+ maxJump[4] = 2
606
+
607
+ newErr = 1e12
608
+ oldErr = 1e13
609
+
610
+ jacobian = cuda.local.array(NV, nb.float32)
611
+ hessian = cuda.local.array(NV_NV, nb.float32)
612
+ t1 = 0
613
+ t2 = 0
614
+
615
+ Nmax = 0
616
+ errFlag = 0
617
+ L = cuda.local.array(NV_NV, nb.float32)
618
+ U = cuda.local.array(NV_NV, nb.float32)
619
+
620
+ # Prevent read/write past end of array
621
+ if ((bx*BlockSize+tx) >= Nfits):
622
+ return
623
+
624
+ for ii in range(NV_NV):
625
+ M[ii] = 0
626
+ Minv[ii] = 0
627
+ hessian[ii] = 0
628
+ L[ii] = 0
629
+ U[ii] = 0
630
+
631
+ # Requires Checking
632
+ idx = sz*sz*bx*BlockSize + sz*sz*tx
633
+ s_data = d_data[idx:idx + sz*sz]
634
+ s_varim = d_varim[idx:idx + sz*sz]
635
+
636
+ # initial values
637
+ newTheta[0], newTheta[1] = kernel_CenterofMass2D(
638
+ sz, s_data)
639
+ Nmax, newTheta[3] = kernel_GaussFMaxMin2D(
640
+ sz, PSFSigma_x, s_data)
641
+ newTheta[2] = max(
642
+ 0.0,
643
+ (Nmax-newTheta[3])*2*pi*PSFSigma_x*PSFSigma_y*math.sqrt(2.0))
644
+ newTheta[3] = max(newTheta[3], 0.01)
645
+ newTheta[4] = 0
646
+
647
+ maxJump[2] = max(newTheta[2], maxJump[2])
648
+
649
+ maxJump[3] = max(newTheta[3], maxJump[3])
650
+
651
+ for ii in range(NV):
652
+ oldTheta[ii] = newTheta[ii]
653
+ jacobian[ii] = 0
654
+
655
+ # updateFitValues
656
+ newErr = 0
657
+ for ii in range(sz):
658
+ for jj in range(sz):
659
+ PSFx, PSFy, newDudt, _, model = kernel_DerivativeIntGauss2Dz(
660
+ ii, jj, newTheta, PSFSigma_x, PSFSigma_y,
661
+ Ax, Ay, Bx, By, gamma, d, newDudt, None, False)
662
+ model += s_varim[sz*jj+ii]
663
+ data = s_data[sz*jj+ii]+s_varim[sz*jj+ii]
664
+
665
+ if (data > 0):
666
+ newErr = newErr + 2*((model-data)-data*math.log(model/data))
667
+ else:
668
+ newErr = newErr + 2*model
669
+ data = 0
670
+
671
+ t1 = 1 - data/model
672
+ for ll in range(NV):
673
+ jacobian[ll] += t1 * newDudt[ll]
674
+
675
+ t2 = data/math.pow(model, 2)
676
+ for ll in range(NV):
677
+ for mm in range(ll, NV, 1):
678
+ hessian[ll*NV + mm] += t2 * newDudt[ll] * newDudt[mm]
679
+ hessian[mm*NV + ll] = hessian[ll*NV + mm]
680
+
681
+ for kk in range(iterations): # main iterative loop # noqa: B007
682
+ if(abs((newErr-oldErr)/newErr) < TOLERANCE):
683
+ break # CONVERGED
684
+ else:
685
+ if(newErr > ACCEPTANCE * oldErr):
686
+ # copy Fitdata
687
+
688
+ for i in range(NV):
689
+ newTheta[i] = oldTheta[i]
690
+ newUpdate[i] = oldUpdate[i]
691
+ newLambda = oldLambda
692
+ newErr = oldErr
693
+ mu = max((1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
694
+ newLambda = SCALE_UP * newLambda
695
+ elif(newErr < oldErr and errFlag == 0):
696
+ newLambda = SCALE_DOWN * newLambda
697
+ mu = 1 + newLambda
698
+
699
+ for i in range(NV):
700
+ hessian[i*NV + i] = hessian[i*NV + i] * mu
701
+
702
+ for ii in range(NV_NV):
703
+ L[ii] = 0
704
+ U[ii] = 0
705
+
706
+ errFlag = kernel_cholesky(hessian, NV, L, U)
707
+ if (errFlag == 0):
708
+ for i in range(NV):
709
+ oldTheta[i] = newTheta[i]
710
+ oldUpdate[i] = newUpdate[i]
711
+ oldLambda = newLambda
712
+ oldErr = newErr
713
+
714
+ newUpdate = kernel_luEvaluate(L, U, jacobian, NV, newUpdate)
715
+
716
+ # updateFitParameters
717
+ for ll in range(NV):
718
+ if (newUpdate[ll]/oldUpdate[ll] < -0.5):
719
+ maxJump[ll] = maxJump[ll] * 0.5
720
+
721
+ newUpdate[ll] = (
722
+ newUpdate[ll] /
723
+ (1+math.fabs(newUpdate[ll]/maxJump[ll])))
724
+ newTheta[ll] = newTheta[ll] - newUpdate[ll]
725
+ # restrict range
726
+ newTheta[0] = max(newTheta[0], (float(sz)-1)/2-sz/4.0)
727
+ newTheta[0] = min(newTheta[0], (float(sz)-1)/2+sz/4.0)
728
+ newTheta[1] = max(newTheta[1], (float(sz)-1)/2-sz/4.0)
729
+ newTheta[1] = min(newTheta[1], (float(sz)-1)/2+sz/4.0)
730
+ newTheta[2] = max(newTheta[2], 1.0)
731
+ newTheta[3] = max(newTheta[3], 0.01)
732
+
733
+ newErr = 0
734
+ for hh in range(NV):
735
+ jacobian[hh] = 0
736
+ for hh in range(NV_NV):
737
+ hessian[hh] = 0
738
+ for ii in range(sz):
739
+ for jj in range(sz):
740
+ # calculating derivatives
741
+ PSFx, PSFy, newDudt, _, model = \
742
+ kernel_DerivativeIntGauss2Dz(
743
+ ii, jj, newTheta, PSFSigma_x, PSFSigma_y,
744
+ Ax, Ay, Bx, By, gamma, d, newDudt, None, False)
745
+
746
+ model += s_varim[sz*jj+ii]
747
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
748
+
749
+ if (data > 0):
750
+ newErr = newErr + \
751
+ 2*((model-data)-data*math.log(model/data))
752
+ else:
753
+ newErr = newErr + 2 * model
754
+ data = 0
755
+
756
+ t1 = 1 - data/model
757
+ for ll in range(NV):
758
+ jacobian[ll] += t1 * newDudt[ll]
759
+
760
+ t2 = data/math.pow(model, 2)
761
+ for ll in range(NV):
762
+ for mm in range(ll, NV, 1):
763
+ hessian[ll*NV+mm] += \
764
+ t2 * newDudt[ll] * newDudt[mm]
765
+ hessian[mm*NV+ll] = hessian[ll*NV+mm]
766
+ else:
767
+ mu = max(
768
+ (1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
769
+ newLambda = SCALE_UP * newLambda
770
+
771
+ # output iteration
772
+ d_Parameters[(NV + 1)*(1+BlockSize*bx+tx) - 1] = kk
773
+
774
+ # Calculating the CRLB and LogLikelihood
775
+ Div = 0.0
776
+ for ii in range(sz):
777
+ for jj in range(sz):
778
+ PSFx, PSFy, newDudt, _, model = kernel_DerivativeIntGauss2Dz(
779
+ ii, jj, newTheta, PSFSigma_x, PSFSigma_y,
780
+ Ax, Ay, Bx, By, gamma, d, newDudt, None, False)
781
+ model += s_varim[sz*jj+ii]
782
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
783
+
784
+ # Building the Fisher Information Matrix
785
+ for kk in range(NV):
786
+ for ll in range(kk, NV, 1):
787
+ M[kk*NV+ll] += newDudt[ll] * newDudt[kk] / model
788
+ M[ll*NV+kk] = M[kk*NV+ll]
789
+
790
+ # LogLikelyhood
791
+ if (model > 0):
792
+ if (data > 0):
793
+ Div += \
794
+ data*math.log(model) - \
795
+ model-data*math.log(data) + data
796
+ else:
797
+ Div += - model
798
+
799
+ # Matrix inverse (CRLB=F^-1) and output assigments
800
+ kernel_MatInvN(M, Minv, Diag, NV)
801
+ # Write to global arrays
802
+ for kk in range(NV):
803
+ d_Parameters[kk + (NV + 1)*(BlockSize*bx+tx)] = newTheta[kk]
804
+ d_CRLBs[kk + NV*(BlockSize*bx+tx)] = Diag[kk]
805
+ d_LogLikelihood[BlockSize*bx+tx] = Div
806
+
807
+ return
808
+
809
+
810
+ @cuda.jit
811
+ def kernel_MLEFit_LM_sigmaxy_sCMOS(
812
+ d_data, PSFSigma, sz, iterations, d_Parameters,
813
+ d_CRLBs, d_LogLikelihood, Nfits, d_varim):
814
+ '''
815
+ basic MLE fitting kernel. No additional parameters are computed.
816
+
817
+ Parameters
818
+ ----------
819
+ d_data : float[]
820
+ array of subregions to fit copied to GPU
821
+ PSFSigma : float
822
+ sigma of the point spread function
823
+ sz : int
824
+ nxn size of the subregion to fit
825
+ iterations : int
826
+ number of iterations for solution to converge
827
+ d_Parameters : float[]
828
+ array of fitting parameters to return for each subregion
829
+ d_CRLBs : float[]
830
+ array of Cramer-Rao lower bound estimates to return for each subregion
831
+ d_LogLikelihood : float[]
832
+ array of loglikelihood estimates to return for each subregion
833
+ Nfits : int
834
+ number of subregions to fit
835
+ d_varim : float[]
836
+ variance map of scmos
837
+ '''
838
+ NV = NV_PS2
839
+ NV_NV = NV_PS2_squared
840
+
841
+ M = cuda.local.array(NV_NV, nb.float32)
842
+ Diag = cuda.local.array(NV, nb.float32)
843
+ Minv = cuda.local.array(NV_NV, nb.float32)
844
+
845
+ tx = cuda.threadIdx.x
846
+ bx = cuda.blockIdx.x
847
+ BlockSize = cuda.blockDim.x
848
+
849
+ model = 0
850
+ data = 0
851
+ Div = 0
852
+
853
+ newTheta = cuda.local.array(NV, nb.float32)
854
+ oldTheta = cuda.local.array(NV, nb.float32)
855
+ newLambda = INIT_LAMBDA
856
+ oldLambda = INIT_LAMBDA
857
+ mu = 0
858
+
859
+ newUpdate = cuda.local.array(NV, nb.float32)
860
+ oldUpdate = cuda.local.array(NV, nb.float32)
861
+ newDudt = cuda.local.array(NV, nb.float32)
862
+ for i in range(NV):
863
+ newUpdate[i] = 1e13
864
+ oldUpdate[i] = 1e13
865
+ newDudt[i] = 0
866
+ maxJump = cuda.local.array(NV, nb.float32)
867
+ maxJump[0] = 1.0
868
+ maxJump[1] = 1.0
869
+ maxJump[2] = 100.0
870
+ maxJump[3] = 20.0
871
+ maxJump[4] = 0.5
872
+ maxJump[5] = 0.5
873
+
874
+ newErr = 1e12
875
+ oldErr = 1e13
876
+
877
+ jacobian = cuda.local.array(NV, nb.float32)
878
+ hessian = cuda.local.array(NV_NV, nb.float32)
879
+ t1 = 0.0
880
+ t2 = 0.0
881
+
882
+ Nmax = 0
883
+ errFlag = 0
884
+ L = cuda.local.array(NV_NV, nb.float32)
885
+ U = cuda.local.array(NV_NV, nb.float32)
886
+
887
+ # Prevent read/write past end of array
888
+ if ((bx*BlockSize+tx) >= Nfits):
889
+ return
890
+
891
+ for ii in range(NV_NV):
892
+ M[ii] = 0
893
+ Minv[ii] = 0
894
+ hessian[ii] = 0
895
+ L[ii] = 0
896
+ U[ii] = 0
897
+
898
+ # Requires Checking
899
+ idx = sz*sz*bx*BlockSize + sz*sz*tx
900
+ s_data = d_data[idx:idx + sz*sz]
901
+ s_varim = d_varim[idx:idx + sz*sz]
902
+
903
+ # initial values
904
+ newTheta[0], newTheta[1] = kernel_CenterofMass2D(
905
+ sz, s_data)
906
+ Nmax, newTheta[3] = kernel_GaussFMaxMin2D(
907
+ sz, PSFSigma, s_data)
908
+ newTheta[2] = max(
909
+ 0.0,
910
+ (Nmax-newTheta[3])*2*pi*PSFSigma*PSFSigma)
911
+ newTheta[3] = max(newTheta[3], 0.01)
912
+ newTheta[4] = PSFSigma
913
+ newTheta[5] = PSFSigma
914
+
915
+ maxJump[2] = max(newTheta[2], maxJump[2])
916
+
917
+ maxJump[3] = max(newTheta[3], maxJump[3])
918
+
919
+ for ii in range(NV):
920
+ oldTheta[ii] = newTheta[ii]
921
+ jacobian[ii] = 0
922
+
923
+ # updateFitValues
924
+ newErr = 0
925
+ for ii in range(sz):
926
+ for jj in range(sz):
927
+ newDudt, model = kernel_DerivativeGauss2D_sigmaxy(
928
+ ii, jj, newTheta, newDudt)
929
+ model += s_varim[sz*jj+ii]
930
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
931
+
932
+ if (data > 0):
933
+ newErr = newErr + 2*((model-data)-data*math.log(model/data))
934
+ else:
935
+ newErr = newErr + 2*model
936
+ data = 0
937
+
938
+ t1 = 1 - data/model
939
+ for ll in range(NV):
940
+ jacobian[ll] += t1 * newDudt[ll]
941
+
942
+ t2 = data/math.pow(model, 2)
943
+ for ll in range(NV):
944
+ for mm in range(ll, NV, 1):
945
+ hessian[ll*NV + mm] += t2 * newDudt[ll] * newDudt[mm]
946
+ hessian[mm*NV + ll] = hessian[ll*NV + mm]
947
+
948
+ for kk in range(iterations): # main iterative loop # noqa: B007
949
+ if(abs((newErr-oldErr)/newErr) < TOLERANCE):
950
+ break # CONVERGED
951
+ else:
952
+ if(newErr > ACCEPTANCE * oldErr):
953
+ # copy Fitdata
954
+ for i in range(NV):
955
+ newTheta[i] = oldTheta[i]
956
+ newUpdate[i] = oldUpdate[i]
957
+ newLambda = oldLambda
958
+ newErr = oldErr
959
+ mu = max((1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
960
+ newLambda = SCALE_UP * newLambda
961
+ elif(newErr < oldErr and errFlag == 0):
962
+ newLambda = SCALE_DOWN * newLambda
963
+ mu = 1 + newLambda
964
+
965
+ for i in range(NV):
966
+ hessian[i*NV + i] = hessian[i*NV + i] * mu
967
+
968
+ for ii in range(NV_NV):
969
+ L[ii] = 0
970
+ U[ii] = 0
971
+
972
+ errFlag = kernel_cholesky(hessian, NV, L, U)
973
+ if (errFlag == 0):
974
+ for i in range(NV):
975
+ oldTheta[i] = newTheta[i]
976
+ oldUpdate[i] = newUpdate[i]
977
+ oldLambda = newLambda
978
+ oldErr = newErr
979
+
980
+ newUpdate = kernel_luEvaluate(L, U, jacobian, NV, newUpdate)
981
+
982
+ # updateFitParameters
983
+ for ll in range(NV):
984
+ if (newUpdate[ll]/oldUpdate[ll] < -0.5):
985
+ maxJump[ll] = maxJump[ll] * 0.5
986
+
987
+ newUpdate[ll] = (
988
+ newUpdate[ll] /
989
+ (1+math.fabs(newUpdate[ll]/maxJump[ll])))
990
+ newTheta[ll] = newTheta[ll] - newUpdate[ll]
991
+ # restrict range
992
+ newTheta[0] = max(newTheta[0], (float(sz)-1)/2-sz/4.0)
993
+ newTheta[0] = min(newTheta[0], (float(sz)-1)/2+sz/4.0)
994
+ newTheta[1] = max(newTheta[1], (float(sz)-1)/2-sz/4.0)
995
+ newTheta[1] = min(newTheta[1], (float(sz)-1)/2+sz/4.0)
996
+ newTheta[2] = max(newTheta[2], 1.0)
997
+ newTheta[3] = max(newTheta[3], 0.01)
998
+ newTheta[4] = max(newTheta[4], PSFSigma/10.0)
999
+ newTheta[5] = max(newTheta[5], PSFSigma/10.0)
1000
+
1001
+ newErr = 0
1002
+ for hh in range(NV):
1003
+ jacobian[hh] = 0
1004
+ for hh in range(NV_NV):
1005
+ hessian[hh] = 0
1006
+ for ii in range(sz):
1007
+ for jj in range(sz):
1008
+ # calculating derivatives
1009
+ newDudt, model = kernel_DerivativeGauss2D_sigmaxy(
1010
+ ii, jj, newTheta, newDudt)
1011
+ model += s_varim[sz*jj+ii]
1012
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
1013
+
1014
+ if (data > 0):
1015
+ newErr = newErr + \
1016
+ 2*((model-data)-data*math.log(model/data))
1017
+ else:
1018
+ newErr = newErr + 2*model
1019
+ data = 0
1020
+
1021
+ t1 = 1 - data/model
1022
+ for ll in range(NV):
1023
+ jacobian[ll] += t1 * newDudt[ll]
1024
+
1025
+ t2 = data/math.pow(model, 2)
1026
+ for ll in range(NV):
1027
+ for mm in range(ll, NV, 1):
1028
+ hessian[ll*NV+mm] += \
1029
+ t2 * newDudt[ll] * newDudt[mm]
1030
+ hessian[mm*NV+ll] = hessian[ll*NV+mm]
1031
+ else:
1032
+ mu = max(
1033
+ (1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
1034
+ newLambda = SCALE_UP * newLambda
1035
+
1036
+ # output iteration
1037
+ d_Parameters[(NV + 1)*(1+BlockSize*bx+tx) - 1] = kk
1038
+
1039
+ # Calculating the CRLB and LogLikelihood
1040
+ Div = 0.0
1041
+ for ii in range(sz):
1042
+ for jj in range(sz):
1043
+ newDudt, model = kernel_DerivativeGauss2D_sigmaxy(
1044
+ ii, jj, newTheta, newDudt)
1045
+ model += s_varim[sz*jj+ii]
1046
+ data = s_data[sz*jj+ii]+s_varim[sz*jj+ii]
1047
+
1048
+ # Building the Fisher Information Matrix
1049
+ for kk in range(NV):
1050
+ for ll in range(kk, NV, 1):
1051
+ M[kk*NV+ll] += newDudt[ll] * newDudt[kk] / model
1052
+ M[ll*NV+kk] = M[kk*NV+ll]
1053
+
1054
+ # LogLikelyhood
1055
+ if (model > 0):
1056
+ if (data > 0):
1057
+ Div += \
1058
+ data*math.log(model) - \
1059
+ model-data*math.log(data) + data
1060
+ else:
1061
+ Div += - model
1062
+
1063
+ # Matrix inverse (CRLB=F^-1) and output assigments
1064
+ kernel_MatInvN(M, Minv, Diag, NV)
1065
+ # Write to global arrays
1066
+ for kk in range(NV):
1067
+ d_Parameters[kk + (NV + 1)*(BlockSize*bx+tx)] = newTheta[kk]
1068
+ d_CRLBs[kk + NV*(BlockSize*bx+tx)] = Diag[kk]
1069
+ d_LogLikelihood[BlockSize*bx+tx] = Div
1070
+
1071
+ return
1072
+
1073
+
1074
+ @cuda.jit
1075
+ def kernel_splineMLEFit_z_sCMOS(
1076
+ d_data, d_coeff, spline_xsize, spline_ysize, spline_zsize, sz,
1077
+ iterations, d_Parameters, d_CRLBs, d_LogLikelihood,
1078
+ initZ, Nfits, d_varim):
1079
+ '''
1080
+ basic MLE fitting kernel. No additional parameters are computed.
1081
+
1082
+ Parameters
1083
+ ----------
1084
+ d_data : float[]
1085
+ array of subregions to fit copied to GPU
1086
+ d_coeff : float[]
1087
+ array of spline coefficients of the PSF model
1088
+ spline_xsize : int
1089
+ x size of spline coefficients
1090
+ spline_ysize : int
1091
+ y size of spline coefficients
1092
+ spline_zsize : int
1093
+ z size of spline coefficients
1094
+ sz : int
1095
+ nxn size of the subregion to fit
1096
+ iterations : int
1097
+ number of iterations for solution to converge
1098
+ d_Parameters : float[]
1099
+ array of fitting parameters to return for each subregion
1100
+ d_CRLBs : float[]
1101
+ array of Cramer-Rao lower bound estimates to return for each subregion
1102
+ d_LogLikelihood : float[]
1103
+ array of loglikelihood estimates to return for each subregion
1104
+ initZ : float
1105
+ intial z position used for fitting
1106
+ Nfits : int
1107
+ number of subregions to fit
1108
+ d_varim : float[]
1109
+ variance map of sCMOS
1110
+ '''
1111
+ NV = NV_PSP
1112
+ NV_NV = NV_PSP_squared
1113
+
1114
+ M = cuda.local.array(NV_NV, nb.float32)
1115
+ Diag = cuda.local.array(NV, nb.float32)
1116
+ Minv = cuda.local.array(NV_NV, nb.float32)
1117
+
1118
+ tx = cuda.threadIdx.x
1119
+ bx = cuda.blockIdx.x
1120
+ BlockSize = cuda.blockDim.x
1121
+
1122
+ xstart = ystart = zstart = 0
1123
+
1124
+ s_coeff = d_coeff
1125
+
1126
+ model = 0
1127
+ data = 0
1128
+ Div = 0
1129
+
1130
+ newTheta = cuda.local.array(NV, nb.float32)
1131
+ oldTheta = cuda.local.array(NV, nb.float32)
1132
+ newLambda = INIT_LAMBDA
1133
+ oldLambda = INIT_LAMBDA
1134
+ mu = 0
1135
+
1136
+ newUpdate = cuda.local.array(NV, nb.float32)
1137
+ oldUpdate = cuda.local.array(NV, nb.float32)
1138
+ newDudt = cuda.local.array(NV, nb.float32)
1139
+ for i in range(NV):
1140
+ newUpdate[i] = 1e13
1141
+ oldUpdate[i] = 1e13
1142
+ newDudt[i] = 0
1143
+ maxJump = cuda.local.array(NV, nb.float32)
1144
+ maxJump[0] = 1.0
1145
+ maxJump[1] = 1.0
1146
+ maxJump[2] = 100.0
1147
+ maxJump[3] = 20.0
1148
+ maxJump[4] = 2
1149
+
1150
+ newErr = 1e12
1151
+ oldErr = 1e13
1152
+
1153
+ off = 0.0
1154
+ jacobian = cuda.local.array(NV, nb.float32)
1155
+ hessian = cuda.local.array(NV_NV, nb.float32)
1156
+ t1 = 0.0
1157
+ t2 = 0.0
1158
+
1159
+ Nmax = 0
1160
+ errFlag = 0
1161
+ L = cuda.local.array(NV_NV, nb.float32)
1162
+ U = cuda.local.array(NV_NV, nb.float32)
1163
+
1164
+ xc = yc = zc = 0.0
1165
+ delta_f = cuda.local.array(64, nb.float32)
1166
+ delta_dxf = cuda.local.array(64, nb.float32)
1167
+ delta_dyf = cuda.local.array(64, nb.float32)
1168
+ delta_dzf = cuda.local.array(64, nb.float32)
1169
+ for ii in range(64):
1170
+ delta_f[ii] = 0
1171
+ delta_dxf[ii] = 0
1172
+ delta_dyf[ii] = 0
1173
+ delta_dzf[ii] = 0
1174
+
1175
+ # Prevent read/write past end of array
1176
+ if ((bx*BlockSize+tx) >= Nfits):
1177
+ return
1178
+
1179
+ for ii in range(NV_NV):
1180
+ M[ii] = 0
1181
+ Minv[ii] = 0
1182
+ hessian[ii] = 0
1183
+ L[ii] = 0
1184
+ U[ii] = 0
1185
+
1186
+ # Requires Checking
1187
+ idx = sz*sz*bx*BlockSize + sz*sz*tx
1188
+ s_data = d_data[idx:idx + sz*sz]
1189
+ s_varim = d_varim[idx:idx + sz*sz]
1190
+
1191
+ # initial values
1192
+ newTheta[0], newTheta[1] = kernel_CenterofMass2D(sz, s_data)
1193
+ Nmax, newTheta[3] = kernel_GaussFMaxMin2D(sz, 1.5, s_data)
1194
+
1195
+ # central pixel of spline model
1196
+ newTheta[3] = max(newTheta[3], 0.01)
1197
+ newTheta[2] = \
1198
+ (Nmax-newTheta[3]) / d_coeff[
1199
+ int(spline_zsize/2) * (spline_xsize*spline_ysize) +
1200
+ int(spline_ysize/2) * spline_xsize +
1201
+ int(spline_xsize/2)] * 4
1202
+
1203
+ # newTheta[4]=float(spline_zsize)/2;
1204
+ newTheta[4] = initZ
1205
+
1206
+ maxJump[2] = max(newTheta[2], maxJump[2])
1207
+ maxJump[3] = max(newTheta[3], maxJump[3])
1208
+ maxJump[4] = max(spline_zsize/3.0, maxJump[4])
1209
+
1210
+ for ii in range(NV):
1211
+ oldTheta[ii] = newTheta[ii]
1212
+ jacobian[ii] = 0
1213
+
1214
+ # updateFitValues
1215
+ xc = -1.0*((newTheta[0]-float(sz)/2)+0.5)
1216
+ yc = -1.0*((newTheta[1]-float(sz)/2)+0.5)
1217
+
1218
+ off = math.floor((float(spline_xsize)+1.0-float(sz))/2)
1219
+
1220
+ xstart = math.floor(xc)
1221
+ xc = xc - xstart
1222
+
1223
+ ystart = math.floor(yc)
1224
+ yc = yc - ystart
1225
+
1226
+ # zstart = floor(newTheta[4]);
1227
+ zstart = math.floor(newTheta[4])
1228
+ zc = newTheta[4] - zstart
1229
+
1230
+ # updateFitValues
1231
+ newErr = 0
1232
+ delta_f, delta_dxf, delta_dyf, delta_dzf = kernel_computeDelta3D(
1233
+ xc, yc, zc, delta_f, delta_dxf, delta_dyf, delta_dzf)
1234
+
1235
+ for ii in range(sz):
1236
+ for jj in range(sz):
1237
+ newDudt, model = kernel_DerivativeSpline(
1238
+ ii + xstart + off, jj + ystart + off, zstart,
1239
+ spline_xsize, spline_ysize, spline_zsize,
1240
+ delta_f, delta_dxf, delta_dyf, delta_dzf,
1241
+ s_coeff, newTheta, newDudt)
1242
+ model += s_varim[sz*jj+ii]
1243
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
1244
+
1245
+ if (data > 0):
1246
+ newErr = newErr + 2*((model-data)-data*math.log(model/data))
1247
+ else:
1248
+ newErr = newErr + 2*model
1249
+ data = 0
1250
+
1251
+ t1 = 1 - data/model
1252
+ for ll in range(NV):
1253
+ jacobian[ll] += t1 * newDudt[ll]
1254
+
1255
+ t2 = data/math.pow(model, 2)
1256
+ for ll in range(NV):
1257
+ for mm in range(ll, NV, 1):
1258
+ hessian[ll*NV + mm] += t2 * newDudt[ll] * newDudt[mm]
1259
+ hessian[mm*NV + ll] = hessian[ll*NV + mm]
1260
+
1261
+ for kk in range(iterations): # main iterative loop # noqa: B007
1262
+ if(abs((newErr-oldErr)/newErr) < TOLERANCE):
1263
+ break # CONVERGED
1264
+ else:
1265
+ if(newErr > ACCEPTANCE * oldErr):
1266
+ # copy Fitdata
1267
+ for i in range(NV):
1268
+ newTheta[i] = oldTheta[i]
1269
+ newUpdate[i] = oldUpdate[i]
1270
+ newLambda = oldLambda
1271
+ newErr = oldErr
1272
+ mu = max((1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
1273
+ newLambda = SCALE_UP * newLambda
1274
+ elif(newErr < oldErr and errFlag == 0):
1275
+ newLambda = SCALE_DOWN * newLambda
1276
+ mu = 1 + newLambda
1277
+
1278
+ for i in range(NV):
1279
+ hessian[i*NV + i] = hessian[i*NV + i] * mu
1280
+
1281
+ for ii in range(NV_NV):
1282
+ L[ii] = 0
1283
+ U[ii] = 0
1284
+
1285
+ errFlag = kernel_cholesky(hessian, NV, L, U)
1286
+
1287
+ if (errFlag == 0):
1288
+ for i in range(NV):
1289
+ oldTheta[i] = newTheta[i]
1290
+ oldUpdate[i] = newUpdate[i]
1291
+ oldLambda = newLambda
1292
+ oldErr = newErr
1293
+
1294
+ newUpdate = kernel_luEvaluate(L, U, jacobian, NV, newUpdate)
1295
+
1296
+ # updateFitParameters
1297
+ for ll in range(NV):
1298
+ if (newUpdate[ll]/oldUpdate[ll] < -0.5):
1299
+ maxJump[ll] = maxJump[ll] * 0.5
1300
+
1301
+ newUpdate[ll] = (
1302
+ newUpdate[ll] /
1303
+ (1+math.fabs(newUpdate[ll]/maxJump[ll])))
1304
+ newTheta[ll] = newTheta[ll] - newUpdate[ll]
1305
+ # restrict range
1306
+ newTheta[0] = max(newTheta[0], (float(sz)-1)/2-sz/4.0)
1307
+ newTheta[0] = min(newTheta[0], (float(sz)-1)/2+sz/4.0)
1308
+ newTheta[1] = max(newTheta[1], (float(sz)-1)/2-sz/4.0)
1309
+ newTheta[1] = min(newTheta[1], (float(sz)-1)/2+sz/4.0)
1310
+ newTheta[2] = max(newTheta[2], 1.0)
1311
+ newTheta[3] = max(newTheta[3], 0.01)
1312
+ newTheta[4] = max(newTheta[4], 0.0)
1313
+ newTheta[4] = min(newTheta[4], float(spline_zsize))
1314
+
1315
+ # updateFitValues
1316
+ xc = -1.0*((newTheta[0]-float(sz)/2)+0.5)
1317
+ yc = -1.0*((newTheta[1]-float(sz)/2)+0.5)
1318
+
1319
+ xstart = math.floor(xc)
1320
+ xc = xc - xstart
1321
+
1322
+ ystart = math.floor(yc)
1323
+ yc = yc - ystart
1324
+
1325
+ zstart = math.floor(newTheta[4])
1326
+ zc = newTheta[4] - zstart
1327
+
1328
+ newErr = 0
1329
+ for hh in range(NV):
1330
+ jacobian[hh] = 0
1331
+ for hh in range(NV_NV):
1332
+ hessian[hh] = 0
1333
+ delta_f, delta_dxf, delta_dyf, delta_dzf = \
1334
+ kernel_computeDelta3D(
1335
+ xc, yc, zc, delta_f, delta_dxf, delta_dyf, delta_dzf)
1336
+
1337
+ for ii in range(sz):
1338
+ for jj in range(sz):
1339
+ # calculating derivatives
1340
+ newDudt, model = kernel_DerivativeSpline(
1341
+ ii + xstart + off, jj + ystart + off, zstart,
1342
+ spline_xsize, spline_ysize, spline_zsize,
1343
+ delta_f, delta_dxf, delta_dyf, delta_dzf,
1344
+ s_coeff, newTheta, newDudt)
1345
+ model += s_varim[sz*jj+ii]
1346
+ data = s_data[sz*jj+ii] + s_varim[sz*jj+ii]
1347
+
1348
+ if (data > 0):
1349
+ newErr = newErr + \
1350
+ 2*((model-data)-data*math.log(model/data))
1351
+ else:
1352
+ newErr = newErr + 2*model
1353
+ data = 0
1354
+
1355
+ t1 = 1 - data/model
1356
+ for ll in range(NV):
1357
+ jacobian[ll] += t1 * newDudt[ll]
1358
+
1359
+ t2 = data/math.pow(model, 2)
1360
+ for ll in range(NV):
1361
+ for mm in range(ll, NV, 1):
1362
+ hessian[ll*NV+mm] += \
1363
+ t2 * newDudt[ll] * newDudt[mm]
1364
+ hessian[mm*NV+ll] = hessian[ll*NV+mm]
1365
+ else:
1366
+ mu = max(
1367
+ (1 + newLambda*SCALE_UP)/(1 + newLambda), 1.3)
1368
+ newLambda = SCALE_UP * newLambda
1369
+
1370
+ # output iteration
1371
+ d_Parameters[(NV + 1)*(1+BlockSize*bx+tx) - 1] = kk
1372
+
1373
+ # Calculating the CRLB and LogLikelihood
1374
+ Div = 0.0
1375
+
1376
+ xc = -1.0*((newTheta[0]-float(sz)/2)+0.5)
1377
+ yc = -1.0*((newTheta[1]-float(sz)/2)+0.5)
1378
+
1379
+ # off = (float(spline_xsize)+1.0-2*float(sz))/2;
1380
+
1381
+ xstart = math.floor(xc)
1382
+ xc = xc - xstart
1383
+
1384
+ ystart = math.floor(yc)
1385
+ yc = yc - ystart
1386
+
1387
+ zstart = math.floor(newTheta[4])
1388
+ zc = newTheta[4] - zstart
1389
+
1390
+ delta_f, delta_dxf, delta_dyf, delta_dzf = kernel_computeDelta3D(
1391
+ xc, yc, zc, delta_f, delta_dxf, delta_dyf, delta_dzf)
1392
+
1393
+ for ii in range(sz):
1394
+ for jj in range(sz):
1395
+ newDudt, model = kernel_DerivativeSpline(
1396
+ ii + xstart + off, jj + ystart + off, zstart,
1397
+ spline_xsize, spline_ysize, spline_zsize,
1398
+ delta_f, delta_dxf, delta_dyf, delta_dzf,
1399
+ s_coeff, newTheta, newDudt)
1400
+ model += s_varim[sz*jj+ii]
1401
+ data = s_data[sz*jj+ii]+s_varim[sz*jj+ii]
1402
+
1403
+ # Building the Fisher Information Matrix
1404
+ for kk in range(NV):
1405
+ for ll in range(kk, NV, 1):
1406
+ M[kk*NV+ll] += newDudt[ll] * newDudt[kk] / model
1407
+ M[ll*NV+kk] = M[kk*NV+ll]
1408
+
1409
+ # LogLikelyhood
1410
+ if (model > 0):
1411
+ if (data > 0):
1412
+ Div += \
1413
+ data*math.log(model) - \
1414
+ model-data*math.log(data) + data
1415
+ else:
1416
+ Div += - model
1417
+
1418
+ # Matrix inverse (CRLB=F^-1) and output assigments
1419
+ kernel_MatInvN(M, Minv, Diag, NV)
1420
+ # Write to global arrays
1421
+ for kk in range(NV):
1422
+ d_Parameters[kk + (NV + 1)*(BlockSize*bx+tx)] = newTheta[kk]
1423
+ d_CRLBs[kk + NV*(BlockSize*bx+tx)] = Diag[kk]
1424
+ d_LogLikelihood[BlockSize*bx+tx] = Div
1425
+
1426
+ return