From 820752952cfa7b41044937278f9f850b6cd2bde9 Mon Sep 17 00:00:00 2001 From: adash Date: Mon, 22 Jun 2009 05:47:08 +0000 Subject: [PATCH] bug fixes to sequential version in Bayes --- .../src/Benchmarks/SingleTM/Bayes/Adtree.java | 18 ++++-------------- .../src/Benchmarks/SingleTM/Bayes/Bayes.java | 6 +++--- Robust/src/Benchmarks/SingleTM/Bayes/Data.java | 1 + .../src/Benchmarks/SingleTM/Bayes/Learner.java | 5 +---- Robust/src/Benchmarks/SingleTM/Bayes/Sort.java | 12 ++++-------- .../Benchmarks/SingleTM/common/QuickSort.java | 6 ++++++ .../Benchmarks/SingleTM/common/Vector_t.java | 5 +---- 7 files changed, 20 insertions(+), 33 deletions(-) diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java b/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java index bfbaba39..c124d593 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Adtree.java @@ -225,7 +225,7 @@ public class Adtree { makeVary(parentIndex, v, start, numRecord, dataPtr); boolean status; if((status = varyVectorPtr.vector_pushBack(varyPtr)) != true) { - System.out.println("varyVectorPtr.vector_pushBack != true"); + System.out.println("Assert failed: varyVectorPtr.vector_pushBack != true"); System.exit(0); } } @@ -242,7 +242,6 @@ public class Adtree { public void adtree_make (Data dataPtr) { - int numRecord = dataPtr.numRecord; numVar = dataPtr.numVar; numRecord = dataPtr.numRecord; dataPtr.data_sort(0, numRecord, 0); @@ -261,15 +260,12 @@ public class Adtree { Vector_t queryVectorPtr, int lastQueryIndex) { - System.out.println("DEBUG: Starting getCount()"); if (nodePtr == null) { - System.out.println("DEBUG: exiting getCount() at point 1, count= 0"); return 0; } int nodeIndex = nodePtr.index; if (nodeIndex >= lastQueryIndex) { - System.out.println("DEBUG: exiting getCount() at point 2, count= "+ nodePtr.count); return nodePtr.count; } @@ -278,12 +274,11 @@ public class Adtree { Query queryPtr = (Query)(queryVectorPtr.vector_at(q)); if (queryPtr == null) { - System.out.println("DEBUG: exiting getCount() at point 3, count= "+ nodePtr.count); return nodePtr.count; } int queryIndex = queryPtr.index; if(queryIndex > lastQueryIndex) { - System.out.println("Assert failed"); + System.out.println("Assert failed: queryIndex > lastQueryIndex in getCount()"); System.exit(0); } @@ -309,7 +304,7 @@ public class Adtree { queryVectorPtr.vector_at(qq)); } } - System.out.println("DEBUG: Calling adtree_getCount, HERE1"); + int superCount = adtree_getCount(superQueryVectorPtr); superQueryVectorPtr.vector_free(); @@ -317,7 +312,6 @@ public class Adtree { int invertCount; if (queryValue == 0) { queryPtr.value = 1; - System.out.println("DEBUG: Calling adtree_getCount, HERE2"); invertCount = getCount(nodePtr, i, q, @@ -326,7 +320,6 @@ public class Adtree { queryPtr.value = 0; } else { queryPtr.value = 0; - System.out.println("DEBUG: Calling adtree_getCount, HERE3"); invertCount = getCount(nodePtr, i, q, @@ -339,27 +332,24 @@ public class Adtree { } else { if (queryValue == 0) { - System.out.println("DEBUG: Calling adtree_getCount, HERE4"); count += getCount(varyPtr.zeroNodePtr, (i + 1), (q + 1), queryVectorPtr, lastQueryIndex); } else if (queryValue == 1) { - System.out.println("DEBUG: Calling adtree_getCount, HERE5"); count += getCount(varyPtr.oneNodePtr, (i + 1), (q + 1), queryVectorPtr, lastQueryIndex); } else { /* QUERY_VALUE_WILDCARD */ - System.out.println("Program shouldn't get here"); // catch bugs in learner + System.out.println("Adtree_getCount Program shouldn't get here"); // catch bugs in learner System.exit(0); } } - System.out.println("DEBUG: exiting getCount() at point 4, count= "+ count); return count; } diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java b/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java index 4f38d3d8..a850b39b 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Bayes.java @@ -337,15 +337,15 @@ public class Bayes extends Thread { boolean status = learnerPtr.netPtr.net_isCycle(); if(status) { - System.out.println("System has an incorrect result"); + System.out.println("Assert failed: system has an incorrect result"); System.exit(0); } #ifndef SIMULATOR float learnScore = learnerPtr.learner_score(); - System.out.println("Learn score= " + learnScore); + System.out.println("Learn score= " + (double)learnScore); #endif - System.out.println("Actual score= " + actualScore); + System.out.println("Actual score= " + (double)actualScore); /* * Clean up diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Data.java b/Robust/src/Benchmarks/SingleTM/Bayes/Data.java index de89697f..fab45955 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Data.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Data.java @@ -327,6 +327,7 @@ public class Data { numVar, numVar, offset); + } diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java b/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java index e1009ca1..b81b4083 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Learner.java @@ -224,11 +224,11 @@ public class Learner { int parentCount = adtreePtr.adtree_getCount(parentQueryVectorPtr); if(parentCount < count || parentCount <= 0) { - System.out.println("Assert failed for computeSpecificLocalLogLikelihood()"); System.exit(0); } float fval = (float)(probability * (Math.log((double)count/ (double)parentCount))); + return fval; } @@ -1532,14 +1532,12 @@ public class Learner { int numTotalParent = 0; float logLikelihood = 0.0f; - //System.out.println("DEBUG: before logLikelihood= " + logLikelihood); for (int v = 0; v < numVar; v++) { IntList parentIdListPtr = netPtr.net_getParentIdListPtr(v); numTotalParent += parentIdListPtr.list_getSize(); - populateQueryVectors(netPtr, v, queries, @@ -1554,7 +1552,6 @@ public class Learner { logLikelihood += localLogLikelihood; } - //System.out.println("DEBUG: after logLikelihood= " + logLikelihood); queryVectorPtr.vector_free(); parentQueryVectorPtr.vector_free(); queries = null; diff --git a/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java b/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java index 623e7545..1f5f0c44 100644 --- a/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java +++ b/Robust/src/Benchmarks/SingleTM/Bayes/Sort.java @@ -163,7 +163,6 @@ public class Sort { int stkptr = 0; - start = 0; int lo = start; int hi = start + (width * (num - 1)); @@ -176,7 +175,6 @@ public class Sort { pv.hi = hi; pv.width = width; pv.n = n; - pv.offset = offset; int typeflag; @@ -187,11 +185,11 @@ public class Sort { /** * debug **/ - //System.out.println("DEBUG: lo= "+ pv.lo + " hi= " + pv.hi + " width= " + pv.width+ " offset= " + pv.offset + " n= " + pv.n + " size= " + size); + //System.out.println("DEBUG: lo= "+ pv.lo + " hi= " + pv.hi + " width= " + pv.width+ " offset= " + offset + " n= " + pv.n + " size= " + size); if (size <= CUTOFF) { - shortsort(base, pv.lo, pv.hi, pv.width, pv.n, pv.offset); + shortsort(base, pv.lo, pv.hi, pv.width, pv.n, offset); } else { @@ -204,10 +202,10 @@ public class Sort { while(true) { do { pv.loguy += pv.width; - } while (pv.loguy <= pv.hi && cmp(base, pv.loguy, pv.lo, pv.n, pv.offset) <= 0); + } while (pv.loguy <= pv.hi && cmp(base, pv.loguy, pv.lo, pv.n, offset) <= 0); do { pv.higuy -= pv.width; - } while (pv.higuy > pv.lo && cmp(base, pv.higuy, pv.lo, pv.n, pv.offset) >= 0); + } while (pv.higuy > pv.lo && cmp(base, pv.higuy, pv.lo, pv.n, offset) >= 0); if (pv.higuy < pv.loguy) { break; } @@ -280,7 +278,6 @@ public class ptrVal { int hi; int width; int n; - int offset; int loguy; int higuy; int max; @@ -292,7 +289,6 @@ public class ptrVal { hi = 0; width = 0; n = 0; - offset = 0; loguy = 0; higuy = 0; max = 0; diff --git a/Robust/src/Benchmarks/SingleTM/common/QuickSort.java b/Robust/src/Benchmarks/SingleTM/common/QuickSort.java index 3c211cd5..51f20a70 100644 --- a/Robust/src/Benchmarks/SingleTM/common/QuickSort.java +++ b/Robust/src/Benchmarks/SingleTM/common/QuickSort.java @@ -132,6 +132,12 @@ public class QuickSort { swap(i, j, a); } + /* =========================================== + * compareQuery + * -- Want smallest ID first + * -- For vector_sort + * =========================================== + */ public boolean less(Object x, Object y) { Query aQueryPtr = (Query) x; Query bQueryPtr = (Query) y; diff --git a/Robust/src/Benchmarks/SingleTM/common/Vector_t.java b/Robust/src/Benchmarks/SingleTM/common/Vector_t.java index 853ff39d..17a70bb1 100644 --- a/Robust/src/Benchmarks/SingleTM/common/Vector_t.java +++ b/Robust/src/Benchmarks/SingleTM/common/Vector_t.java @@ -60,7 +60,6 @@ public class Vector_t { int newCapacity = capacity * 2; Object[] newElements = new Object[newCapacity]; - //void** newElements = (void**)malloc(newCapacity * sizeof(void*)); if (newElements == null) { return false; } @@ -119,9 +118,7 @@ public class Vector_t { public void vector_sort () { - //qsort.sort(elements, 0, (elements.length - 1)); - qsort.sort(elements); - //qsort(elements, size, 4, compare); + qsort.sort(elements, 0, size); } /* ============================================================================= -- 2.34.1