Package com.jgaap.util

Examples of com.jgaap.util.Event


    EventSet known2;
   
   
   
    Vector<Event> test1 = new Vector<Event>();
    test1.add(new Event("mary", null));
    test1.add(new Event("had", null));
    test1.add(new Event("a", null));
    test1.add(new Event("little", null));
    test1.add(new Event("lamb", null));
    test1.add(new Event("whose", null));
    test1.add(new Event("fleece", null));
    test1.add(new Event("was", null));
    test1.add(new Event("white", null));
    test1.add(new Event("as", null));
    test1.add(new Event("snow", null));
    known1.addEvents(test1);
    //known1.setAuthor("Mary");
   
   
   
   
    //Same event set
    double Result = new CrossEntropyDivergence().divergence(new EventMap(known1), new EventMap(known1));
   
    //System.out.println(s);
   
   
    assertTrue(DistanceTestHelper.inRange(Result, 2.3978952, 0.0000001));
   
    //different event sets
   
    test1  = new Vector<Event>();
    Vector<Event> test2 = new Vector<Event>();
   
    test1.add(new Event("alpha", null));
    test1.add(new Event("beta", null));
    known1 = new EventSet();
    known1.addEvents(test1);
   
    test2.add(new Event("alpha", null));
    test2.add(new Event("alpha", null));
    test2.add(new Event("alpha", null));
    test2.add(new Event("beta", null));
    known2 = new EventSet();
    known2.addEvents(test2);
   
    Result = new CrossEntropyDivergence().divergence(new EventMap(known1), new EventMap(known2));
   
    //System.out.println(Result);
   
    assertTrue(DistanceTestHelper.inRange(Result, 0.836988, 0.000001));
   
    //Reversed Event Sets
   
    Result = new CrossEntropyDivergence().divergence(new EventMap(known2), new EventMap(known1));
   
    //System.out.println(Result);
   
    assertTrue(DistanceTestHelper.inRange(Result, 0.693147, 0.000001));
   
    //Test with Smoothing
    test2 = new Vector<Event>();
   
    test2.add(new Event("alpha", null));
    test2.add(new Event("alpha", null));
    test2.add(new Event("beta", null));
    test2.add(new Event("gamma", null));
    known2 = new EventSet();
    known2.addEvents(test2);
 
   
    //System.out.println("Start Here");
View Full Code Here


    String[] eventArray = new String(stripPunctuation.process(outDef.toString().toCharArray())).split("\\s+");

    for (int i = 0; i < eventArray.length; i++) {
      if (!stopWords.contains(eventArray[i]))
        eventSet.addEvent(new Event(eventArray[i], this));
    }

    return eventSet;
  }
View Full Code Here

  public void testDistance()
      throws DistanceCalculationException {
    EventSet set1 = new EventSet();
    EventSet set2 = new EventSet();
    Vector<Event> test1 = new Vector<Event>();
    test1.add(new Event("one", null));
    test1.add(new Event("two", null));
    test1.add(new Event("three", null));
    test1.add(new Event("four", null));
    test1.add(new Event("five", null));
    test1.add(new Event("six", null));
    test1.add(new Event("seven", null));
    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 ChordDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, Math.sqrt(1.8), 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 ChordDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, Math.sqrt(2.0), 0.0000000001));
  }
View Full Code Here

     
      EventSet sampleSet = eventDriver.createEventSet(text.toCharArray());
     
      EventSet expectedSet = new EventSet();
      Vector<Event> tmp = new Vector<Event>();
      tmp.add(new Event("The", eventDriver));
      tmp.add(new Event("The", eventDriver));
       expectedSet.addEvents(tmp);
      
        assertTrue(expectedSet.equals(sampleSet));
        }
View Full Code Here

    // test 1 : identical distributions
    EventSet es1 = new EventSet();
    EventSet es2 = new EventSet();
    Vector<Event> test1 = new Vector<Event>();
    test1.add(new Event("alpha", null));
    test1.add(new Event("beta", null));
    test1.add(new Event("beta", null));
    test1.add(new Event("gamma", null));
    test1.add(new Event("gamma", null));
    test1.add(new Event("gamma", null));
    es1.addEvents(test1);
    es2.addEvents(test1);
    assertTrue(new PearsonCorrelationDistance().distance(new EventMap(es1), new EventMap(es2)) == 0);

    // test 2 : identical probabilities but different distributions
    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("B", null));
    test1.add(new Event("B", null));
    test1.add(new Event("C", 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("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", 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("E", null));
    test2.add(new Event("E", null));

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

    // test 3 : Perfect anticorrelation
    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 PearsonCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    //System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 2.0, 0.0000000001));

    // test 4 : non-trivial calculation
    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    test2 = new Vector<Event>();

    test1.add(new Event("A", 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));

    test2.add(new Event("A", null));
    test2.add(new Event("A", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", null));
    test2.add(new Event("B", 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("C", null));
    test2.add(new Event("C", null));

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new PearsonCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 1-0.9608, 0.001));

    // test 5 : edge case (NaN)
    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    test2 = new Vector<Event>();

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

    test2.add(new Event("A", null));
    test2.add(new Event("B", 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));

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new PearsonCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
    assertTrue(DistanceTestHelper.inRange(result, 1.0, 0.001));

    // test 6 : edge case (point mass)
    es1=new EventSet();
    es2=new EventSet();
    test1 = new Vector<Event>();
    test2 = new Vector<Event>();

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

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

    es1.addEvents(test1);
    es2.addEvents(test2);
    result = new PearsonCorrelationDistance().distance(new EventMap(es1), new EventMap(es2));
    System.out.println(result);
View Full Code Here

    EventDriver eventDriver = new TruncatedFreqEventDriver();
    EventSet sampleEventSet = eventDriver.createEventSet(text.toCharArray());
    EventSet expectedEventSet = new NumericEventSet();
    Vector<Event> tmp = new Vector<Event>();

    tmp.add(new Event("16.", eventDriver));
    tmp.add(new Event("5.4", eventDriver));
    tmp.add(new Event("9.2", eventDriver));
    tmp.add(new Event("5.9", eventDriver));
    tmp.add(new Event("6.2", eventDriver));
    tmp.add(new Event("8.2", eventDriver));
    tmp.add(new Event("8.5", eventDriver));
    tmp.add(new Event("8.1", eventDriver));
    tmp.add(new Event("6.7", eventDriver));
    tmp.add(new Event("8.3", eventDriver));
    tmp.add(new Event("5.7", eventDriver));
    tmp.add(new Event("6.5", eventDriver));
    tmp.add(new Event("8.5", eventDriver));
    tmp.add(new Event("6.2", eventDriver));
    tmp.add(new Event("5.9", eventDriver));
    tmp.add(new Event("5.7", eventDriver));
    tmp.add(new Event("7.4", eventDriver));

    expectedEventSet.addEvents(tmp);

System.out.println("Expected is " + expectedEventSet.toString());
System.out.println("Actual is " + sampleEventSet.toString());
View Full Code Here

public class CoefficientOfVariationTest {
  @Test
  public void testProcess() throws EventCullingException {
    List<EventSet> eventSets = new ArrayList<EventSet>();
    EventSet eventSet1 = new EventSet();
    eventSet1.addEvent(new Event("A", null));
    eventSet1.addEvent(new Event("A", null));
    eventSet1.addEvent(new Event("A", null));
    eventSet1.addEvent(new Event("A", null));
    eventSet1.addEvent(new Event("A", null));
    eventSet1.addEvent(new Event("B", null));
    eventSet1.addEvent(new Event("B", null));
    eventSet1.addEvent(new Event("B", null));
    eventSet1.addEvent(new Event("C", null));
    eventSets.add(eventSet1);
    EventSet eventSet2 = new EventSet();
    eventSet2.addEvent(new Event("A", null));
    eventSet2.addEvent(new Event("B", null));
    eventSet2.addEvent(new Event("C", null));
    eventSet2.addEvent(new Event("D", null));
    eventSet2.addEvent(new Event("E", null));
    eventSet2.addEvent(new Event("F", null));
    eventSet2.addEvent(new Event("F", null));
    eventSet2.addEvent(new Event("G", null));
    eventSet2.addEvent(new Event("H", null));
    eventSets.add(eventSet2);
    EventSet eventSet3 = new EventSet();
    eventSet3.addEvent(new Event("E", null));
    eventSet3.addEvent(new Event("E", null));
    eventSet3.addEvent(new Event("E", null));
    eventSet3.addEvent(new Event("F", null));
    eventSet3.addEvent(new Event("A", null));
    eventSet3.addEvent(new Event("B", null));
    eventSet3.addEvent(new Event("D", null));
    eventSet3.addEvent(new Event("H", null));
    eventSet3.addEvent(new Event("C", null));
    eventSets.add(eventSet3);

    CoefficientOfVariation culler = new CoefficientOfVariation();
        culler.setParameter("numEvents", 4);
        Set<Event> results = culler.train(eventSets);
    Set<Event> expected = new HashSet<Event>();
    expected.add(new Event("B", null));
    expected.add(new Event("C", null));
    expected.add(new Event("D", null));
    expected.add(new Event("H", null))

    assertTrue(expected.equals(results));
   
 
  }
View Full Code Here

  public void testDistance()
      throws DistanceCalculationException {
    EventSet set1 = new EventSet();
    EventSet set2 = new EventSet();
    Vector<Event> test1 = new Vector<Event>();
    test1.add(new Event("one", null));
    test1.add(new Event("two", null));
    test1.add(new Event("three", null));
    test1.add(new Event("four", null));
    test1.add(new Event("five", null));
    test1.add(new Event("six", null));
    test1.add(new Event("seven", null));
    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 SoergleDistance().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 SoergleDistance().distance(new EventMap(set1), new EventMap(set2));
    assertTrue(DistanceTestHelper.inRange(result, 1.0, 0.0000000001));
  }
View Full Code Here

    EventDriver eventDriver = new SuffixEventDriver();
    EventSet sampleEventSet = eventDriver.createEventSet(text.toCharArray());
    EventSet expectedEventSet = new EventSet();
    Vector<Event> tmp = new Vector<Event>();

    tmp.add(new Event("ted", eventDriver));
    tmp.add(new Event("ers", eventDriver));
    tmp.add(new Event("est", eventDriver));

    expectedEventSet.addEvents(tmp);
    System.out.println(sampleEventSet.toString());
    assertTrue(expectedEventSet.equals(sampleEventSet));
  }
View Full Code Here

  @Override
  public EventSet createEventSet(char[] text) {
    int n = getParameter("N", 2);
    EventSet eventSet = new EventSet(text.length);
    for (int i = 0; i <= text.length - n; i++) {
      eventSet.addEvent(new Event(new String(text, i, n), this));
    }
    return eventSet;
  }
View Full Code Here

TOP

Related Classes of com.jgaap.util.Event

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.