diff --git a/src/diffpy/srmise/modelevaluators/aic.py b/src/diffpy/srmise/modelevaluators/aic.py index 8841111..1a1973b 100644 --- a/src/diffpy/srmise/modelevaluators/aic.py +++ b/src/diffpy/srmise/modelevaluators/aic.py @@ -54,10 +54,19 @@ def evaluate(self, fit, count_fixed=False, kshift=0): """Return quality of fit for given ModelCluster using AIC (Akaike's Information Criterion). Parameters - fit: A ModelCluster - count_fixed: Whether fixed parameters are considered. - kshift: (0) Treat the model has having this many additional - parameters. Negative values also allowed.""" + ---------- + fit : ModelCluster instance + The ModelCluster instance to evaluate. + count_fixed : bool + Whether fixed parameters are considered. Default is False. + kshift : int + Treat the model has having this many additional + parameters. Negative values also allowed. Default is 0. + + Returns + ------- + quality : float + The quality of fit for given ModelCluster.""" # Number of parameters. By default, fixed parameters are ignored. k = fit.model.npars(count_fixed=count_fixed) + kshift if k < 0: @@ -79,12 +88,34 @@ def evaluate(self, fit, count_fixed=False, kshift=0): return self.stat def minpoints(self, npars): - """Calculates the minimum number of points required to make an estimate of a model's quality.""" + """Calculates the minimum number of points required to make an estimate of a model's quality. + + Parameters + ---------- + npars : int + The number of parameters in the model. + + Returns + ------- + int + The minimum number of points required to make an estimate of a model's quality. + """ return 1 - def parpenalty(self, k, n): - """Returns the cost for adding k parameters to the current model cluster.""" + def parpenalty(self, k): + """Returns the cost for adding k parameters to the current model cluster. + + Parameters + ---------- + k : int + The number of added parameters in the model. + + Returns + ------- + float + The penalty cost for adding k parameters to the current model cluster. + """ # Weight the penalty for additional parameters. # If this isn't 1 there had better be a good reason. @@ -94,11 +125,26 @@ def parpenalty(self, k, n): def growth_justified(self, fit, k_prime): """Returns whether adding k_prime parameters to the given model (ModelCluster) is justified - given the current quality of the fit. The assumption is that adding k_prime parameters will + given the current quality of the fit. + + The assumption is that adding k_prime parameters will result in "effectively 0" chiSquared cost, and so adding it is justified if the cost of adding these parameters is less than the current chiSquared cost. The validity of this assumption (which depends on an unknown chiSquared value) and the impact of the errors used should be examined more thoroughly in the future. + + Parameters + ---------- + fit : ModelCluster instance + The ModelCluster instance to evaluate. + + k_prime : int + The prime number of added parameters in the model. + + Returns + ------- + bool + Whether adding k_prime parameters to the given model is justified. """ if self.chisq is None: @@ -124,7 +170,18 @@ def growth_justified(self, fit, k_prime): @staticmethod def akaikeweights(aics): - """Return sequence of Akaike weights for sequence of AICs""" + """Return sequence of Akaike weights for sequence of AICs + + Parameters + ---------- + aics : array-like + The sequence of AIC instance. + + Returns + ------- + array-like + The sequence of Akaike weights + """ aic_stats = np.array([aic.stat for aic in aics]) aic_min = min(aic_stats) @@ -132,7 +189,17 @@ def akaikeweights(aics): @staticmethod def akaikeprobs(aics): - """Return sequence of Akaike probabilities for sequence of AICs""" + """Return sequence of Akaike probabilities for sequence of AICs + + Parameters + ---------- + aics : array-like + The sequence of AIC instance. + + Returns + ------- + array-like + The sequence of Akaike probabilities""" aic_weights = AIC.akaikeweights(aics) return aic_weights / np.sum(aic_weights)