|
| 1 | +#A template for defining a new distribution |
| 2 | +importall Distributions |
| 3 | +# Note: these don't exist in Distributions.jl yet |
| 4 | +export moment, cumulant, freecumulant, cf, cgf, mgf |
| 5 | + |
| 6 | +#Change type below to an actual type: |
| 7 | +# DiscreteUnivariateDistribution |
| 8 | +# ContinuousUnivariateDistribution |
| 9 | +# DiscreteMultivariateDistribution |
| 10 | +# ContinuousMultivariateDistribution |
| 11 | +# ContinuousMatrixDistribution |
| 12 | +# DiscreteMatrixDistribution |
| 13 | +type ThisDistribution <: Distribution |
| 14 | + data::Any #Internal fields |
| 15 | + #beta::Real |
| 16 | + ThisDistribution(data) = new(data) #Constructor |
| 17 | +end |
| 18 | + |
| 19 | +#Methods for the distribution |
| 20 | +#The methods commented out below have default fallback methods |
| 21 | + |
| 22 | +#Distribution function methods |
| 23 | +#ccdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # complementary cdf i.e. 1 - cdf |
| 24 | +cdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # cumulative distribution function |
| 25 | +#cquantile(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # complementary quantile (i.e. using prob in right hand tail) |
| 26 | +#invlogccdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # complementary quantile based on log probability |
| 27 | +#invlogcdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # quantile based on log probability |
| 28 | +#logccdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # ccdf returning log-probability |
| 29 | +#logcdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # cdf returning log-probability |
| 30 | +#logpdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # log probability density |
| 31 | +#logpmf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # log probability mass |
| 32 | +#pmf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # probability mass function (DiscreteDistribution) |
| 33 | +pdf(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # probability density function (ContinuousDistribution) |
| 34 | +quantile(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # inverse of cdf (defined for p in (01)) |
| 35 | +insupport(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # predicate is x in the support of the distribution? |
| 36 | + |
| 37 | +#Entropy methods |
| 38 | +#binaryentropy(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # entropy of distribution in bits |
| 39 | +entropy(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # entropy of distribution in nats |
| 40 | + |
| 41 | +#Measures of central tendency methods |
| 42 | +mean(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # mean of distribution |
| 43 | +median(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # median of distribution |
| 44 | +modes(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # mode(s) of distribution as vector |
| 45 | +kurtosis(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # kurtosis of the distribution |
| 46 | +skewness(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # skewness of the distribution |
| 47 | +#std(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # standard deviation of distribution |
| 48 | +var(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # variance of distribution |
| 49 | +moment(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) # moment of distribution |
| 50 | +cumulant(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) # cumulant of distribution |
| 51 | +freecumulant(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) # free cumulant of distribution |
| 52 | + |
| 53 | +#Generating function methods |
| 54 | +cf(X::ThisDistribution, t::Real)=error(string("Not defined for ", typeof(X), " distribution")) # characteristic function |
| 55 | +cgf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) # cumulant generating function |
| 56 | +mgf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) # moment generating function |
| 57 | + |
| 58 | +#Sampling methods |
| 59 | +rand(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # random sampler |
| 60 | + |
| 61 | +#Regression methods for generalized linear models (GLM) |
| 62 | +canonicallink(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # canonical link function for a distribution |
| 63 | +#deviance(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # deviance of fitted and observed responses |
| 64 | +#devresid(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # vector of squared deviance residuals |
| 65 | +fit(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # fit a distribution to data |
| 66 | +linkfun(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # link function mapping mu to eta the linear predictor |
| 67 | +linkinv(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # inverse link mapping eta to mu |
| 68 | +mueta(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # derivative of inverse link function |
| 69 | +#mustart(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # starting values of mean vector in GLMs |
| 70 | +valideta(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # validity check on linear predictor |
| 71 | +validmu(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) # validity check on mean vector |
| 72 | + |
0 commit comments