|
| 1 | +#A template for defining a new distribution |
| 2 | +importall Distributions |
| 3 | +# Note: these don't exist in Distributions.jl yet |
| 4 | +export ThisDistribution, 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 | +#Standardized distribution - mean 0, variance 1 |
| 20 | + |
| 21 | +#Methods for the distribution |
| 22 | +#The methods commented out below have default fallback methods |
| 23 | + |
| 24 | +# Distribution function methods |
| 25 | +############################### |
| 26 | + |
| 27 | +# complementary cdf i.e. 1 - cdf |
| 28 | +#ccdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 29 | + |
| 30 | +# cumulative distribution function |
| 31 | +cdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 32 | + |
| 33 | +#complementary quantile based on log probability |
| 34 | +#invlogccdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 35 | + |
| 36 | +# quantile based on log probability |
| 37 | +#invlogcdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 38 | + |
| 39 | +# ccdf returning log-probability |
| 40 | +#logccdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 41 | + |
| 42 | +# cdf returning log-probability |
| 43 | +#logcdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 44 | + |
| 45 | +# log probability density |
| 46 | +#logpdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 47 | + |
| 48 | +# probability density function |
| 49 | +pdf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 50 | + |
| 51 | +# inverse of cdf (defined for p in (01)) |
| 52 | +quantile(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 53 | + |
| 54 | +# complementary quantile (i.e. using prob in right hand tail) |
| 55 | +#cquantile(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 56 | + |
| 57 | +# predicate is x in the support of the distribution? |
| 58 | +insupport(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 59 | + |
| 60 | + |
| 61 | +#Entropy methods |
| 62 | +################ |
| 63 | + |
| 64 | +# entropy of distribution in bits |
| 65 | +#binaryentropy(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 66 | + |
| 67 | +# entropy of distribution in nats |
| 68 | +entropy(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 69 | + |
| 70 | +#Measures of central tendency methods |
| 71 | +##################################### |
| 72 | + |
| 73 | +# mean of distribution |
| 74 | +mean(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 75 | + |
| 76 | +# median of distribution |
| 77 | +median(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 78 | + |
| 79 | +# mode(s) of distribution as vector |
| 80 | +modes(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 81 | + |
| 82 | +# standard deviation of distribution |
| 83 | +#std(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 84 | + |
| 85 | +# variance of distribution |
| 86 | +var(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 87 | + |
| 88 | +# skewness of the distribution |
| 89 | +skewness(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 90 | + |
| 91 | +# kurtosis of the distribution |
| 92 | +kurtosis(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 93 | + |
| 94 | +# excess kurtosis of the distribution |
| 95 | +excess_kurtosis(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 96 | + |
| 97 | +# moment of distribution |
| 98 | +moment(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) |
| 99 | + |
| 100 | +# cumulant of distribution |
| 101 | +cumulant(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) |
| 102 | + |
| 103 | +# free cumulant of distribution |
| 104 | +freecumulant(X::ThisDistribution, order::Integer)=error(string("Not defined for ", typeof(X), " distribution")) |
| 105 | + |
| 106 | + |
| 107 | +#Generating function methods |
| 108 | +############################ |
| 109 | + |
| 110 | +# characteristic function |
| 111 | +cf(X::ThisDistribution, t::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 112 | + |
| 113 | +# cumulant generating function |
| 114 | +cgf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 115 | + |
| 116 | +# moment generating function |
| 117 | +mgf(X::ThisDistribution, x::Real)=error(string("Not defined for ", typeof(X), " distribution")) |
| 118 | + |
| 119 | +#Sampling methods |
| 120 | +################# |
| 121 | + |
| 122 | +# random sampler |
| 123 | +rand(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 124 | + |
| 125 | + |
| 126 | +#Regression methods for generalized linear models (GLM) |
| 127 | +####################################################### |
| 128 | + |
| 129 | +# canonical link function for a distribution |
| 130 | +canonicallink(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 131 | + |
| 132 | +# deviance of fitted and observed responses |
| 133 | +#deviance(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 134 | + |
| 135 | +# vector of squared deviance residuals |
| 136 | +#devresid(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 137 | + |
| 138 | +# fit a distribution to data |
| 139 | +fit(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 140 | + |
| 141 | +# link function mapping mu to eta the linear predictor |
| 142 | +linkfun(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 143 | + |
| 144 | +# inverse link mapping eta to mu |
| 145 | +linkinv(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 146 | + |
| 147 | +# derivative of inverse link function |
| 148 | +mueta(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 149 | + |
| 150 | +# starting values of mean vector in GLMs |
| 151 | +#mustart(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 152 | + |
| 153 | +# validity check on linear predictor |
| 154 | +valideta(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 155 | + |
| 156 | +# validity check on mean vector |
| 157 | +validmu(X::ThisDistribution)=error(string("Not defined for ", typeof(X), " distribution")) |
| 158 | + |
0 commit comments