-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGlmModel.java
More file actions
108 lines (86 loc) · 4.09 KB
/
Copy pathGlmModel.java
File metadata and controls
108 lines (86 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package mascot.glmmodel;
import beast.base.core.Input;
import beast.base.core.Input.Validate;
import beast.base.core.Loggable;
import beast.base.inference.CalculationNode;
import beast.base.inference.StateNode;
import beast.base.inference.StateNodeInitialiser;
import beast.base.spec.inference.parameter.BoolVectorParam;
import beast.base.spec.domain.Real;
import beast.base.spec.inference.parameter.RealScalarParam;
import beast.base.spec.inference.parameter.RealVectorParam;
import java.util.List;
public abstract class GlmModel extends CalculationNode implements Loggable, StateNodeInitialiser {
public Input<CovariateList> covariateListInput = new Input<>("covariateList", "input of covariates", Validate.REQUIRED);
public Input<RealVectorParam<? extends Real>> scalerInput = new Input<>("scaler", "input of covariates scaler", Validate.REQUIRED);
public Input<BoolVectorParam> indicatorInput = new Input<>("indicator", "input of covariates scaler", Validate.REQUIRED);
public Input<RealScalarParam<Real>> clockInput = new Input<>("clock", "clock rate of the parameter",Validate.REQUIRED);
public Input<RealVectorParam<? extends Real>> errorInput = new Input<>("error", "time variant error term in the GLM model for the rates");
public Input<RealVectorParam<? extends Real>> constantErrorInput = new Input<>("constantError", "time invariant error term in the GLM model for the rates");
public int nrIntervals;
public int verticalEntries;
public abstract double[] getRates(int i);
public boolean isDirty(){
for (int i = 0; i < scalerInput.get().size(); i++)
if(scalerInput.get().isDirty(i))
return true;
for (int i = 0; i < indicatorInput.get().size(); i++)
if(indicatorInput.get().isDirty(i))
return true;
if (errorInput.get() != null)
for (int i = 0; i < errorInput.get().size(); i++)
if(errorInput.get().isDirty(i))
return true;
if (constantErrorInput.get() != null)
for (int i = 0; i < constantErrorInput.get().size(); i++)
if(constantErrorInput.get().isDirty(i))
return true;
if (clockInput.get().somethingIsDirty())
return true;
return false;
}
public void setNrIntervals(int i, int dim, boolean isMigration){
nrIntervals = i;
if (isMigration){
// calc the two possible lengths of the covariates
int l2 = i*(dim*(dim-1));
// check that the dimension of the covariates are correct
for (int j = 0; j < covariateListInput.get().size(); j++){
if (covariateListInput.get().get(j).getDimension()!=l2)
throw new RuntimeException("The dimension of the the covariate \"" + covariateListInput.get().get(j).getID() + "\" is wrong.\n" +
"The current dimension is " + covariateListInput.get().get(j).getDimension() +
", but should be equal to the number of rate shifts\n"+
"i.e. it should be " +l2 + "\n");
}
}else{
// calc the two possible lengths of the covariates
int l2 = i*dim;
for (int j = 0; j < covariateListInput.get().size(); j++){
if (covariateListInput.get().get(j).getDimension()!=l2)
throw new RuntimeException("The dimension of the the covariate \"" + covariateListInput.get().get(j).getID() + "\" is wrong.\n" +
"The current dimension is " + covariateListInput.get().get(j).getDimension() +
", but should be equal to the number of rate shifts\n"+
"i.e. it should be " +l2 + "\n");
}
}
verticalEntries = covariateListInput.get().get(0).getDimension()/(nrIntervals);
}
public void setNrDummy(){
verticalEntries = 0;
}
// Subclasses (LogLinear, etc.) fix up the dimensions of scaler /
// indicator / error parameters during their own initAndValidate. The
// default initStateNodes is a no-op; getInitialisedStateNodes reports
// the parameters this class takes responsibility for so the framework
// can dedupe.
@Override
public void initStateNodes() {
}
@Override
public void getInitialisedStateNodes(List<StateNode> stateNodes) {
stateNodes.add(scalerInput.get());
stateNodes.add(indicatorInput.get());
if (errorInput.get() != null) stateNodes.add(errorInput.get());
if (constantErrorInput.get() != null) stateNodes.add(constantErrorInput.get());
}
}