Skip to content

Commit

Permalink
Merge pull request #36 from dityas/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dityas authored Jan 2, 2020
2 parents f232a24 + 4dc1804 commit ca40bd6
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 3 deletions.
Binary file modified Protos/build/Protos.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion Protos/src/thinclab/executables/POMDPSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void solvePOMDP() {
this.solver =
new OfflineSymbolicPerseus(
this.pomdp,
new SSGABeliefExpansion(this.pomdp, this.searchDepth, 10),
new SSGABeliefExpansion(this.pomdp, this.searchDepth, 5),
this.perseusRounds,
this.numDpBackups);

Expand Down
5 changes: 4 additions & 1 deletion Protos/src/thinclab/legacy/DDnode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ private void precomputeHash() {
if (this.children[i] != null)
builder.append(this.children[i].hashCode());

else logger.error("Null child at " + i + " something might be seriously wrong.");
else {
logger.error("Null child at " + i + " something might be seriously wrong.");
logger.error("Error causing DD is " + this.toDDTree());
}
}

this.hash = builder.toHashCode();
Expand Down
62 changes: 62 additions & 0 deletions Protos/src/thinclab/solvers/OfflineSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public abstract class OfflineSolver extends BaseSolver {

CircularFifoBuffer<Float> bErrorVals = new CircularFifoBuffer<Float>(5);

/* for checking used beliefs and num alpha vectors */
int numSimilar = 0;
int numAlphas = -1;
int numBeliefs = -1;

private static final Logger logger = Logger.getLogger(OfflineSolver.class);

// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -104,5 +109,62 @@ public float getErrorVariance(float bellManError) {
return variance;

}

public boolean isNumAlphaConstant(int numAlphas) {
/*
* Checks if the number of alpha vectors hasn't changed in the last 5 iterations
*/

if (this.numAlphas != numAlphas) {
this.numAlphas = numAlphas;
return false;
}

else return true;
}

public boolean isNumUsedBeliefsConstant(int numUsedBeliefs, int numBeliefs) {
/*
* Checks if number of used beliefs is same as number of total beliefs
* for the last 5 iterations. This could mean convergence
*/

if (numUsedBeliefs == numBeliefs) {

if (this.numBeliefs != numUsedBeliefs) {
this.numBeliefs = numUsedBeliefs;
return false;
}

else {
return true;
}
}

else return false;
}

public boolean declareApproxConvergenceForAlphaVectors(
int numAlphas, int numUsedBeliefs, int numBeliefs) {
/*
* Checks if the number of alpha vectors and the number of used beliefs is the
* same for the last few iterations.
*/

if (this.isNumAlphaConstant(numAlphas) &&
this.isNumUsedBeliefsConstant(numUsedBeliefs, numBeliefs)) {

this.numSimilar += 1;

if (this.numSimilar >= 5) {
this.numSimilar = 0;
return true;
}

else return false;
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ public void boundedPerseusStartFromCurrent(
break;
}

if (this.declareApproxConvergenceForAlphaVectors(
this.alphaVectors.length, numIter, beliefRegion.length)) {
logger.warn("DECLARING APPROXIMATE CONVERGENCE AT ERROR: " + bellmanErr
+ " BECAUSE ALL BELIEFS ARE BEING USED AND NUM ALPHAS IS CONSTANT");
break;
}

}

}
Expand Down
62 changes: 62 additions & 0 deletions Protos/src/thinclab/solvers/OnlineSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public abstract class OnlineSolver extends BaseSolver {
PolicyCache pCache = new PolicyCache(5);

CircularFifoBuffer<Float> bErrorVals = new CircularFifoBuffer<Float>(5);

/* for checking used beliefs and num alpha vectors */
int numSimilar = 0;
int numAlphas = -1;
int numBeliefs = -1;

// ------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -120,5 +125,62 @@ public float getErrorVariance(float bellManError) {
return variance;

}

public boolean isNumAlphaConstant(int numAlphas) {
/*
* Checks if the number of alpha vectors hasn't changed in the last 5 iterations
*/

if (this.numAlphas != numAlphas) {
this.numAlphas = numAlphas;
return false;
}

else return true;
}

public boolean isNumUsedBeliefsConstant(int numUsedBeliefs, int numBeliefs) {
/*
* Checks if number of used beliefs is same as number of total beliefs
* for the last 5 iterations. This could mean convergence
*/

if (numUsedBeliefs == numBeliefs) {

if (this.numBeliefs != numUsedBeliefs) {
this.numBeliefs = numUsedBeliefs;
return false;
}

else {
return true;
}
}

else return false;
}

public boolean declareApproxConvergenceForAlphaVectors(
int numAlphas, int numUsedBeliefs, int numBeliefs) {
/*
* Checks if the number of alpha vectors and the number of used beliefs is the
* same for the last few iterations.
*/

if (this.isNumAlphaConstant(numAlphas) &&
this.isNumUsedBeliefsConstant(numUsedBeliefs, numBeliefs)) {

this.numSimilar += 1;

if (this.numSimilar >= 5) {
this.numSimilar = 0;
return true;
}

else return false;
}

return false;
}

}
2 changes: 1 addition & 1 deletion Protos/src/thinclab/tests/TestOnlineSymbolicPerseus.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void testIPOMDPNextBelStates() throws Exception {
*/
IPOMDP tigerL1IPOMDP = new IPOMDP(parser, 2, 20);

for (int t = 0; t < 10; t++) {
for (int t = 0; t < 5; t++) {

HashMap<String, NextBelState> nextStates =
NextBelState.oneStepNZPrimeBelStates(
Expand Down

0 comments on commit ca40bd6

Please sign in to comment.