From 4855675e5d6c5b0505d2ed141bb5ebcad386cb94 Mon Sep 17 00:00:00 2001 From: Stefan Stoll Date: Wed, 9 Mar 2022 22:38:24 -0800 Subject: [PATCH] gauss: change width to std (#280) * gauss: change width to std * Fix typo Co-authored-by: Luis Fabregas <48292540+luisfabib@users.noreply.github.com> --- deerlab/dd_models.py | 49 ++++--- docsrc/source/basics.rst | 4 +- docsrc/source/fitting_guide.rst | 6 +- docsrc/source/modelling_guide.rst | 86 ++++++------ examples/advanced/ex_droplets_model.py | 24 ++-- .../ex_extracting_gauss_constraints.py | 4 +- .../ex_global_twostates_parametric.py | 18 +-- test/test_dipolarmodel.py | 24 ++-- test/test_model_class.py | 126 +++++++++--------- test/test_model_lincombine.py | 34 ++--- test/test_model_link.py | 8 +- test/test_model_merge.py | 20 +-- test/test_model_penalty.py | 6 +- test/test_model_relate.py | 44 +++--- test/test_profile_analysis.py | 24 ++-- test/test_snlls.py | 22 +-- test/test_snlls_nlls.py | 8 +- test/test_snlls_rlls.py | 8 +- 18 files changed, 257 insertions(+), 258 deletions(-) diff --git a/deerlab/dd_models.py b/deerlab/dd_models.py index 7e5681de..5f06da3b 100644 --- a/deerlab/dd_models.py +++ b/deerlab/dd_models.py @@ -154,14 +154,14 @@ def _nonparametric(): where `\left` is the mean distance and `\sigma` the standard deviation. """ -def _gauss(r,mean,width): - return _multigaussfun(r,mean,width) +def _gauss(r,mean,std): + return _multigaussfun(r,mean,std) # Create model dd_gauss = Model(_gauss,constants='r') dd_gauss.description = 'Gaussian distribution model' # Parameters dd_gauss.mean.set(description='Mean', lb=1.0, ub=20, par0=3.5, units='nm') -dd_gauss.width.set(description='Standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss.std.set(description='Standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') # Add documentation dd_gauss.__doc__ = _dd_docstring(dd_gauss,notes) + docstr_example('dd_gauss') @@ -177,16 +177,16 @@ def _gauss(r,mean,width): where `\left_i` are the mean distances, `\sigma_i` the standard deviations, and `a_i` are the amplitudes of the Gaussians. """ -def _gauss2(r,mean1,width1,mean2,width2): - return _multigaussfun(r,[mean1,mean2],[width1,width2]) +def _gauss2(r,mean1,std1,mean2,std2): + return _multigaussfun(r,[mean1,mean2],[std1,std2]) # Create model dd_gauss2 = Model(_gauss2,constants='r') dd_gauss2.description = 'Sum of two Gaussian distributions model' # Parameters dd_gauss2.mean1.set(description='1st Gaussian mean', lb=1.0, ub=20, par0=2.5, units='nm') dd_gauss2.mean2.set(description='2nd Gaussian mean', lb=1.0, ub=20, par0=4.5, units='nm') -dd_gauss2.width1.set(description='1st Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') -dd_gauss2.width2.set(description='2nd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss2.std1.set(description='1st Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss2.std2.set(description='2nd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') dd_gauss2.addlinear('amp1',description='1st Gaussian amplitude', lb=0, par0=1, units='') dd_gauss2.addlinear('amp2',description='2nd Gaussian amplitude', lb=0, par0=1, units='') # Add documentation @@ -204,8 +204,8 @@ def _gauss2(r,mean1,width1,mean2,width2): where `\left_i` are the mean distances, `\sigma_i` the standard deviations, and `a_i` are the amplitudes of the Gaussians. """ -def _gauss3(r,mean1,width1,mean2,width2,mean3,width3): - return _multigaussfun(r,[mean1,mean2,mean3],[width1,width2,width3]) +def _gauss3(r,mean1,std1,mean2,std2,mean3,std3): + return _multigaussfun(r,[mean1,mean2,mean3],[std1,std2,std3]) # Create model dd_gauss3 = Model(_gauss3,constants='r') dd_gauss3.description = 'Sum of three Gaussian distributions model' @@ -213,9 +213,9 @@ def _gauss3(r,mean1,width1,mean2,width2,mean3,width3): dd_gauss3.mean1.set(description='1st Gaussian mean', lb=1.0, ub=20, par0=2.5, units='nm') dd_gauss3.mean2.set(description='2nd Gaussian mean', lb=1.0, ub=20, par0=3.5, units='nm') dd_gauss3.mean3.set(description='3rd Gaussian mean', lb=1.0, ub=20, par0=5.0, units='nm') -dd_gauss3.width1.set(description='1st Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') -dd_gauss3.width2.set(description='2nd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') -dd_gauss3.width3.set(description='3rd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss3.std1.set(description='1st Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss3.std2.set(description='2nd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gauss3.std3.set(description='3rd Gaussian standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') dd_gauss3.addlinear('amp1',description='1st Gaussian amplitude', lb=0, par0=1, units='') dd_gauss3.addlinear('amp2',description='2nd Gaussian amplitude', lb=0, par0=1, units='') dd_gauss3.addlinear('amp3',description='3rd Gaussian amplitude', lb=0, par0=1, units='') @@ -239,15 +239,15 @@ def _gauss3(r,mean1,width1,mean2,width2,mean3,width3): where `\left` is the mean distance,`\sigma` is the standard deviation, and `\beta` is the kurtosis of the distribution. """ -def _gengauss(r,mean,width,kurt): - P = kurt/(2*width*spc.gamma(1/kurt))*np.exp(-abs(r-mean)/width**kurt) +def _gengauss(r,mean,std,kurt): + P = kurt/(2*std*spc.gamma(1/kurt))*np.exp(-abs(r-mean)/std**kurt) return _normalize(r,P) # Create model dd_gengauss = Model(_gengauss,constants='r') dd_gengauss.description = 'Generalized Gaussian distribution model' # Parameters dd_gengauss.mean.set(description='Mean', lb=1.0, ub=20, par0=3.5, units='nm') -dd_gengauss.width.set(description='Standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_gengauss.std.set(description='Standard deviation', lb=0.05, ub=2.5, par0=0.2, units='nm') dd_gengauss.kurt.set(description='Kurtosis', lb=0.25, ub=15, par0=5.0, units='') # Add documentation dd_gengauss.__doc__ = _dd_docstring(dd_gengauss,notes) + docstr_example('dd_gengauss') @@ -265,20 +265,20 @@ def _gengauss(r,mean,width,kurt):


-:math:`P(r) = \frac{1}{\sqrt{2\pi}}\exp\left(-\frac{(r-\left)^2}{\sqrt(2)\sigma^2}\right)\frac{1}{2}\left(1 + \mathrm{erf}\left(\frac{(r-\left)}{\sqrt{2}\sigma}\right) \right)` +:math:`P(r) = \frac{1}{\sqrt{2\pi}}\exp\left(-\frac{(r-\left)^2}{2\sigma^2}\right)\left(1 + \mathrm{erf}\left(\frac{(r-\left)}{\sqrt{2}\sigma}\right) \right)` where `\left` is the center distance,`\sigma` is the spread, and `\alpha` is the skewness of the distribution. -""" -def _skewgauss(r,center,width,skew): - x = (r-center)/width/np.sqrt(2) - P = 1/np.sqrt(2*np.pi)*np.exp(-x**2)*(1 + spc.erf(skew*x)) +""" +def _skewgauss(r,center,std,skew): + x = (r-center)/std + P = 1/np.sqrt(2*np.pi)*np.exp(-x**2/2)*(1 + spc.erf(skew*x/np.sqrt(2))) return _normalize(r,P) # Create model dd_skewgauss = Model(_skewgauss,constants='r') dd_skewgauss.description = 'Skew Gaussian distribution model' # Parameters dd_skewgauss.center.set(description='Center', lb=1.0, ub=20, par0=3.5, units='nm') -dd_skewgauss.width.set(description='Spread', lb=0.05, ub=2.5, par0=0.2, units='nm') +dd_skewgauss.std.set(description='Spread', lb=0.05, ub=2.5, par0=0.2, units='nm') dd_skewgauss.skew.set(description='Skewness', lb=-25, ub=25, par0=5, units='') # Add documentation dd_skewgauss.__doc__ = _dd_docstring(dd_skewgauss,notes) + docstr_example('dd_skewgauss') @@ -1018,12 +1018,11 @@ def _wormchain(r,contour,persistence): Radial Distribution Function of Semiflexible Polymers Phys. Rev. Lett. 77(12), 2581-2584, 1996 """ -def _wormgauss(r,contour,persistence,width): - sigma = width +def _wormgauss(r,contour,persistence,std): P = _wlc(r,contour,persistence) # Compute Gaussian convolution window idx = np.argmax(P) - gauss = np.exp(-((r - r[idx])/sigma)**2) + gauss = np.exp(-((r - r[idx])/std)**2) # Convolution with size retention P = np.convolve(gauss,P,mode='full') # Adjust new convoluted axis @@ -1040,6 +1039,6 @@ def _wormgauss(r,contour,persistence,width): # Parameters dd_wormgauss.contour.set(description='Contour length', lb=1.5, ub=10, par0=3.7, units='nm') dd_wormgauss.persistence.set(description='Persistence length', lb=2, ub=100, par0=10, units='nm') -dd_wormgauss.width.set(description='Gaussian standard deviation', lb=0.01, ub=5, par0=0.2, units='nm') +dd_wormgauss.std.set(description='Gaussian standard deviation', lb=0.01, ub=5, par0=0.2, units='nm') # Add documentation dd_wormgauss.__doc__ = _dd_docstring(dd_wormgauss,notes) + docstr_example('dd_wormgauss') diff --git a/docsrc/source/basics.rst b/docsrc/source/basics.rst index b57d4fea..65de1372 100644 --- a/docsrc/source/basics.rst +++ b/docsrc/source/basics.rst @@ -31,14 +31,14 @@ Parametric distance distributions >>>print(dl.dd_gauss) Description: Gaussian distribution model - Signature: (r, mean, width) + Signature: (r, mean, std) Constants: [r] Parameter Table: ======= ======= ======= ======== ======== ======= ==================== Name Lower Upper Type Frozen Units Description ======= ======= ======= ======== ======== ======= ==================== mean 1 20 nonlin No nm Mean - width 0.05 2.5 nonlin No nm Standard deviation + std 0.05 2.5 nonlin No nm Standard deviation ======= ======= ======= ======== ======== ======= ==================== diff --git a/docsrc/source/fitting_guide.rst b/docsrc/source/fitting_guide.rst index 5b7be473..11947f9b 100644 --- a/docsrc/source/fitting_guide.rst +++ b/docsrc/source/fitting_guide.rst @@ -177,8 +177,8 @@ In this example, let us construct a penalty that imposes the smoothness of a Gau # Differential operator of second order L = dl.regoperator(x,2) # Define the penalty function - def smoothness_fcn(center,width): - gaussian = gauss(center,width) + def smoothness_fcn(center,std): + gaussian = gauss(center,std) penalty_vector = L@gaussian return penalty_vector # Construct the penalty @@ -219,7 +219,7 @@ A summary of the fit can be accessed by printing the ``FitResult`` object as ret Parameter Value 95%-Confidence interval Units Description =========== ======= ========================= ======= ================ center 5.002 (4.995,5.010) None None - width 0.204 (0.196,0.212) None None + std 0.204 (0.196,0.212) None None scale 0.999 (0.999,0.999) None Scaling factor =========== ======= ========================= ======= ================ diff --git a/docsrc/source/modelling_guide.rst b/docsrc/source/modelling_guide.rst index 91104aa1..00d37f90 100644 --- a/docsrc/source/modelling_guide.rst +++ b/docsrc/source/modelling_guide.rst @@ -57,14 +57,14 @@ A summary of the model and all its parameters and related attributes can be quic >>>print(dl.dd_gauss) Description: Gaussian distribution model - Signature: (r, mean, width) + Signature: (r, mean, std) Constants: [r] Parameter Table: ======= ======= ======= ======== ======== ======= ==================== Name Lower Upper Type Frozen Units Description ======= ======= ======= ======== ======== ======= ==================== mean 1 20 nonlin No nm Mean - width 0.05 2.5 nonlin No nm Standard deviation + std 0.05 2.5 nonlin No nm Standard deviation ======= ======= ======= ======== ======== ======= ==================== .. _modelling_modifying_parameters: @@ -77,8 +77,8 @@ Any editable parameter attribute can be modified by simple assigning the new val model = dl.dd_gauss # Set a new value for the `mean` parameter upper boundary model.mean.ub = 10 - # Set a start value for the `width` parameter - model.width.par0 = 10 + # Set a start value for the `std` parameter + model.std.par0 = 10 The ``set`` method allows the assignment of multiple new attribute values to the same parameter. The attributes are specified as keywords and the values as argumes. For example: :: @@ -143,8 +143,8 @@ centered about `\langle x \rangle`, and with a width given by `\sigma`. The func x = np.linspace(0,10,500) # Define the non-linear function - def gaussian_fcn(center,width): - y = np.exp(-(x-center)**2/(2*width**2)) + def gaussian_fcn(center,std): + y = np.exp(-(x-center)**2/(2*std**2)) return y # Construct the model gauss = dl.Model(gaussian_fcn) @@ -153,21 +153,21 @@ To control that the model has been properly constructed, we can print the model >>> print(gauss) Description: None - Signature: (center, width) + Signature: (center, std) Constants: [] Parameter Table: ======== ======= ======= ======== ======== ======= ============= Name Lower Upper Type Frozen Units Description ======== ======= ======= ======== ======== ======= ============= center -inf inf nonlin No None None - width -inf inf nonlin No None None + std -inf inf nonlin No None None ======== ======= ======= ======== ======== ======= ============= -We can see that the model has properly introduced the two non-linear parameters ``center`` and ``width``. By default, all new parameters are initialized unbounded (i.e. ``lb=-np.inf`` and ``ub=+np.inf``). Any attributes can be changed freely after the model has been generated. For example :: +We can see that the model has properly introduced the two non-linear parameters ``center`` and ``std``. By default, all new parameters are initialized unbounded (i.e. ``lb=-np.inf`` and ``ub=+np.inf``). Any attributes can be changed freely after the model has been generated. For example :: # Set the boundaries of the model parameters gauss.center.set(lb=0, ub=10) - gauss.width.set(lb=0, ub=0.5) + gauss.std.set(lb=0, ub=0.5) Models with linear parameters @@ -222,9 +222,9 @@ Therefore, we could define the following function: :: x = np.linspace(0,10,500) # Define the non-linear function - def bigaussian_fcn(center1,width1,center2,width2): - gauss1 = np.exp(-(x-center1)**2/(2*width1**2)) # First Gaussian component - gauss2 = np.exp(-(x-center2)**2/(2*width2**2)) # Second Gaussian component + def bigaussian_fcn(center1,std1,center2,std2): + gauss1 = np.exp(-(x-center1)**2/(2*std1**2)) # First Gaussian component + gauss2 = np.exp(-(x-center2)**2/(2*std2**2)) # Second Gaussian component Anonlin = np.vstack([y1,y2]) # Stack them vertically into a matrix return Anonlin # Construct the model @@ -237,21 +237,21 @@ As before, we can check the state of the model by printing the ``mymodel`` objec >>> print(bigauss) Description: None - Signature: (center1, width1, center2, width2, weight1, weight2) + Signature: (center1, std1, center2, std2, weight1, weight2) Constants: [] Parameter Table: ========= ======= ======= ======== ======== ======= ============= Name Lower Upper Type Frozen Units Description ========= ======= ======= ======== ======== ======= ============= center1 -inf inf nonlin No None None - width1 -inf inf nonlin No None None + std1 -inf inf nonlin No None None center2 -inf inf nonlin No None None - width2 -inf inf nonlin No None None + std2 -inf inf nonlin No None None weight1 0 inf linear No None None weight2 0 inf linear No None None ========= ======= ======= ======== ======== ======= ============= -We can see that the model has been correctly built, with four non-linear parameters (``center1``, ``center2``, ``width1``, and ``width2``) +We can see that the model has been correctly built, with four non-linear parameters (``center1``, ``center2``, ``std1``, and ``std2``) and with two linear parameters (``weight1`` and ``weight2``), as indicated by the ``Type`` column. We can check whether a parameter is linear or non-linear by accessing its ``linear`` attribute, e.g. :: >>> bigauss.center1.linear @@ -355,8 +355,8 @@ For example, let's model a Gaussian function defined on an arbitrary axis: centered about `\langle x \rangle`, with a width given by `\sigma`. The function has two non-linear parameters (`\langle x \rangle` and `\sigma`), and no linear parameters. The axis `x` should be modifiable but not a parameter. Therefore, we could define the following function with the axis set as a constant: :: # Define the non-linear function - def gaussian_fcn(x,center,width): - y = np.exp(-(x-center)**2/(2*width**2)) + def gaussian_fcn(x,center,std): + y = np.exp(-(x-center)**2/(2*std**2)) return y # Construct the model xgauss = dl.Model(gaussian_fcn, constants='x') @@ -365,14 +365,14 @@ Let us print the model to examine the resulting model: :: >>>print(xgauss) Description: None - Signature: (x, center, width) + Signature: (x, center, std) Constants: [x] Parameter Table: ======== ======= ======= ======== ======== ======= ============= Name Lower Upper Type Frozen Units Description ======== ======= ======= ======== ======== ======= ============= center -inf inf nonlin No None None - width -inf inf nonlin No None None + std -inf inf nonlin No None None ======== ======= ======= ======== ======== ======= ============= We can see that the model has only the two non-linear parameters as expected, and under ``Constants`` we can see that ``x`` has been adequately defined. From the ``Signature`` we can also check that the ``x`` constant can be passed to evaluate the model. @@ -387,14 +387,14 @@ All ``Model`` objects can be called as normal functions by specifying the parame >>>print(xgauss) Description: None - Signature: (x, center, width) + Signature: (x, center, std) Constants: [x] Parameter Table: ======== ======= ======= ======== ======== ======= ============= Name Lower Upper Type Frozen Units Description ======== ======= ======= ======== ======== ======= ============= center -inf inf nonlin No None None - width -inf inf nonlin No None None + std -inf inf nonlin No None None ======== ======= ======= ======== ======== ======= ============= In the model printout, under ``Signature`` the exact signature of the model is given. The order and names of the arguments are as shown there. @@ -408,23 +408,23 @@ Keyword arguments provide a simple way of specifying model arguments without nee # Define model parameters and constants axis = np.linspace(0,10,200) mycenter = 5 - mywidth = 0.3 + mystd = 0.3 # Evaluate using keyword arguments - y = model(x=axis, width=mywidth, center=mycenter) + y = model(x=axis, std=mystd, center=mycenter) Calling with positional arguments ********************************* Positional arguments do not require knowledge of the parameters'/constants' names but of the order, they are defined. -In the example above, we would need to first pass ``x``, ``center`` and ``width`` in that exact order :: +In the example above, we would need to first pass ``x``, ``center`` and ``std`` in that exact order :: # Define model parameters and constants axis = np.linspace(0,10,200) mycenter = 5 - mywidth = 0.3 + mystd = 0.3 # Evaluate using positional arguments - y = xgauss(axis,mycenter,mywidth) + y = xgauss(axis,mycenter,mystd) Calling with mixed arguments **************************** @@ -434,9 +434,9 @@ A mixture of positional and keyword arguments can be used to specify the model a # Define model parameters and constants axis = np.linspace(0,10,200) mycenter = 5 - mywidth = 0.3 + mystd = 0.3 # Evaluate using mixed arguments - y = xgauss(axis,width=mywidth,center=mycenter) + y = xgauss(axis,std=mystd,center=mycenter) Model operations @@ -632,36 +632,36 @@ Example: Two Gaussians of equal width For this example, we will model a bimodal Gaussian function where both Gaussian components have equal widths but are centered differently. We will use the ``bigauss`` from :ref:`a previous example ` as the basis model. -To enforce equality of widths for the two Gaussians in the ``bigauss`` model, we must link the ``width1`` and ``width2`` parameters toghether. Since there will only be one width parameter in the linked model, we will assign the link to a new ``width`` parameter :: +To enforce equality of widths for the two Gaussians in the ``bigauss`` model, we must link the ``std1`` and ``std2`` parameters together. Since there will only be one width parameter in the linked model, we will assign the link to a new ``std`` parameter :: # Link the width parameters - bigauss_linked = dl.link(bigauss, width=['width1','width2']) + bigauss_linked = dl.link(bigauss, std=['std1','std2']) and check the model by printing it :: >>>print(bigauss_linked) Description: None - Signature: (center1, width, center2, weight1, weight2) + Signature: (center1, std, center2, weight1, weight2) Constants: [] Parameter Table: ========= ======= ======= ======== ======== ======= ============= Name Lower Upper Type Frozen Units Description ========= ======= ======= ======== ======== ======= ============= center1 -inf inf nonlin No None None - width -inf inf nonlin No None None + std -inf inf nonlin No None None center2 -inf inf nonlin No None None weight1 0 inf linear No None None weight2 0 inf linear No None None ========= ======= ======= ======== ======== ======= ============= -The model now has the new ``width`` parameter instead of the ``width1`` and ``width2`` parameters. The linkage can be checked by comparing the two models :: +The model now has the new ``std`` parameter instead of the ``std1`` and ``std2`` parameters. The linkage can be checked by comparing the two models :: # Evaluate the original model - response_unlinked = bigauss(center1=5, width1=0.3, amplitude1=1, - center2=3, width2=0.3, amplitude1=2) + response_unlinked = bigauss(center1=5, std1=0.3, amplitude1=1, + center2=3, std2=0.3, amplitude1=2) # Evaluate the linked model - response_linked = bigauss(center1=5, amplitude1=1, width=0.3 + response_linked = bigauss(center1=5, amplitude1=1, std=0.3 center2=3, amplitude1=2) @@ -698,16 +698,16 @@ Example: Two Gaussians of related width For this example, we will model a bimodal Gaussian function where one of the Gaussian components has twice the width of the other one. We will use the ``bigauss`` from :ref:`a previous example ` as the basis model. -To enforce the functional relationship between the widths of the two Gaussians in the ``bigauss`` model, we must relate the ``width1`` parameter to the ``width2`` parameter, such that the former's value is twice the latter's value :: +To enforce the functional relationship between the widths of the two Gaussians in the ``bigauss`` model, we must relate the ``std1`` parameter to the ``std2`` parameter, such that the former's value is twice the latter's value :: # Relate the width parameters - bigauss_related = dl.relate(bigauss, width1 = lambda width2: 2*width2) + bigauss_related = dl.relate(bigauss, std1 = lambda std2: 2*std2) and check the model by printing it :: >>>print(bigauss_related) Description: None - Signature: (center1, width1, center2, weight1, weight2) + Signature: (center1, std1, center2, weight1, weight2) Constants: [] Parameter Table: ========= ======= ======= ======== ======== ======= ============= @@ -715,12 +715,12 @@ and check the model by printing it :: ========= ======= ======= ======== ======== ======= ============= center1 -inf inf nonlin No None None center2 -inf inf nonlin No None None - width2 -inf inf nonlin No None None + std2 -inf inf nonlin No None None weight1 0 inf linear No None None weight2 0 inf linear No None None ========= ======= ======= ======== ======== ======= ============= -The ``width1`` parameter has been removed from the parameter list as it is now given twice the value of ``width2``. +The ``std1`` parameter has been removed from the parameter list as it is now given twice the value of ``std2``. Adding isolated non-linear parameters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/examples/advanced/ex_droplets_model.py b/examples/advanced/ex_droplets_model.py index 81661818..8be581a8 100644 --- a/examples/advanced/ex_droplets_model.py +++ b/examples/advanced/ex_droplets_model.py @@ -68,8 +68,8 @@ def dropletmodel(t): Dld = ['stretch_2_1','stretch_2_2'], rmean_dis = ['mean_1_1','mean_1_2'], rmean_ld = ['mean_2_1','mean_2_2'], - width_dis = ['width_1_1','width_1_2'], - width_ld = ['width_2_1','width_2_2'], + std_dis = ['std_1_1','std_1_2'], + std_ld = ['std_2_1','std_2_2'], lam1 = ['lam1_1','lam1_2'], lam2 = ['lam2_1','lam2_2'], reftime1 = ['reftime1_1','reftime1_2']) @@ -81,8 +81,8 @@ def dropletmodel(t): globalModel.Dld.set( lb=2, ub=4, par0=2.5) globalModel.rmean_dis.set( lb=3, ub=6.35, par0=3.7) globalModel.rmean_ld.set( lb=1, ub=8, par0=2.6) -globalModel.width_dis.set( lb=0.25, ub=0.74, par0=0.44) -globalModel.width_ld.set( lb=0.2, ub=2, par0=0.7) +globalModel.std_dis.set( lb=0.25, ub=0.74, par0=0.44) +globalModel.std_ld.set( lb=0.2, ub=2, par0=0.7) globalModel.lam1.set( lb=0.3, ub=0.5, par0=0.4) globalModel.lam2.set( lb=0.0, ub=0.2, par0=0.08) globalModel.reftime1.set( lb=0.1, ub=0.3, par0=0.2) @@ -108,8 +108,8 @@ def dropletmodel(t): ax2 = plt.subplot(3,2,2) -Vdis_fit = Vdismodel1(decay=fit.kdis,mean=fit.rmean_dis,width=fit.width_dis,reftime1=fit.reftime1,reftime2=fit.reftime2_1,lam1=fit.lam1,lam2=fit.lam2,scale=1) -Vld_fit = Vldmodel1(decay=fit.kld,stretch=fit.Dld,mean=fit.rmean_ld,width=fit.width_ld,reftime1=fit.reftime1,reftime2=fit.reftime2_1,lam1=fit.lam1,lam2=fit.lam2,scale=1) +Vdis_fit = Vdismodel1(decay=fit.kdis,mean=fit.rmean_dis,std=fit.std_dis,reftime1=fit.reftime1,reftime2=fit.reftime2_1,lam1=fit.lam1,lam2=fit.lam2,scale=1) +Vld_fit = Vldmodel1(decay=fit.kld,stretch=fit.Dld,mean=fit.rmean_ld,std=fit.std_ld,reftime1=fit.reftime1,reftime2=fit.reftime2_1,lam1=fit.lam1,lam2=fit.lam2,scale=1) ax2.plot(ts[0],Vdis_fit,color=violet,label=f'Dispersed fraction {fit.eta*100:.1f}%') ax2.plot(ts[0],Vld_fit,color=orange,label=f'Liquid-droplet fraction {(1-fit.eta)*100:.1f}%') @@ -130,8 +130,8 @@ def dropletmodel(t): ax4 = plt.subplot(3,2,4) -Vdis_fit = Vdismodel2(decay=fit.kdis,mean=fit.rmean_dis,width=fit.width_dis,reftime1=fit.reftime1,reftime2=fit.reftime2_2,lam1=fit.lam1,lam2=fit.lam2,scale=1) -Vld_fit = Vldmodel2(decay=fit.kld,stretch=fit.Dld,mean=fit.rmean_ld,width=fit.width_ld,reftime1=fit.reftime1,reftime2=fit.reftime2_2,lam1=fit.lam1,lam2=fit.lam2,scale=1) +Vdis_fit = Vdismodel2(decay=fit.kdis,mean=fit.rmean_dis,std=fit.std_dis,reftime1=fit.reftime1,reftime2=fit.reftime2_2,lam1=fit.lam1,lam2=fit.lam2,scale=1) +Vld_fit = Vldmodel2(decay=fit.kld,stretch=fit.Dld,mean=fit.rmean_ld,std=fit.std_ld,reftime1=fit.reftime1,reftime2=fit.reftime2_2,lam1=fit.lam1,lam2=fit.lam2,scale=1) ax4.plot(ts[1],Vdis_fit,color=violet,label=f'Dispersed fraction {fit.eta*100:.1f}%') ax4.plot(ts[1],Vld_fit,color=orange,label=f'Liquid-droplet fraction {(1-fit.eta)*100:.1f}%') @@ -142,15 +142,15 @@ def dropletmodel(t): plt.subplot(3,1,3) -Pdis_fcn = lambda rmean_dis,width_dis: dl.dd_gauss(r,rmean_dis,width_dis) -Pld_fcn = lambda rmean_ld,width_ld: dl.dd_gauss(r,rmean_ld,width_ld) +Pdis_fcn = lambda rmean_dis,std_dis: dl.dd_gauss(r,rmean_dis,std_dis) +Pld_fcn = lambda rmean_ld,std_ld: dl.dd_gauss(r,rmean_ld,std_ld) Pdis_uq = fit.propagate(Pdis_fcn,lb=np.zeros_like(r)) Pld_uq = fit.propagate(Pld_fcn,lb=np.zeros_like(r)) -plt.plot(r,Pdis_fcn(fit.rmean_dis,fit.width_dis),label=f'Dispersed fraction {fit.eta*100:.1f}%',color=violet) +plt.plot(r,Pdis_fcn(fit.rmean_dis,fit.std_dis),label=f'Dispersed fraction {fit.eta*100:.1f}%',color=violet) plt.fill_between(r,Pdis_uq.ci(95)[:,0],Pdis_uq.ci(95)[:,1],alpha=0.3,linewidth=0,color=violet) -plt.plot(r,Pld_fcn(fit.rmean_ld,fit.width_ld),label=f'Liquid-droplet fraction {(1-fit.eta)*100:.1f}%',color=orange) +plt.plot(r,Pld_fcn(fit.rmean_ld,fit.std_ld),label=f'Liquid-droplet fraction {(1-fit.eta)*100:.1f}%',color=orange) plt.fill_between(r,Pld_uq.ci(95)[:,0],Pld_uq.ci(95)[:,1],alpha=0.3,linewidth=0,color=orange) plt.legend(frameon=False,loc='best') diff --git a/examples/advanced/ex_extracting_gauss_constraints.py b/examples/advanced/ex_extracting_gauss_constraints.py index ac34a9a4..a491a154 100644 --- a/examples/advanced/ex_extracting_gauss_constraints.py +++ b/examples/advanced/ex_extracting_gauss_constraints.py @@ -52,8 +52,8 @@ print(f'Gaussian components with (95%-confidence intervals):') print(f' mean1 = {fit.mean1:2.2f} ({fit.mean1Uncert.ci(95)[0]:2.2f}-{fit.mean1Uncert.ci(95)[1]:2.2f}) nm') print(f' mean2 = {fit.mean2:2.2f} ({fit.mean2Uncert.ci(95)[0]:2.2f}-{fit.mean2Uncert.ci(95)[1]:2.2f}) nm') -print(f' width1 = {fit.width1:2.2f} ({fit.width1Uncert.ci(95)[0]:2.2f}-{fit.width1Uncert.ci(95)[1]:2.2f}) nm') -print(f' width2 = {fit.width2:2.2f} ({fit.width2Uncert.ci(95)[0]:2.2f}-{fit.width2Uncert.ci(95)[1]:2.2f}) nm') +print(f' std1 = {fit.std1:2.2f} ({fit.std1Uncert.ci(95)[0]:2.2f}-{fit.std1Uncert.ci(95)[1]:2.2f}) nm') +print(f' std2 = {fit.std2:2.2f} ({fit.std2Uncert.ci(95)[0]:2.2f}-{fit.std2Uncert.ci(95)[1]:2.2f}) nm') print(f' amplitude1 = {fit.amp1:2.2f} ({fit.amp1Uncert.ci(95)[0]:2.2f}-{fit.amp1Uncert.ci(95)[1]:2.2f})') print(f' amplitude2 = {fit.amp2:2.2f} ({fit.amp2Uncert.ci(95)[0]:2.2f}-{fit.amp2Uncert.ci(95)[1]:2.2f})') diff --git a/examples/advanced/ex_global_twostates_parametric.py b/examples/advanced/ex_global_twostates_parametric.py index 86565140..1b6a4f45 100644 --- a/examples/advanced/ex_global_twostates_parametric.py +++ b/examples/advanced/ex_global_twostates_parametric.py @@ -28,9 +28,9 @@ # Define the distance vector r = np.linspace(2,7,200) # Define a custom distance distribution model function -def Ptwostates(meanA,meanB,widthA,widthB,fracA): - PA = fracA*dl.dd_gauss(r,meanA,widthA) - PB = (1-fracA)*dl.dd_gauss(r,meanB,widthB) +def Ptwostates(meanA,meanB,stdA,stdB,fracA): + PA = fracA*dl.dd_gauss(r,meanA,stdA) + PB = (1-fracA)*dl.dd_gauss(r,meanB,stdB) P = PA + PB P /= np.trapz(P) return P @@ -39,8 +39,8 @@ def Ptwostates(meanA,meanB,widthA,widthB,fracA): # Set the parameter boundaries and start values Pmodel.meanA.set( lb=2, ub=7, par0=5) Pmodel.meanB.set( lb=2, ub=7, par0=3) -Pmodel.widthA.set( lb=0.05, ub=0.8, par0=0.1) -Pmodel.widthB.set( lb=0.05, ub=0.8, par0=0.1) +Pmodel.stdA.set( lb=0.05, ub=0.8, par0=0.1) +Pmodel.stdB.set( lb=0.05, ub=0.8, par0=0.1) Pmodel.fracA.set( lb=0, ub=1, par0=0.5) # Generate the individual dipolar signal models @@ -56,8 +56,8 @@ def Ptwostates(meanA,meanB,widthA,widthB,fracA): globalmodel = dl.link(globalmodel, meanA = ['meanA_1', 'meanA_2', 'meanA_3'], meanB = ['meanB_1', 'meanB_2', 'meanB_3'], - widthA = ['widthA_1', 'widthA_2', 'widthA_3'], - widthB = ['widthB_1', 'widthB_2', 'widthB_3']) + stdA = ['stdA_1', 'stdA_2', 'stdA_3'], + stdB = ['stdB_1', 'stdB_2', 'stdB_3']) # Fit the datasets to the model globally fit = dl.fit(globalmodel,Vexps) @@ -74,8 +74,8 @@ def Ptwostates(meanA,meanB,widthA,widthB,fracA): Vfit_ci = fit.modelUncert[i].ci(95) # Get the fitted distributions of the two states - PAfit = fracAfit[i]*dl.dd_gauss(r,fit.meanA,fit.widthA) - PBfit = fracBfit[i]*dl.dd_gauss(r,fit.meanB,fit.widthB) + PAfit = fracAfit[i]*dl.dd_gauss(r,fit.meanA,fit.stdA) + PBfit = fracBfit[i]*dl.dd_gauss(r,fit.meanB,fit.stdB) # Plot plt.subplot(Nsignals,2,2*i+1) diff --git a/test/test_dipolarmodel.py b/test/test_dipolarmodel.py index 219bd107..337db982 100644 --- a/test/test_dipolarmodel.py +++ b/test/test_dipolarmodel.py @@ -50,7 +50,7 @@ def test_names(): "Check that the model has correct parameter names" model = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1) - parameters = ['mean','width','conc','mod','reftime','scale'] + parameters = ['mean','std','conc','mod','reftime','scale'] for param in parameters: assert hasattr(model,param) @@ -86,7 +86,7 @@ def test_call_keywords(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1) - Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,width=0.2,scale=1e5) + Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V1path) # ====================================================================== @@ -97,7 +97,7 @@ def test_phenomenological_Bmodel(): Vmodel = dipolarmodel(t,r,dd_gauss,Bmodel=bg_exp,npathways=1) - Vsim = Vmodel(mod=0.3,reftime=0.0,mean=3,width=0.2,decay=0.1,scale=1e5) + Vsim = Vmodel(mod=0.3,reftime=0.0,mean=3,std=0.2,decay=0.1,scale=1e5) assert np.allclose(Vsim,V1path_phenoB) # ====================================================================== @@ -108,7 +108,7 @@ def test_no_Bmodel(): Vmodel = dipolarmodel(t,r,dd_gauss,None,npathways=1) - Vsim = Vmodel(mod=0.3,reftime=0.0,mean=3,width=0.2,scale=1e5) + Vsim = Vmodel(mod=0.3,reftime=0.0,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V1path_noB) # ====================================================================== @@ -119,7 +119,7 @@ def test_model_1pathways(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1) - Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,width=0.2,scale=1e5) + Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V1path) # ====================================================================== @@ -131,7 +131,7 @@ def test_model_2pathways(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=2) Vsim = Vmodel(lam1=0.3,reftime1=0.0,lam2=0.1, - reftime2=2,conc=50,mean=3,width=0.2,scale=1e5) + reftime2=2,conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V2path) # ====================================================================== @@ -144,7 +144,7 @@ def test_model_3pathways(): Vsim = Vmodel(lam1=0.3,reftime1=0.0, lam2=0.1,reftime2=2, lam3=0.1, reftime3=5, - conc=50,mean=3,width=0.2,scale=1e5) + conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V3path) # ====================================================================== @@ -200,7 +200,7 @@ def test_model_1harmonics(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1,harmonics=1) - Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,width=0.2,scale=1e5) + Vsim = Vmodel(mod=0.3,reftime=0.0,conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V1harm) # ====================================================================== @@ -212,7 +212,7 @@ def test_model_2harmonics(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=2,harmonics=[1,2]) Vsim = Vmodel(lam1=0.3,reftime1=0.0,lam2=0.1, - reftime2=2,conc=50,mean=3,width=0.2,scale=1e5) + reftime2=2,conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V2harm) # ====================================================================== @@ -225,7 +225,7 @@ def test_model_3harmonics(): Vsim = Vmodel(lam1=0.3,reftime1=0.0, lam2=0.1,reftime2=2, lam3=0.1, reftime3=5, - conc=50,mean=3,width=0.2,scale=1e5) + conc=50,mean=3,std=0.2,scale=1e5) assert np.allclose(Vsim,V3harm) # ====================================================================== @@ -390,8 +390,8 @@ def test_orisel(): Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1) Vmodelorisel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1,orisel=lambda theta: np.ones_like(theta)) - Vref = Vmodel(mean=3,width=0.2,mod=0.3,reftime=0,conc=200,scale=1e2) - Vorisel = Vmodelorisel(mean=3,width=0.2,mod=0.3,reftime=0,conc=200,scale=1e2) + Vref = Vmodel(mean=3,std=0.2,mod=0.3,reftime=0,conc=200,scale=1e2) + Vorisel = Vmodelorisel(mean=3,std=0.2,mod=0.3,reftime=0,conc=200,scale=1e2) assert np.allclose(Vref,Vorisel,rtol=1e-4) # ====================================================================== diff --git a/test/test_model_class.py b/test/test_model_class.py index f0218dec..801eb456 100644 --- a/test/test_model_class.py +++ b/test/test_model_class.py @@ -6,16 +6,16 @@ # Simple non-linear function for testing x = np.linspace(0,5,100) -def gauss(mean,width): - return np.exp(-(x-mean)**2/width**2/2) +def gauss(mean,std): + return np.exp(-(x-mean)**2/std**2/2) # Non-linear definition -def gauss2(mean1,mean2,width1,width2,amp1,amp2): - return amp1*gauss(mean1,width1) + amp2*gauss(mean2,width2) +def gauss2(mean1,mean2,std1,std2,amp1,amp2): + return amp1*gauss(mean1,std1) + amp2*gauss(mean2,std2) # Linear + Non-linear definition -def gauss2_design(mean1,mean2,width1,width2): - return np.atleast_2d([gauss(mean1,width1), gauss(mean2,width2)]).T +def gauss2_design(mean1,mean2,std1,std2): + return np.atleast_2d([gauss(mean1,std1), gauss(mean2,std2)]).T # Linear + Non-linear definition def gauss2_identity(): @@ -25,7 +25,7 @@ def gauss2_identity(): def gauss2_scaled(scale): return scale*np.eye(len(x)) -mock_data = gauss2(mean1=3,mean2=4,width1=0.5,width2=0.2,amp1=0.5,amp2=0.6) +mock_data = gauss2(mean1=3,mean2=4,std1=0.5,std2=0.2,amp1=0.5,amp2=0.6) def test_construction_length(): @@ -41,7 +41,7 @@ def test_construction_names(): "Check that the model is contructed correctly with the correct parameter names" model = Model(gauss) - assert 'mean' in model.__dict__ and 'width' in model.__dict__ + assert 'mean' in model.__dict__ and 'std' in model.__dict__ #================================================================ def test_parameters_set(): @@ -57,8 +57,8 @@ def test_call_keywords(): #================================================================ "Check that calling the model with parameter returns the correct response" model = Model(gauss) - response = model(mean=3,width=0.5) - reference = gauss(mean=3,width=0.5) + response = model(mean=3,std=0.5) + reference = gauss(mean=3,std=0.5) assert np.allclose(response,reference) #================================================================ @@ -77,7 +77,7 @@ def test_call_mixed(): #================================================================ "Check that calling the model with parameter returns the correct response" model = Model(gauss) - response = model(3,width=0.5) + response = model(3,std=0.5) reference = gauss(3,0.5) assert np.allclose(response,reference) @@ -120,8 +120,8 @@ def test_addlinear_call_keywords(): model = Model(gauss2_design) model.addlinear('amp1') model.addlinear('amp2') - response = model(mean1=3,mean2=4,width1=0.2,width2=0.3,amp1=0.5,amp2=0.4) - reference = gauss2(mean1=3,mean2=4,width1=0.2,width2=0.3,amp1=0.5,amp2=0.4) + response = model(mean1=3,mean2=4,std1=0.2,std2=0.3,amp1=0.5,amp2=0.4) + reference = gauss2(mean1=3,mean2=4,std1=0.2,std2=0.3,amp1=0.5,amp2=0.4) assert np.allclose(response,reference) #================================================================ @@ -146,8 +146,8 @@ def test_addlinear_call_mixed(): model = Model(gauss2_design) model.addlinear('amp1') model.addlinear('amp2') - response = model(3,4,0.2,width2=0.3,amp1=0.5,amp2=0.4) - reference = gauss2(3,4,0.2,width2=0.3,amp1=0.5,amp2=0.4) + response = model(3,4,0.2,std2=0.3,amp1=0.5,amp2=0.4) + reference = gauss2(3,4,0.2,std2=0.3,amp1=0.5,amp2=0.4) assert np.allclose(response,reference) #================================================================ @@ -186,7 +186,7 @@ def test_addlinear_vector_call_keywords(): "Check that calling the model with scalar and vector parameters returns the correct response" model = Model(gauss2_identity) model.addlinear('gaussian', vec=len(x)) - reference = gauss2(mean1=3,mean2=4,width1=0.2,width2=0.3,amp1=0.5,amp2=0.4) + reference = gauss2(mean1=3,mean2=4,std1=0.2,std2=0.3,amp1=0.5,amp2=0.4) response = model(gaussian=reference) assert np.allclose(response,reference) @@ -227,8 +227,8 @@ def test_mixed_vector_call_keywords(): "Check that calling the model with scalar and vector parameters returns the correct response" model = Model(gauss2_scaled) model.addlinear('gaussian', vec=len(x)) - reference = 5*gauss2(mean1=3,mean2=4,width1=0.2,width2=0.3,amp1=0.5,amp2=0.4) - response = model(scale=5,gaussian=gauss2(mean1=3,mean2=4,width1=0.2,width2=0.3,amp1=0.5,amp2=0.4)) + reference = 5*gauss2(mean1=3,mean2=4,std1=0.2,std2=0.3,amp1=0.5,amp2=0.4) + response = model(scale=5,gaussian=gauss2(mean1=3,mean2=4,std1=0.2,std2=0.3,amp1=0.5,amp2=0.4)) assert np.allclose(response,reference) #================================================================ @@ -281,8 +281,8 @@ def test_addnonlinear_call_keywords(): model = Model(gauss) model.addnonlinear('trivial1') model.addnonlinear('trivial2') - response = model(mean=3,width=0.2,trivial1=1,trivial2=1) - reference = gauss(mean=3,width=0.2) + response = model(mean=3,std=0.2,trivial1=1,trivial2=1) + reference = gauss(mean=3,std=0.2) assert np.allclose(response,reference) #================================================================ @@ -305,16 +305,16 @@ def _getmodel(type): model = Model(gauss2) model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.1, ub=5, par0=0.2) - model.width2.set(lb=0.1, ub=5, par0=0.2) + model.std1.set(lb=0.1, ub=5, par0=0.2) + model.std2.set(lb=0.1, ub=5, par0=0.2) model.amp1.set(lb=0, ub=5, par0=1) model.amp2.set(lb=0, ub=5, par0=1) elif type=='semiparametric': model = Model(gauss2_design) model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.1, ub=5, par0=0.2) - model.width2.set(lb=0.1, ub=5, par0=0.2) + model.std1.set(lb=0.1, ub=5, par0=0.2) + model.std2.set(lb=0.1, ub=5, par0=0.2) model.addlinear('amp1',lb=0, ub=5) model.addlinear('amp2',lb=0, ub=5) elif type=='nonparametric': @@ -329,10 +329,10 @@ def test_preserve_original(): "Check that the original model is not changed by the function" model = Model(gauss) model.mean.par0 = 3 - model.width.par0 = 0.2 + model.std.par0 = 0.2 _ = fit(model,mock_data) - assert model._parameter_list() == ['mean','width'] + assert model._parameter_list() == ['mean','std'] # ====================================================================== @@ -436,8 +436,8 @@ def test_fit_fullyfrozen_nonlinear(): model = _getmodel('semiparametric') model.mean1.freeze(3) model.mean2.freeze(4) - model.width1.freeze(0.5) - model.width2.freeze(0.2) + model.std1.freeze(0.5) + model.std2.freeze(0.2) fitResult = fit(model,mock_data) @@ -486,7 +486,7 @@ def test_CIs_parametric(): fitResult = fit(model,mock_data) - assert_attributes_cis(fitResult,['mean1','mean2','width1','width2','amp1','amp2']) + assert_attributes_cis(fitResult,['mean1','mean2','std1','std2','amp1','amp2']) #================================================================ def test_CIs_semiparametric(): @@ -496,7 +496,7 @@ def test_CIs_semiparametric(): fitResult = fit(model,mock_data) - assert_attributes_cis(fitResult,['mean1','mean2','width1','width2','amp1','amp2']) + assert_attributes_cis(fitResult,['mean1','mean2','std1','std2','amp1','amp2']) #================================================================ def test_CIs_nonparametric(): @@ -518,7 +518,7 @@ def test_bootCIs_parametric(): noisydata = mock_data + whitegaussnoise(x,0.01,seed=1) fitResult = fit(model,noisydata,bootstrap=3) - assert_attributes_cis(fitResult,['mean1','mean2','width1','width2','amp1','amp2']) + assert_attributes_cis(fitResult,['mean1','mean2','std1','std2','amp1','amp2']) #================================================================ def test_bootCIs_semiparametric(): @@ -529,7 +529,7 @@ def test_bootCIs_semiparametric(): noisydata = mock_data + whitegaussnoise(x,0.01,seed=1) fitResult = fit(model,noisydata,bootstrap=3) - assert_attributes_cis(fitResult,['mean1','mean2','width1','width2','amp1','amp2']) + assert_attributes_cis(fitResult,['mean1','mean2','std1','std2','amp1','amp2']) #================================================================ def test_bootCIs_nonparametric(): @@ -544,22 +544,22 @@ def test_bootCIs_nonparametric(): #================================================================ # Simple non-linear function for testing -def gauss_axis(axis,mean,width): - return np.exp(-(axis-mean)**2/width**2/2) +def gauss_axis(axis,mean,std): + return np.exp(-(axis-mean)**2/std**2/2) # Non-linear definition -def gauss2_axis(axis,mean1,mean2,width1,width2,amp1,amp2): - return amp1*gauss_axis(axis,mean1,width1) + amp2*gauss_axis(axis,mean2,width2) +def gauss2_axis(axis,mean1,mean2,std1,std2,amp1,amp2): + return amp1*gauss_axis(axis,mean1,std1) + amp2*gauss_axis(axis,mean2,std2) # Linear + Non-linear definition -def gauss2_design_axis(axis,mean1,mean2,width1,width2): - return np.atleast_2d([gauss_axis(axis,mean1,width1), gauss_axis(axis,mean2,width2)]).T +def gauss2_design_axis(axis,mean1,mean2,std1,std2): + return np.atleast_2d([gauss_axis(axis,mean1,std1), gauss_axis(axis,mean2,std2)]).T # Linear + Non-linear definition def gauss2_identity_axis(axis): return np.eye(len(axis)) -mock_data_fcn = lambda axis: gauss2_axis(axis,mean1=3,mean2=4,width1=0.5,width2=0.2,amp1=0.5,amp2=0.6) +mock_data_fcn = lambda axis: gauss2_axis(axis,mean1=3,mean2=4,std1=0.5,std2=0.2,amp1=0.5,amp2=0.6) def test_model_with_constant_positional(): @@ -581,7 +581,7 @@ def test_model_with_constant_keywords(): x = np.linspace(0,10,300) reference = gauss_axis(x,3,0.5) - response = model(axis=x, mean=3, width=0.5) + response = model(axis=x, mean=3, std=0.5) assert np.allclose(reference,response) #================================================================ @@ -593,7 +593,7 @@ def test_model_with_constant_mixed(): x = np.linspace(0,10,300) reference = gauss_axis(x,3,0.5) - response = model(x, mean=3, width=0.5) + response = model(x, mean=3, std=0.5) assert np.allclose(reference,response) #================================================================ @@ -604,24 +604,24 @@ def _getmodel_axis(type,vec=50): model = Model(gauss2_axis,constants='axis') model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.01, ub=5, par0=0.2) - model.width2.set(lb=0.01, ub=5, par0=0.2) + model.std1.set(lb=0.01, ub=5, par0=0.2) + model.std2.set(lb=0.01, ub=5, par0=0.2) model.amp1.set(lb=0, ub=5, par0=1) model.amp2.set(lb=0, ub=5, par0=1) elif type=='semiparametric': model = Model(gauss2_design_axis,constants='axis') model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.01, ub=5, par0=0.2) - model.width2.set(lb=0.01, ub=5, par0=0.2) + model.std1.set(lb=0.01, ub=5, par0=0.2) + model.std2.set(lb=0.01, ub=5, par0=0.2) model.addlinear('amp1',lb=0, ub=5) model.addlinear('amp2',lb=0, ub=5) elif type=='semiparametric_vec': model = Model(gauss2_design_axis,constants='axis') model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.01, ub=5, par0=0.2) - model.width2.set(lb=0.01, ub=5, par0=0.2) + model.std1.set(lb=0.01, ub=5, par0=0.2) + model.std2.set(lb=0.01, ub=5, par0=0.2) model.addlinear('amps',lb=0, ub=5, vec=2) elif type=='nonparametric': model = Model(lambda x: gauss2_design_axis(x,3,4,0.5,0.2),constants='x') @@ -688,11 +688,11 @@ def test_fit_semiparametric_vec_constant(): assert np.allclose(fitResult.model,mock_data_fcn(x),atol=1e-3) #================================================================ -def gauss_multiaxis(axis1,axis2,mean,width): - return np.exp(-(axis1-mean)**2/width**2/2) +def gauss_multiaxis(axis1,axis2,mean,std): + return np.exp(-(axis1-mean)**2/std**2/2) -def gauss2_multiaxis(axis1,axis2,mean1,mean2,width1,width2,amp1,amp2): - return amp1*gauss_axis(axis1,mean1,width1) + amp2*gauss_axis(axis2,mean2,width2) +def gauss2_multiaxis(axis1,axis2,mean1,mean2,std1,std2,amp1,amp2): + return amp1*gauss_axis(axis1,mean1,std1) + amp2*gauss_axis(axis2,mean2,std2) def test_model_with_multiple_constants(): @@ -715,8 +715,8 @@ def test_model_with_multiple_constants_fit(): model = Model(gauss2_multiaxis,constants=['axis1','axis2']) model.mean1.set(lb=0, ub=10, par0=2) model.mean2.set(lb=0, ub=10, par0=4) - model.width1.set(lb=0.01, ub=5, par0=0.2) - model.width2.set(lb=0.01, ub=5, par0=0.2) + model.std1.set(lb=0.01, ub=5, par0=0.2) + model.std2.set(lb=0.01, ub=5, par0=0.2) model.amp1.set(lb=0, ub=5, par0=1) model.amp2.set(lb=0, ub=5, par0=1) @@ -732,8 +732,8 @@ def test_model_constant_same_values_keywords(): "Check that a model with axis can be defined and called with same values as parameters" model = Model(gauss_axis,constants='axis') - reference = gauss_axis(axis=3,mean=3,width=0.5) - response = model(axis=3,mean=3,width=0.5) + reference = gauss_axis(axis=3,mean=3,std=0.5) + response = model(axis=3,mean=3,std=0.5) assert np.allclose(reference,response) #================================================================ @@ -750,16 +750,16 @@ def test_model_constant_same_values_positional(): #================================================================ -def model(phase, center, width): - y = gauss(center, width) +def model(phase, center, std): + y = gauss(center, std) y = y*np.exp(-1j*phase) return y mymodel = Model(model) mymodel.phase.set(par0=2*np.pi/5, lb=-np.pi, ub=np.pi) mymodel.center.set(par0=4, lb=1, ub=6) -mymodel.width.set(par0=0.2, lb=0.05, ub=5) +mymodel.std.set(par0=0.2, lb=0.05, ub=5) -y = mymodel(phase=np.pi/5, center=3, width=0.5) +y = mymodel(phase=np.pi/5, center=3, std=0.5) def test_complex_model_complex_data(): # ====================================================================== @@ -782,7 +782,7 @@ def test_real_model_complex_data(): "Check the fit of a real-valued model to complex-valued data" mymodel = Model(gauss) mymodel.mean.set(par0=4, lb=1, ub=6) - mymodel.width.set(par0=0.2, lb=0.05, ub=5) + mymodel.std.set(par0=0.2, lb=0.05, ub=5) fitResult = fit(mymodel,y.real + 1j*np.zeros_like(y.imag)) assert np.allclose(fitResult.model.real,y.real) and np.allclose(fitResult.model.imag,np.zeros_like(y.real)) @@ -861,7 +861,7 @@ def test_fit_evaluate_callable(): x = np.linspace(0,10,200) fitResult = fit(model,mock_data_fcn(x),x) - fcn = lambda mean1,mean2,width1,width2,amps: gauss2_design_axis(x,mean1,mean2,width1,width2)@amps + fcn = lambda mean1,mean2,std1,std2,amps: gauss2_design_axis(x,mean1,mean2,std1,std2)@amps response = fitResult.evaluate(fcn) assert np.allclose(response,mock_data_fcn(x)) @@ -950,7 +950,7 @@ def test_fit_propagate_callable(): x = np.linspace(0,10,200) fitResult = fit(model,mock_data_fcn(x),x) - fcn = lambda mean1,mean2,width1,width2,amps: gauss2_design_axis(x,mean1,mean2,width1,width2)@amps + fcn = lambda mean1,mean2,std1,std2,amps: gauss2_design_axis(x,mean1,mean2,std1,std2)@amps modeluq = fitResult.propagate(fcn, lb=np.zeros_like(x)) assert_cis(modeluq) @@ -1029,7 +1029,7 @@ def test_fit_propagate_callable_bootstrapped(): x = np.linspace(0,10,200) fitResult = fit(model,mock_data_fcn(x),x,bootstrap=3) - fcn = lambda mean1,mean2,width1,width2,amps: gauss2_design_axis(x,mean1,mean2,width1,width2)@amps + fcn = lambda mean1,mean2,std1,std2,amps: gauss2_design_axis(x,mean1,mean2,std1,std2)@amps modeluq = fitResult.propagate(fcn, lb=np.zeros_like(x)) assert_cis(modeluq) diff --git a/test/test_model_lincombine.py b/test/test_model_lincombine.py index 39991d07..e0febe77 100644 --- a/test/test_model_lincombine.py +++ b/test/test_model_lincombine.py @@ -20,7 +20,7 @@ def test_preserve_original(): model2 = dl.bg_hom3d _ = lincombine(model1,model2) - assert model1._parameter_list() == ['mean','width'] and model2._parameter_list() == ['conc','lam'] + assert model1._parameter_list() == ['mean','std'] and model2._parameter_list() == ['conc','lam'] # ====================================================================== # ====================================================================== @@ -70,7 +70,7 @@ def test_twomodels_param_names(): model2 = dl.dd_gauss model = lincombine(model1,model2) - assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','width_1','width_2'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','std_1','std_2'] ]) # ====================================================================== # ====================================================================== @@ -93,8 +93,8 @@ def test_twomodels_addweights(): x = np.linspace(0,10,400) ref = model1(x,3,0.2) + model2(x,4,0.5) - response = model(r_1=x,r_2=x,mean_1=3,width_1=0.2, - mean_2=4,width_2=0.5, + response = model(r_1=x,r_2=x,mean_1=3,std_1=0.2, + mean_2=4,std_2=0.5, scale_1=1,scale_2=1, weight_1=1,weight_2=1) @@ -111,13 +111,13 @@ def test_twomodels_addweights_values(): ref1 = model1(x,3,0.2) ref2 = model2(x,4,0.5) - response1 = model(r_1=x,r_2=x,mean_1=3,width_1=0.2, - mean_2=4,width_2=0.5, + response1 = model(r_1=x,r_2=x,mean_1=3,std_1=0.2, + mean_2=4,std_2=0.5, scale_1=1,scale_2=1, weight_1=1,weight_2=0) - response2 = model(r_1=x,r_2=x,mean_1=3,width_1=0.2, - mean_2=4,width_2=0.5, + response2 = model(r_1=x,r_2=x,mean_1=3,std_1=0.2, + mean_2=4,std_2=0.5, scale_1=1,scale_2=1, weight_1=0,weight_2=1) @@ -193,7 +193,7 @@ def test_threemodels_param_names(): model3 = dl.dd_gauss model = lincombine(model1,model2,model3) - assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','mean_3','width_1','width_2','width_3'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','mean_3','std_1','std_2','std_3'] ]) # ====================================================================== # ====================================================================== @@ -219,7 +219,7 @@ def test_threemodels_addweights(): ref = model1(x,3,0.2) + model2(x,4,0.5) + model3(x,3.7,10) response = model(r_1=x,r_2=x,r_3=x, - mean_1=3,width_1=0.2, + mean_1=3,std_1=0.2, location_2=4,spread_2=0.5, contour_3=3.7,persistence_3=10, scale_1=1,scale_2=1,scale_3=1, @@ -241,21 +241,21 @@ def test_threemodels_addweights_values(): ref3 = model3(x,5,0.1) response1 = model(r_1=x,r_2=x,r_3=x, - mean_1=3,width_1=0.2, + mean_1=3,std_1=0.2, location_2=4,spread_2=0.5, - mean_3=5,width_3=0.1, + mean_3=5,std_3=0.1, scale_1=1,scale_2=1,scale_3=1, weight_1=1,weight_2=0,weight_3=0) response2 = model(r_1=x,r_2=x,r_3=x, - mean_1=3,width_1=0.2, + mean_1=3,std_1=0.2, location_2=4,spread_2=0.5, - mean_3=5,width_3=0.1, + mean_3=5,std_3=0.1, scale_1=1,scale_2=1,scale_3=1, weight_1=0,weight_2=1,weight_3=0) response3 = model(r_1=x,r_2=x,r_3=x, - mean_1=3,width_1=0.2, + mean_1=3,std_1=0.2, location_2=4,spread_2=0.5, - mean_3=5,width_3=0.1, + mean_3=5,std_3=0.1, scale_1=1,scale_2=1,scale_3=1, weight_1=0,weight_2=0,weight_3=1) @@ -337,7 +337,7 @@ def test_vec_param_names(): model2 = model_vec model = lincombine(model1,model2) - assert all([ str in model._parameter_list() for str in ['mean_1','width_1','Pvec_2'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','std_1','Pvec_2'] ]) # ====================================================================== # ====================================================================== diff --git a/test/test_model_link.py b/test/test_model_link.py index 281fb277..3074a449 100644 --- a/test/test_model_link.py +++ b/test/test_model_link.py @@ -39,7 +39,7 @@ def test_link_signature(): linkedmodel = link(model,mean=['mean1','mean2']) - assert linkedmodel.signature==['r', 'mean', 'width1', 'width2', 'amp1', 'amp2'] + assert linkedmodel.signature==['r', 'mean', 'std1', 'std2', 'amp1', 'amp2'] # ====================================================================== # ====================================================================== @@ -49,7 +49,7 @@ def test_link_multiple(): linkedmodel = link(model, mean1=['mean1','mean2'], - width2=['width2','width3']) + std2=['std2','std3']) assert linkedmodel.Nparam == model.Nparam - 2 # ====================================================================== @@ -76,9 +76,9 @@ def test_link_fit(): linkedmodel = link(model, mean=['mean1','mean2'], - width=['width1','width2']) + std=['std1','std2']) linkedmodel.mean.par0 = 3 - linkedmodel.width.par0 = 0.5 + linkedmodel.std.par0 = 0.5 x = np.linspace(0,10,400) ref = model(x,3,0.5,3,0.5,1,1) diff --git a/test/test_model_merge.py b/test/test_model_merge.py index 240ef7a5..5aa74294 100644 --- a/test/test_model_merge.py +++ b/test/test_model_merge.py @@ -20,7 +20,7 @@ def test_preserve_original(): model2 = dl.bg_hom3d _ = merge(model1,model2) - assert model1._parameter_list() == ['mean','width'] and model2._parameter_list() == ['conc','lam'] + assert model1._parameter_list() == ['mean','std'] and model2._parameter_list() == ['conc','lam'] # ====================================================================== # ====================================================================== @@ -70,7 +70,7 @@ def test_twomodels_param_names(): model2 = dl.dd_gauss model = merge(model1,model2) - assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','width_1','width_2'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','std_1','std_2'] ]) # ====================================================================== # ====================================================================== @@ -94,8 +94,8 @@ def test_twomodels_addweights(): ref1 = model1(x,3,0.2) ref2 = model2(x,4,0.5) - response = model(r_1=x,r_2=x,mean_1=3,width_1=0.2, - mean_2=4,width_2=0.5, + response = model(r_1=x,r_2=x,mean_1=3,std_1=0.2, + mean_2=4,std_2=0.5, scale_1=1,scale_2=1, weight_1=1,weight_2=1) @@ -174,7 +174,7 @@ def test_threemodels_param_names(): model = merge(model1,model2,model3) - assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','mean_3','width_1','width_2','width_3'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','mean_2','mean_3','std_1','std_2','std_3'] ]) # ====================================================================== # ====================================================================== @@ -200,8 +200,8 @@ def test_threemodels_addweights(): ref1 = model1(x,3,0.2) ref2 = model2(x,4,0.5) - response = model(r_1=x,r_2=x,mean_1=3,width_1=0.2, - mean_2=4,width_2=0.5, + response = model(r_1=x,r_2=x,mean_1=3,std_1=0.2, + mean_2=4,std_2=0.5, scale_1=1,scale_2=1, weight_1=1,weight_2=1) @@ -279,7 +279,7 @@ def test_vec_param_names(): model2 = model_vec model = merge(model1,model2) - assert all([ str in model._parameter_list() for str in ['mean_1','width_1','Pvec_2'] ]) + assert all([ str in model._parameter_list() for str in ['mean_1','std_1','Pvec_2'] ]) # ====================================================================== # ====================================================================== @@ -317,7 +317,7 @@ def test_merge_linked(): "Check that that merge works correctly for models with linked parameters" submodel1 = dl.dd_gauss submodel2 = dl.dd_gauss2 - submodel2 = dl.link(submodel2, mean=['mean1','mean2'], width=['width1','width2']) + submodel2 = dl.link(submodel2, mean=['mean1','mean2'], std=['std1','std2']) x = np.linspace(0,10,100) ref1 = submodel1(x,3,0.2) @@ -326,7 +326,7 @@ def test_merge_linked(): # Create a global model model = dl.merge(submodel1,submodel2, addweights=True) - response = model(x,x,mean_1=3,width_1=0.2,mean_2=4,width_2=0.3,amp1_2=1,amp2_2=1,scale_1=1, weight_1=1, weight_2=1) + response = model(x,x,mean_1=3,std_1=0.2,mean_2=4,std_2=0.3,amp1_2=1,amp2_2=1,scale_1=1, weight_1=1, weight_2=1) assert all([np.allclose(response[n],ref) for n,ref in enumerate([ref1,ref2])]) # ====================================================================== diff --git a/test/test_model_penalty.py b/test/test_model_penalty.py index 69e41d29..34935eee 100644 --- a/test/test_model_penalty.py +++ b/test/test_model_penalty.py @@ -6,8 +6,8 @@ x = np.linspace(0,4,50) mock_data = dd_gauss(x,2,0.2) + whitegaussnoise(x,0.005,seed=1) -def penalty_fcn(mean,width): - P = dd_gauss(x,mean,width) +def penalty_fcn(mean,std): + P = dd_gauss(x,mean,std) P = P/np.trapz(P,x) return np.sqrt(P*(x - np.trapz(P*x,x))**2*np.mean(np.diff(x))) @@ -26,7 +26,7 @@ def test_signature(): penaltyobj = Penalty(penalty_fcn,'icc') - assert np.all(penaltyobj.signature==['mean','width']) + assert np.all(penaltyobj.signature==['mean','std']) # ====================================================================== # ====================================================================== diff --git a/test/test_model_relate.py b/test/test_model_relate.py index 88e68300..609db098 100644 --- a/test/test_model_relate.py +++ b/test/test_model_relate.py @@ -7,7 +7,7 @@ def test_type(): "Check that the function returns a valid model type" model = dl.dd_gauss - newmodel = relate(model, width = lambda mean: mean/2) + newmodel = relate(model, std = lambda mean: mean/2) assert isinstance(newmodel,Model) # ====================================================================== @@ -17,8 +17,8 @@ def test_preserve_original(): "Check that the original input model is not changed by the function" model = dl.dd_gauss - _ = relate(model, width = lambda mean: mean/2) - assert model._parameter_list() == ['mean','width'] + _ = relate(model, std = lambda mean: mean/2) + assert model._parameter_list() == ['mean','std'] # ====================================================================== # ====================================================================== @@ -28,7 +28,7 @@ def test_relate_signature(): newmodel = relate(model,mean1= lambda mean2: mean2) - assert newmodel.signature==['r', 'mean1', 'width1', 'width2', 'amp1', 'amp2'] + assert newmodel.signature==['r', 'mean1', 'std1', 'std2', 'amp1', 'amp2'] # ====================================================================== # ====================================================================== @@ -36,7 +36,7 @@ def test_Nparam_nonlin(): "Check that the output model has the right number of parameters" model = dl.dd_gauss - newmodel = relate(model, width = lambda mean: mean/2) + newmodel = relate(model, std = lambda mean: mean/2) assert newmodel.Nnonlin == model.Nnonlin - 1 # ====================================================================== @@ -45,7 +45,7 @@ def test_Nparam_lin(): "Check that the related model has the right number of parameters" model = dl.dd_gauss2 - newmodel = relate(model, width1 = lambda mean1: mean1/2) + newmodel = relate(model, std1 = lambda mean1: mean1/2) assert newmodel.Nlin == model.Nlin # ====================================================================== @@ -55,7 +55,7 @@ def test_Nparam(): "Check that the related model has the right number of parameters" model = dl.dd_gauss2 - newmodel = relate(model, width1 = lambda mean1: mean1/2) + newmodel = relate(model, std1 = lambda mean1: mean1/2) assert newmodel.Nparam == model.Nparam - 1 # ====================================================================== @@ -64,7 +64,7 @@ def test_Nparam_list(): "Check that the related model has the right number of parameters" model = dl.dd_gauss3 - newmodel = relate(model, width1 = lambda mean1: mean1/2) + newmodel = relate(model, std1 = lambda mean1: mean1/2) assert newmodel.Nparam == len(newmodel._parameter_list()) # ====================================================================== @@ -73,7 +73,7 @@ def test_param_names(): "Check that the related model has the adjusted parameter names" model = dl.dd_gauss - newmodel = relate(model, width = lambda mean: mean/2) + newmodel = relate(model, std = lambda mean: mean/2) assert all([ str in newmodel._parameter_list() for str in ['mean'] ]) # ====================================================================== @@ -84,7 +84,7 @@ def test_relate_one_nonlinear(): x = np.linspace(0,10,400) ref = model(x,4,0.2) - newmodel = relate(model, width = lambda mean: mean/20) + newmodel = relate(model, std = lambda mean: mean/20) response = newmodel(x,4) assert np.allclose(response,ref) @@ -99,8 +99,8 @@ def test_relate_two_nonlinear(): newmodel = relate(model, mean1 = lambda mean2: mean2/2, - width1 = lambda width2: width2*2) - response = newmodel(r=x,mean2=6,width2=0.1,amp1=1,amp2=1) + std1 = lambda std2: std2*2) + response = newmodel(r=x,mean2=6,std2=0.1,amp1=1,amp2=1) assert np.allclose(response,ref) # ====================================================================== @@ -113,9 +113,9 @@ def test_relate_two_nonlinear_2(): ref = model(x,3,0.2,3,0.1,1,1) newmodel = relate(model, - mean1 = lambda width2, width1: 10*(width1+width2), - mean2 = lambda width2, width1: 10*(width1+width2),) - response = newmodel(r=x,width1=0.2,width2=0.1,amp1=1,amp2=1) + mean1 = lambda std2, std1: 10*(std1+std2), + mean2 = lambda std2, std1: 10*(std1+std2),) + response = newmodel(r=x,std1=0.2,std2=0.1,amp1=1,amp2=1) assert np.allclose(response,ref) # ====================================================================== @@ -127,7 +127,7 @@ def test_relate_fit(): x = np.linspace(0,10,400) ref = model(x,4,0.2) - newmodel = relate(model, width = lambda mean: mean/20) + newmodel = relate(model, std = lambda mean: mean/20) result = fit(newmodel,ref,x) @@ -143,7 +143,7 @@ def test_relate_addednonlinear(): ref = model(x,4,0.2,5) model.addnonlinear('factor') - newmodel = relate(model, width = lambda factor: factor/5) + newmodel = relate(model, std = lambda factor: factor/5) response = newmodel(r=x,mean=4,factor=1,amp=5) assert np.allclose(response,ref) @@ -158,13 +158,13 @@ def test_relate_conflict_order(): # No conflict, there parameters are ordered correctly newmodel = relate(model, - width2=lambda width1: width1*2, - width1=lambda mean1: mean1/20,) + std2=lambda std1: std1*2, + std1=lambda mean1: mean1/20,) - # Conflict: width1 is deleted first, but width2 depends on it + # Conflict: std1 is deleted first, but std2 depends on it conflictmodel = relate(model, - width1=lambda mean1: mean1/20, - width2=lambda width1: width1*2) + std1=lambda mean1: mean1/20, + std2=lambda std1: std1*2) response1 = newmodel(r=x,mean1=4,mean2=5,amp1=1,amp2=1) response2 = conflictmodel(r=x,mean1=4,mean2=5,amp1=1,amp2=1) diff --git a/test/test_profile_analysis.py b/test/test_profile_analysis.py index ba6ce04e..e18761d9 100644 --- a/test/test_profile_analysis.py +++ b/test/test_profile_analysis.py @@ -14,7 +14,7 @@ def test_types(): model = deepcopy(dd_gauss) model.addlinear('scale',par0 = 1) - y = model(r,mean=3,width=0.2,scale=1) + whitegaussnoise(r,sigma,seed=1) + y = model(r,mean=3,std=0.2,scale=1) + whitegaussnoise(r,sigma,seed=1) profuq = profile_analysis(model,y,r,samples=3,noiselvl=sigma) @@ -28,16 +28,16 @@ def test_basics(): r = np.linspace(2,6,300) sigma = 0.1 model = dd_gauss - y = model(r,mean=3,width=0.2) + whitegaussnoise(r,sigma,seed=1) + y = model(r,mean=3,std=0.2) + whitegaussnoise(r,sigma,seed=1) profuq = profile_analysis(model,y,r,samples=3,noiselvl=sigma) x,pdf = profuq['mean'].pardist() mean_mean = x[np.argmax(pdf)] - x,pdf = profuq['width'].pardist() - width_mean = x[np.argmax(pdf)] + x,pdf = profuq['std'].pardist() + std_mean = x[np.argmax(pdf)] - assert np.allclose([mean_mean,width_mean],[3,0.2],rtol=1e-2) + assert np.allclose([mean_mean,std_mean],[3,0.2],rtol=1e-2) # ====================================================================== @@ -52,16 +52,16 @@ def test_globalmodel(): model = merge(modelA,modelB) model = link(model, mean=['mean_1','mean_2'], - width=['width_1','width_2']) - y = model(r,r,mean=3,width=0.2,scale_1=1,scale_2=1) - y[0] += whitegaussnoise(r,sigma,seed=1) + std=['std_1','std_2']) + y = model(r,r,mean=3,std=0.2,scale_1=1,scale_2=1) + y[0] += whitegaussnoise(r,sigma,seed=1) y[1] += whitegaussnoise(r,sigma,seed=1) profuq = profile_analysis(model,y,r,r,samples=3,noiselvl=sigma) x,pdf = profuq['mean'].pardist() mean_mean = x[np.argmax(pdf)] - x,pdf = profuq['width'].pardist() + x,pdf = profuq['std'].pardist() width_mean = x[np.argmax(pdf)] assert np.allclose([mean_mean,width_mean],[3,0.2],rtol=1e-2) @@ -75,11 +75,11 @@ def test_specific_parameters(): sigma = 0.1 model = deepcopy(dd_gauss) - y = model(r,mean=3,width=0.2) + whitegaussnoise(r,sigma,seed=1) + y = model(r,mean=3,std=0.2) + whitegaussnoise(r,sigma,seed=1) profuq = profile_analysis(model,y,r,samples=3,noiselvl=sigma,parameters='mean') - assert 'mean'in profuq.keys() and not 'width' in profuq.keys() + assert 'mean'in profuq.keys() and not 'std' in profuq.keys() # ====================================================================== @@ -97,7 +97,7 @@ def test_grids(): r = np.linspace(2,6,300) sigma = 0.1 model = dd_gauss - y = model(r,mean=3,width=0.2) + whitegaussnoise(r,sigma,seed=1) + y = model(r,mean=3,std=0.2) + whitegaussnoise(r,sigma,seed=1) grid = {'mean':np.linspace(3,5,3)} profuq = profile_analysis(model,y,r,parameters='mean',grids=grid,noiselvl=sigma) diff --git a/test/test_snlls.py b/test/test_snlls.py index a82f24ea..f9dd620f 100644 --- a/test/test_snlls.py +++ b/test/test_snlls.py @@ -609,8 +609,8 @@ def test_frozen_param(): "Check that linear and nonlinear parameters can be frozen during the optimization" r = np.linspace(0,6,300) def Amodel(p): - mean1,mean2,width1,width2 = p - return np.atleast_2d([dd_gauss.nonlinmodel(r,mean1,width1), dd_gauss.nonlinmodel(r,mean2,width2)]).T + mean1,mean2,std1,std2 = p + return np.atleast_2d([dd_gauss.nonlinmodel(r,mean1,std1), dd_gauss.nonlinmodel(r,mean2,std2)]).T x = np.array([0.5,0.6]) y = Amodel([3,5,0.2,0.3])@x @@ -629,8 +629,8 @@ def test_frozen_Nparam(): "Check that the correct number of linear and nonlinear parameters are return even when freezing" r = np.linspace(0,6,90) def Amodel(p): - mean1,mean2,width1,width2 = p - return np.atleast_2d([dd_gauss.nonlinmodel(r,mean1,width1), dd_gauss.nonlinmodel(r,mean2,width2)]).T + mean1,mean2,std1,std2 = p + return np.atleast_2d([dd_gauss.nonlinmodel(r,mean1,std1), dd_gauss.nonlinmodel(r,mean2,std2)]).T x = np.array([0.5,0.6]) y = Amodel([3,5,0.2,0.3])@x nonlin_frozen = [None,5,None,None] @@ -650,12 +650,12 @@ def test_complex_model_complex_data(): x = np.linspace(0,7,100) def model(p): - phase, center, width = p - y = dd_gauss(x,center, width) + phase, center, std = p + y = dd_gauss(x,center, std) y = y*np.exp(-1j*phase) return y - y = model([np.pi/5, 3, 0.5]) + y = model([np.pi/5, 3, 0.5]) fitResult = snlls(y,model,par0=[2*np.pi/5,4,0.2],lb=[-np.pi,1,0.05],ub=[np.pi,6,5]) @@ -668,8 +668,8 @@ def test_complex_model_uncertainty(): x = np.linspace(0,7,100) def model(p): - phase, center, width = p - y = dd_gauss(x,center, width) + phase, center, std = p + y = dd_gauss(x,center, std) y = y*np.exp(-1j*phase) return y @@ -690,8 +690,8 @@ def test_masking(): x = np.linspace(0,7,100) def model(p): - center, width = p - y = dd_gauss(x,center, width) + center, std = p + y = dd_gauss(x,center, std) return y mask = np.ones_like(x).astype(bool) diff --git a/test/test_snlls_nlls.py b/test/test_snlls_nlls.py index 30083a19..e83357af 100644 --- a/test/test_snlls_nlls.py +++ b/test/test_snlls_nlls.py @@ -331,8 +331,8 @@ def test_frozen_param(): "Check that parameters can be frozen during the optimization" r = np.linspace(0,6,300) def model(param): - mean1,mean2,width1,width2,amp1,amp2 = param - return amp1*dd_gauss(r,mean1,width1) + amp2*dd_gauss(r,mean2,width2) + mean1,mean2,std1,std2,amp1,amp2 = param + return amp1*dd_gauss(r,mean1,std1) + amp2*dd_gauss(r,mean2,std2) y = model([3,4,0.2,0.3,0.5,0.6]) par0 = [3.1,4.2,0.2,0.3,0.5,0.6] @@ -351,8 +351,8 @@ def test_frozen_Nparam(): "Check that the correct number of parameters are returned even with frozen parameters" r = np.linspace(0,6,300) def model(param): - mean1,mean2,width1,width2,amp1,amp2 = param - return amp1*dd_gauss(r,mean1,width1) + amp2*dd_gauss(r,mean2,width2) + mean1,mean2,std1,std2,amp1,amp2 = param + return amp1*dd_gauss(r,mean1,std1) + amp2*dd_gauss(r,mean2,std2) y = model([3,4,0.2,0.3,0.5,0.6]) par0 = [2,2,0.5,0.5,0.5,0.5] lb = [0,0,0.01,0.01,0,0] diff --git a/test/test_snlls_rlls.py b/test/test_snlls_rlls.py index bf5cf8b6..5e0fc194 100644 --- a/test/test_snlls_rlls.py +++ b/test/test_snlls_rlls.py @@ -341,8 +341,8 @@ def test_frozen_values(): # ====================================================================== "Check that linear parameters can be frozen during the optimization" x = np.linspace(0,6,100) - def gauss(mean,width): - return np.exp(-(x-mean)**2/width**2/2) + def gauss(mean,std): + return np.exp(-(x-mean)**2/std**2/2) A = np.squeeze(np.atleast_2d([gauss(3,0.4), gauss(4,0.2)]).T) y = A@np.array([0.5,0.6]) @@ -357,8 +357,8 @@ def test_frozen_Nparam(): # ====================================================================== "Check that the correct number of parameters are returned even with frozen parameters" x = np.linspace(0,6,100) - def gauss(mean,width): - return np.exp(-(x-mean)**2/width**2/2) + def gauss(mean,std): + return np.exp(-(x-mean)**2/std**2/2) A = np.squeeze(np.atleast_2d([gauss(3,0.4), gauss(4,0.2)]).T) y = A@np.array([0.5,0.6]) xfrozen = [0.5,None]