From fa52c51eb82fe2deb6e3c0f923c76df9084ddebb Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 20 Aug 2024 17:35:23 +0800 Subject: [PATCH 1/2] numpydoc build for ModelCovariance --- src/diffpy/srmise/modelcluster.py | 77 ++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/src/diffpy/srmise/modelcluster.py b/src/diffpy/srmise/modelcluster.py index 668612e..8ac2ac6 100644 --- a/src/diffpy/srmise/modelcluster.py +++ b/src/diffpy/srmise/modelcluster.py @@ -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) @@ -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 -------- @@ -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." @@ -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)) @@ -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." @@ -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)) @@ -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." @@ -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." From 71003761553ca9c36fe8eb37a1214cbd7bdb6d0b Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 20 Aug 2024 20:38:27 +0800 Subject: [PATCH 2/2] update format type and fix indentation issue --- src/diffpy/srmise/modelcluster.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diffpy/srmise/modelcluster.py b/src/diffpy/srmise/modelcluster.py index 8ac2ac6..e3208da 100644 --- a/src/diffpy/srmise/modelcluster.py +++ b/src/diffpy/srmise/modelcluster.py @@ -153,9 +153,9 @@ def transform(self, in_format, out_format, **kwds): Parameters ---------- - in_format : Any + in_format : str The current format of parameters - out_format : Any + out_format : str The new format for parameters Keywords @@ -282,7 +282,7 @@ def getuncertainty(self, i): Returns ------- float - The uncertainty of variable at index i. + 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)) @@ -329,7 +329,7 @@ def get(self, i): Returns ------- (float, float) - The value and uncertainty of variable at index i. + The value and uncertainty of variable at index i. """ return (self.getvalue(i), self.getuncertainty(i))