Skip to content

Commit 2b8c446

Browse files
numpydoc build for aic.py (#93)
1 parent f7cc015 commit 2b8c446

File tree

1 file changed

+77
-10
lines changed
  • src/diffpy/srmise/modelevaluators

1 file changed

+77
-10
lines changed

src/diffpy/srmise/modelevaluators/aic.py

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
5454
"""Return quality of fit for given ModelCluster using AIC (Akaike's Information Criterion).
5555
5656
Parameters
57-
fit: A ModelCluster
58-
count_fixed: Whether fixed parameters are considered.
59-
kshift: (0) Treat the model has having this many additional
60-
parameters. Negative values also allowed."""
57+
----------
58+
fit : ModelCluster instance
59+
The ModelCluster instance to evaluate.
60+
count_fixed : bool
61+
Whether fixed parameters are considered. Default is False.
62+
kshift : int
63+
Treat the model has having this many additional
64+
parameters. Negative values also allowed. Default is 0.
65+
66+
Returns
67+
-------
68+
quality : float
69+
The quality of fit for given ModelCluster."""
6170
# Number of parameters. By default, fixed parameters are ignored.
6271
k = fit.model.npars(count_fixed=count_fixed) + kshift
6372
if k < 0:
@@ -79,12 +88,34 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
7988
return self.stat
8089

8190
def minpoints(self, npars):
82-
"""Calculates the minimum number of points required to make an estimate of a model's quality."""
91+
"""Calculates the minimum number of points required to make an estimate of a model's quality.
92+
93+
Parameters
94+
----------
95+
npars : int
96+
The number of parameters in the model.
97+
98+
Returns
99+
-------
100+
int
101+
The minimum number of points required to make an estimate of a model's quality.
102+
"""
83103

84104
return 1
85105

86-
def parpenalty(self, k, n):
87-
"""Returns the cost for adding k parameters to the current model cluster."""
106+
def parpenalty(self, k):
107+
"""Returns the cost for adding k parameters to the current model cluster.
108+
109+
Parameters
110+
----------
111+
k : int
112+
The number of added parameters in the model.
113+
114+
Returns
115+
-------
116+
float
117+
The penalty cost for adding k parameters to the current model cluster.
118+
"""
88119

89120
# Weight the penalty for additional parameters.
90121
# If this isn't 1 there had better be a good reason.
@@ -94,11 +125,26 @@ def parpenalty(self, k, n):
94125

95126
def growth_justified(self, fit, k_prime):
96127
"""Returns whether adding k_prime parameters to the given model (ModelCluster) is justified
97-
given the current quality of the fit. The assumption is that adding k_prime parameters will
128+
given the current quality of the fit.
129+
130+
The assumption is that adding k_prime parameters will
98131
result in "effectively 0" chiSquared cost, and so adding it is justified if the cost of adding
99132
these parameters is less than the current chiSquared cost.
100133
The validity of this assumption (which depends on an unknown chiSquared value)
101134
and the impact of the errors used should be examined more thoroughly in the future.
135+
136+
Parameters
137+
----------
138+
fit : ModelCluster instance
139+
The ModelCluster instance to evaluate.
140+
141+
k_prime : int
142+
The prime number of added parameters in the model.
143+
144+
Returns
145+
-------
146+
bool
147+
Whether adding k_prime parameters to the given model is justified.
102148
"""
103149

104150
if self.chisq is None:
@@ -124,15 +170,36 @@ def growth_justified(self, fit, k_prime):
124170

125171
@staticmethod
126172
def akaikeweights(aics):
127-
"""Return sequence of Akaike weights for sequence of AICs"""
173+
"""Return sequence of Akaike weights for sequence of AICs
174+
175+
Parameters
176+
----------
177+
aics : array-like
178+
The sequence of AIC instance.
179+
180+
Returns
181+
-------
182+
array-like
183+
The sequence of Akaike weights
184+
"""
128185

129186
aic_stats = np.array([aic.stat for aic in aics])
130187
aic_min = min(aic_stats)
131188
return np.exp(-(aic_stats - aic_min) / 2.0)
132189

133190
@staticmethod
134191
def akaikeprobs(aics):
135-
"""Return sequence of Akaike probabilities for sequence of AICs"""
192+
"""Return sequence of Akaike probabilities for sequence of AICs
193+
194+
Parameters
195+
----------
196+
aics : array-like
197+
The sequence of AIC instance.
198+
199+
Returns
200+
-------
201+
array-like
202+
The sequence of Akaike probabilities"""
136203
aic_weights = AIC.akaikeweights(aics)
137204
return aic_weights / np.sum(aic_weights)
138205

0 commit comments

Comments
 (0)