Skip to content

Commit

Permalink
small adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
yxu927 committed Aug 9, 2024
1 parent 6f74889 commit 556f4a1
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lphy-base/src/test/java/lphy/base/LPhyExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected void testLPhyExamplesInDir(File exampleDir) {

List<String> ignoreFiles = Arrays.asList(
// give the lphy file name here, if it is not tested
"h5n1BDSS.lphy"
);

List<String> failedByParser = new ArrayList<>();
Expand Down Expand Up @@ -100,18 +101,28 @@ protected void testLPhyExamplesInDir(File exampleDir) {
System.out.println("Successfully parse " + fileName + "\n");

//*** Test re-sampling ***//
final long[] seeds = new long[]{666L, 777L};

List<Value> res1 = GraphicalModelUtils.getAllValuesFromSinks(lPhyMetaParser);
final int nAllVal = res1.size();
Sampler sampler = new Sampler(lPhyMetaParser);
try {
List<Value> res = sampler.sample(666L); // only for birth death
assertEquals(nAllVal, res.size(), "Resample " + fileName +
", but the returned values ");
} catch (Exception e) {
if (!failedBySample.contains(fileName)) failedBySample.add(fileName);
// Display in stdout
System.out.println("Err: example " + fileName + " failed during re-sampling !!! \n");
e.printStackTrace();
for (long seed : seeds) {
try {
List<Value> res;
// to avoid memory issue of random sampling BD trees
if (exampleDir.getPath().endsWith("birth-death"))
res = sampler.sample(seed); // only for birth death
else
res = sampler.sample(null); // random seed

assertEquals(nAllVal, res.size(), "Resample " + fileName +
", but the returned values ");
} catch (Exception e) {
if (!failedBySample.contains(fileName)) failedBySample.add(fileName);
// Display in stdout
System.out.println("Err: example " + fileName + " failed during re-sampling !!! \n");
e.printStackTrace();
}
}

// clean parser dict for reusing it safely
Expand Down

0 comments on commit 556f4a1

Please sign in to comment.