Package com.jgaap.util

Examples of com.jgaap.util.EventMap


  public void train(List<Document> knowns){
    ImmutableSet.Builder<Event> eventsBuilder = ImmutableSet.builder();
    ImmutableMap.Builder<Document, EventMap> knownHistogramsBuilder = ImmutableMap.builder();
    List<EventMap> histograms = new ArrayList<EventMap>(knowns.size());
    for(Document known : knowns){
      EventMap histogram = new EventMap(known);
      eventsBuilder.addAll(histogram.uniqueEvents());
      histograms.add(histogram);
      knownHistogramsBuilder.put(known, histogram);
    }
    events = eventsBuilder.build();
    knownHistograms = knownHistogramsBuilder.build();
    EventMap mu = EventMap.centroid(histograms);
    double[][] s = new double[events.size()][events.size()];
    int i = 0;
    for(Event x : events){
      int j =0;
      for(Event y : events){
        double tmp = 0;
        for(EventMap histogram : histograms){
          tmp += (histogram.relativeFrequency(x)-mu.relativeFrequency(x))*(histogram.relativeFrequency(y)-mu.relativeFrequency(y));
        }
        s[i][j] = tmp/(events.size()-1);
        if(i == j) {
          s[i][j] += 0.00001;
        }
View Full Code Here


  }
 
  @Override
  public List<Pair<String, Double>> analyze(Document unknown) {
    List<Pair<String, Double>> results = new ArrayList<Pair<String,Double>>();
    EventMap histogram = new EventMap(unknown);
    for(Entry<Document, EventMap> entry : knownHistograms.entrySet()){
      double[][] tmp = new double[events.size()][1];
      int i = 0;
      for(Event event : events){
        tmp[i][0] = histogram.relativeFrequency(event)-entry.getValue().relativeFrequency(event);
        i++;
      }
      Matrix<Float64> difference = Float64Matrix.valueOf(tmp);
      Matrix<Float64> radicand = difference.transpose().times(inverseCovarianceMatrix).times(difference);
      double result = radicand.get(0, 0).sqrt().doubleValue();
View Full Code Here

  public void train(List<Document> knowns) {
    ImmutableMap.Builder<Document, EventMap> knownEventMapsBuilder = ImmutableMap.builder();
    ImmutableMultimap.Builder<String, Document> knownDocumentsBuilder = ImmutableMultimap.builder();
    Multimap<String, EventMap> knownHistograms = HashMultimap.create();
    for(Document known : knowns){
      EventMap eventMap = new EventMap(known);
      knownEventMapsBuilder.put(known, eventMap);
      knownHistograms.put(known.getAuthor(), eventMap);
      knownDocumentsBuilder.put(known.getAuthor(), known);
    }
    knownEventMaps = knownEventMapsBuilder.build();
View Full Code Here

    List<EventMap> currentAuthorHistograms = new ArrayList<EventMap>(authorDocuments.size());
    for (Document document : authorDocuments) {
      if (!document.equals(known))
        currentAuthorHistograms.add(knownEventMaps.get(document));
    }
    EventMap currentAuthorCentroid = EventMap.centroid(currentAuthorHistograms);
    EventMap currentEventMap = knownEventMaps.get(known);
    try {
      results.add(new Pair<String, Double>(currentAuthor,distance.distance(currentEventMap, currentAuthorCentroid), 2));
      for (Map.Entry<String, EventMap> entry : knownCentroids.entrySet()) {
        if (!entry.getKey().equals(currentAuthor)) {
          results.add(new Pair<String, Double>(entry.getKey(),distance.distance(currentEventMap, entry.getValue()), 2));
View Full Code Here

  public void train(List<Document> knowns) {
    useCentroid = "true".equalsIgnoreCase(getParameter("centroid"));
    ImmutableSet.Builder<Event> eventsBuilder = ImmutableSet.builder();
    ImmutableMultimap.Builder<String, EventMap> knownHistogramsBuilder = ImmutableMultimap.builder();
    for (Document known : knowns) {
      EventMap eventMap = new EventMap(known);
      eventsBuilder.addAll(eventMap.uniqueEvents());
      knownHistogramsBuilder.put(known.getAuthor(), eventMap);
    }
    events = eventsBuilder.build();
    knownHistograms = knownHistogramsBuilder.build();
   
View Full Code Here

   * sigma|) (Basically, a Manhattan Distance normalized by the standard
   * deviation of a word across the known author list)
   */
  public List<Pair<String, Double>> analyze(Document unknown) {
    List<Pair<String, Double>> results = new ArrayList<Pair<String, Double>>();
    EventMap unknownEventMap = new EventMap(unknown);
    if (useCentroid) {
      for (Entry<String, EventMap> entry : knownCentroids.entrySet()) {
        double delta = 0.0;
        for (Event event : events) {
          Double knownFrequency = entry.getValue().relativeFrequency(event);
          if (knownFrequency == null) {
            knownFrequency = 0.0;
          }
          delta += Math.abs((unknownEventMap.relativeFrequency(event) - knownFrequency) / eventStddev.get(event));
        }
        results.add(new Pair<String, Double>(entry.getKey(), delta,2));
      }
    } else {
      for (Entry<String, Collection<EventMap>> entry : knownHistograms.asMap().entrySet()) {
        for (EventMap histogram : entry.getValue()) {
          double delta = 0.0;
          for (Event event : events) {
            delta += Math.abs((unknownEventMap.relativeFrequency(event) - histogram.relativeFrequency(event)) / eventStddev.get(event));
          }
          results.add(new Pair<String, Double>(entry.getKey(), delta,2));
        }
      }
    }
View Full Code Here

  @Override
  public void train(List<Document> knowns) {
    Multimap<String, EventMap> knownHistograms = HashMultimap.create();
    for (Document known : knowns) {
      EventMap eventMap = new EventMap(known);
      knownHistograms.put(known.getAuthor(), eventMap);
    }
    ImmutableMap.Builder<String, Histogram> mapBuilder = ImmutableMap.builder();
    for (Entry<String, Collection<EventMap>> entry : knownHistograms.asMap().entrySet()) {
      mapBuilder.put(entry.getKey(), EventMap.centroid(entry.getValue()));
View Full Code Here

    knownCentroids = mapBuilder.build();
  }

  @Override
  public List<Pair<String, Double>> analyze(Document unknown) throws AnalyzeException {
    Histogram unknownHistogram = new EventMap(unknown);
    List<Pair<String, Double>> result = new ArrayList<Pair<String, Double>>(knownCentroids.size());
    for (Entry<String, Histogram> knownEntry : knownCentroids.entrySet()) {
      try {
        double current = distance.distance(unknownHistogram, knownEntry.getValue());
        logger.debug(unknown.getTitle()+" ("+unknown.getFilePath()+")"+" -> "+knownEntry.getKey()+":"+current);
View Full Code Here

      for (int i = 0; i < samples; i++) {
        EventSet eventSet = new EventSet(sampleSize);
        for (int j = 0; j < sampleSize; j++) {
          eventSet.addEvent(entry.getValue().next());
        }
        EventMap histogram = new EventMap(eventSet);
        histograms.add(histogram);
      }
      authorHistogramsBuilder.putAll(entry.getKey(), histograms);
    }
    authorHistograms = authorHistogramsBuilder.build();
View Full Code Here

    List<Pair<String, Double>> rawResults = new ArrayList<Pair<String, Double>>();
    EventSet unknownEventSet = new EventSet();
    for(EventSet eventSet : unknownDocument.getEventSets().values()){
      unknownEventSet.addEvents(eventSet);
    }
    EventMap unknownHistogram = new EventMap(unknownEventSet);
    for (Entry<String, Collection<EventMap>> entry : authorHistograms.asMap().entrySet()) {
      for (EventMap knownHistogram : entry.getValue()) {
        try {
          rawResults.add(new Pair<String, Double>(entry.getKey(), distance.distance(unknownHistogram, knownHistogram), 2));
        } catch (DistanceCalculationException e) {
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.