<commit_before>package experimentalcode.lisa;

import de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm;
import de.lmu.ifi.dbs.elki.algorithm.clustering.EM;
import de.lmu.ifi.dbs.elki.algorithm.outlier.ABOD;
import de.lmu.ifi.dbs.elki.data.RealVector;
import de.lmu.ifi.dbs.elki.database.AssociationID;
import de.lmu.ifi.dbs.elki.database.Database;
import de.lmu.ifi.dbs.elki.result.AnnotationResult;
import de.lmu.ifi.dbs.elki.result.AnnotationsFromDatabase;
import de.lmu.ifi.dbs.elki.result.MultiResult;
import de.lmu.ifi.dbs.elki.result.OrderingFromAssociation;
import de.lmu.ifi.dbs.elki.result.Result;
import de.lmu.ifi.dbs.elki.result.ResultUtil;
import de.lmu.ifi.dbs.elki.utilities.Description;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException;
import de.lmu.ifi.dbs.elki.utilities.pairs.Pair;

import java.util.Iterator;
import java.util.List;
/**
 * outlier detection algorithm using EM Clustering. If an object does not belong to any cluster it is supposed to be an outlier.
 * if the probability for an object to belong to the most probable cluster is still relatively low this object is an outlier 
 * @author lisa
 *
 * @param <V>
 */
public class EMOutlierDetection<V extends RealVector<V, ?>> extends AbstractAlgorithm<V, MultiResult>{
  EM emClustering;
  
  public static final AssociationID<Double> DBOD_MAXCPROB= AssociationID.getOrCreateAssociationID("dbod_maxcprob", Double.class);
  /**
   * Provides the result of the algorithm.
   */
  MultiResult result;

  /**
   * Constructor, adding options to option handler.
   */
  public EMOutlierDetection() {
    super();

    }
  
  /**
   * Calls the super method
   * and sets additionally the values of the parameter
   * {@link #K_PARAM}, {@link #N_PARAM} 
   */
  @Override
  public String[] setParameters(String[] args) throws ParameterException {
      String[] remainingParameters = super.setParameters(args);
      remainingParameters= emClustering.setParameters(remainingParameters);
      return remainingParameters;
  }

  /**
   * Runs the algorithm in the timed evaluation part.
   */

  @Override
  protected MultiResult runInTime(Database<V> database) throws IllegalStateException {
    AnnotationResult<List<Double>> probabilities; 
    emClustering.run(database);
    Iterator<Integer> iter = database.iterator();
    if (iter.hasNext()){
      Double maxProb = 0.0;
      Integer id = iter.next();
      List<AnnotationResult<List<Double>>> annotations = result.filterResults(AnnotationResult.class);
      for (AnnotationResult<List<Double>> annotation : annotations){
        for (Pair<String, List<Double>> pair : annotation.getAnnotations(iter.next())){
          if (pair != null && pair.getFirst() != null && pair.getFirst().equals(AssociationID.PROBABILITY_CLUSTER_I_GIVEN_X)){
            List<Double> probs = pair.getSecond(); 
       
            for(Double prob: probs) {
              if(prob > maxProb) {
                maxProb = prob;
              }
            }
          }                                                                                                                      
        }
      }
      database.associate(DBOD_MAXCPROB, id, maxProb);     
  
    } 
    else {
      throw new RuntimeException("Database empty.");
    }
 
    AnnotationsFromDatabase<V, Double> res1 = new AnnotationsFromDatabase<V, Double>(database);
    res1.addAssociation(DBOD_MAXCPROB);
     // Ordering
     OrderingFromAssociation<Double, V> res2 = new OrderingFromAssociation<Double, V>(database, DBOD_MAXCPROB, true); 
     // combine results.
     
     result = new MultiResult();
     result.addResult(res1);
     result.addResult(res2);
     return result;
 
  
    

  }

  @Override
  public Description getDescription() {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public MultiResult getResult() {
    
    return result;
  }
  
}
<commit_msg>Commit the AnnotationResult changes.<commit_after>package experimentalcode.lisa;

import java.util.Iterator;
import java.util.List;

import de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm;
import de.lmu.ifi.dbs.elki.algorithm.clustering.EM;
import de.lmu.ifi.dbs.elki.data.RealVector;
import de.lmu.ifi.dbs.elki.database.AssociationID;
import de.lmu.ifi.dbs.elki.database.Database;
import de.lmu.ifi.dbs.elki.result.AnnotationFromDatabase;
import de.lmu.ifi.dbs.elki.result.AnnotationResult;
import de.lmu.ifi.dbs.elki.result.MultiResult;
import de.lmu.ifi.dbs.elki.result.OrderingFromAssociation;
import de.lmu.ifi.dbs.elki.utilities.Description;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException;
import de.lmu.ifi.dbs.elki.utilities.pairs.Pair;
/**
 * outlier detection algorithm using EM Clustering. If an object does not belong to any cluster it is supposed to be an outlier.
 * if the probability for an object to belong to the most probable cluster is still relatively low this object is an outlier 
 * @author lisa
 *
 * @param <V>
 */
public class EMOutlierDetection<V extends RealVector<V, ?>> extends AbstractAlgorithm<V, MultiResult>{
  EM emClustering;
  
  public static final AssociationID<Double> DBOD_MAXCPROB= AssociationID.getOrCreateAssociationID("dbod_maxcprob", Double.class);
  /**
   * Provides the result of the algorithm.
   */
  MultiResult result;

  /**
   * Constructor, adding options to option handler.
   */
  public EMOutlierDetection() {
    super();

    }
  
  /**
   * Calls the super method
   * and sets additionally the values of the parameter
   * {@link #K_PARAM}, {@link #N_PARAM} 
   */
  @Override
  public String[] setParameters(String[] args) throws ParameterException {
      String[] remainingParameters = super.setParameters(args);
      remainingParameters= emClustering.setParameters(remainingParameters);
      return remainingParameters;
  }

  /**
   * Runs the algorithm in the timed evaluation part.
   */

  @Override
  protected MultiResult runInTime(Database<V> database) throws IllegalStateException {
    AnnotationResult<List<Double>> probabilities; 
    emClustering.run(database);
    Iterator<Integer> iter = database.iterator();
    if (iter.hasNext()){
      Double maxProb = 0.0;
      Integer id = iter.next();
      List<AnnotationResult<List<Double>>> annotations = result.filterResults(AnnotationResult.class);
      for (AnnotationResult<List<Double>> annotation : annotations){
        for (Pair<String, List<Double>> pair : annotation.getAnnotations(iter.next())){
          if (pair != null && pair.getFirst() != null && pair.getFirst().equals(AssociationID.PROBABILITY_CLUSTER_I_GIVEN_X)){
            List<Double> probs = pair.getSecond(); 
       
            for(Double prob: probs) {
              if(prob > maxProb) {
                maxProb = prob;
              }
            }
          }                                                                                                                      
        }
      }
      database.associate(DBOD_MAXCPROB, id, maxProb);     
  
    } 
    else {
      throw new RuntimeException("Database empty.");
    }
 
    AnnotationFromDatabase<Double, V> res1 = new AnnotationFromDatabase<Double, V>(database, DBOD_MAXCPROB);
     // Ordering
     OrderingFromAssociation<Double, V> res2 = new OrderingFromAssociation<Double, V>(database, DBOD_MAXCPROB, true); 
     // combine results.
     
     result = new MultiResult();
     result.addResult(res1);
     result.addResult(res2);
     return result;
 
  
    

  }

  @Override
  public Description getDescription() {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public MultiResult getResult() {
    
    return result;
  }
  
}

{'fraction_non_alphanumeric': 0.1023244062657908, 'fraction_numerical': 0.001642243557352198, 'mean_word_length': 2.6333180357962367, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '128872', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2298, 'n_words': 505}