| 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 |
package dr.inference.operators.hmc.deprecated; |
| 27 |
|
| 28 |
import dr.inference.operators.AdaptationMode; |
| 29 |
import dr.inference.distribution.MomentDistributionModel; |
| 30 |
import dr.inference.model.LatentFactorModel; |
| 31 |
import dr.inference.model.MatrixParameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@Deprecated |
| 38 |
public class LoadingsHamiltonianMCParser extends AbstractXMLObjectParser { |
| 39 |
public static final String LOADINGS_HAMILTONIAN_MC="loadingsHamiltonianMC"; |
| 40 |
public static final String WEIGHT="weight"; |
| 41 |
public static final String STEP_SIZE="stepSize"; |
| 42 |
public static final String N_STEPS="nSteps"; |
| 43 |
public static final String MOMENTUM_SD="momentumSd"; |
| 44 |
|
| 45 |
@Override |
| 46 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 47 |
|
| 48 |
LatentFactorModel lfm=(LatentFactorModel) xo.getChild(LatentFactorModel.class); |
| 49 |
MomentDistributionModel prior=(MomentDistributionModel) xo.getChild(MomentDistributionModel.class); |
| 50 |
double weight=xo.getDoubleAttribute(WEIGHT); |
| 51 |
AdaptationMode mode= AdaptationMode.parseMode(xo); |
| 52 |
int nSteps=xo.getIntegerAttribute(N_STEPS); |
| 53 |
double stepSize=xo.getDoubleAttribute(STEP_SIZE); |
| 54 |
double momentumSd= xo.getDoubleAttribute(MOMENTUM_SD); |
| 55 |
MatrixParameter loadings=(MatrixParameter) xo.getChild(MatrixParameter.class); |
| 56 |
|
| 57 |
return new LoadingsHamiltonianMC(lfm, prior, weight, mode, stepSize, nSteps, momentumSd, loadings); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 62 |
return rules; |
| 63 |
} |
| 64 |
|
| 65 |
private static final XMLSyntaxRule[] rules = { |
| 66 |
AttributeRule.newDoubleRule(WEIGHT), |
| 67 |
AttributeRule.newDoubleRule(STEP_SIZE), |
| 68 |
AttributeRule.newIntegerRule(N_STEPS), |
| 69 |
AttributeRule.newDoubleRule(MOMENTUM_SD), |
| 70 |
new ElementRule(LatentFactorModel.class), |
| 71 |
new ElementRule(MomentDistributionModel.class), |
| 72 |
new ElementRule(MatrixParameter.class), |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
@Override |
| 77 |
public String getParserDescription() { |
| 78 |
return "Hamiltonian Monte Carlo for loadings matrix in a latent factor model"; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public Class getReturnType() { |
| 83 |
return LoadingsHamiltonianMC.class; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public String getParserName() { |
| 88 |
return LOADINGS_HAMILTONIAN_MC; |
| 89 |
} |
| 90 |
} |