@@ -0,0 +1,2753 @@
+package dr.evomodel.sitemodel;%0D%0A%0D%0Aimport dr.inference.model.*;%0D%0Aimport dr.inference.distribution.ParametricDistributionModel;%0D%0A%0D%0A/**%0D%0A * @author Chieh-Hsi Wu%0D%0A *%0D%0A * This class models the relative loci rates using the given discritized parametric distribution. %0D%0A */%0D%0Apublic class DiscretizedLociRates extends AbstractModel %7B%0D%0A%0D%0A    private CompoundParameter lociRates;%0D%0A    private Parameter rateCategoryParameter;%0D%0A    private ParametricDistributionModel distrModel;%0D%0A    private double normalizeRateTo;%0D%0A    private double%5B%5D rates;%0D%0A    private boolean normalize;%0D%0A    private int categoryCount;%0D%0A    private double scaleFactor;%0D%0A%0D%0A%0D%0A    public DiscretizedLociRates(%0D%0A            CompoundParameter lociRates,%0D%0A            Parameter rateCategoryParameter,%0D%0A            ParametricDistributionModel model,%0D%0A            double normalizeLociRateTo,%0D%0A            boolean normalize,%0D%0A            int categoryCount) %7B%0D%0A        super(%22DiscretizedLociRatesModel%22);%0D%0A        this.lociRates = lociRates;%0D%0A        this.rateCategoryParameter = rateCategoryParameter;%0D%0A        this.distrModel = model;%0D%0A        this.normalizeRateTo = normalizeLociRateTo;%0D%0A        this.normalize = normalize;%0D%0A        this.categoryCount = categoryCount;%0D%0A        rates = new double%5BcategoryCount%5D;%0D%0A        setupRates();%0D%0A%0D%0A%0D%0A        addModel(distrModel);%0D%0A        addVariable(rateCategoryParameter);%0D%0A%0D%0A    %7D%0D%0A%0D%0A    private void setupRates()%7B%0D%0A        double categoryIntervalSize = 1.0/categoryCount;%0D%0A        for(int i = 0; i %3C categoryCount; i++)%7B%0D%0A            rates%5Bi%5D= distrModel.quantile((i+0.5)*categoryIntervalSize);%0D%0A        %7D%0D%0A%0D%0A        if(normalize)%7B%0D%0A           computeFactor();%0D%0A        %7D%0D%0A        int lociCount = rateCategoryParameter.getDimension();%0D%0A        for(int i = 0; i %3C lociCount; i ++)%7B%0D%0A            lociRates.setParameterValue(i,rates%5B(int)rateCategoryParameter.getParameterValue(i)%5D*scaleFactor);%0D%0A        %7D%0D%0A%0D%0A    %7D%0D%0A    public void handleModelChangedEvent(Model model, Object object, int index) %7B%0D%0A        if (model == distrModel) %7B%0D%0A            setupRates();%0D%0A            fireModelChanged();%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) %7B%0D%0A        setupRates();%0D%0A    %7D%0D%0A%0D%0A    protected void storeState() %7B%0D%0A    %7D%0D%0A    protected void acceptState() %7B%0D%0A    %7D%0D%0A    protected void restoreState() %7B%0D%0A        setupRates();%0D%0A    %7D%0D%0A    private void computeFactor()%7B%0D%0A        double sumRates = 0.0;%0D%0A        int lociCount = rateCategoryParameter.getDimension();%0D%0A        for(int i = 0; i %3C lociCount; i++)%7B%0D%0A            sumRates += rates%5B(int)rateCategoryParameter.getParameterValue(i)%5D;%0D%0A        %7D%0D%0A        scaleFactor = normalizeRateTo/(sumRates/categoryCount);%0D%0A    %7D%0D%0A%0D%0A%7D%0D%0A

Models the relative loci rates using the given discritized parametric distribution.