Package com.sun.sgs.impl.service.nodemap.affinity.graph

Examples of com.sun.sgs.impl.service.nodemap.affinity.graph.AffinityGraphBuilder


@RunWith(FilteredNameRunner.class)
public class TestAffinityGroupGoodness {

    @Test
    public void testToyModularityAndJaccard() {
        AffinityGraphBuilder builder = new TestToyBuilder();

        final long gen = 1;
        Collection<AffinityGroup> group1 = new HashSet<AffinityGroup>();
        HashSet<Identity> identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("3"));
        AffinitySet a = new AffinitySet(1, gen, identitySet);
        group1.add(a);
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        AffinitySet b = new AffinitySet(2, gen, identitySet);
        group1.add(b);

        double modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 group1);
        Assert.assertEquals(0.22, modularity, .001);

        Collection<AffinityGroup> group2 = new HashSet<AffinityGroup>();
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("3"));
        a = new AffinitySet(3, gen, identitySet);
        group2.add(a);
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        b = new AffinitySet(4, gen, identitySet);
        group2.add(b);

        modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 group2);
        Assert.assertEquals(0.08, modularity, .001);

        double jaccard = AffinityGroupGoodness.calcJaccard(group1, group2);
        System.out.println("Jaccard index is " + jaccard);
View Full Code Here


        Assert.assertEquals(0.333, jaccard, .001);
    }

    @Test
    public void testToyModularityAndJaccardWithWeights() {
        AffinityGraphBuilder builder = new TestToyWeightBuilder();

        final long gen = 1;
        Collection<AffinityGroup> group1 = new HashSet<AffinityGroup>();
        HashSet<Identity> identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("3"));
        AffinitySet a = new AffinitySet(1, gen, identitySet);
        group1.add(a);
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        AffinitySet b = new AffinitySet(2, gen, identitySet);
        group1.add(b);

        double modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 group1);
        Assert.assertEquals(0.22, modularity, .001);

        Collection<AffinityGroup> group2 = new HashSet<AffinityGroup>();
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("3"));
        a = new AffinitySet(3, gen, identitySet);
        group2.add(a);
        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        b = new AffinitySet(4, gen, identitySet);
       
        group2.add(b);

        modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 group2);
        Assert.assertEquals(0.08, modularity, .001);

        double jaccard = AffinityGroupGoodness.calcJaccard(group1, group2);
        System.out.println("Jaccard index is " + jaccard);
View Full Code Here


    @Test
    public void testZachModularity() {
        final long gen = 1;
        AffinityGraphBuilder builder = new ZachBuilder();
        Collection<AffinityGroup> groups = new HashSet<AffinityGroup>();

        HashSet<Identity> identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("3"));
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        identitySet.add(new DummyIdentity("6"));
        identitySet.add(new DummyIdentity("7"));
        identitySet.add(new DummyIdentity("8"));
        identitySet.add(new DummyIdentity("11"));
        identitySet.add(new DummyIdentity("12"));
        identitySet.add(new DummyIdentity("13"));
        identitySet.add(new DummyIdentity("14"));
        identitySet.add(new DummyIdentity("17"));
        identitySet.add(new DummyIdentity("18"));
        identitySet.add(new DummyIdentity("20"));
        identitySet.add(new DummyIdentity("22"));
        AffinitySet a = new AffinitySet(1, gen, identitySet);
        groups.add(a);

        identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("9"));
        identitySet.add(new DummyIdentity("10"));
        identitySet.add(new DummyIdentity("15"));
        identitySet.add(new DummyIdentity("16"));
        identitySet.add(new DummyIdentity("19"));
        identitySet.add(new DummyIdentity("21"));
        identitySet.add(new DummyIdentity("23"));
        identitySet.add(new DummyIdentity("24"));
        identitySet.add(new DummyIdentity("25"));
        identitySet.add(new DummyIdentity("26"));
        identitySet.add(new DummyIdentity("27"));
        identitySet.add(new DummyIdentity("28"));
        identitySet.add(new DummyIdentity("29"));
        identitySet.add(new DummyIdentity("30"));
        identitySet.add(new DummyIdentity("31"));
        identitySet.add(new DummyIdentity("32"));
        identitySet.add(new DummyIdentity("33"));
        identitySet.add(new DummyIdentity("34"));
        AffinitySet b = new AffinitySet(2, gen, identitySet);
        groups.add(b);

        double modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 groups);
        System.out.println("Modularity for correct Zachary's karate club is " +
                modularity);
    }
View Full Code Here

    }

    @Test
    public void testModularityCalc() {
        final long gen = 1;
        AffinityGraphBuilder builder = new ZachBuilder();
        Collection<AffinityGroup> groups = new HashSet<AffinityGroup>();
        AffinitySet a = new AffinitySet(49, gen, new DummyIdentity("17"));
        groups.add(a);

        HashSet<Identity> identitySet = new HashSet<Identity>();
        identitySet.add(new DummyIdentity("1"));
        identitySet.add(new DummyIdentity("2"));
        identitySet.add(new DummyIdentity("3"));
        identitySet.add(new DummyIdentity("4"));
        identitySet.add(new DummyIdentity("5"));
        identitySet.add(new DummyIdentity("6"));
        identitySet.add(new DummyIdentity("7"));
        identitySet.add(new DummyIdentity("8"));
        identitySet.add(new DummyIdentity("9"));
        identitySet.add(new DummyIdentity("10"));
        identitySet.add(new DummyIdentity("11"));
        identitySet.add(new DummyIdentity("12"));
        identitySet.add(new DummyIdentity("13"));
        identitySet.add(new DummyIdentity("14"));
        identitySet.add(new DummyIdentity("15"));
        identitySet.add(new DummyIdentity("16"));
//        identitySet.add(new DummyIdentity("17"));
        identitySet.add(new DummyIdentity("18"));
        identitySet.add(new DummyIdentity("19"));
        identitySet.add(new DummyIdentity("20"));
        identitySet.add(new DummyIdentity("21"));
        identitySet.add(new DummyIdentity("22"));
        identitySet.add(new DummyIdentity("23"));
        identitySet.add(new DummyIdentity("24"));
        identitySet.add(new DummyIdentity("25"));
        identitySet.add(new DummyIdentity("26"));
        identitySet.add(new DummyIdentity("27"));
        identitySet.add(new DummyIdentity("28"));
        identitySet.add(new DummyIdentity("29"));
        identitySet.add(new DummyIdentity("30"));
        identitySet.add(new DummyIdentity("31"));
        identitySet.add(new DummyIdentity("32"));
        identitySet.add(new DummyIdentity("33"));
        identitySet.add(new DummyIdentity("34"));
        AffinitySet b = new AffinitySet(2, gen, identitySet);
        groups.add(b);

        double modularity =
            AffinityGroupGoodness.calcModularity(builder.getAffinityGraph(),
                                                 groups);
        System.out.println("Modularity test club partition is " +
                modularity);
    }
View Full Code Here

        lpa.shutdown();
    }

    @Test
    public void testZachary() throws Exception {
        AffinityGraphBuilder builder = new ZachBuilder();
        Properties props = new Properties();
        props.put("com.sun.sgs.impl.service.nodemap.affinity.numThreads",
                    String.valueOf(numThreads));
        // third argument true:  gather statistics
        SingleLabelPropagation lpa =
View Full Code Here

                idents[i] = new DummyIdentity(String.valueOf(i));
                nms.assignNode(this.getClass(), idents[i]);
            }
           
            // Node 1 uses.
            AffinityGraphBuilder builder1 = driver1.getGraphBuilder();
            AccessedObjectsDetailTest detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o1"));
            detail.addAccess(new String("o2"));
            detail.addAccess(new String("o3"));
            detail.addAccess(new String("o5"));
            detail.addAccess(new String("o8"));
            detail.addAccess(new String("o11"));
            detail.addAccess(new String("o12"));
            detail.addAccess(new String("o16"));
            detail.addAccess(new String("o18"));
            detail.addAccess(new String("o20"));
            detail.addAccess(new String("o32"));
            detail.addAccess(new String("o84"));
            builder1.updateGraph(idents[1], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o1"));
            detail.addAccess(new String("o13"));
            detail.addAccess(new String("o87"));
            builder1.updateGraph(idents[4], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o2"));
            detail.addAccess(new String("o4"));
            detail.addAccess(new String("o15"));
            builder1.updateGraph(idents[7], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o7"));
            detail.addAccess(new String("o40"));
            builder1.updateGraph(idents[10], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o12"));
            detail.addAccess(new String("o13"));
            builder1.updateGraph(idents[13], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o35"));
            detail.addAccess(new String("o43"));
            builder1.updateGraph(idents[16], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o36"));
            detail.addAccess(new String("o44"));
            builder1.updateGraph(idents[19], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o20"));
            detail.addAccess(new String("o21"));
            builder1.updateGraph(idents[22], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o23"));
            detail.addAccess(new String("o26"));
            builder1.updateGraph(idents[25], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o24"));
            detail.addAccess(new String("o25"));
            detail.addAccess(new String("o26"));
            detail.addAccess(new String("o50"));
            builder1.updateGraph(idents[28], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o30"));
            detail.addAccess(new String("o31"));
            builder1.updateGraph(idents[31], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o31"));
            detail.addAccess(new String("o40"));
            detail.addAccess(new String("o41"));
            detail.addAccess(new String("o42"));
            detail.addAccess(new String("o43"));
            detail.addAccess(new String("o44"));
            detail.addAccess(new String("o45"));
            detail.addAccess(new String("o46"));
            detail.addAccess(new String("o47"));
            detail.addAccess(new String("o48"));
            detail.addAccess(new String("o49"));
            detail.addAccess(new String("o50"));
            detail.addAccess(new String("o51"));
            detail.addAccess(new String("o52"));
            detail.addAccess(new String("o53"));
            builder1.updateGraph(idents[34], detail);

            // Node 2
            AffinityGraphBuilder builder2 = driver2.getGraphBuilder();
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o1"));
            detail.addAccess(new String("o17"));
            detail.addAccess(new String("o19"));
            detail.addAccess(new String("o21"));
            detail.addAccess(new String("o30"));
            detail.addAccess(new String("o85"));
            builder2.updateGraph(idents[2], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o2"));
            detail.addAccess(new String("o9"));
            builder2.updateGraph(idents[5], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o1"));
            builder2.updateGraph(idents[8], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o8"));
            detail.addAccess(new String("o9"));
            detail.addAccess(new String("o10"));
            builder2.updateGraph(idents[11], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o84"));
            detail.addAccess(new String("o85"));
            detail.addAccess(new String("o86"));
            detail.addAccess(new String("o87"));
            detail.addAccess(new String("o41"));
            builder2.updateGraph(idents[14], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o14"));
            detail.addAccess(new String("o15"));
            builder2.updateGraph(idents[17], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o18"));
            detail.addAccess(new String("o19"));
            detail.addAccess(new String("o45"));
            builder2.updateGraph(idents[20], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o38"));
            detail.addAccess(new String("o47"));
            builder2.updateGraph(idents[23], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o22"));
            detail.addAccess(new String("o23"));
            builder2.updateGraph(idents[26], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o27"));
            detail.addAccess(new String("o51"));
            detail.addAccess(new String("o66"));
            builder2.updateGraph(idents[29], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o23"));
            detail.addAccess(new String("o66"));
            detail.addAccess(new String("o32"));
            detail.addAccess(new String("o39"));
            detail.addAccess(new String("o53"));
            builder2.updateGraph(idents[32], detail);

            // Node 3
            AffinityGraphBuilder builder3 = driver3.getGraphBuilder();
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o1"));
            detail.addAccess(new String("o6"));
            detail.addAccess(new String("o7"));
            detail.addAccess(new String("o24"));
            detail.addAccess(new String("o27"));
            detail.addAccess(new String("o33"));
            detail.addAccess(new String("o86"));
            builder3.updateGraph(idents[3], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o3"));
            detail.addAccess(new String("o4"));
            detail.addAccess(new String("o10"));
            detail.addAccess(new String("o14"));
            builder3.updateGraph(idents[6], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o5"));
            detail.addAccess(new String("o6"));
            detail.addAccess(new String("o31"));
            builder3.updateGraph(idents[9], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o11"));
            builder3.updateGraph(idents[12], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o34"));
            detail.addAccess(new String("o42"));
            builder3.updateGraph(idents[15], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o16"));
            detail.addAccess(new String("o17"));
            builder3.updateGraph(idents[18], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o37"));
            detail.addAccess(new String("o46"));
            builder3.updateGraph(idents[21], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o22"));
            detail.addAccess(new String("o25"));
            detail.addAccess(new String("o28"));
            detail.addAccess(new String("o48"));
            builder3.updateGraph(idents[24], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o29"));
            detail.addAccess(new String("o49"));
            builder3.updateGraph(idents[27], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o28"));
            detail.addAccess(new String("o29"));
            detail.addAccess(new String("o52"));
            builder3.updateGraph(idents[30], detail);
            detail = new AccessedObjectsDetailTest();
            detail.addAccess(new String("o28"));
            detail.addAccess(new String("o31"));
            detail.addAccess(new String("o33"));
            detail.addAccess(new String("o34"));
            detail.addAccess(new String("o35"));
            detail.addAccess(new String("o36"));
            detail.addAccess(new String("o37"));
            detail.addAccess(new String("o38"));
            detail.addAccess(new String("o39"));
            builder3.updateGraph(idents[33], detail);

            UndirectedGraph<LabelVertex, WeightedEdge> graphModel =
                    new ZachBuilder().getAffinityGraph();
            System.out.println("MODEL GRAPH IS " + graphModel);
            LPADriver driver = (LPADriver)
                finderField.get(serverNode.getNodeMappingService());
            GraphListener serverListener = driver.getGraphListener();
            AffinityGraphBuilder builder = driver.getGraphBuilder();
            // The graph can only be found on the server side.  Let's make
            // sure it looks like the expected Zachary graph.
            // The core server graph listener builds a DistGraphBuilder,
            // which (on the core node) creates the DistGraphBuilderServerImpl.
            // We can find it if we look for the group finder.
            AffinityGraphBuilder serverBuilder =
                    (AffinityGraphBuilder) builder.getAffinityGroupFinder();
            UndirectedGraph<LabelVertex, WeightedEdge> graph =
                    serverBuilder.getAffinityGraph();
            System.out.println("GRAPH IS " + graph);
            Assert.assertEquals(34, graph.getVertexCount());
            Assert.assertEquals(78, graph.getEdgeCount());
            ProfileCollector col =
                serverNode.getSystemRegistry().
View Full Code Here

TOP

Related Classes of com.sun.sgs.impl.service.nodemap.affinity.graph.AffinityGraphBuilder

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.