@Test (expectedExceptions=IndexOutOfBoundsException.class ) public void testSetBadGetNegative() { logger.warn("Executing testSetBadGetNegative"); empty.get(-1); }
@Test public void testTenElements() { logger.warn("Executing testTenElements"); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(i+1, (int)hasTen.get(i)); } }
@Test public void testSetExpanding() { logger.warn("Executing testSetExpanding"); Assert.assertEquals(0, empty.size()); empty.set(3, 1); Assert.assertEquals(4, empty.size()); Assert.assertEquals(empty.get(0), null); Assert.assertEquals(empty.get(1), null); Assert.assertEquals(empty.get(2), null); Assert.assertEquals(1, (int)empty.get(3)); }
@Override public Pair<ExpandingArrayList<Long>, Long> treeReduce(Pair<ExpandingArrayList<Long>, Long> lhs, Pair<ExpandingArrayList<Long>, Long> rhs) { ExpandingArrayList<Long> nt = new ExpandingArrayList<Long>(); nt.addAll(lhs.first); int index = 0; for (Long l : rhs.first) { if (nt.get(index) == null) nt.add(l); else nt.set(index,nt.get(index) + l); index++; } return new Pair<ExpandingArrayList<Long>, Long>(nt, lhs.second + rhs.second); }
@Test public void testSetExpandingBig() { logger.warn("Executing testSetExpandingBig"); Assert.assertEquals(0, empty.size()); empty.set(1000, 1000); Assert.assertEquals(1001, empty.size()); for ( int i = 0; i < 1000; i++ ) Assert.assertEquals(empty.get(i), null); Assert.assertEquals(1000, (int)empty.get(1000)); }
@Test public void testSettingTenElements() { logger.warn("Executing testSettingTenElements"); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(i+1, (int)hasTen.set(i, 2*i)); } Assert.assertEquals(10, hasTen.size()); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(2*i, (int)hasTen.get(i)); } }
/** * Put mapResult into this MapResultsQueue, associated with its jobID * @param mapResult a non-null map result */ public synchronized void put(final MapResult<MapType> mapResult) { if ( mapResult == null ) throw new IllegalArgumentException("mapResult cannot be null"); // make sure that nothing is at the job id for map assert queue.size() < mapResult.getJobID() || queue.get(mapResult.getJobID()) == null; queue.set(mapResult.getJobID(), mapResult); }
/** * Should we reduce the next value in the mapResultQueue? * * @return true if we should reduce */ public synchronized boolean nextValueIsAvailable() { final MapResult<MapType> nextMapResult = queue.get(nextJobID()); if ( nextMapResult == null ) { // natural case -- the next job hasn't had a value added yet return false; } else if ( nextMapResult.getJobID() != nextJobID() ) { // sanity check -- the job id at next isn't the one we expect throw new IllegalStateException("Next job ID " + nextMapResult.getJobID() + " is not == previous job id " + prevJobID + " + 1"); } else { // there's a value at the next job id, so return true return true; } }
@Test public void testSet1() { logger.warn("Executing testSet1"); Assert.assertEquals(0, empty.size()); empty.set(0, 1); Assert.assertEquals(1, empty.size()); Assert.assertEquals(1, (int)empty.get(0)); empty.set(1, 2); Assert.assertEquals(2, empty.size()); Assert.assertEquals(2, (int)empty.get(1)); // doesn't expand empty.set(0, 3); Assert.assertEquals(2, empty.size()); Assert.assertEquals(3, (int)empty.get(0)); }
/** * Can only be called when nextValueIsAvailable is true * @return * @throws InterruptedException */ // TODO -- does this have to be synchronized? -- I think the answer is no public synchronized MapResult<MapType> take() throws InterruptedException { final MapResult<MapType> result = queue.get(nextJobID()); // make sure the value we've fetched has the right id assert result.getJobID() == nextJobID(); prevJobID = result.getJobID(); queue.set(prevJobID, null); return result; } }
@Test public void testSetExpandingReset() { logger.warn("Executing testSetExpandingReset"); Assert.assertEquals(0, empty.size()); empty.set(3, 3); empty.set(2, 2); empty.set(1, 1); empty.set(0, 0); Assert.assertEquals(4, empty.size()); for ( int i = 0; i < 4; i++ ) Assert.assertEquals(i, (int)empty.get(i)); }
public void evaluateFinalModelParameters( final List<VariantDatum> data ) { sumProb = 0.0; zeroOutMu(); zeroOutSigma(); int datumIndex = 0; for( final VariantDatum datum : data ) { final double prob = pVarInGaussian.get(datumIndex++); sumProb += prob; incrementMu( datum, prob ); } divideEqualsMu( sumProb ); datumIndex = 0; final Matrix pVarSigma = new Matrix(mu.length, mu.length); for( final VariantDatum datum : data ) { final double prob = pVarInGaussian.get(datumIndex++); for( int iii = 0; iii < mu.length; iii++ ) { for( int jjj = 0; jjj < mu.length; jjj++ ) { pVarSigma.set(iii, jjj, prob * (datum.annotations[iii]-mu[iii]) * (datum.annotations[jjj]-mu[jjj])); } } sigma.plusEquals( pVarSigma ); } sigma.timesEquals( 1.0 / sumProb ); resetPVarInGaussian(); // clean up some memory }
final double prob = pVarInGaussian.get(datumIndex++); sumProb += prob; incrementMu( datum, prob ); final Matrix pVarSigma = new Matrix(mu.length, mu.length); for( final VariantDatum datum : data ) { final double prob = pVarInGaussian.get(datumIndex++); for( int iii = 0; iii < mu.length; iii++ ) { for( int jjj = 0; jjj < mu.length; jjj++ ) {