Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/java/com/yahoo/sketches/theta/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,6 @@ private static final boolean estMode(final long thetaLong, final boolean empty)

/**
* Instantiates a Heap Sketch from Memory. SerVer 1 & 2 already handled.
* @param famID the Family ID
* @param ordered true if the sketch is of the Compact family and ordered
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* The seed required to instantiate a non-compact sketch.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/yahoo/sketches/theta/UnionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ private UnionImpl(final UpdateSketch gadget, final long seed) {
*/
static UnionImpl initNewHeapInstance(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf) {
final UpdateSketch gadget = new HeapQuickSelectSketch(
lgNomLongs, seed, p, rf, true); //create with UNION family
final UpdateSketch gadget = //create with UNION family
new HeapQuickSelectSketch(lgNomLongs, seed, p, rf, true);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
Expand All @@ -114,8 +114,8 @@ static UnionImpl initNewDirectInstance(
final ResizeFactor rf,
final MemoryRequestServer memReqSvr,
final WritableMemory dstMem) {
final UpdateSketch gadget = new DirectQuickSelectSketch(
lgNomLongs, seed, p, rf, memReqSvr, dstMem, true); //create with UNION family
final UpdateSketch gadget = //create with UNION family
new DirectQuickSelectSketch(lgNomLongs, seed, p, rf, memReqSvr, dstMem, true);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import com.yahoo.sketches.tuple.DeserializeResult;
import com.yahoo.sketches.tuple.SummaryDeserializer;

/**
* @author Lee Rhodes
*/
public class DoubleSummaryDeserializer implements SummaryDeserializer<DoubleSummary> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Lee Rhodes
*/
public class ArrayOfStringsSummary implements UpdatableSummary<String[]> {
public static final int PRIME = 0x7A3C_CA71;
private static final int PRIME = 0x7A3C_CA71;
private String[] nodesArr = null;

ArrayOfStringsSummary() { //required for ArrayOfStringsSummaryFactory
Expand Down Expand Up @@ -90,6 +90,9 @@ public ArrayOfStringsSummary copy() {
return nodes;
}

/**
* @return the nodes array for this summary.
*/
public String[] getValue() {
return nodesArr.clone();
}
Expand Down Expand Up @@ -154,6 +157,10 @@ static long stringArrHash(final String[] strArray) {
return XxHash64.hashChars(s.toCharArray(), 0, s.length(), PRIME);
}

/**
* @param s the string to hash
* @return the hash of the string
*/
public static long stringHash(final String s) {
return XxHash64.hashChars(s.toCharArray(), 0, s.length(), PRIME);
}
Expand Down
49 changes: 25 additions & 24 deletions src/test/java/com/yahoo/sketches/BinomialBoundsNTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/**
* @author Kevin Lang
*/
@SuppressWarnings("javadoc")
public class BinomialBoundsNTest {

public static double[] runTestAux (long max_numSamplesI, int ci, double min_p) {
Expand All @@ -41,54 +42,54 @@ public static double[] runTestAux (long max_numSamplesI, int ci, double min_p) {
double sum3 = 0.0;
double sum4 = 0.0;
long count = 0;

while (numSamplesI <= max_numSamplesI) { /* was <= */
p = 1.0;

while (p >= min_p) {
lb = BinomialBoundsN.getLowerBound (numSamplesI, p, ci, false);
ub = BinomialBoundsN.getUpperBound (numSamplesI, p, ci, false);

// if (numSamplesI == 300 && p > 0.365 && p < 0.367) { ub += 0.01; } // artificial discrepancy

// the logarithm helps discrepancies to not be swamped out of the total
sum1 += Math.log (lb + 1.0);
sum1 += Math.log (lb + 1.0);
sum2 += Math.log (ub + 1.0);
count += 2;

if (p < 1.0) {
lb = BinomialBoundsN.getLowerBound (numSamplesI, 1.0 - p, ci, false);
ub = BinomialBoundsN.getUpperBound (numSamplesI, 1.0 - p, ci, false);
sum3 += Math.log (lb + 1.0);
sum4 += Math.log (ub + 1.0);
count += 2;
}

p *= 0.99;
}
numSamplesI = Math.max (numSamplesI+1, 1001*numSamplesI/1000);
numSamplesI = Math.max (numSamplesI+1, (1001*numSamplesI)/1000);
}

println(String.format("{%.15e, %.15e, %.15e, %.15e, %d}", sum1, sum2, sum3, sum4, count));
double[] arrOut = {sum1, sum2, sum3, sum4, count};
return arrOut;
}

private static final double TOL = 1E-15;

@Test
public static void checkBounds() {
int i = 0;
for (int ci = 1; ci <= 3; ci++, i++) {
double[] arr = runTestAux (20, ci, 1e-3);
for (int j=0; j<5; j++) {
assertTrue((arr[j] / std[i][j] -1.0) < TOL);
assertTrue(((arr[j] / std[i][j]) -1.0) < TOL);
}
}
for (int ci = 1; ci <= 3; ci++, i++) {
double[] arr = runTestAux (200, ci, 1e-5);
for (int j=0; j<5; j++) {
assertTrue((arr[j] / std[i][j] -1.0) < TOL);
assertTrue(((arr[j] / std[i][j]) -1.0) < TOL);
}
}
//comment last one out for a shorter test
Expand All @@ -99,22 +100,22 @@ public static void checkBounds() {
// }
// }
}

// With all 3 enabled the test should produce in groups of 3 */
private static final double[][] std = {
{7.083330682531043e+04, 8.530373642825481e+04, 3.273647725073409e+04, 3.734024243699785e+04, 57750},
{6.539415269641498e+04, 8.945522372568645e+04, 3.222302546497840e+04, 3.904738469737429e+04, 57750},
{6.006043493107306e+04, 9.318105731423477e+04, 3.186269956585285e+04, 4.096466221922520e+04, 57750},

{2.275584770163813e+06, 2.347586549014998e+06, 1.020399409477305e+06, 1.036729927598294e+06, 920982},
{2.243569126699713e+06, 2.374663344107342e+06, 1.017017233582122e+06, 1.042597845553438e+06, 920982},
{2.210056231903739e+06, 2.400441267999687e+06, 1.014081235946986e+06, 1.049480769755676e+06, 920982},

{4.688240115809608e+07, 4.718067204619278e+07, 2.148362024482338e+07, 2.153118905212302e+07, 12834414},
{4.674205938540214e+07, 4.731333757486791e+07, 2.146902141966406e+07, 2.154916650733873e+07, 12834414},
{4.659896614422579e+07, 4.744404182094614e+07, 2.145525391547799e+07, 2.156815612325058e+07, 12834414}
};

@Test
public static void checkCheckArgs() {
try {
Expand All @@ -129,7 +130,7 @@ public static void checkCheckArgs() {
//pass
}
}

@Test
public static void checkComputeApproxBino_LB_UB() {
long n = 100;
Expand All @@ -143,12 +144,12 @@ public static void checkComputeApproxBino_LB_UB() {
result = getUpperBound(n, theta, 1, true);
assertEquals(result, 0.0, 0.0);
}

@Test(expectedExceptions = SketchesArgumentException.class)
public static void checkThetaLimits1() {
BinomialBoundsN.getUpperBound(100, 1.1, 1, false);
}

@Test
public static void boundsExample() {
println("BinomialBoundsN Example:");
Expand All @@ -164,17 +165,17 @@ public static void boundsExample() {
println("LB: "+lb);
println("");
}

@Test
public void printlnTest() {
println("PRINTING: "+this.getClass().getName());
}

/**
* @param s value to print
* @param s value to print
*/
static void println(String s) {
//System.out.println(s); //disable here
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
/**
* @author Kevin Lang
*/
@SuppressWarnings("javadoc")
public class BoundsOnBinomialProportionsTest {

@Test
Expand All @@ -51,7 +52,7 @@ public static void tinyLBTest () {
// System.out.printf ("LB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, lb);
}
}

@Test
public static void tinyUBTest () {
// these answers were computed using a different programming language and therefore might not match exactly.
Expand All @@ -68,7 +69,7 @@ public static void tinyUBTest () {
// System.out.printf ("UB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, ub);
}
}

// This is for Kevin's use only, and will not be one of the unit tests.
public static void lotsOfSpewage (long maxN) {
for (long n = 0; n <= maxN; n++) {
Expand Down Expand Up @@ -113,7 +114,7 @@ public static void checkNumStdDevZero() {
println("LB: "+lb);
println("UB: "+ub);
}

@Test
public static void checkInputs() {
try {
Expand All @@ -139,24 +140,24 @@ public static void checkInputs() {
}
assertEquals(estimateUnknownP(0, 0), 0.5, 0.0);
}

@Test
public static void checkErf() {
assertTrue(erf(-2.0) < 0.99);
assertTrue(erf(2.0) > 0.99);
}

@Test
public void printlnTest() {
println("PRINTING: "+this.getClass().getName());
}

/**
* @param s value to print
* @param s value to print
*/
static void println(String s) {
//System.out.println(s); //disable here
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.testng.annotations.Test;

@SuppressWarnings("javadoc")
public class BoundsOnRatiosInSampledSetsTest {

@Test
Expand All @@ -37,31 +38,31 @@ public void checkNormalReturns() {
getLowerBoundForBoverA(500, 100, 0.75);
getLowerBoundForBoverA(500, 100, 1.0);
assertEquals(getLowerBoundForBoverA(0, 0, .1), 0.0, 0.0);

getUpperBoundForBoverA(500, 100, .1);
getUpperBoundForBoverA(500, 100, 0.75);
getUpperBoundForBoverA(500, 100, 1.0);
assertEquals(getUpperBoundForBoverA(0, 0, .1), 1.0, 0.0);

getEstimateOfBoverA(500,100);
getEstimateOfA(500, .1);
getEstimateOfB(100, .1);
assertEquals(getEstimateOfBoverA(0, 0), .5, 0.0);
}

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkInputA() {
checkInputs(-1, 0, .3);
}

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkInputB() {
checkInputs(500, -1, .3);
}

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkInputF() {
checkInputs(500, 100, -1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.yahoo.sketches.theta.Sketches;
import com.yahoo.sketches.theta.UpdateSketch;

@SuppressWarnings("javadoc")
public class BoundsOnRatiosInThetaSketchedSetsTest {

@Test
Expand All @@ -38,7 +39,7 @@ public void checkNormalReturns() {
int uA = 10000;
int uC = 100000;
for (int i=0; i<uA; i++) { skA.update(i); }
for (int i=0; i<uC; i++) { skC.update(i+uA/2); }
for (int i=0; i<uC; i++) { skC.update(i+(uA/2)); }
Intersection inter = Sketches.setOperationBuilder().buildIntersection();
inter.update(skA);
inter.update(skC);
Expand Down Expand Up @@ -76,7 +77,7 @@ public void checkAbnormalReturns() {
int uA = 100000;
int uC = 10000;
for (int i=0; i<uA; i++) { skA.update(i); }
for (int i=0; i<uC; i++) { skC.update(i+uA/2); }
for (int i=0; i<uC; i++) { skC.update(i+(uA/2)); }
BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skC);
}

Expand All @@ -86,7 +87,7 @@ public void printlnTest() {
}

/**
* @param s value to print
* @param s value to print
*/
static void println(String s) {
//System.out.println(s); //disable here
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/yahoo/sketches/ByteArrayUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/**
* @author Lee Rhodes
*/
@SuppressWarnings("javadoc")
public class ByteArrayUtilTest {

@Test
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/yahoo/sketches/FamilyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**
* @author Lee Rhodes
*/
@SuppressWarnings("javadoc")
public class FamilyTest {

@Test
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/yahoo/sketches/HashOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.yahoo.memory.WritableMemory;

@SuppressWarnings("javadoc")
public class HashOperationsTest {

//Not otherwise already covered
Expand Down
Loading