Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–168 unchanged (168 lines)
169 resultSet.add(new Cluster<T>(firstPoint));
170
171 final double[] dx2 = new double[pointSet.size()];
172 while (resultSet.size() < k) {
173 // For each data point x, compute D(x), the distance between x and
174 // the nearest center that has already been chosen.
175 int sum = 0;
176 for (int i = 0; i < pointSet.size(); i++) {
177 final T p = pointSet.get(i);
178 final Cluster<T> nearest = getNearestCluster(resultSet, p);
179 final double d = p.distanceFrom(nearest.getCenter());
180 sum += d * d;
181 dx2[i] = sum;
…lines 182–334 unchanged (153 lines)

After

…lines 1–168 unchanged (168 lines)
169 resultSet.add(new Cluster<T>(firstPoint));
170
171 final double[] dx2 = new double[pointSet.size()];
172 while (resultSet.size() < k) {
173 // For each data point x, compute D(x), the distance between x and
174 // the nearest center that has already been chosen.
175 double sum = 0;
176 for (int i = 0; i < pointSet.size(); i++) {
177 final T p = pointSet.get(i);
178 final Cluster<T> nearest = getNearestCluster(resultSet, p);
179 final double d = p.distanceFrom(nearest.getCenter());
180 sum += d * d;
181 dx2[i] = sum;
…lines 182–334 unchanged (153 lines)

Before

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "math"
. "."
identifier "stat"
. "."
identifier "clustering"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "ArrayList"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "List"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Random"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "math"
. "."
identifier "exception"
. "."
identifier "ConvergenceException"
; ";"
import_declaration (+22 nodes collapsed)
import_declaration (+25 nodes collapsed)
block_comment "/**\n * Clustering algorithm based on David Arthur and Sergei"...
class_declaration
modifiers
public "public"
class "class"
identifier "KMeansPlusPlusClusterer"
type_parameters
< "<"
type_parameter
type_identifier "T"
type_bound
extends "extends"
generic_type
type_identifier "Clusterable"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
class_body
{ "{"
block_comment "/** Strategies to use for replacing an empty cluster. */"
enum_declaration (+24 nodes collapsed)
block_comment "/** Random generator for choosing initial centers. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Random"
variable_declarator
identifier "random"
; ";"
block_comment "/** Selected strategy for empty clusters. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "EmptyClusterStrategy"
variable_declarator
identifier "emptyStrategy"
; ";"
block_comment "/** Build a clusterer.\n * <p>\n * The default strateg"...
constructor_declaration (+27 nodes collapsed)
block_comment "/** Build a clusterer.\n * @param random random generator"...
constructor_declaration (+39 nodes collapsed)
block_comment "/**\n * Runs the K-means++ clustering algorithm.\n *\n "...
method_declaration (+419 nodes collapsed)
block_comment "/**\n * Adds the given points to the closest {@link Clust"...
method_declaration (+93 nodes collapsed)
block_comment "/**\n * Use K-means++ to choose the initial centers.\n "...
method_declaration
modifiers
private "private"
static "static"
type_parameters
< "<"
type_parameter
type_identifier "T"
type_bound
extends "extends"
generic_type
type_identifier "Clusterable"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
generic_type
type_identifier "List"
type_arguments
< "<"
generic_type
type_identifier "Cluster"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
identifier "chooseInitialCenters"
formal_parameters (+26 nodes collapsed)
block
{ "{"
local_variable_declaration (+25 nodes collapsed)
local_variable_declaration (+34 nodes collapsed)
line_comment "// Choose one center uniformly at random from among the data"...
local_variable_declaration (+29 nodes collapsed)
expression_statement (+21 nodes collapsed)
local_variable_declaration (+27 nodes collapsed)
while_statement
while "while"
parenthesized_expression
( "("
binary_expression
method_invocation
identifier "resultSet"
. "."
identifier "size"
argument_list
( "("
) ")"
< "<"
identifier "k"
) ")"
block
{ "{"
line_comment "// For each data point x, compute D(x), the distance between"...
line_comment "// the nearest center that has already been chosen."
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "sum"
= "="
decimal_integer_literal "0"
; ";"
for_statement (+108 nodes collapsed)
line_comment "// Add one new data point as a center. Each point x is chose"...
line_comment "// probability proportional to D(x)2"
local_variable_declaration
modifiers
final "final"
floating_point_type
double "double"
variable_declarator
identifier "r"
= "="
binary_expression
method_invocation
identifier "random"
. "."
identifier "nextDouble"
argument_list
( "("
) ")"
* "*"
identifier "sum"
; ";"
for_statement (+82 nodes collapsed)
} "}"
return_statement
return "return"
identifier "resultSet"
; ";"
} "}"
block_comment "/**\n * Get a random point from the {@link Cluster} with "...
method_declaration (+268 nodes collapsed)
block_comment "/**\n * Get a random point from the {@link Cluster} with "...
method_declaration (+183 nodes collapsed)
block_comment "/**\n * Get the point farthest to its cluster center\n "...
method_declaration (+239 nodes collapsed)
block_comment "/**\n * Returns the nearest {@link Cluster} to the given "...
method_declaration (+143 nodes collapsed)
} "}"

After

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "math"
. "."
identifier "stat"
. "."
identifier "clustering"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "ArrayList"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "List"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Random"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "math"
. "."
identifier "exception"
. "."
identifier "ConvergenceException"
; ";"
import_declaration (+22 nodes collapsed)
import_declaration (+25 nodes collapsed)
block_comment "/**\n * Clustering algorithm based on David Arthur and Sergei"...
class_declaration
modifiers
public "public"
class "class"
identifier "KMeansPlusPlusClusterer"
type_parameters
< "<"
type_parameter
type_identifier "T"
type_bound
extends "extends"
generic_type
type_identifier "Clusterable"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
class_body
{ "{"
block_comment "/** Strategies to use for replacing an empty cluster. */"
enum_declaration (+24 nodes collapsed)
block_comment "/** Random generator for choosing initial centers. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Random"
variable_declarator
identifier "random"
; ";"
block_comment "/** Selected strategy for empty clusters. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "EmptyClusterStrategy"
variable_declarator
identifier "emptyStrategy"
; ";"
block_comment "/** Build a clusterer.\n * <p>\n * The default strateg"...
constructor_declaration (+27 nodes collapsed)
block_comment "/** Build a clusterer.\n * @param random random generator"...
constructor_declaration (+39 nodes collapsed)
block_comment "/**\n * Runs the K-means++ clustering algorithm.\n *\n "...
method_declaration (+419 nodes collapsed)
block_comment "/**\n * Adds the given points to the closest {@link Clust"...
method_declaration (+93 nodes collapsed)
block_comment "/**\n * Use K-means++ to choose the initial centers.\n "...
method_declaration
modifiers
private "private"
static "static"
type_parameters
< "<"
type_parameter
type_identifier "T"
type_bound
extends "extends"
generic_type
type_identifier "Clusterable"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
generic_type
type_identifier "List"
type_arguments
< "<"
generic_type
type_identifier "Cluster"
type_arguments
< "<"
type_identifier "T"
> ">"
> ">"
identifier "chooseInitialCenters"
formal_parameters (+26 nodes collapsed)
block
{ "{"
local_variable_declaration (+25 nodes collapsed)
local_variable_declaration (+34 nodes collapsed)
line_comment "// Choose one center uniformly at random from among the data"...
local_variable_declaration (+29 nodes collapsed)
expression_statement (+21 nodes collapsed)
local_variable_declaration (+27 nodes collapsed)
while_statement
while "while"
parenthesized_expression
( "("
binary_expression
method_invocation
identifier "resultSet"
. "."
identifier "size"
argument_list
( "("
) ")"
< "<"
identifier "k"
) ")"
block
{ "{"
line_comment "// For each data point x, compute D(x), the distance between"...
line_comment "// the nearest center that has already been chosen."
local_variable_declaration
floating_point_type
double "double"
variable_declarator
identifier "sum"
= "="
decimal_integer_literal "0"
; ";"
for_statement (+108 nodes collapsed)
line_comment "// Add one new data point as a center. Each point x is chose"...
line_comment "// probability proportional to D(x)2"
local_variable_declaration
modifiers
final "final"
floating_point_type
double "double"
variable_declarator
identifier "r"
= "="
binary_expression
method_invocation
identifier "random"
. "."
identifier "nextDouble"
argument_list
( "("
) ")"
* "*"
identifier "sum"
; ";"
for_statement (+82 nodes collapsed)
} "}"
return_statement
return "return"
identifier "resultSet"
; ";"
} "}"
block_comment "/**\n * Get a random point from the {@link Cluster} with "...
method_declaration (+268 nodes collapsed)
block_comment "/**\n * Get a random point from the {@link Cluster} with "...
method_declaration (+183 nodes collapsed)
block_comment "/**\n * Get the point farthest to its cluster center\n "...
method_declaration (+239 nodes collapsed)
block_comment "/**\n * Returns the nearest {@link Cluster} to the given "...
method_declaration (+143 nodes collapsed)
} "}"