Skip to content

Commit

Permalink
Merge pull request #44 from junniest/master
Browse files Browse the repository at this point in the history
Changed post-sim rejection count to any rejection.
  • Loading branch information
tgvaughan authored Feb 27, 2017
2 parents ce5e12f + 4ef2cee commit 3a8625f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/master/BeastTreeFromMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public class BeastTreeFromMaster extends Tree implements StateNodeInitialiser {
"A post-simulation condition.",
new ArrayList<>());

public Input<Integer> maxPostSimConditionRejectsInput =
new Input<>("maxPostSimConditionRejects",
"Maximum number of post simulation condition failures" +
public Input<Integer> maxConditionRejectsInput =
new Input<>("maxConditionRejects",
"Maximum number of condition failures" +
"before aborting. (Default is no limit.)");

public Input<Boolean> samplePopulationSizesInput = new Input<>(
Expand Down Expand Up @@ -187,7 +187,7 @@ public void initAndValidate() {
for (PostSimCondition postSimCondition : postSimConditionsInput.get())
itraj.setInputValue("postSimCondition", postSimCondition);

itraj.setInputValue("maxPostSimConditionRejects", maxPostSimConditionRejectsInput.get());
itraj.setInputValue("maxConditionRejects", maxConditionRejectsInput.get());

for (InheritanceTrajectoryOutput output : outputsInput.get())
itraj.setInputValue("output", output);
Expand Down
10 changes: 5 additions & 5 deletions src/master/Ensemble.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public class Ensemble extends Runnable {
"A post-simulation condition.",
new ArrayList<>());

public Input<Integer> maxPostSimConditionRejectsInput =
new Input<>("maxPostSimConditionRejects",
"Maximum number of post simulation condition failures" +
public Input<Integer> maxConditionRejectsInput =
new Input<>("maxConditionRejects",
"Maximum number of condition failures" +
"before aborting. (Default is no limit.)");

// Outputs to write:
Expand Down Expand Up @@ -158,8 +158,8 @@ public void initAndValidate() {
for (PostSimCondition condition : postSimConditionsInput.get())
spec.addPostSimCondition(condition);

if (maxPostSimConditionRejectsInput.get() != null)
spec.setMaxPostSimConditionRejects(maxPostSimConditionRejectsInput.get());
if (maxConditionRejectsInput.get() != null)
spec.setMaxConditionRejects(maxConditionRejectsInput.get());

// Set seed if provided, otherwise use default BEAST seed:
if (seedInput.get()!=null)
Expand Down
8 changes: 4 additions & 4 deletions src/master/EnsembleSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class EnsembleSummary extends Runnable {
"A post-simulation condition.",
new ArrayList<>());

public Input<Integer> maxPostSimConditionRejectsInput =
new Input<>("maxPostSimConditionRejects",
public Input<Integer> maxConditionRejectsInput =
new Input<>("maxConditionRejects",
"Maximum number of post simulation condition failures" +
"before aborting. (Default is no limit.)");
// Individual moments:
Expand Down Expand Up @@ -156,8 +156,8 @@ public void initAndValidate() {
for (PostSimCondition condition : postSimConditionsInput.get())
spec.addPostSimCondition(condition);

if (maxPostSimConditionRejectsInput.get() != null)
spec.setMaxPostSimConditionRejects(maxPostSimConditionRejectsInput.get());
if (maxConditionRejectsInput.get() != null)
spec.setMaxConditionRejects(maxConditionRejectsInput.get());

// Check for zero-length moment and moment group lists (no point to calculation!)
if (momentGroupsInput.get().isEmpty() && momentsInput.get().isEmpty())
Expand Down
8 changes: 4 additions & 4 deletions src/master/InheritanceEnsemble.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public class InheritanceEnsemble extends Runnable {
"A post-simulation condition.",
new ArrayList<>());

public Input<Integer> maxPostSimConditionRejectsInput =
new Input<>("maxPostSimConditionRejects",
public Input<Integer> maxConditionRejectsInput =
new Input<>("maxConditionRejects",
"Maximum number of post simulation condition failures" +
"before aborting. (Default is no limit.)");

Expand Down Expand Up @@ -196,8 +196,8 @@ public void initAndValidate() {
for (PostSimCondition condition : postSimConditionsInput.get())
spec.addPostSimCondition(condition);

if (maxPostSimConditionRejectsInput.get() != null)
spec.setMaxPostSimConditionRejects(maxPostSimConditionRejectsInput.get());
if (maxConditionRejectsInput.get() != null)
spec.setMaxConditionRejects(maxConditionRejectsInput.get());

// Set seed if provided, otherwise use default BEAST seed:
if (seedInput.get()!=null)
Expand Down
23 changes: 15 additions & 8 deletions src/master/InheritanceTrajectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public void initAndValidate() {
for (PostSimCondition condition : postSimConditionsInput.get())
spec.addPostSimCondition(condition);

if (maxPostSimConditionRejectsInput.get() != null)
spec.setMaxPostSimConditionRejects(maxPostSimConditionRejectsInput.get());
if (maxConditionRejectsInput.get() != null)
spec.setMaxConditionRejects(maxConditionRejectsInput.get());

// Set seed if provided, otherwise use default BEAST seed:
if (seedInput.get()!=null)
Expand All @@ -191,7 +191,7 @@ public void run() {
try {
simulate();
} catch (RejectCountExceeded ex) {
System.err.println("Maximum number of post-simulation condition " +
System.err.println("Maximum number of condition " +
"rejections exceeded. Aborting.");
System.exit(1);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ private void simulate() throws RejectCountExceeded {
sampleDt = spec.getSampleDt();

boolean postSimReject;
int postSimRejectCount = 0;
int rejectCount = 0;
do { // Perform simulations until no post-simulation rejection occurs

initialiseSimulation();
Expand Down Expand Up @@ -288,7 +288,14 @@ private void simulate() throws RejectCountExceeded {
// Rejection: Abort and start a new simulation
if (spec.getVerbosity()>0)
System.err.println("Rejection end condition met "
+ "at time " + t);
+ "at time " + t);
rejectCount += 1;

if (spec.getMaxConditionRejects()>=0 &&
rejectCount > spec.getMaxConditionRejects()) {
throw new RejectCountExceeded();
}

initialiseSimulation();
continue;
} else {
Expand Down Expand Up @@ -448,10 +455,10 @@ private void simulate() throws RejectCountExceeded {
if (spec.getVerbosity()>0)
System.err.println("Post-simulation rejection condition met.");

postSimRejectCount += 1;
rejectCount += 1;

if (spec.getMaxPostSimConditionRejects()>=0 &&
postSimRejectCount > spec.getMaxPostSimConditionRejects()) {
if (spec.getMaxConditionRejects()>=0 &&
rejectCount > spec.getMaxConditionRejects()) {
throw new RejectCountExceeded();
}

Expand Down
28 changes: 18 additions & 10 deletions src/master/Trajectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public class Trajectory extends Runnable {
"A post-simulation condition.",
new ArrayList<>());

public Input<Integer> maxPostSimConditionRejectsInput =
new Input<>("maxPostSimConditionRejects",
public Input<Integer> maxConditionRejectsInput =
new Input<>("maxConditionRejects",
"Maximum number of post simulation condition failures" +
"before aborting. (Default is no limit.)");

Expand Down Expand Up @@ -167,8 +167,8 @@ public void initAndValidate() {
for (PostSimCondition condition : postSimConditionsInput.get())
spec.addPostSimCondition(condition);

if (maxPostSimConditionRejectsInput.get() != null)
spec.setMaxPostSimConditionRejects(maxPostSimConditionRejectsInput.get());
if (maxConditionRejectsInput.get() != null)
spec.setMaxConditionRejects(maxConditionRejectsInput.get());

// Set seed if provided, otherwise use default BEAST seed:
if (seedInput.get()!=null)
Expand All @@ -188,7 +188,7 @@ public void run() {
try {
simulate();
} catch (RejectCountExceeded ex) {
System.err.println("Maximum number of post-simulation condition " +
System.err.println("Maximum number of condition " +
"rejections exceeded. Aborting.");
System.exit(1);
}
Expand Down Expand Up @@ -233,7 +233,7 @@ private void simulate() throws RejectCountExceeded {

// Loop until any post-simulation rejection conditions fail.
boolean postSimulationReject;
int postSimRejectCount = 0;
int rejectCount = 0;
do {
sampledStates.clear();
sampledTimes.clear();
Expand Down Expand Up @@ -282,7 +282,15 @@ private void simulate() throws RejectCountExceeded {
if (endConditionMet.isRejection()) {
if (spec.verbosity>0)
System.err.println("Rejection end condition met "
+ "at time " + t);
+ "at time " + t);

rejectCount += 1;

if (spec.getMaxConditionRejects()>=0 &&
rejectCount > spec.getMaxConditionRejects()) {
throw new RejectCountExceeded();
}

currentState = new PopulationState(spec.initPopulationState);
clearSamples();
sampleState(currentState, 0.0);
Expand Down Expand Up @@ -365,10 +373,10 @@ private void simulate() throws RejectCountExceeded {
if (spec.getVerbosity()>0)
System.err.println("Post-simulation rejection condition met.");

postSimRejectCount += 1;
rejectCount += 1;

if (spec.getMaxPostSimConditionRejects()>=0 &&
postSimRejectCount > spec.getMaxPostSimConditionRejects()) {
if (spec.getMaxConditionRejects()>=0 &&
rejectCount > spec.getMaxConditionRejects()) {
throw new RejectCountExceeded();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/master/TrajectorySpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class TrajectorySpec {
// Leaf count post-simulation conditions:
List<PostSimCondition> postSimConditions;

int maxPostSimConditionRejects = -1;
int maxConditionRejects = -1;


// Whether to collect evenly spaced samples or let the state stepper
Expand Down Expand Up @@ -201,17 +201,17 @@ public void addPostSimCondition(PostSimCondition condition) {
*
* @param n limit to set
*/
public void setMaxPostSimConditionRejects(int n) {
maxPostSimConditionRejects = n;
public void setMaxConditionRejects(int n) {
maxConditionRejects = n;
}

/**
* Retrieve maximum number of post-sim condition rejects allowed before
* aborting. A value of -1 implies no limit.
*
*/
public int getMaxPostSimConditionRejects() {
return maxPostSimConditionRejects;
public int getMaxConditionRejects() {
return maxConditionRejects;
}

/**
Expand Down

0 comments on commit 3a8625f

Please sign in to comment.