Skip to content

Commit caab0af

Browse files
numpydoc build for aicc.py (#94)
1 parent 2b8c446 commit caab0af

File tree

1 file changed

+73
-7
lines changed
  • src/diffpy/srmise/modelevaluators

1 file changed

+73
-7
lines changed

Diff for: src/diffpy/srmise/modelevaluators/aicc.py

+73-7
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
5555
5656
Parameters
5757
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."""
58+
The ModelCluster to evaluate.
59+
count_fixed : bool
60+
Whether fixed parameters are considered. Default is False.
61+
kshift : int
62+
Treat the model has having this many additional
63+
parameters. Negative values also allowed. Default is 0.
64+
65+
Returns
66+
-------
67+
float
68+
Quality of AICc"""
6169
# Number of parameters. By default, fixed parameters are ignored.
6270
k = fit.model.npars(count_fixed=count_fixed) + kshift
6371
if k < 0:
@@ -79,14 +87,39 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
7987
return self.stat
8088

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

84103
# From the denominator of AICc, it is clear that the first positive finite contribution to
85104
# parameter cost is at n>=k+2
86105
return npars + 2
87106

88107
def parpenalty(self, k, n):
89-
"""Returns the cost for adding k parameters to the current model cluster."""
108+
"""Returns the cost for adding k parameters to the current model cluster.
109+
110+
Parameters
111+
----------
112+
k : int
113+
The number of parameters to add.
114+
115+
n : int
116+
The number of data points.
117+
118+
Returns
119+
-------
120+
float
121+
The cost for adding k parameters to the current model cluster.
122+
"""
90123

91124
# Weight the penalty for additional parameters.
92125
# If this isn't 1 there had better be a good reason.
@@ -101,6 +134,18 @@ def growth_justified(self, fit, k_prime):
101134
and so adding it is justified if the cost of adding these parameters is less than the current
102135
chiSquared cost. The validity of this assumption (which depends on an unknown chiSquared value)
103136
and the impact of the errors used should be examined more thoroughly in the future.
137+
138+
Parameters
139+
----------
140+
fit : ModelCluster
141+
The ModelCluster to evaluate.
142+
k_prime : int
143+
The prime number of parameters to add.
144+
145+
Returns
146+
-------
147+
bool
148+
Whether the current model cluster is justified or not.
104149
"""
105150

106151
if self.chisq is None:
@@ -126,15 +171,36 @@ def growth_justified(self, fit, k_prime):
126171

127172
@staticmethod
128173
def akaikeweights(aics):
129-
"""Return sequence of Akaike weights for sequence of AICs"""
174+
"""Return sequence of Akaike weights for sequence of AICs
175+
176+
Parameters
177+
----------
178+
aics : array-like
179+
The squence of AIC instances
180+
181+
Returns
182+
-------
183+
array-like
184+
The sequence of Akaike weights
185+
"""
130186

131187
aic_stats = np.array([aic.stat for aic in aics])
132188
aic_min = min(aic_stats)
133189
return np.exp(-(aic_stats - aic_min) / 2.0)
134190

135191
@staticmethod
136192
def akaikeprobs(aics):
137-
"""Return sequence of Akaike probabilities for sequence of AICs"""
193+
"""Return sequence of Akaike probabilities for sequence of AICs
194+
195+
Parameters
196+
----------
197+
aics : array-like
198+
The squence of AIC instances
199+
200+
Returns
201+
-------
202+
array-like
203+
The sequence of Akaike probabilities"""
138204
aic_weights = AICc.akaikeweights(aics)
139205
return aic_weights / np.sum(aic_weights)
140206

0 commit comments

Comments
 (0)