Skip to content

numpydoc build for ModelCovariance #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 70 additions & 7 deletions src/diffpy/srmise/modelcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ def setcovariance(self, model, cov):

Parameters
----------
model - A ModelParts object
cov - The nxn covariance matrix for n model parameters. If the parameterization includes "fixed"
parameters not included in the covariance matrix, the matrix is expanded to include these
parameters with 0 uncertainty.
model : ModelParts
The ModelParts instance
cov : ndarray
The nxn covariance matrix for n model parameters. If the parameterization includes "fixed"
parameters not included in the covariance matrix, the matrix is expanded to include these
parameters with 0 uncertainty.
"""
tempcov = np.array(cov)

Expand Down Expand Up @@ -151,8 +153,10 @@ def transform(self, in_format, out_format, **kwds):

Parameters
----------
in_format - The current format of parameters
out_format - The new format for parameters
in_format : str
The current format of parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these in put and output parameters? If you can figure out what the parameters are please make this more informative.

out_format : str
The new format for parameters

Keywords
--------
Expand Down Expand Up @@ -229,6 +233,18 @@ def getcorrelation(self, i, j):

The standard deviation of fixed parameters is 0, in which case the correlation is
undefined, but return 0 for simplicity.

Parameters
----------
i : int
The index of variable in peak mapping
j : int
The index of variable in peak mapping

Returns
-------
float
The correlation between variables i and j
"""
if self.cov is None:
emsg = "Cannot get correlation on undefined covariance matrix."
Expand Down Expand Up @@ -257,6 +273,16 @@ def getuncertainty(self, i):

The variable may be specified as an integer, or as a two-component tuple of integers (l, m)
which indicate the mth parameter of modelpart l.

Parameters
----------
i : int
The index of variable in peak mapping

Returns
-------
float
The uncertainty of variable at index i.
"""
(l, m) = i if i in self.pmap else self.ipmap[i]
return np.sqrt(self.getcovariance(i, i))
Expand All @@ -266,6 +292,18 @@ def getcovariance(self, i, j):

The variables may be specified as integers, or as a two-component tuple of integers (l, m)
which indicate the mth parameter of modelpart l.

Parameters
----------
i : int
The index of variable in peak mapping
j : int
The index of variable in peak mapping

Returns
-------
float
The covariance between variables at indeex i and j.
"""
if self.cov is None:
emsg = "Cannot get correlation on undefined covariance matrix."
Expand All @@ -282,6 +320,16 @@ def get(self, i):

The variable may be specified as an integer, or as a two-component tuple of integers (l, m)
which indicate the mth parameter of modelpart l.

Parameters
----------
i : int
The index of variable in peak mapping

Returns
-------
(float, float)
The value and uncertainty of variable at index i.
"""
return (self.getvalue(i), self.getuncertainty(i))

Expand All @@ -294,8 +342,13 @@ def correlationwarning(self, threshold=0.8):

Parameters
----------
threshold - A real number between 0 and 1.
threshold : float
A real number between 0 and 1.

Returns
-------
tuple (i, j, c)
Indices of the modelpart and their correlations.
"""
if self.cov is None:
emsg = "Cannot calculate correlation on undefined covariance matrix."
Expand Down Expand Up @@ -323,6 +376,16 @@ def prettypar(self, i):

The variable may be specified as an integer, or as a two-component tuple of integers (l, m)
which indicate the mth parameter of modelpart l.

Parameters
----------
i : int
The index of variable in peak mapping

Returns
-------
str
'value (uncertainty)' for variable at index i.
"""
if self.model is None or self.cov is None:
return "Model and/or Covariance matrix undefined."
Expand Down
Loading