| 1 |
package dr.inference.operators; |
| 2 |
|
| 3 |
import dr.inference.distribution.DistributionLikelihood; |
| 4 |
import dr.inference.distribution.IndependentInverseGammaDistributionModel; |
| 5 |
import dr.inference.model.Parameter; |
| 6 |
import dr.math.distributions.GammaDistribution; |
| 7 |
import dr.math.distributions.InverseGammaDistribution; |
| 8 |
|
| 9 |
public class ShrinkageAugmentedGibbsOperator extends SimpleMCMCOperator implements GibbsOperator { |
| 10 |
|
| 11 |
Parameter localShape; |
| 12 |
Parameter globalShape; |
| 13 |
|
| 14 |
Parameter localAugmented; |
| 15 |
Parameter globalAugmented; |
| 16 |
Parameter local; |
| 17 |
Parameter global; |
| 18 |
|
| 19 |
double localAugmentedShape; |
| 20 |
double localAugmentedRate; |
| 21 |
double globalAugmentedShape; |
| 22 |
double globalAugmentedRate; |
| 23 |
|
| 24 |
double pathParameter; |
| 25 |
|
| 26 |
|
| 27 |
public ShrinkageAugmentedGibbsOperator(double weight, DistributionLikelihood localAugmentedPrior, DistributionLikelihood globalAugmentedPrior, |
| 28 |
IndependentInverseGammaDistributionModel localPrior, |
| 29 |
IndependentInverseGammaDistributionModel globalPrior){ |
| 30 |
setWeight(weight); |
| 31 |
GammaDistribution localAugmentedPriorGamma = (GammaDistribution) localAugmentedPrior.getDistribution(); |
| 32 |
GammaDistribution globalAugmentedPriorGamma = (GammaDistribution) globalAugmentedPrior.getDistribution(); |
| 33 |
|
| 34 |
this.localShape = localPrior.getShape(); |
| 35 |
this.globalShape = globalPrior.getShape(); |
| 36 |
|
| 37 |
this.local = localPrior.getData(); |
| 38 |
this.global = globalPrior.getData(); |
| 39 |
this.localAugmented = localPrior.getScale(); |
| 40 |
this.globalAugmented = globalPrior.getScale(); |
| 41 |
|
| 42 |
localAugmentedShape = localAugmentedPriorGamma.getShape(); |
| 43 |
localAugmentedRate = 1 / localAugmentedPriorGamma.getScale(); |
| 44 |
globalAugmentedShape = globalAugmentedPriorGamma.getShape(); |
| 45 |
globalAugmentedRate = 1 / globalAugmentedPriorGamma.getScale(); |
| 46 |
this.pathParameter = 1; |
| 47 |
} |
| 48 |
|
| 49 |
public int getStepCount() { |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public String getOperatorName() { |
| 55 |
return "ShrinkageAugmentedGibbsOperator"; |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public double doOperation() { |
| 60 |
for (int i = 0; i < local.getDimension(); i++) { |
| 61 |
double shape = localAugmentedShape + localShape.getParameterValue(i); |
| 62 |
double rate = localAugmentedRate + 1 / local.getParameterValue(i); |
| 63 |
|
| 64 |
localAugmented.setParameterValueQuietly(i, GammaDistribution.nextGamma(shape, 1 / rate)); |
| 65 |
} |
| 66 |
localAugmented.fireParameterChangedEvent(); |
| 67 |
|
| 68 |
double shape = globalAugmentedShape + globalShape.getParameterValue(0); |
| 69 |
double rate = globalAugmentedRate + 1 / global.getParameterValue(0); |
| 70 |
|
| 71 |
globalAugmented.setParameterValue(0, GammaDistribution.nextGamma(shape, 1 / rate)); |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
} |