public abstract class Model extends Value
pr(d), and
    negative-log probability, nlPr(d), of a datum, d.
    Most instances of Model are likely to be instances of UPModel.M
    and often the UnParameterised-Model's
    Estimator estimates a
    fully parameterised Model from a given data-set, for example,
    MML.Normal estimates a Normal (Gaussian) probability distribution,
    Nμ,σ. Among example Models,
    MultiState.M has non-trivial
    statistical-parameters but
    Discretes.Uniform.M does not.
    There are sub-classes of Model, such as Discretes.M and
    Multivariate.M, that make it easier to create certain kinds of
    Model.  Note that a Model is a first-class Value.FunctionModel and
    SeriesModel.| Modifier and Type | Class and Description | 
|---|---|
static class  | 
Model.Defaults
A subclass of  
Model that sets default methods
       stats(ds,lo,hi),
       stats(add,ss0,ss1) and
       nlLH(ss), even if they are slow. | 
class  | 
Model.Transform
Transform (the data for) Model.this by Function f
       (which is the problem defining parameter). 
 | 
Value.Atomic, Value.Bool, Value.Char, Value.Chars, Value.Cts, Value.Defer, Value.Discrete, Value.Enum, Value.Inc_Or, Value.Int, Value.Lambda, Value.List, Value.Maybe, Value.Option, Value.Real, Value.Scannable, Value.Structured, Value.Triv, Value.Tuple| Modifier and Type | Field and Description | 
|---|---|
protected double | 
msg1
Where appropriate, the lengths of the first (msg1),
       and second (msg2) parts of an
       [MML]
       message transmitting
       (i) a Model (parameter estimate) θ, and
       (ii) training data-set ds|θ. 
 | 
protected double | 
msg2
Where appropriate, the lengths of the first (msg1),
       and second (msg2) parts of an
       [MML]
       message transmitting
       (i) a Model (parameter estimate) θ, and
       (ii) training data-set ds|θ. 
 | 
protected Value | 
sp
Holds the statistical parameter(s), if any, of 'this' Model;
       is returned by  
statParams(). | 
| Constructor and Description | 
|---|
Model(double msg1,
     double msg2,
     Value sp)
 | 
| Modifier and Type | Method and Description | 
|---|---|
Estimator | 
asEstimator(Value ps)
Return an Estimator that always "estimates" 'this' Model. 
 | 
Model | 
asGiven(double msg2)
Return 'this' Model as a "given", with zero first-part
       message length, and a specified second-part, msg2,
        
asGiven(0,msg2). | 
Model | 
asGiven(double msg1,
       double msg2)
Enables setting the first- and second-part message lengths, msg1
       and msg2, after having estimated the statistical parameter(s) of
       a Model, say. 
 | 
UPModel | 
asUPModel()
It might be necessary, in some context, to treat 'this' fully
       parameterised Model as an  
UnParameterised Model,
       having trivial problem-definition parameter, that always produces
       (by apply, estimator,
       etc.) 'this' Model asGiven, so to say. | 
Value.Tuple | 
m1m2sp()
 | 
double | 
msg()
The length of a two-part MML message, 'M; (ds|M)', where ds was
       the training-data used when estimating 'this' Model 'M'. 
 | 
double | 
msg1()
Length of the 1st part, 'M', of a two-part MML message
       'M; (ds|M)', where ds was the training data. 
 | 
double | 
msg1bits()
msg1() in bits. | 
double | 
msg2()
Length of the 2nd part, '(ds|M)', of a two-part MML message
       'M; (ds|M)', where D was the training-data. 
 | 
double | 
msg2bits()
msg2() in bits. | 
double | 
msgBits()
msg() in bits. | 
double | 
nl2LH(Value ss)
The  
nlLH(ss) of (sufficient stats, ss, of)
       a data-set, ds, but in bits, instead of nits. | 
double | 
nl2Pr(Value d)
Return the negative log2 probability, nl2Pr, of datum 'd',
       in bits. 
 | 
abstract double | 
nlLH(Value ss)
Given sufficient statistics,
       ss =  
stats(ds), of a data-set, ds,
       return the negative log LikeliHood, nlLH(ss), of ds. | 
abstract double | 
nlPr(Value d)
The negative loge  
probability of a datum,
       'd', in nits;  nlPr must be defined when implementing a Model. | 
double | 
pr(Value d)
The probability of a datum, 'd', given 'this' Model; also see
        
nlPr(d). | 
Value | 
random()
Return a random Value from the modelled population, if possible. 
 | 
Vector | 
random(int n)
Return 'n'  
random() Values, if possible. | 
Series | 
randomSeries()
 | 
Value | 
statParams()
 | 
abstract Value | 
stats(boolean add,
     Value ss0,
     Value ss1)
Combine  
statisticses,
       ss0 ± ss1. | 
Value | 
stats(boolean add,
     Value ss0,
     Vector ds,
     int lo,
     int hi)
Combine statisticses ss0 and
       stats(ds,lo,hi). | 
Value | 
stats(Vector ds)
Return sufficient statistics,
        
stats(ds,0,ds.nElts()), of
       a data-set 'ds'. | 
abstract Value | 
stats(Vector ds,
     int lo,
     int hi)
For 'this' Model, calculate sufficient statistics, 'ss', of elements
       [lo, hi) of 'ds', e.g., for use in  
nlLH(ss). | 
double | 
sumNlPr(Vector ds)
 | 
java.lang.String | 
toString()
Show the details of 'this' Model. 
 | 
Model | 
transform(Function f)
Transform 'this' already parameterised Model by Function 'f',
       roughly transform: (a→b)→Model a→Model b. 
 | 
Type | 
type()
Returns  
Type.MODEL. | 
protected void | 
zeroTriv(double msg1,
        Value sp)
Check msg1 = 0 and sp = (), that both are trivial. 
 | 
protected final double msg1
protected final double msg2
protected final Value sp
statParams().  Also see the
       problem-defining parameters.public Model(double msg1,
             double msg2,
             Value sp)
public Type type()
Type.MODEL.public Value statParams()
estimated),
       if any, of 'this' Model as stored in sp.
       Also see m1m2sp() and UPModel.apply(la.la.Value).public Value.Tuple m1m2sp()
public double msg1()
msg()].public double msg2()
msg()].public double msg()
κk,
         and likelihood f(ds|θ').
       msg1+msg2 easily available from
       the Model. Also note that if a Model is used twice in a message,
       it is only transmitted once, and must be "free" the second time.public double msg1bits()
msg1() in bits.public double msg2bits()
msg2() in bits.public double msgBits()
msg() in bits.public double pr(Value d)
nlPr(d).  Note that for a large, complex datum, d,
       pr(d) may underflow to zero. Best stick with nlPr(d) in such cases.
       This default pr(d) calls nlPr(d).public abstract double nlPr(Value d)
probability of a datum,
       'd', in nits;  nlPr must be defined when implementing a Model.
       Also see nl2Pr(d).public final double sumNlPr(Vector ds)
nlLH(ss)
       and stats(ds) instead?  sumNlPr(ds)
       and nlLH(ss) should be equal but the latter is
       often quicker (where ss=stats(ds)).
       Also see Model.Defaults.nlLH(la.la.Value).public double nl2Pr(Value d)
nits but
       people often like information to be displayed in bits.public Value random()
public Vector random(int n)
random() Values, if possible.
       The result can be used as an artificial (test-) data-set, say.public Series randomSeries()
Series which repeatedly
       returns a
       random() Value from 'this' Model,
       provided the Model can do so.  But don't forget to
       advance() or it won't be
       very random!  Also see Adaptive.M.randomSeries().public Value stats(Vector ds)
stats(ds,0,ds.nElts()), of
       a data-set 'ds'.
       There is unlikely to be any need for a subclass (a Model)
       to override stats(ds).  Also see nlLH(ss).public abstract Value stats(Vector ds, int lo, int hi)
nlLH(ss).
       An option is to return the data itself, as in Model.Defaults,
       but many Models can do better.
       Note that ss=stats(ds,lo,hi) and nlLH(ss) must
       be consistent.  A UPModel.M's
       stats(ds,lo,hi) might
       be able to make use of an enclosing UPModel's
       stats(ds,lo,hi) if the same
       stats(...) are used for estimating, but this is not always
       the case, e.g., see Model BestOf.M.public abstract Value stats(boolean add, Value ss0, Value ss1)
statisticses,
       ss0 ± ss1.
       '+' if 'add' is true, else '−'.
       An option is to return the data itself, as in Model.Defaults,
       but many Models can do better. Also see
       stats(add,ss0,ds,lo,hi).public Value stats(boolean add, Value ss0, Vector ds, int lo, int hi)
Combine statisticses ss0 and
       stats(ds,lo,hi). This allows
       advantage to be taken of additive (incremental) statistics, e.g.,
       by Intervals. There is unlikely to be a need for a
       subclass (a Model) to override stats(add,ss0,ds,lo,hi).public abstract double nlLH(Value ss)
stats(ds), of a data-set, ds,
       return the negative log LikeliHood, nlLH(ss), of ds.  Make sure that
       nlLH(ss), ss = stats(ds,lo,hi),
       and any Estimator are consistent!public double nl2LH(Value ss)
nlLH(ss) of (sufficient stats, ss, of)
       a data-set, ds, but in bits, instead of nits.public java.lang.String toString()
public Model transform(Function f)
Transform(f).Mdl.
       Note that 'f' must be 1-to-1.UPModel.transform(la.la.Function); note
       that, as distributions, upm(sp).transform(f)=upm.transform(f)(sp).Continuous.M.transform(f) and
       R_D.M.transform(f).public Model asGiven(double msg2)
asGiven(0,msg2).
       This may be necessary because the Model may be competing
       against others on some new "training" data-set. For example,
       asUPModel() returns asGiven(msg2). Also see
       UPModel.M.asGiven(msg2).public Model asGiven(double msg1, double msg2)
asGiven(msg2).protected void zeroTriv(double msg1,
                        Value sp)
public UPModel asUPModel()
UnParameterised Model,
       having trivial problem-definition parameter, that always produces
       (by apply, estimator,
       etc.) 'this' Model asGiven, so to say.
       Note that the result is just a UPModel so, if you want a subclass,
       override asUPModel suitably. If you want 'this' Model as an Estimator
       use asEstimator(triv).  Also see
       FunctionModel.asUPModel() and SeriesModel.asUPModel().public Estimator asEstimator(Value ps)
asUPModel(). Note, ps=triv!