Skip to content

Commit

Permalink
change realparameter to function in betarange distribtuin
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandouglas committed Oct 1, 2024
1 parent 5ab450c commit 8a0802d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/beastlabs/math/distributions/BetaRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.commons.math.distribution.BetaDistributionImpl;

import beast.base.core.Description;
import beast.base.core.Function;
import beast.base.inference.Distribution;
import beast.base.core.Input;
import beast.base.inference.State;
Expand All @@ -18,10 +19,10 @@
public class BetaRange extends Distribution {

final public Input<RealParameter> parameterInput = new Input<>("x", "the parameter at which the density is calculated", Input.Validate.REQUIRED);
final public Input<RealParameter> alphaInput = new Input<>("alpha", "first shape parameter (default 1)");
final public Input<RealParameter> betaInput = new Input<>("beta", "the other shape parameter (default 1)");
final public Input<RealParameter> lowerInput = new Input<>("lower", "lower limit of the parameter (default 0)");
final public Input<RealParameter> upperInput = new Input<>("upper", "upper limit of the parameter (default 1)");
final public Input<Function> alphaInput = new Input<>("alpha", "first shape parameter (default 1)");
final public Input<Function> betaInput = new Input<>("beta", "the other shape parameter (default 1)");
final public Input<Function> lowerInput = new Input<>("lower", "lower limit of the parameter (default 0)");
final public Input<Function> upperInput = new Input<>("upper", "upper limit of the parameter (default 1)");



Expand All @@ -30,7 +31,7 @@ public class BetaRange extends Distribution {
@Override
public void initAndValidate() {

System.out.println("BETARANGE");
//System.out.println("BETARANGE");

}

Expand All @@ -41,21 +42,24 @@ public void initAndValidate() {
@Override
public double calculateLogP() {

System.out.println("BETARANGE");
//System.out.println("BETARANGE");

logP = 0;

RealParameter param = parameterInput.get();
for (int i = 0; i < param.getDimension(); i ++) {

System.out.println("BETARANGE " + i + ": " + logP);
//System.out.println("BETARANGE " + i + ": " + logP);

double val = param.getValue(i);
double alpha = getValOrDefault(alphaInput.get(), i, 1);
double beta = getValOrDefault(betaInput.get(), i, 1);
double lower = getValOrDefault(lowerInput.get(), i, 0);
double upper = getValOrDefault(upperInput.get(), i, 1);


//System.out.println("BETARANGE " + lower + ": " + upper);

// Range check
if (alpha <= 0 || beta <= 0) continue;
if (val <= lower || val >= upper) {
Expand Down Expand Up @@ -86,16 +90,16 @@ public double calculateLogP() {
* @param defaultVal
* @return
*/
private double getValOrDefault(RealParameter param, int index, double defaultVal) {
private double getValOrDefault(Function param, int index, double defaultVal) {

// If the parameter is null, use the default value
if (param == null) return defaultVal;

// If the parameter has 1 dimension get the 1st value
if (param.getDimension() == 1) return param.getValue();
if (param.getDimension() == 1) return param.getArrayValue();

// Multiple dimensions -> return the value at 'index'
return param.getValue(index);
return param.getArrayValue(index);

}

Expand Down

0 comments on commit 8a0802d

Please sign in to comment.