<commit_before>package ml.grafos.okapi.clustering.kmeans;

import java.io.IOException;

import ml.grafos.okapi.common.data.ArrayListOfDoubleArrayListWritable;
import ml.grafos.okapi.common.data.DoubleArrayListWritable;

import org.apache.giraph.aggregators.IntSumAggregator;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.master.DefaultMasterCompute;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.python.modules.math;

/**
 * 
 * The k-means clustering algorithm partitions <code>N</code> data points (observations) into <code>k</code> clusters.
 * The input consists of data points with a <code>pointID</code> and a vector of coordinates.
 * 
 * The algorithm is iterative and works as follows.
 * In the initialization phase, <code>k</code> clusters are chosen from the input points at random.
 * 
 * In each iteration:
 * 1. each data point is assigned to the cluster center which is closest to it, by means of euclidean distance
 * 2. new cluster centers are recomputed, by calculating the arithmetic mean of the assigned points
 * 
 * Convergence is reached when the positions of the cluster centers do not change.
 *
 * http://en.wikipedia.org/wiki/K-means_clustering
 * 
 */
public class KMeansClustering {

  /**
   * The prefix for the cluster center aggregators, used to store the cluster centers coordinates.
   * Each of them aggregates the vector coordinates of points assigned to the cluster center,
   * in order to compute the means as the coordinates of the new cluster centers.
   */
  private static String CENTER_AGGR_PREFIX = "center.aggr.prefix";

  /**
   * The prefix for the aggregators used to store the number of points 
   * assigned to each cluster center
   */
  private static String ASSIGNED_POINTS_PREFIX = "assigned.points.prefix";
  
  /** The initial centers aggregator*/
  private static String INITIAL_CENTERS = "kmeans.initial.centers";
  
  /** Maximum number of iterations */
  public static final String MAX_ITERATIONS = "kmeans.iterations";
  /** Default value for iterations */
  public static final int ITERATIONS_DEFAULT = 100;
  /** Number of cluster centers */
  public static final String CLUSTER_CENTERS_COUNT = "kmeans.cluster.centers.count";<commit_msg>change visibility to public for the fields accessed by the test<commit_after>package ml.grafos.okapi.clustering.kmeans;

import java.io.IOException;

import ml.grafos.okapi.common.data.ArrayListOfDoubleArrayListWritable;
import ml.grafos.okapi.common.data.DoubleArrayListWritable;

import org.apache.giraph.aggregators.IntSumAggregator;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.master.DefaultMasterCompute;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.python.modules.math;

/**
 * 
 * The k-means clustering algorithm partitions <code>N</code> data points (observations) into <code>k</code> clusters.
 * The input consists of data points with a <code>pointID</code> and a vector of coordinates.
 * 
 * The algorithm is iterative and works as follows.
 * In the initialization phase, <code>k</code> clusters are chosen from the input points at random.
 * 
 * In each iteration:
 * 1. each data point is assigned to the cluster center which is closest to it, by means of euclidean distance
 * 2. new cluster centers are recomputed, by calculating the arithmetic mean of the assigned points
 * 
 * Convergence is reached when the positions of the cluster centers do not change.
 *
 * http://en.wikipedia.org/wiki/K-means_clustering
 * 
 */
public class KMeansClustering {

  /**
   * The prefix for the cluster center aggregators, used to store the cluster centers coordinates.
   * Each of them aggregates the vector coordinates of points assigned to the cluster center,
   * in order to compute the means as the coordinates of the new cluster centers.
   */
  public static String CENTER_AGGR_PREFIX = "center.aggr.prefix";

  /**
   * The prefix for the aggregators used to store the number of points 
   * assigned to each cluster center
   */
  public static String ASSIGNED_POINTS_PREFIX = "assigned.points.prefix";
  
  /** The initial centers aggregator*/
  public static String INITIAL_CENTERS = "kmeans.initial.centers";
  
  /** Maximum number of iterations */
  public static final String MAX_ITERATIONS = "kmeans.iterations";
  /** Default value for iterations */
  public static final int ITERATIONS_DEFAULT = 100;
  /** Number of cluster centers */
  public static final String CLUSTER_CENTERS_COUNT = "kmeans.cluster.centers.count";
{'fraction_non_alphanumeric': 0.08276714021000618, 'fraction_numerical': 0.0020588840848260242, 'mean_word_length': 4.32092004381161, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347102', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1340, 'n_words': 483}