Example usage for org.apache.mahout.cf.taste.impl.common FastIDSet isEmpty

List of usage examples for org.apache.mahout.cf.taste.impl.common FastIDSet isEmpty

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.common FastIDSet isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Usage

From source file:com.webir.popcornsaver.cluster.FarthestNeighborClusterSimilarity.java

License:Apache License

@Override
public double getSimilarity(FastIDSet cluster1, FastIDSet cluster2) throws TasteException {
    if (cluster1.isEmpty() || cluster2.isEmpty()) {
        return Double.NaN;
    }/* www . j a va2 s  . c  o  m*/
    double leastSimilarity = Double.POSITIVE_INFINITY;
    LongPrimitiveIterator someUsers = SamplingLongPrimitiveIterator.maybeWrapIterator(cluster1.iterator(),
            samplingRate);
    while (someUsers.hasNext()) {
        long userID1 = someUsers.next();
        LongPrimitiveIterator it2 = cluster2.iterator();
        while (it2.hasNext()) {
            double theSimilarity = similarity.userSimilarity(userID1, it2.next());
            if (theSimilarity < leastSimilarity) {
                leastSimilarity = theSimilarity;
            }
        }
    }
    // We skipped everything? well, at least try comparing the first Users to get some value
    if (leastSimilarity == Double.POSITIVE_INFINITY) {
        return similarity.userSimilarity(cluster1.iterator().next(), cluster2.iterator().next());
    }
    return leastSimilarity;
}

From source file:net.myrrix.common.collection.FastIDSetTest.java

License:Apache License

@Test
public void testRemove() {
    FastIDSet set = new FastIDSet();
    set.add(1);/* w w  w  . ja  v  a  2  s . c  o m*/
    set.remove(1);
    assertEquals(0, set.size());
    assertTrue(set.isEmpty());
    assertFalse(set.contains(1));
}

From source file:net.myrrix.common.collection.FastIDSetTest.java

License:Apache License

@Test
public void testClear() {
    FastIDSet set = new FastIDSet();
    set.add(1);/*from  w  w w .j  av a  2 s .  c om*/
    set.clear();
    assertEquals(0, set.size());
    assertTrue(set.isEmpty());
    assertFalse(set.contains(1));
}

From source file:net.myrrix.common.collection.FastIDSetTest.java

License:Apache License

@Test
public void testSizeEmpty() {
    FastIDSet set = new FastIDSet();
    assertEquals(0, set.size());/*w  w  w . ja v a  2  s  . c om*/
    assertTrue(set.isEmpty());
    set.add(1);
    assertEquals(1, set.size());
    assertFalse(set.isEmpty());
    set.remove(1);
    assertEquals(0, set.size());
    assertTrue(set.isEmpty());
}

From source file:net.myrrix.common.collection.FastIDSetTest.java

License:Apache License

@Test
public void testVersusHashSet() {
    FastIDSet actual = new FastIDSet(1);
    Collection<Integer> expected = new HashSet<Integer>(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Integer key = r.nextInt(100);
        if (d < 0.4) {
            assertEquals(expected.contains(key), actual.contains(key));
        } else {// www . j a  va  2s  .  co  m
            if (d < 0.7) {
                assertEquals(expected.add(key), actual.add(key));
            } else {
                assertEquals(expected.remove(key), actual.remove(key));
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}