Package edu.cmu.graphchi.walks.distributions

Examples of edu.cmu.graphchi.walks.distributions.DiscreteDistribution


        long after=0;

        for (Integer firstKey : distributions.keySet()) {
            ConcurrentHashMap<Integer, DiscreteDistribution> map = distributions.get(firstKey);
            for (Integer secondKey : map.keySet()) {
                DiscreteDistribution prevDist, newDist;
                synchronized (distrLocks.get(firstKey).get(secondKey)) {
                    prevDist = map.get(secondKey);
                    newDist =  prevDist.filteredAndShift(2);
                    map.put(secondKey, newDist);
                }
                before += prevDist.memorySizeEst();
                after += newDist.memorySizeEst();
            }
        }

        logger.info("** Compacted: " + (before / 1024. / 1024. / 1024.) + " GB --> " +
View Full Code Here


                        distributions.get(firstKey);
                    if (dmap == null) {
                        dmap = new ConcurrentHashMap<Integer, DiscreteDistribution>();
                        distributions.put(firstKey, dmap);
                    }
                    dmap.put(secondKey, new DiscreteDistribution());
                    ConcurrentHashMap<Integer, IntegerBuffer> bmap = buffers.get(firstKey);
                    if (bmap == null) {
                        bmap = new ConcurrentHashMap<Integer, IntegerBuffer>();
                        buffers.put(firstKey, bmap);
                    }
View Full Code Here

    }

    private void mergeWith(int firstKey, int secondKey, DiscreteDistribution distr) {
        ensureExists(firstKey, secondKey);
        synchronized (distrLocks.get(firstKey).get(secondKey)) {
            DiscreteDistribution mergeInto = distributions.get(firstKey).get(secondKey);
            DiscreteDistribution merged = DiscreteDistribution.merge(mergeInto, distr);
            distributions.get(firstKey).put(secondKey, merged);
        }
    }
View Full Code Here

        synchronized (buffer) {
            arr = buffer.toIntArray();
            buffers.get(firstKey).put(secondKey, new IntegerBuffer(BUFFER_CAPACITY));
        }
        Arrays.sort(arr);
        DiscreteDistribution dist = new DiscreteDistribution(arr);
        mergeWith(firstKey, secondKey, dist);
    }
View Full Code Here

                                    }
                                    parallelExecutor.submit(new Runnable() { public void run() {
                                        try {
                                            int[] d = toDrain.toIntArray();
                                            Arrays.sort(d);
                                            DiscreteDistribution dist = new DiscreteDistribution(d);
                                            mergeWith(first, second, dist);
                                        } catch (Exception err ) {
                                            err.printStackTrace();
                                        } finally {
                                            outstanding.decrementAndGet();
View Full Code Here

*/
public class TestDiscreteDistribution {

    @Test
    public void testTrivialConstruction() {
        DiscreteDistribution empty = new DiscreteDistribution(new int[0]);
        assertEquals(0, empty.getCount(0));
        assertEquals(0, empty.getCount(1));

        DiscreteDistribution singleton = new DiscreteDistribution(new int[] {876});
        assertEquals(1, singleton.getCount(876));
        assertEquals(0, singleton.getCount(875));
        assertEquals(0, singleton.getCount(877));
    }
View Full Code Here

        assertEquals(0, singleton.getCount(877));
    }

    @Test
    public void testConstruction() {
        DiscreteDistribution d1 = new DiscreteDistribution(new int[] {1,1,1,8,8,8,9,22,22,22,22,22});
        assertEquals(3, d1.getCount(1));
        assertEquals(3, d1.getCount(8));
        assertEquals(1, d1.getCount(9));
        assertEquals(5, d1.getCount(22));
        assertEquals(0, d1.getCount(0));
        assertEquals(0, d1.getCount(10));
        assertEquals(0, d1.getCount(10324324));
    }
View Full Code Here

        assertEquals(0, d1.getCount(10324324));
    }

    @Test
    public void testMerge() {
        DiscreteDistribution d1 = new DiscreteDistribution(new int[] {1,1,1,8,8,8,9,22,22,22,22,22});
        DiscreteDistribution d2 = new DiscreteDistribution(new int[] {1,1,1,8,8,8,9,22,22,22,22,22});
        DiscreteDistribution merged = DiscreteDistribution.merge(d1, d2);

        assertEquals(3 * 2, merged.getCount(1));
        assertEquals(3 * 2, merged.getCount(8));
        assertEquals(2,     merged.getCount(9));
        assertEquals(5 * 2, merged.getCount(22));
        assertEquals(0, merged.getCount(0));
        assertEquals(0, merged.getCount(10));
        assertEquals(0, merged.getCount(10324324));

        DiscreteDistribution d3 = new DiscreteDistribution(new int[] {1,7,8,1000,1000,1000,2000,2000,30000});
        DiscreteDistribution merged2 = DiscreteDistribution.merge(d1, d3);
        assertEquals(4, merged2.getCount(1));
        assertEquals(1, merged2.getCount(7));
        assertEquals(4, merged2.getCount(8));
        assertEquals(1, merged2.getCount(9));
        assertEquals(5, merged2.getCount(22));
        assertEquals(3, merged2.getCount(1000));
        assertEquals(2, merged2.getCount(2000));
        assertEquals(1, merged2.getCount(30000));

        assertEquals(8, merged2.size());

        DiscreteDistribution empty = new DiscreteDistribution();
        DiscreteDistribution mergedWithEmpty = DiscreteDistribution.merge(empty, d1);
        DiscreteDistribution mergedWithEmpty2 = DiscreteDistribution.merge(d2, empty);
        assertTrue(d1 == mergedWithEmpty);
        assertTrue(d2 == mergedWithEmpty2);

    }
View Full Code Here

        for(Map.Entry<Integer ,Integer> e : rightSet.entrySet()) {
            for(int j=0; j<e.getValue(); j++) rightArray.add(e.getKey());
        }


        DiscreteDistribution leftDist = new DiscreteDistribution(toIntArray(leftArray));
        DiscreteDistribution rightDist = new DiscreteDistribution(toIntArray(rightArray));
        DiscreteDistribution mergedDist1 = DiscreteDistribution.merge(leftDist, rightDist);
        DiscreteDistribution mergedDist2 = DiscreteDistribution.merge(rightDist, leftDist);

        for(int i=0; i < 5000; i++) {
            int lc = (leftSet.containsKey(i) ? leftSet.get(i) : 0);
            int rc = (rightSet.containsKey(i) ? rightSet.get(i) : 0);

            assertEquals(lc, leftDist.getCount(i));
            assertEquals(rc, rightDist.getCount(i));
            assertEquals(lc + rc, mergedDist1.getCount(i));
            assertEquals(lc + rc, mergedDist2.getCount(i));

        }
    }
View Full Code Here

            } while (countToId.containsKey(n)); // Unique count keys
            countToId.put(n, i);
            insertMultiple(workArr, i, n);
        }

        DiscreteDistribution dist = new DiscreteDistribution(toIntArray(workArr));

        IdCount[] top = dist.getTop(10);


        int j = 0;
        for(Map.Entry <Integer, Integer> e : countToId.entrySet()) {
            IdCount topEntryJ = top[j];
View Full Code Here

TOP

Related Classes of edu.cmu.graphchi.walks.distributions.DiscreteDistribution

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.