Package com.jgaap.util

Examples of com.jgaap.util.EventMap


    test1.add(new Event("eight", null));
    test1.add(new Event("nine", null));
    test1.add(new Event("ten", null));     
    set1.addEvents(test1);
    set2.addEvents(test1);
    double result = new ChiSquareDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, 0.0, 0.0000000001));
   
   
    set2 = new EventSet();
    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("1", null));
    test2.add(new Event("2", null));
    test2.add(new Event("3", null));
    test2.add(new Event("4", null));
    test2.add(new Event("5", null));
    test2.add(new Event("6", null));
    test2.add(new Event("7", null));
    test2.add(new Event("8", null));
    test2.add(new Event("9", null));
    test2.add(new Event("10", null));
    set2.addEvents(test2);
    result = new ChiSquareDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, 2.0, 0.0000000001));
  }
View Full Code Here


    test1.add(new Event("lazy", null));
    test1.add(new Event("dog", null));
    test1.add(new Event(".", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new ManhattanDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);
    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("3", null));
    test2.add(new Event("..", null));
    test2.add(new Event("1", null));
    test2.add(new Event("4", null));
    test2.add(new Event("11", null));
    test2.add(new Event("5", null));
    test2.add(new Event("2", null));
    test2.add(new Event("6", null));
    test2.add(new Event("55", null));
    test2.add(new Event("33", null));
    es2 = new EventSet();
    es2.addEvents(test2);
    double result = new ManhattanDistance().distance(new EventMap(es1), new EventMap(es2));
    assertTrue(DistanceTestHelper.inRange(result, 2.0, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("dog", null));
    test1.add(new Event(".", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
   
    assertTrue(new NominalKSDistance().distance(new EventMap(es1), new EventMap(es2)) == 0.00);
   
    Vector<Event> test2 = new Vector<Event>();//set with the same number of elements, only one repeats and none are the same as in test1
    test2.add(new Event("33", null));
    test2.add(new Event("5", null));
    test2.add(new Event("6", null));
    test2.add(new Event("8", null));
    test2.add(new Event("44", null));
    test2.add(new Event("7", null));
    test2.add(new Event("33", null));
    test2.add(new Event("10", null));
    test2.add(new Event("2", null));
    test2.add(new Event("..", null));
    es2 = new EventSet();
    es2.addEvents(test2);
    double result = new NominalKSDistance().distance(new EventMap(es1), new EventMap(es2));
    assertTrue(DistanceTestHelper.inRange(result, 1.00, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("eight", null));
    test1.add(new Event("nine", null));
    test1.add(new Event("ten", null));     
    set1.addEvents(test1);
    set2.addEvents(test1);
    double result = new BrayCurtisDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, 0.0, 0.0000000001));
   
   
    set2 = new EventSet();
    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("1", null));
    test2.add(new Event("2", null));
    test2.add(new Event("3", null));
    test2.add(new Event("4", null));
    test2.add(new Event("5", null));
    test2.add(new Event("6", null));
    test2.add(new Event("7", null));
    test2.add(new Event("8", null));
    test2.add(new Event("9", null));
    test2.add(new Event("10", null));
    set2.addEvents(test2);
    result = new BrayCurtisDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, 1.0, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("gamma", null));
    test1.add(new Event("gamma", null));
    test1.add(new Event("delta", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new KendallCorrelationDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);

    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    Vector<Event> test2 = new Vector<Event>();
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("C", null));
    test1.add(new Event("C", null));
    test1.add(new Event("C", null));
    test1.add(new Event("D", null));
    test1.add(new Event("D", null));
    test1.add(new Event("E", null));

    test2.add(new Event("A", null));
    test2.add(new Event("A", null));
    test2.add(new Event("A", null));
    test2.add(new Event("B", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("E", null));
    test2.add(new Event("E", null));

    es1.addEvents(test1);
    es2.addEvents(test2);
    double result = new KendallCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    //System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 1.2, 0.0000000001));

    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    test2 = new Vector<Event>();

    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("C", null));

    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("A", null));

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new KendallCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    //System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 2.0, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("alpha", null));
    test1.add(new Event("beta", null));
    test1.add(new Event("gamma", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new IntersectionDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);

    /* test 2 -- different distributions, total overlap */
    Vector<Event> test2 = new Vector<Event>();
    es2=new EventSet();
    test2.add(new Event("alpha", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("gamma", null));
    es2.addEvents(test2);
    assertTrue(new IntersectionDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);

    /* test 3 -- totally disjoint (== 1.0) */
    es2=new EventSet();
    test2 = new Vector<Event>();
    test2.add(new Event("omega", null));
    es2.addEvents(test2);
    assertTrue(new IntersectionDistance().distance(new EventMap(es1), new EventMap(es2)) == 1.0);
   
    /* test 4 -- Partial overlap.  5 (3/3) elem., one in common */
    es2 = new EventSet();
    test2 = new Vector<Event>();
    test2.add(new Event("gamma", null));
    test2.add(new Event("delta", null));
    test2.add(new Event("epsilon", null));
    es2.addEvents(test2);

    double result = new IntersectionDistance().distance(new EventMap(es1), new EventMap(es2));
    assertTrue(DistanceTestHelper.inRange(result, 0.8, 0.0000000001));

    /* test 5 -- subset:  4 elem., one in common */
    es1=new EventSet();
    test1 = new Vector<Event>();
    test1.add(new Event("alpha", null));
    test1.add(new Event("beta", null));
    test1.add(new Event("gamma", null));
    test1.add(new Event("delta", null));
    es1.addEvents(test1);

    es2=new EventSet();
    test2 = new Vector<Event>();
    test2.add(new Event("delta", null));
    es2.addEvents(test2);
    result = new IntersectionDistance().distance(new EventMap(es1), new EventMap(es2));
    assertTrue(DistanceTestHelper.inRange(result, 0.75, 0.0000000001));

    /* test 6 -- superset:  4 elem., one in common */
    result = new IntersectionDistance().distance(new EventMap(es2), new EventMap(es1));
    assertTrue(DistanceTestHelper.inRange(result, 0.75, 0.0000000001));


  }
View Full Code Here

    test1.add(new Event("gamma", null));
    test1.add(new Event("gamma", null));
    test1.add(new Event("delta", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    double result = new KendallCorrelationTauBDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
    assertTrue( result == 0);

    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    Vector<Event> test2 = new Vector<Event>();
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("C", null));
    test1.add(new Event("C", null));
    test1.add(new Event("C", null));
    test1.add(new Event("D", null));
    test1.add(new Event("D", null));
    test1.add(new Event("E", null));

    test2.add(new Event("A", null));
    test2.add(new Event("A", null));
    test2.add(new Event("A", null));
    test2.add(new Event("B", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("D", null));
    test2.add(new Event("E", null));
    test2.add(new Event("E", null));

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new KendallCorrelationTauBDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 1.2, 0.0000000001));

    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    test2 = new Vector<Event>();

    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("A", null));
    test1.add(new Event("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("C", null));

    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("C", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("A", null));

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new KendallCorrelationTauBDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 2.0, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("lazy", null));
    test1.add(new Event("dog", null));
    test1.add(new Event(".", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new HistogramDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);
    es2=new EventSet();
    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("3", null));
    test2.add(new Event("..", null));
    test2.add(new Event("1", null));
    test2.add(new Event("4", null));
    test2.add(new Event("11", null));
    test2.add(new Event("5", null));
    test2.add(new Event("2", null));
    test2.add(new Event("6", null));
    test2.add(new Event("55", null));
    test2.add(new Event("33", null));
    es2.addEvents(test2);
    double result = new HistogramDistance().distance(new EventMap(es1), new EventMap(es2));
    assertTrue(DistanceTestHelper.inRange(result, 0.2, 0.0000000001));
  }
View Full Code Here

    test1.add(new Event("lazy", null));
    test1.add(new Event("dog", null));
    test1.add(new Event(".", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new KeseljWeightedDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);
    Vector<Event> test2 = new Vector<Event>();
    test2.add(new Event("3", null));
    test2.add(new Event("..", null));
    test2.add(new Event("1", null));
    test2.add(new Event("4", null));
    test2.add(new Event("11", null));
    test2.add(new Event("5", null));
    test2.add(new Event("2", null));
    test2.add(new Event("6", null));
    test2.add(new Event("55", null));
    test2.add(new Event("33", null));
    es2 = new EventSet();
    es2.addEvents(test2);
    double result = new KeseljWeightedDistance().distance(new EventMap(es1), new EventMap(es2));
    //System.out.println("test 2 result is " + result);
    assertTrue(DistanceTestHelper.inRange(result, 20.0, 0.0000000001));

    // and now for the fun stuff, where the weighting matters
    Vector<Event> test3 = new Vector<Event>();
    // each event has probability 0.2, generates 0.111... distance
    test3.add(new Event("The", null));
    test3.add(new Event("quick", null));
    test3.add(new Event("brown", null));
    test3.add(new Event("fox", null));
    test3.add(new Event("jumps", null));
    // five events missing -- should add 5.0 as distance
    es2 = new EventSet();
    es2.addEvents(test3);
    result = new KeseljWeightedDistance().distance(new EventMap(es1), new EventMap(es2));
    //System.out.println("test 3 result is " + result);
    assertTrue(DistanceTestHelper.inRange(result, 5.5555555555, 0.000001));
  }
View Full Code Here

    List<EventMap> knownEventMaps = new ArrayList<EventMap>();
    allAuthorNames = new HashSet<String>();
    allEvents = new LinkedHashSet<Event>();
    for (Document document : knownDocuments) {
      allAuthorNames.add(document.getAuthor());
      EventMap eventMap = new EventMap(document);
     
      allEvents.addAll(eventMap.uniqueEvents());
      knownEventMaps.add(eventMap);
    }

    /*
     * Put together WEKA "Instances" object, which defines the attributes
     * (aka "events" or "features").
     */
    attributeList = new FastVector(allEvents.size() + 1);

    authorNames = new FastVector(allAuthorNames.size()+1);
    for (String currentAuthorName : allAuthorNames) {
      authorNames.addElement(currentAuthorName);
    }
    authorNames.addElement("Unknown");
    Attribute authorNameAttribute = new Attribute("authorName", authorNames);
    attributeList.addElement(authorNameAttribute);

    for (Event event : allEvents) {
      Attribute eventAttribute = new Attribute(event.getEvent());
      attributeList.addElement(eventAttribute); // Each unique event is an
                            // attribute in WEKA
    }

    /*
     * Create the training "Instances" object, which is essentially the set
     * of feature vectors for the training data.
     */
    trainingSet = new Instances("JGAAP", attributeList, knownDocuments.size());
    trainingSet.setClassIndex(0); // The label (author name) is in position
                    // 0.

    /*
     * Put together the training set
     */
    for (int i = 0; i < knownEventMaps.size(); i++) {
      EventMap knownEventMap = knownEventMaps.get(i);
      Instance currentTrainingDocument = new Instance(
          allEvents.size() + 1);
      currentTrainingDocument.setValue((Attribute) attributeList
          .elementAt(0), knownDocuments.get(i).getAuthor());
      int j = 1; // Start counting events (at 1, since 0 is the author
            // label)
      for (Event event : allEvents) {
        currentTrainingDocument.setValue(
            (Attribute) attributeList.elementAt(j),
            knownEventMap.normalizedFrequency(event));
        j++;
      }
      trainingSet.add(new SparseInstance(currentTrainingDocument));
    }   

View Full Code Here

TOP

Related Classes of com.jgaap.util.EventMap

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.