Skip to content

Commit

Permalink
numpydoc build for ModelCovariance
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhua0320 committed Aug 20, 2024
1 parent 6458a3e commit fa52c51
Showing 1 changed file with 70 additions and 7 deletions.
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 : Any
The current format of parameters
out_format : Any
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

0 comments on commit fa52c51

Please sign in to comment.