L EARNING TO L INK
A BSTRACT
Clustering is an important part of many modern data analysis pipelines, including network analysis and data retrieval.
There are many different clustering algorithms developed by various communities, and it is often not clear which algorithm will give the best performance on a speciﬁc clustering task.
Similarly, we often have multiple ways to measure distances between data points, and the best clustering performance might require a non-trivial combination of those metrics.
In this work, we study data-driven algorithm selection and metric learning for clustering problems, where the goal is to simultaneously learn the best algorithm and metric for a speciﬁc application.
The family of clustering algorithms we consider is parameterized linkage based procedures that includes single and complete linkage.
The family of distance functions we learn over are convex combinations of base distance functions.
We design efﬁcient learning algorithms which receive samples from an application-speciﬁc distribution over clustering instances and learn a near-optimal distance and clustering algorithm from these classes.
We also carry out a comprehensive empirical evaluation of our techniques showing that they can lead to signiﬁcantly improved clustering performance on real-world datasets.
I NTRODUCTION
Overview.
Clustering is an important component of modern data analysis.
For example, we might cluster emails as a pre-processing step for spam detection, or we might cluster individuals in a social network in order to suggest new connections.
There are a myriad of different clustering algorithms, and it is not always clear what algorithm will give the best performance on a speciﬁc clustering task.
Similarly, we often have multiple different ways to measure distances between data points, and it is not obvious which distance metric will lead to the best performance.
In this work, we study data-driven algorithm selection and metric learning for clustering problems, where the goal is to use data to simultaneously learn the best algorithm and metric for a speciﬁc application such as clustering emails or users of a social network.
An application is modeled as a distribution over clustering tasks, we observe an i.i.d.
sample of clustering instances drawn from that distribution, and our goal is to choose an approximately optimal algorithm from a parameterized family of algorithms (according to some well-deﬁned loss function).
This corresponds to settings where we repeatedly solve clustering instances (e.g., clustering the emails that arrive each day) and we want to use historic instances to learn the best clustering algorithm and metric.
The family of clustering algorithms we learn over consists of parameterized linkage based procedures and includes single and complete linkage, which are widely used in practice and optimal in many cases (Awasthi et al., 2014;
Saeed et al., 2003; White et al., 2010; Awasthi et al., 2012; Balcan and Liang, 2016; Grosswendt and Roeglin, 2015).
The family of distance metrics we learn over consists of convex combinations of base distance functions.
We design efﬁcient learning algorithms that receive samples from an application-speciﬁc distribution over clustering instances and simultaneously learn both a near-optimal distance metric and clustering algorithm from these classes.
We contribute to a recent line of work that provides learning-theoretical guarantees for data-driven algorithm conﬁguration (Gupta and
Roughgarden, 2017; Balcan et al., 2017; 2018a;b; 2019).
These papers analyze the intrinsic complexity of parameterized algorithm families in order to provide sample complexity guarantees, that is, bounds on the number of sample instances needed in order to ﬁnd an approximately optimal algorithm for a given application domain.
Our results build on the work of Balcan et al.
(2017), who studied the problem of learning the best clustering algorithm from a class of linkage based procedures, but did not study learning the best metric.
In addition to our sample complexity guarantees, we develop a number of algorithmic tools that enable learning application speciﬁc clustering algorithms and metrics for realistically large clustering instances.
We use our efﬁcient implementations to conduct comprehensive experiments on clustering domains derived from both real-world and synthetic datasets.
These experiments demonstrate that learning application-speciﬁc algorithms and metrics can lead to signiﬁcant performance improvements over standard algorithms and metrics.
Our Results.
We study linkage-based clustering algorithms that take as input a clustering instance S and output a hierarchical clustering of S represented as a binary cluster tree .
Each node in the tree represents a cluster in the data at one level of granularity, with the leaves corresponding to individual data points and the root node corresponding to the entire dataset.
Each internal node represents a cluster obtained by merging its two children.
Linkage-based clustering algorithms build a cluster tree from the leaves up, starting with each point belonging to its own cluster and repeatedly merging the “closest” pair of clusters until only one remains.
The parameters of our algorithm family control both the metric used to measure pointwise distances, as well as how the linkage algorithm measures distances between clusters (in terms of the distances between their points).
This work has two major contributions.
Our ﬁrst contribution is to provide sample complexity guarantees for learning effective application-speciﬁc distance metrics for use with linkage-based clustering algorithms.
The key challenge is that, if we ﬁx a clustering algorithm from the family we study and a single clustering instance S , the algorithm output is a piecewise constant function of our metric family’s parameters.
This implies that, unlike many standard learning problems, the loss we want to minimize is very sensitive to the metric parameters and small perturbations to the optimal parameters can lead to high loss.
Our main technical insight is that for any clustering instance S , we can partition the parameter space of our metric family into a relatively small number of regions such that the ordering over pairs of points in S given by the metric is constant on each region.
The clustering output by all algorithms in the family we study only depends on the ordering over pairs of points induced by the metric, and therefore their output is also a piecewise constant function of the metric parameters with not too many pieces.
We leverage this structure to bound the intrinsic complexity of the learning problem, leading to uniform convergence guarantees.
By combining our results with those of Balcan et al.
, we show how to simultaneously learn both an application-speciﬁc metric and linkage algorithm.
Our second main contribution is a comprehensive empirical evaluation of our proposed methods, enabled by new algorithmic insights for efﬁciently learning application-speciﬁc algorithms and metrics from sample clustering instances.
For any ﬁxed clustering instance, we show that we can use an execution tree data structure to efﬁciently construct a coarse partition of the joint parameter space so that on each region the output clustering is constant.
Roughly speaking, the execution tree compactly describes all possible sequences of merges the linkage algorithm might make together with the parameter settings for the algorithm and metric that lead to that merge sequence.
The learning procedure proposed by Balcan et al.
(2017) takes a more combinatorial approach, resulting in partitions of the parameter space that have many unnecessary regions and increased overall running time.
Balcan et al.
(2018a)
and Balcan et al.
(2018b) also use an execution tree approach for different algorithm families, however their speciﬁc approaches to enumerating the tree are not efﬁcient enough to be used in our setting.
We show that using a depth-ﬁrst traversal of the execution tree leads to signiﬁcantly reduced memory requirements, since in our setting the execution tree is shallow but very wide.
Using our efﬁcient implementations, we evaluate our learning algorithms on several real world and synthetic clustering applications.
We learn the best algorithm and metric for clustering applications derived from MNIST, CIFAR-10,
Omniglot, Places2, and a synthetic rings and disks distribution.
Across these different tasks the optimal clustering algorithm and metric vary greatly.
Moreover, in most cases we achieve signiﬁcant improvements in clustering quality over standard clustering algorithms and metrics.
Related work.
Gupta and Roughgarden (2017) introduced the theoretical framework for analyzing algorithm conﬁguration problems that we study in this work.
They provide sample complexity guarantees for greedy algorithms for canonical subset selection problems including the knapsack problem, maximum weight independent set, and machine scheduling.
Some recent works provide sample complexity guarantees for learning application-speciﬁc clustering algorithms.
Balcan et al.
(2017) consider several parameterized families of linkage based clustering algorithms, one of which is a special case of the family studied in this paper.
Their sample complexity results are also based on showing that for a single clustering instance, we can ﬁnd a partitioning of the algorithm parameter space into regions where the output clustering is constant.
The families of linkage procedures they study have a single parameter, while our linkage algorithm and metric families have multiple.
Moreover, they suppose we are given a ﬁxed metric for each clustering instance and do not study the problem of learning an application-speciﬁc metric.
Balcan et al.
(2018b) study the related problem of learning the best initialization procedure and local search method to use in a clustering algorithm inspired by Lloyd’s method for k -means clustering.
Their sample complexity results are again based on demonstrating that for any clustering instance, there exists a partitioning of the parameter space on which the algorithm’s output is constant.
The parameter space partitions in both of these related works are deﬁned by linear separators.
Due to the interactions between the distance metric and the linkage algorithm, our partitions are deﬁned by quadratic functions.
The procedures proposed by prior work for ﬁnding an empirically optimal algorithm for a collection of problem instances roughly fall into two categories: combinatorial approaches and approaches based on an execution-tree data structure.
Gupta and Roughgarden (2017) and Balcan et al.
(2017) are two examples of the combinatorial approach.
They show that the boundaries in the constant-output partition of the algorithm parameter space always occur at the solutions to ﬁnitely many equations that depend on the problem instance.
To ﬁnd an empirically optimal algorithm, they ﬁnd all solutions to these problem-dependent equations to explicitly construct a partition of the parameter space.
Unfortunately, only a small subset of the solutions are actual boundaries in the partition.
Consequently, their partitions contain many extra regions and suffer from long running times.
The execution-tree based approaches ﬁnd the coarsest possible partitioning of the parameter space such that the algorithm output is constant.
Balcan et al.
(2018b)
and Balcan et al.
(2018a)
both use execution trees to ﬁnd empirically optimal algorithm parameters for different algorithm families.
However, the speciﬁc algorithms used to construct and enumerate the execution tree are different from those explored in this paper and are not suitable in our setting.
L EARNING C LUSTERING A LGORITHMS
The problem we study is as follows.
Let X be a data domain.
A clustering instance consists of a point set S = { x 1 , . . .
, x n } ⊂ X and an (unknown) target clustering Y =
( C 1 , . . .
, C k ) , where the sets C 1 , . . .
, C k partition S into k clusters.
Linkage-based clustering algorithms output a hierarchical clustering of the input data, represented by a cluster tree.
We measure the agreement of a cluster tree T with the target clustering Y =
( C 1 , . . .
, C k ) in terms of the
Hamming distance between Y and the closest pruning of T into k clusters (i.e., k disjoint subtrees that contain all the leaves of T ).
More formally, we deﬁne the loss (cid:96) ( T, Y ) =
min P 1 ,...,P k min σ ∈ S n 1 | S | (cid:80) ki =1 | C i \ P σ i | , where A \ B denotes set difference, the ﬁrst minimum is over all prunings P 1 , . . .
, P k of the cluster tree T , and the second minimum is over all permutations of the k cluster indices.
This formulation allows us to handle the case where each clustering task has a different number of clusters , and where the desired number might not be known in advance.
Our analysis applies to any loss function (cid:96) measuring the quality of the output cluster tree T , but we focus on the Hamming distance for simplicity.
Given a distribution D over clustering instances (i.e., point sets together with target clusterings), our goal is to ﬁnd the algorithm A from a family A with the lowest expected loss for an instance sampled from D .
As training data, we assume that we are given an i.i.d.
sample of clustering instances annotated with their target clusterings drawn from the application distribution D .
We study linkage-based clustering algorithms.
These algorithms construct a hierarchical clustering of a point set by starting with each point belonging to a cluster of its own and then they repeatedly merge the closest pair of clusters until only one remains.
There are two distinct notions of distance at play in linkage-based algorithms: ﬁrst, the notion of distance between pairs of points (e.g., Euclidean distance between feature vectors, edit distance between strings, or the Jaccard distance between sets).
Second, these algorithms must deﬁne a distance function between clusters, which we refer to as a merge function to avoid confusion.
A merge function D deﬁnes the distance between a pair of clusters A, B ⊂ X in terms of the pairwise distances given by a metric d between their points.
For example, single linkage uses the merge function D min ( A, B ; d ) = min a ∈ A,b ∈ B d ( a, b ) and complete linkage uses the merge function
D max ( A, B ; d ) = max a ∈ A,b ∈ B d ( a, b ) .
Our parameterized family of linkage-based clustering algorithms allows us to vary both the metric used to measure distances between points, as well as the merge function used to measure distances between clusters.
To vary the metric, we suppose we have access to L metrics d 1 , . . .
, d L deﬁned on our data universe X , and our goal is to ﬁnd the best convex combination of those metrics.
That is, for any parameter vector β ∈ ∆ L = { β ∈ [0 , 1] L | (cid:80) i β i = 1 } , we deﬁne a metric d β ( x, x (cid:48) )
= (cid:80) i β i · d i ( x, x (cid:48) ) .
This deﬁnition is suitable across a wide range of applications, since it allows us to learn the best combination of a given set of metrics for the application at hand.
Similarly, for varying the merge function, we suppose we have L (cid:48) merge functions D 1 , . . .
, D L (cid:48) .
For any parameter α ∈ ∆ L (cid:48) , deﬁne the merge function
D α
( A, B ; d ) =
(cid:80)
i
α
i D i
( A, B ; d ) .
For each pair of parameters β ∈ ∆ L and α ∈ ∆ L (cid:48) , we obtain a different clustering algorithm (i.e., one that repeatedly merges the pair of clusters minimizing D α ( · , · ; d β ) ).
Pseudocode for this method is given in Algorithm 1.
In the pseudocode, clusters are represented by binary trees with leaves corresponding to the points belonging to that cluster.
For any clustering instance S ⊂ X , we let A α , β ( S ) denote the cluster tree output by Algorithm 1 when run with parameter vectors α and β .
Let N =
{ Leaf( x 1 ) , . . .
, Leaf( x n ) } be the initial set of nodes (one leaf per point).
While |N| >(a) Let A, B ∈ N be the clusters in N minimizing
D α
( A, B ; d β ) .
(b) Remove clusters A and B from N and add Node( A, B ) to N . 3.
Return the cluster tree (the only element of N ).
First, we provide sample complexity results that hold for any collection of metrics d 1 , . . .
, d L and any collection of merge functions D 1 , . . .
, D L (cid:48) that belong to the following family:
Deﬁnition 1.
A merge function D is 2-point-based if for any pair of clusters A, B ⊂ X and any metric d , there exists a pair of points (
a, b ) ∈
A × B such that D
( A, B ; d ) =
d ( a, b ) .
Moreover, the pair of points deﬁning the merge distance must depend only on the ordering of pairwise distances.
More formally, if d and d (cid:48) are two metrics s.t.
for all a, a (cid:48) ∈ A and b, b (cid:48) ∈ B , we have d ( a, b ) ≤ d ( a (cid:48) , b (cid:48) )
if and only if d (cid:48) ( a, b ) ≤ d (cid:48) ( a (cid:48) , b (cid:48) ) , then D ( A, B ; d ) =
d ( a, b ) implies that
D ( A, B ; d (cid:48) )
=
d (cid:48) ( a, b ) .
For example, both single and complete linkage are 2-point-based merge functions, since they output the distance between the closest or farthest pair of points, respectively.
Theorem 1.
Fix any metrics d 1 , . . .
, d L , 2-point-based merge functions D 1 , . . .
, D L (cid:48) , and distribution D over clustering instances with at most n points.
For any parameters (cid:15) > 0 and δ > 0 , let ( S 1 , Y 1 ) , . . .
, ( S N , Y N ) be an i.i.d.
sample of N = O (cid:16) 1 (cid:15) 2 (cid:16) ( L (cid:48)
+ L ) 2 L (cid:48) log (cid:16)
[Equation]
L (cid:48)
+ L ) 2 L (cid:48)
n
[Equation] [Equation]
(cid:17) clustering instances with target clusterings drawn from D .
Then with probability at least 1 − δ over the draw of the sample, we have
[Equation]
The key step in the proof of Theorem 1 is to show that for any clustering instance S with target clustering Y , the function ( α , β ) (cid:55)→ (cid:96) ( A α , β ( S ) , Y ) is piecewise constant with not too many pieces and where each piece is simple.
Intuitively, this guarantees that for any collection of clustering instances, we cannot see too much variation in the loss of the algorithm on those instances as we vary over the parameter space.
In Appendix A we use this fact to bound the empirical Rademacher complexity of the learning problem and obtain the uniform convergence guarantee in Theorem 1.
In the remainder of this section, we prove the key structural property.
We let ζ =
( α , β ) ∈
∆ L (cid:48) × ∆ L denote a pair of parameter vectors for Algorithm 1, viewed as a vector in R L (cid:48)
+ L .
Our parameter space partition will be induced by the sign-pattern of M quadratic functions.
Deﬁnition 2 (Sign-pattern Partition) .
The sign-pattern partition of R p induced M functions f 1 , . . .
, f M : R p
→ R is deﬁned as follows:
Let F : R p
→ {± 1 } M be the function F ( ζ )
= (cid:0) sign( f 1 ( ζ )) , . .
, sign( f M ( ζ )) (cid:1) .
Two points ζ , ζ (cid:48)
∈ R p belong to the same region in the partition
iff F ( ζ ) =
F ( ζ (cid:48) ) .
Each region is of the form Z = { ζ ∈ R p | F ( ζ ) =
b } , for some sign-pattern vector b ∈ {± 1 } M .
We show that for any ﬁxed metrics d 1 , . . .
, d L and clustering instance S
= { x 1 , . . .
, x n } ⊂ X , we can ﬁnd a signpattern partitioning of ∆ L induced by linear functions such that, on each region, the ordering over pairs of points in S induced by the metric d β is constant.
An important consequence of this result is that for each region Z in this partitioning of ∆ L , the following holds: For any 2-point-based merge function D and any pair of clusters A, B ⊂ S , there exists a pair of points ( a, b ) ∈
A × B such that D
( A, B ; d β ) =
d β ( a, b ) for all β ∈ Z .
In other words, restricted to β parameters belonging to Z , the same pair of points ( a, b ) deﬁnes the D -merge distance for the clusters A and B .
Lemma 1.
Fix any metrics d 1 , . . .
, d L and a clustering instance S ⊂ X .
There exists a set H of O ( | S | 4 ) linear functions mapping R L to R with the following property: if two metric parameters β , β (cid:48) ∈ ∆ L belong to the same region in the sign-pattern partition induced by H , then the ordering over pairs of points in S given by d β and d β (cid:48) are the same.
That is, for all points a, b, a (cid:48) , b (cid:48) ∈ S we have d β ( a, b ) ≤ d β ( a (cid:48) , b (cid:48) )
iff d β (cid:48) ( a, b ) ≤ d β (cid:48)
( a (cid:48) , b (cid:48) ) .
Proof sketch.
For any pair of points a, b ∈ S , the distance d β ( a, b ) is a linear function of the parameter β .
Therefore, for any four points a, b, a (cid:48) , b (cid:48) ∈ S , we have that d β ( a, b ) ≤ d β ( a (cid:48) , b (cid:48) )
iff h a,b,a (cid:48) ,b (cid:48) ( β ) ≤ 0 , where h a,b,a (cid:48) ,b (cid:48) is the linear function given by h a,b,a (cid:48) ,b (cid:48) ( β ) =
d β ( a, b ) − d β ( a (cid:48) , b (cid:48) ) .
Let H =
{ h a,b,a (cid:48) ,b (cid:48) | a, b, a (cid:48) , b (cid:48) ∈ S } be the collection of all such linear functions arising from any subset of 4 points.
On each region of the sign-pattern partition induced by H , all comparisons of pairwise distances in S are ﬁxed, implying that the ordering over pairs of points in S is ﬁxed.
Building on Lemma 1, we now prove the main structural property of Algorithm 1.
We argue that for any clustering instance S ⊂ X , there is a partition induced by quadratic functions of ∆ L (cid:48) × ∆ L ⊂ R L (cid:48)
+ L over α and β into regions such that on each region, the ordering over all pairs of clusters according to the merge distance D α ( · , · ; d β ) is ﬁxed.
This implies that for all ( α , β ) in one region of the partition, the output of Algorithm 1 when run on S is constant, since the algorithm output only depends on the ordering over pairs of clusters in S given by D α ( · , · ; d β ) .
Lemma 2.
Fix any metrics d 1 , . . .
, d L , any 2-point-based merge functions D 1 , . . .
, D L (cid:48) , and clustering instance
S ⊂ X .
There exists a set Q of O ( | S | 4 L (cid:48) ) quadratic functions deﬁned on R L (cid:48)
+ L so that if parameters ( α , β ) and ( α (cid:48) , β (cid:48) ) belong to the same region of the sign-pattern partition induced by Q , then the ordering over pairs of clusters in S given by D α ( · , · ; d β ) and D α (cid:48) ( · , · ; d β (cid:48) ) is the same.
That is, for all clusters A, B, A (cid:48) , B (cid:48)
⊂ S , we have that
[Equation]
Proof sketch.
Let H be the linear functions constructed in Lemma 1 and ﬁx any region Z in the sign-pattern partition induced by H .
For any i ∈ [ L (cid:48) ] , since the merge function D i is 2-point-based and the ordering over pairs of points according to d β ( · , · ) in the region Z is ﬁxed, for any clusters
A, B, A (cid:48) , B (cid:48)
⊂ S we can ﬁnd points a i , b i , a (cid:48)
i , b (cid:48)
i such that D i ( A, B ; d β ) =
d β ( a i , b i ) and D i ( A (cid:48) , B (cid:48) ; d β ) =
d β ( a (cid:48)
i , b (cid:48) i ) for all β ∈ R .
Therefore, expanding the deﬁnition of D α , we have that D α ( A, B ; d β ) ≤ D
α
( A (cid:48) , B (cid:48) ;
d β ) iff q A,B,A (cid:48) ,B (cid:48)
( α , β ) ≤ 0 , where q A,B,A (cid:48) ,B (cid:48)
( α , β ) =
(cid:80) i (cid:80) j
α i β j ( d j ( a i , b i ) − d j ( a (cid:48) i , b (cid:48) i )) .
Observe that the coefﬁcients of each quadratic function depend only on 4 L (cid:48) points in S , so there are only O ( | S | 4 L (cid:48) ) possible quadratics of this from collected across all regions Z in the sign-pattern partition induced by H and all subsets of 4 clusters.
Together with H , this set of quadratic functions partitions the joint parameter space into regions where the ordering over all pairs of clusters is ﬁxed.
A consequence of Lemma 2 is that for any clustering instance S with target clustering Y , the function ( α , β ) (cid:55)→ (cid:96) ( A α , β ( S ) , Y ) is piecewise constant, where the constant partitioning is the sign-pattern partition induced by O ( | S | 4 L (cid:48) ) quadratic functions.
The proof of Theorem 1 now follows from using this fact to bound the empirical Rademacher complexity of the learning problem.
Extensions.
The above analysis can be extended to handle several more general settings.
First, we can accommodate many speciﬁc merge functions that are not included in the 2-point-based family, at the cost of increasing the number of quadratic functions |Q| needed in Lemma 2.
For example, if one of the merge functions is average linkage,
D avg ( A, B ; d ) = 1 | A |·| B | (cid:80) a ∈ A,b ∈ B d ( a, b ) , then |Q| will be exponential in the dataset size n .
Fortunately, our sample complexity analysis depends only on log( |Q| ) , so this still leads to non-trivial sample complexity guarantees (though the computational algorithm selection problem becomes harder).
We can also extend the analysis to more intricate methods for combining the metrics and merge functions.
For example, our analysis applies to polynomial combinations of metrics and merges at the cost of increasing the complexity of the functions deﬁning the piecewise constant partition.
E FFICIENT A LGORITHM S ELECTION
In this section we provide efﬁcient algorithms for learning low-loss clustering algorithms and metrics for applicationspeciﬁc distributions D deﬁned over clustering instances.
We begin by focusing on the special case where we have a single metric and our goal is to learn the best combination of two merge functions (i.e., L = 1 and L (cid:48)
= 2 ).
This special case is already algorithmically interesting.
Next, we show how to apply similar techniques to the case of learning the best combination of two metrics when using the complete linkage merge function (i.e., L = 2 and L (cid:48)
= 1 ).
Finally, we discuss how to generalize our techniques to other cases.
Learning the Merge Function.
We will use the following simpliﬁed notation for mixing two base merge functions
D
( A, B ; d ) and D 1 ( A, B ; d ) : for each parameter α ∈ [0 , 1] , let
D α
( A, B ; d ) =
(1 − α ) D
( A, B ; d ) + αD 1 ( A, B ; d ) denote the convex combination with weight (1 − α ) on D 0 and weight α on D 1 .
We let A merge α ( S ; D 0 , D 1 ) denote the cluster tree produced by the algorithm with parameter α , and A merge ( D 0 , D 1 ) =
{ A merge α ( · ; D 0 , D 1 ) | α ∈ [0 , 1] } denote the parameterized algorithm family.
𝛼 ∈ [0,1] 𝛼 ∈
[0,1] 𝛼 ∈ (½,1] 𝛼 ∈ [0,½] 𝛼 ∈ [0,½] 𝛼 ∈ (½,1]
Our goal is to design efﬁcient procedures for ﬁnding the algorithm from A merge ( D 0 , D 1 ) (and more general families) that has the lowest average loss on a sample of labeled clustering instances ( S 1 , Y 1 ) , . . .
, ( S N , Y N ) where Y i =
( C ( i ) 1 , . . .
, C ( i ) k i ) is the target clustering for instance S i .
Recall that the loss function (cid:96) ( T, Y ) computes the Hamming distance between the target clustering Y and the closest pruning of the cluster tree T .
Formally, our goal is to solve the following optimization problem: argmin
[Equation]
The key challenge is that, for a ﬁxed clustering instance S we can partition the parameter space [0 , 1] into ﬁnitely many intervals such that for each interval
I , the cluster tree output by the algorithm A merge α
( S ; D 0 , D 1 ) is the same for every parameter in α ∈ I .
It follows that the loss function is a piecewise constant function of the algorithm parameter.
Therefore, the optimization problem is non-convex and the loss derivative is zero wherever it is deﬁned, rendering gradient descent and similar algorithms ineffective.
We solve the optimization problem by explicitly computing the piecewise constant loss function for each instance S i .
That is, for instance i
we ﬁnd a collection of discontinuity locations
=
c ( i )< . . .
< c ( i ) M i = 1 and values v ( i ) 1 , . .
, v ( i ) M i ∈
R
so that for each j ∈ [ M i ] , running the algorithm on instance S i with a parameter in [ c ( i ) j − 1 , c ( i ) j ) has loss equal to v ( i ) j .
Given this representation of the loss function for each of the N instances, ﬁnding the parameter with minimal average loss can be done in O ( M log( M )) time, where M = (cid:80) i M i is the total number of discontinuities from all N loss functions.
The bulk of the computational cost is incurred by computing the piecewise constant loss functions, which we focus on for the rest of the section.
We exploit a more powerful structural property of the algorithm family to compute the piecewise constant losses: for a clustering instance S and any length t , the sequence of ﬁrst t merges performed by the algorithm is a piecewise constant function of the parameter (our sample complexity results only used that the ﬁnal tree is piecewise constant).
For length t = 0 , the partition is a single region containing all parameters in [0 , 1] , since every algorithm trivially starts with the empty sequence of merges.
For each length t > 0 , the piecewise constant partition for the ﬁrst t merges is a reﬁnement of the partition for t − 1 merges.
We can represent this sequence of partitions using a partition tree, where each node in the tree is labeled by an interval, the nodes at depth t describe the partition of [0 , 1] after t merges, and edges represent subset relationships.
This tree represents all possible execution paths for the algorithm family when run on the instance
S as we vary the algorithm parameter.
In particular, each path from the root node to a leaf corresponds to one possible sequence of merges.
We therefore call this tree the execution tree of the algorithm family when run on S .
Figureshows an example execution tree for the family A merge (D min , D max ) .
To ﬁnd the piecewise constant loss function for a clustering instance S , it is sufﬁcient to enumerate the leaves of the execution tree and compute the corresponding losses.
The following result, proved in Appendix B, shows that the execution tree for A merge ( D 0 , D 1 ) is well deﬁned.
Lemma 3.
For any merge functions D 0 and D 1 and any clustering instance S , the execution tree for A merge (D 0 , D 1 ) when run on S is well deﬁned.
That is, there exists a partition tree s.t.
for any node v at depth t , the same sequence of ﬁrst t merges is performed by A merge α for all α in node v ’s interval.
The fundamental operation required to perform a depth-ﬁrst traversal of the execution tree is ﬁnding a node’s children.
That is, given a node, its parameter interval [ α lo , α hi ) , and the set of clusters at that node C 1 , . . .
, C m , ﬁnd all possible merges that will be chosen by the algorithm for α ∈ [ α lo , α hi ) .
We know that for each pair of merges ( C i , C j ) and ( C (cid:48)
i , C (cid:48) j ) , there is a single critical parameter value where the algorithm switches from preferring to merge ( C i , C j ) to ( C (cid:48)
i , C (cid:48) j ) .
A direct algorithm that runs in O ( m 4 ) time for ﬁnding the children of a node in the execution tree is to compute all O ( m 4 ) critical parameter values and test which pair of clusters will be merged on each interval between
𝐷 " distance 𝛼 𝛼 𝐶 % ,𝐶 ’ 𝐶 % ,𝐶 ( 𝐶 ’ ,𝐶 ( 𝑐 %( 𝑐 %’ (a) First iteration 𝐷 " distance 𝛼 𝛼 $% 𝛼 &’ 𝐶 ) ,𝐶 + 𝐶 ) ,𝐶 , 𝐶 + ,𝐶 , 𝑐 ) 𝑐 + 𝐶 + ,𝐶 , wins 𝐶 ) ,𝐶 , wins 𝐶 ) ,𝐶 + wins (b) Final output consecutive critical parameters.
We provide a more efﬁcient algorithm that runs in time O ( m 2 M ) , where M ≤ m 2 is the number of children of the node.
Fix any node in the execution tree.
Given the node’s parameter interval I =
[ α lo , α hi ) and the set of clusters C 1 , . . .
, C m resulting from that node’s merge sequence, we use a sweep-line algorithm to determine all possible next merges and the corresponding parameter intervals.
First, we calculate the merge for α = α lo by enumeration in O ( m 2 ) time.
Suppose clusters C i and C j are the optimal merge for α .
We then determine the largest value α (cid:48) for which C i and C j are still merged by solving the linear equation
D α ( C i , C j ) =
D α
( C k , C l ) for all other pairs of clusters C k and C l , keeping track of the minimal solution larger than α .
Since there are only O ( m 2 ) alternative pairs of clusters, this takes O ( m 2 ) time.
Denote the minimal solution larger than α by c ∈
I .
We are guaranteed that A merge α (cid:48) will merge clusters C i and C j for all α (cid:48) ∈
[ α, c ) .
We repeat this procedure starting from α
= c
to determine the next merge and corresponding interval, and so on, sweeping through the α parameter space until α ≥ α hi .
Algorithm 2 in Appendix B provides pseudocode for this approach and Figure 2 shows an example.
Our next result bounds the running time of this procedure.
Lemma 4.
Let C 1 , . .
, C m be a collection of clusters, D 0 and D 1 be any pair of merge functions, and [ α lo , α hi ) be a subset of the parameter space.
If there are M distinct cluster pairs C i , C j that minimize
D α
( C i , C j ) for values of α ∈ [ α lo , α hi ) , then the running time of Algorithm 2 is O
( Mm 2 K ) , where K is the cost of evaluating the merge functions D 0 and D 1 .
With this, our algorithm for computing the piecewise constant loss function for an instance S performs a depth-ﬁrst traversal of the leaves of the execution tree for A merge (D 0 , D 1 ) , using Algorithm 2 to determine the children of each node.
When we reach a leaf in the depth-ﬁrst traversal, we have both the corresponding parameter interval I ⊂ [0 , 1] , as well as the cluster tree T such that A merge α ( S )
=
T for all α ∈
I .
We then evaluate the loss (cid:96) ( T, Y ) to get one piece of the piecewise constant loss function.
Detailed pseudocode for this approach is given in Algorithm 3 in Appendix B.
Theorem 2.
Let S = { x 1 , . . .
, x n } be a clustering instance and D 0 and D 1 be any two merge functions.
Suppose that the execution tree of A merge (D 0 , D 1 ) on S has E edges.
Then the total running time of Algorithm 3 is O
( En 2 K ) , where
K is the cost of evaluating D 0 and D 1 once.
We can express the running time of Algorithm 3 in terms of the number of discontinuities of the function α (cid:55)→
A merge α ( S ) .
There is one leaf of the execution tree for each constant interval of this function, and the path from the root of the execution tree to that leaf is of length n − 1 .
Therefore, the cost associated with that path is at most O ( Kn 3 ) and enumerating the execution tree to obtain the piecewise constant loss function for a given instance S spends O
( Kn 3 ) time for each constant interval of α
(cid:55)→ A merge α ( S ) .
In contrast, the combinatorial approach of Balcan et al.
(2017) requires that we run α -linkage once for every interval in their partition of [0 , 1] , which always contains O ( n 8 ) intervals (i.e., it is a reﬁnement of the piecewise constant partition).
Since each run of α -Linkage costs O ( Kn 2 log n ) time, this leads to a running time of O
( Kn 10 log n ) .
The key advantage of our approach stems from the fact that the number of discontinuities of the function α (cid:55)→ A merge α ( S ) is often several orders of magnitude smaller than O ( n 8 ) .
Learning the Metric.
Next we present efﬁcient algorithms for computing the piecewise constant loss function for a single clustering instance when interpolating between two base metrics and using complete linkage.
For a pair of ﬁxed base metrics d 0 and d 1 and any parameter value β ∈ [0 , 1] , deﬁne d β ( a, b ) =
(1 − β ) d 0 ( a, b ) + βd 1 ( a, b ) .
Let
A metric β ( S ; d 0 , d 1 ) denote the output of running complete linkage with the metric d β , and A metric ( d 0 , d 1 ) denote the family of all such algorithms.
We prove that for this algorithm family, the execution tree is well deﬁned and provide an efﬁcient algorithm for ﬁnding the children of each node in the execution tree, allowing us to use a depth-ﬁrst traversal to ﬁnd the piecewise constant loss function for any clustering instance S .
Lemma 5.
For any metrics d 0 and d 1 and any clustering instance S , the execution tree for the family A metric (d 0 , d 1 ) when run on S is well deﬁned.
That is, there exists a partition tree s.t.
for any node v at depth t , the same sequence of ﬁrst t merges is performed by A metric β for all β in node v ’s interval.
Next, we provide an efﬁcient procedure for determining the children of a node v in the execution tree of A metric (d 0 , d 1 ) .
Given the node’s parameter interval I =
[ β lo , β hi ) and the set of clusters C 1 , . . .
, C m resulting from that node’s sequence of merges, we again use a sweep-line procedure to ﬁnd the possible next merges and the corresponding parameter intervals.
First, we determine the pair of clusters that will be merged by A metric β for β =
β lo by enumerating all pairs of clusters.
Suppose the winning pair is C i and C j and let x ∈ C
i and x (cid:48) ∈
C
j be the farthest pair of points between the two clusters.
Next, we ﬁnd the largest value of β (cid:48) for which we will still merge the clusters C i and C j .
To do this, we enumerate all other pairs of clusters C k and C l and all pairs of points
y ∈ C k and y (cid:48)
∈ C l , and solve the linear equation d β ’ ( x, x (cid:48) )
=
d β ( y, y (cid:48) ) , keeping track of the minimal solution larger than β .
Denote the minimal solution larger than β by c .
We are guaranteed that for all β (cid:48) ∈ [ β, c ) , the pair of clusters merged will be C i and C j .
Then we repeat the process with β
=
c to ﬁnd the next merge and corresponding interval, and so on, until β ≥ β hi .
Pseudocode for this procedure is given in Algorithm 4 in
Appendix B.
The following Lemma bounds the running time:
Lemma 6.
Let C 1 , . .
, C m be a collection of clusters, d 0 and d 1 be any pair of metrics, and [ β lo , β hi ) be a subset of the parameter space.
If there are M distinct cluster pairs C i , C j that complete linkage would merge when using the metric d β for β ∈ [ β lo , β hi ) , the running time of Algorithm 4 is O
( Mn 2 ) .
Our algorithm for computing the piecewise constant loss function for an instance S is almost identical for the case of the merge function: it performs a depth-ﬁrst traversal of the leaves of the execution tree for A metric (d 0 , d 1 ) , using
Algorithm 4 to determine the children of each node.
Detailed pseudocode for this approach is given in Algorithm 5 in
Appendix B. The following Theorem characterizes the overall running time of the algorithm.
Theorem 3.
Let S = { x 1 , . . .
, x n } be a clustering instance and d 0 and d 1 be any two merge functions.
Suppose that the execution tree of A metric (d 0 , d 1 ) on S has E edges.
Then the total running time of Algorithm 5 is O
( En 2 ) .
Extension to general algorithm families.
In this section we introduced efﬁcient algorithm selection procedures for two special cases where the algorithm family has a single parameter.
Working with a one-dimensional parameter space allowed us to compute partitions of the parameter space using efﬁcient sweep-line procedures.
The key additional challenge when working with higher-dimensional parameter spaces is that the partition of the parameter space given by each level of the execution tree becomes more complicated, deﬁned by the sign-pattern partition induced by a collection of quadratic functions.
Efﬁcient execution-tree based algorithm selection procedures for our more general algorithm family will require an analog of the sweep-line algorithms described above that efﬁciently compute the children of a node in the execution tree, together with a minimal number of quadratic functions describing the partition.
It may also be promising to explore combinatorial-style algorithm selection procedures.
As a consequence of Lemma 2, for any collection of N clustering instances with at most n points, we can ﬁnd O
( Nn 4 L (cid:48) )
quadratic functions whose sign-pattern partition divides the parameter space into polynomially many regions where the algorithm output is constant on every instance.
It follows that we can ﬁnd an empirically optimal parameter in polynomial time if we are able to identify a parameter from each region of the sign-pattern partition in polynomial time.
For example, when the parameter space is R 2 , for each vertex v of each region in the sign-pattern partition, there is a pair of quadratic functions such that q i ( v ) =
q j ( v ) = 0 .
By solving this equation for all pairs of quadratic functions, we are able to ﬁnd a parameter from each region.
An interesting future direction is to develop efﬁcient analogs for higher-dimensional parameter spaces.
E XPERIMENTS
In this section we evaluate the performance of our learning procedures when ﬁnding algorithms for application-speciﬁc clustering distributions.
Our experiments demonstrate that the best algorithm for different applications varies greatly, and that in many cases we can have large gains in cluster quality using a mixture of base merge functions or metrics.
Experimental setup.
In each experiment we deﬁne a distribution D over clustering tasks.
For each clustering instance, the loss of the cluster tree output by a clustering algorithm is measured in terms of the loss (cid:96) ( S, Y ) , which computes the Hamming distance between the target clustering and the closest pruning of the cluster tree.
We draw N sample clustering tasks from the given distribution and use the algorithms developed in Section 3 to exactly compute the average empirical loss for every algorithm in one algorithm family.
The theoretical results from Section 2 ensure that these plots generalize to new samples from the same distribution, so our focus is on demonstrating empirical improvements in clustering loss obtained by learning the merge function or metric.
Clustering distributions.
Most of our clustering distributions are generated from classiﬁcation datasets by sampling a subset of the dataset and using the class labels as the target clustering.
We brieﬂy describe our instance distributions together with the metrics used for each below.
Complete details for the distributions can be found in Appendix C.
MNIST Subsets.
The MNIST dataset (LeCun et al., 1998) contains images of hand-written digits from 0 to 9 .
We generate a random clustering instance from this data by choosing k = 5 random digits and sampling 200 images from each digit, giving a total of n = 1000 images.
We measure distance between any pairs of images using the Euclidean distance between their pixel intensities.
CIFAR-10 Subsets.
We similarly generate clustering instances from the CIFAR-10 dataset (Krizhevsky, 2009).
To generate an instance, we select k = 5 classes at random and then sample 50 images from each class, leading to a total of n = 250 images.
We measure distances between examples using the cosine distance between feature embedding extracted from a pre-trained Google inception network (Szegedy et al., 2015).
Omniglot Subsets.
The Omniglot dataset (Lake et al., 2015) contains written characters from 50 alphabets, with a total of 1623 different characters.
To generate a clustering instance from the omniglot data, we choose one of the alphabets at random, we sample k from { 5 , . . .
, 10 } uniformly at random, choose k random characters from the alphabet, and include all 20 examples of those characters in the clustering instance.
We use two metrics for the omniglot data: ﬁrst, cosine distances between neural network feature embeddings of the character images from a simpliﬁed version of
AlexNet (Krizhevsky et al., 2012).
Second, each character is also described by a “stroke”, which is a sequence of coordinates ( x t , y t )
Tt =1 describing the trajectory of the pen when writing the character.
We hand-design a metric based on the stroke data: the distance between a pair of characters is the average distance from a point on either stroke to its nearest neighbor on the other stroke.
A formal deﬁnition is given in the appendix.
Places2 Subsets.
The Places2 dataset consists of images of 365 different place categories, including “volcano”, “gift shop”, and “farm” (Zhou et al., 2017).
To generate a clustering instance from the places data, we choose k randomly from { 5 , . .
10 } , choose k random place categories, and then select 20 random examples from each chosen category.
We use two metrics for this data distribution.
First, we use cosine distances between feature embeddings generated by a
VGG16 network (Simonyan and Zisserman, 2015) pre-trained on ImageNet (Deng et al., 2009).
Second, we compute color histograms in HSV space for each image and use the cosine distance between the histograms.
Places
Diverse Subsets.
We also construct an instance distribution from a subset of the Places2 classes which have diverse color histograms.
We expect the color histogram metric to perform better on this distribution.
To generate a clustering instance, we pick k = 4 classes from aquarium, discotheque, highway, iceberg, kitchen, lawn, stage-indoor, underwater ocean deep, volcano, and water tower.
We include 50 randomly sampled images from each chosen class, leading to a total of n = 200 points per instance.
Synthetic Rings and Disks.
We consider a two dimensional synthetic distribution where each clustering instance hasclusters, where two are ring-shaped and two are disk-shaped.
To generate each instance we sample 100 points uniformly at random from each ring or disk.
The two rings have radiuses 0 .
4 and 0 . 8 , respectively,
and are both centered at the origin.
The two disks have radius 0 .
and are centered at (1 . 5 , 0 . 4) and (1 . 5 , − 0 . 4) , respectively.
For this data, we measure distances between points in terms of the Euclidean distance between them.
Results
Learning the Merge Function.
Figure 3 shows the average loss when interpolating between single and complete linkage as well as between average and complete linkage for each of the clustering instance distributions described above.
For each value of the parameter α ∈ [0 , 1] , we report the average loss over N = 1000 i.i.d.
instances drawn from the corresponding distribution.
We see that the optimal parameters vary across different clustering instances.
For example, when interpolating between single and complete linkage, the optimal parameters are α = 0 .
874 for MNIST, α = 0 .
98 for CIFAR-10, α = 0 .
179 for Rings and Disks, and α = 0 .
931 for Omniglot.
Moreover, using the parameter that is optimal for one distribution on another would lead to signiﬁcantly worse clustering performance.
Next, we also see that for different distributions, it is possible to achieve non-trivial improvements over single, complete, and average linkage by interpolating between them.
For example, on the Rings and Disks distribution we see an improvement of almost 0 .
2 error, meaning that an additional 20% of the data is correctly clustered.
[Figure]
Learning the Metric.
Next we consider learning the best metric for the Omniglot, Places2, and Places
Diverse instance distributions.
Each of these datasets is equipped with one hand-designed metric and one metric based on neural-network embeddings.
The parameter β = 0 corresponds to the hand-designed metric, while β = 1 corresponds to the embedding.
Figure 4 shows the empirical loss for each parameter β averaged over N = 4000 samples for each distribution.
On all three distributions the neural network embedding performs better than the hand-designed metric, but we can achieve non-trivial performance improvements by mixing the two metrics.
On Omniglot, the optimal parameter is at β =
.which improves the Hamming error by 0 . 091 , meaning that we correctly cluster nearly 10% more of the data.
For the
Places2 distribution we see an improvement of approximately 1% with the optimal parameter being β = 0 .
88 , while for the Places2 Diverse distribution the improvement is approximately 3 .
4% with the optimal β being 0 .
[Figure]
Number of Discontinuities.
The efﬁciency of our algorithm selection procedures stems from the fact that their running time scales with the true number of discontinuities in each loss function, rather than a worst-case upper bound.
Of all the experiments we ran, interpolating between single interpolating between single and complete linkage for MNIST had the most discontinuities per loss function with an average of 362 .
6 discontinuities per function.
Given that these instances have n = 1000 points, this leads to a speedup of roughly n 8 / 362 .
6 ≈ 2 .
76 × 10 21 over the combinatorial algorithm that solves for all O ( n 8 ) critical points and runs the clustering algorithm once for each.
Table 1 in Appendix C shows the average number of discontinuities per loss function for all of the above experiments
[Figure]
C ONCLUSION
In this work we study both the sample and algorithmic complexity of learning linkage-based clustering algorithms with low loss for speciﬁc application domains.
We give strong bounds on the number of sample instances required from an application domain in order to ﬁnd an approximately optimal algorithm from a rich family of algorithms that allows us to vary both the metric and merge function used by the algorithm.
We complement our sample complexity results with efﬁcient algorithms for ﬁnding empirically optimal algorithms for a sample of instances.
Finally, we carry out experiments on both real-world and synthetic clustering domains demonstrating that our procedures can often ﬁnd algorithms that signiﬁcantly outperform standard linkage-based clustering algorithms.
An important future direction for learning linkage based clustering algorithms is the design of efﬁcient algorithm selection procedures for higher dimensional parameter spaces.
A CKNOWLEDGEMENTS
This work was supported in part by NSF grants CCF-1535967, IIS-1618714, IIS-1901403, CCF-1910321, SES-1919453, an Amazon Research Award, a Bloomberg Research Grant, a Microsoft Research Faculty Fellowship and by the generosity of Eric and Wendy Schmidt by recommendation of the Schmidt Futures program.
A A PPENDIX FOR L EARNING C LUSTERING A LGORITHMS
We begin by providing complete proofs for the piecewise structural Lemmas from the main body.
Lemma 1.
Fix any metrics d 1 , . . .
, d L and a clustering instance S ⊂ X .
There exists a set H of O ( | S | 4 ) linear functions mapping R L to R with the following property: if two metric parameters β , β (cid:48) ∈ ∆ L belong to the same region in the sign-pattern partition induced by H , then the ordering over pairs of points in S given by d β and d β (cid:48) are the same.
That is, for all points a, b, a (cid:48) , b (cid:48) ∈ S we have d β ( a, b ) ≤ d β ( a (cid:48) , b (cid:48) )
iff d β (cid:48) ( a, b ) ≤ d β (cid:48)
( a (cid:48) , b (cid:48) ) .
Proof.
Let S be any clustering instance and ﬁx points a, b, a (cid:48) , b (cid:48) ∈ S .
For any parameter β ∈ ∆ L , by deﬁnition of d β , we have that
[Equation]
b ) ≤ d β ( a (cid:48) , b (cid:48) )
⇐⇒
L (cid:88) i =
β i
d i ( a, b ) ≤
L (cid:88) i =
β i
d i ( a (cid:48) , b (cid:48) )
⇐⇒
L (cid:88) i =
β i ( d i ( a, b ) − d i ( a (cid:48) , b (cid:48) )) ≤ 0 .
Deﬁne the linear function h a,b,a (cid:48) ,b (cid:48) ( β ) =
(cid:80) Li
=1 β i
( d i ( a, b ) − d i ( a (cid:48) , b (cid:48) )) .
Then we have that d β ( a, b ) ≤ d β ( a (cid:48) , b (cid:48) ) if h a,b,a (cid:48) ,b (cid:48) ( β ) ≤ 0 and d β ( a, b ) >
d β ( a (cid:48) , b (cid:48) )
if h a,b,a (cid:48) ,b (cid:48) ( β ) > 0 .
Let H =
{ h a,b,a (cid:48) ,b (cid:48) | a, b, a (cid:48) , b (cid:48) ∈ S } be the collection of all such linear functions collected over all possible subsets of 4 points in S .
Now suppose that β and β (cid:48) belong to the same region in the sign-pattern partition induced by H .
For any points a, b, a (cid:48) , b (cid:48) ∈ S , we are guaranteed that sign( h a,b,a (cid:48) ,b (cid:48) ( β ))
=
sign( h a,b,a (cid:48) ,b (cid:48)
( β (cid:48) )) , which by the above arguments imply that d β ( a, b ) ≤ d β ( a (cid:48) , b (cid:48) )
iff d β (cid:48) ( a, b ) ≤ d β (cid:48)
( a (cid:48) , b (cid:48) ) , as required.
Lemma 2.
Fix any metrics d 1 , . . .
, d L , any 2-point-based merge functions D 1 , . . .
, D L (cid:48) , and clustering instance
S ⊂ X .
There exists a set Q of O ( | S | 4 L (cid:48) ) quadratic functions deﬁned on R L (cid:48)
+ L so that if parameters ( α , β ) and ( α (cid:48) , β (cid:48) ) belong to the same region of the sign-pattern partition induced by Q , then the ordering over pairs of clusters in S given by D α ( · , · ; d β ) and D α (cid:48) ( · , · ; d β (cid:48) ) is the same.
That is, for all clusters A, B, A (cid:48) , B (cid:48)
⊂ S , we have that
D α
( A, B ; d β ) ≤ D
α
( A (cid:48) , B (cid:48) ; d β ) iff D α (cid:48)
( A, B ; d β (cid:48) )
≤ D α (cid:48)
( A (cid:48) , B (cid:48) ; d β (cid:48) ) .
Proof.
From Lemma 1, we know we can ﬁnd a set H of O ( | S | 4 ) linear functions deﬁned on R L that induce a signpattern partition of the β parameter space ∆
L ⊂ R L into regions where the ordering over pairs of points according to the d β distance is constant.
Now let Z ⊂ ∆ L be any region of the sign-pattern partition of ∆ L induced by H .
From Lemma 1, we know that for all parameters β ∈ Z , the ordering over pairs of points in S according to d β is ﬁxed.
For any 2-point-based merge function, the pair of points used to measure the distance between a pair of clusters depends only on the ordering of pairs of points according to distance.
Therefore, since D 1 , . . .
, D L (cid:48) are all 2-point-based, we know that for any pair of clusters ( A, B ) and each merge function index
i ∈
[ L (cid:48) ] , there exists a pair of points ( a i , b i ) ∈
A × B such that
D i ( A, B ; d β ) =
d β ( a i , b i ) for all β ∈ Z .
In other words, all of the merge functions measure distances between A and
B using a ﬁxed pair of points for all values of the metric parameter β in the region Z .
Similarly, let A (cid:48) , B (cid:48)
⊂ S be any other pair of clusters and ( a (cid:48)
i , b (cid:48) i ) ∈ A (cid:48)
× B (cid:48) be the pairs of points deﬁning D
i ( A (cid:48) , B (cid:48) ; d β ) for each i ∈
[ L (cid:48) ] .
Then for all β ∈ Z , we have that
[Equation]
⇐⇒
[Equation]
Now deﬁne
[Table]
function
[Equation]
For all β ∈ Z , we are guaranteed that D α ( A, B ; d β ) ≤ D α
( A (cid:48) , B (cid:48) ; d β ) if and only if q A,B,A (cid:48) ,B (cid:48)
( α , β ) ≤ 0 .
Notice that the coefﬁcients of q A,B,A (cid:48) ,B (cid:48) only depend on 4 L (cid:48) points in S , which implies that if we collect these quadratic functions over all quadruples of clusters
A, B, A (cid:48) , B (cid:48)
⊂ S , we will only obtain O ( | S | 4 L (cid:48) ) different quadratic functions.
These O ( | S | 4 L (cid:48) )
functions induce a sign-pattern partition of ∆ L (cid:48)
× Z for which the desired conclusion holds.
Next, observe that the coefﬁcients in the quadratic functions deﬁned above do not depend on the region Z we started with.
It follows that the same set of O ( | S | 4 L (cid:48) ) quadratic functions partition any other region Z (cid:48) in the sign-pattern partition induced by H so that the claim holds on ∆ L (cid:48)
× Z (cid:48) .
Now let Q contain the linear functions in H (viewed as quadratic functions over R L (cid:48)
+ L by placing a zero coefﬁcient on all quadratic terms and terms depending on α ), together with the O ( | S | 4 L (cid:48) ) quadratic functions deﬁned above.
Then we have that |Q| =
O ( | S | 4 + | S | 4 L (cid:48) )
=
O ( | S | 4 L (cid:48) ) .
Now suppose that ( α , β ) and ( α (cid:48) , β (cid:48) ) belong to the same region of the sign-pattern partition of ∆ L (cid:48) × ∆ L ⊂ R L (cid:48)
+ L induced by the quadratic functions Q .
Since Q contains H , this implies that β and β (cid:48) belong to the same region Z in the sign-pattern partition induced by H .
Moreover, since
Q contains all the quadratic functions deﬁned in (1), it follows that D α ( A, B ; d β ) ≤ D
α
( A (cid:48) , B (cid:48) ; d β ) if and only if
D α (cid:48)
( A, B ; d β (cid:48) )
≤ D α (cid:48)
( A (cid:48) , B (cid:48) ; d β (cid:48) ) , as required.
Our proof of Theorem 1 depends crucially on the number of regions in the sign-pattern partition induced by a collection of functions.
Based on the work of Buck (1943), we know that when the functions f 1 , . . .
, f M are linear , then the number of regions is at most (3 M ) p —a substantial improvement over the naive bound of 2 M .
We can also leverage this result to bound the number of regions by (3 M ) p 2 + p when the functions are quadratic by viewing each quadratic function as a linear function on a ( p 2 + p ) -dimensional space.
The following result summarizes these facts.
Lemma 7.
Let T be the number of regions in the sign-pattern partition of R p induced by f 1 , . . .
, f M : R p
→
R .
The following statements hold.
If the functions are linear, i.e., f i ( ζ ) = w (cid:62) i ζ + r i for w i ∈ R p and r i ∈ R , then T ≤ (3 M ) p . 2.
If the functions are quadratic, i.e., f i ( ζ ) = ζ (cid:62) Q i ζ + w (cid:62) i ζ + r i for Q i ∈ R p × p , w i ∈
R p and r i ∈ R , then T ≤ (3 M ) p 2 + p .
Proof.
The proof of the ﬁrst statement follows from the work of Buck (1943) which shows that if H is a collection of M hyperplanes in R p , then the number of connected components of R p \ H is at most (3 M ) p .
To connect this to the sign-pattern partitioning induced by the collection of linear functions f 1 , . .
. , f M , let H be the set of M hyperplanes deﬁned by { ζ ∈ R p | f i ( ζ ) = 0 } for i ∈
[ M ] .
The connected components of R p \ H correspond exactly to the sign-pattern partition of the functions f 1 , . . .
, f M , and by the result of Buck (1943), it follows that the number of regions in the partition is at most (3 M ) p .
Equivalently, we know that |{ F ( ζ ) | ζ ∈ R p }| ≤ (3 M ) p , where
F ( ζ ) =
(cid:0) sign( f 1 ( ζ )) , . .
, sign( f M ( ζ )) (cid:1) is the sign-pattern function.
That is, F takes at most (3 M ) p distinct values.
Next we use the ﬁrst statement to prove the second statement.
Let ϕ : R p
→ R p 2 + p be the function that maps a vector ζ to the vector containing all products of pairs of elements from ζ concatenated to the beginning of ζ :
[Equation]
Let q ( ζ ) =
ζ (cid:62) Q ζ + w (cid:62) ζ + r be a quadratic function where Q ∈ R p × p , w ∈ R p , and r ∈ R .
Now let
[Equation]
Then we have that q ( ζ ) = v (cid:62) ϕ
( ζ ) .
In other words, q is a linear function of ϕ ( ζ ) .
This guarantees that we can ﬁnd M linear functions h 1 , . . .
, h M : R p 2 + p
→ R such that f i ( ζ )
=
h i ( ϕ ( ζ )) for all i ∈ [ M ] .
Let H : R p 2 + p → {± 1 } M be the sign-pattern function for h 1 , . .
, h M .
Then we have
[Equation]
where the last inequality follows from the ﬁrst statement for linear functions.
It follows that the number of regions in the sign-pattern partition induced by M quadratic functions is at most (3 M ) p 2 + p .
With this, we are ready to prove Theorem 1.
Theorem 1.
Fix any metrics d 1 , . . .
, d L , 2-point-based merge functions D 1 , . . .
, D L (cid:48) , and distribution D over clustering instances with at most n points.
For any parameters (cid:15) > 0 and δ > 0 , let ( S 1 , Y 1 ) , . . .
, ( S N , Y N ) be an i.i.d.
sample of N =
O
[Equation] [Equation]
[Equation]
log
[Equation]
clustering instances with target clusterings drawn from D .
Then with probability at least 1 − δ over the draw of the sample, we have
[Equation]
Proof of Theorem 1.
Our goal is to provide a uniform convergence guarantee that ensures the sample loss of any pair of parameters ( α , β ) is close to its expected cost on the underlying distribution.
Towards that end, deﬁne the family of loss functions F = { f α , β : ( S, Y )
(cid:55)→ (cid:96) ( A α , β ( S ) , Y ) | ( α , β ∈ ∆ L (cid:48) × ∆ L } , where the function f α , β ﬁxes algorithm parameters and maps each clustering instance S with target clustering Y to that algorithm’s loss when run on ( S, Y ) .
We will bound the empirical Rademacher complexity of F to prove uniform convergence guarantees.
Let
S =
{ ( S 1 , Y 1 ) , . . .
, ( S N , Y N ) } be a sample of clustering instances with target clusterings drawn from the distribution
D .
The empirical Rademacher complexity of the class of functions F on the sample S is given by
[Equation]
where σ is a vector of N independent Rademacher random variables.
From Lemma 2, we know that we can ﬁnd a collection of O ( n 4 L (cid:48) ) quadratic functions for each clustering instance S i so that the output of Algorithm 1 when run on S i is constant on each region of the induced sign-pattern partition of the parameter space.
Let Q be the collection of O ( Nn 4 L (cid:48) )
quadratic functions collected across all N clustering instances
S 1 , . . .
, S N .
Whenever two parameter settings ( α , β ) and ( α (cid:48) , β (cid:48) ) belong to the same region in the sign-pattern partition induced by Q , we know that for all instance indices i , we have (cid:96) α , β ( S i , Y i ) =
(cid:96) α (cid:48) , β (cid:48)
( S i , Y i ) .
Applying the second statement of Lemma 7, we know that this partition has at most T = (3 |Q| )
( L (cid:48)
+ L )
+( L (cid:48)
+ L ) regions.
This implies that we can ﬁnd a collection of T parameter vectors ( α 1 , β 1 ) , . . .
, ( α T , β T ) (by taking one from each region in the partition) so that the following holds: for every ( α , β ) ∈ ∆ L (cid:48) × ∆ L , there exists a j ∈ [ T ] such that for all clustering instances ( S i , Y i ) in the sample S we have f α , β ( S i , Y i ) =
f α j , β j ( S i , Y i ) .
With this, we can bound the empirical
Rademacher complexity as follows:
[Equation]
Now, using the fact that the losses take values in [0 , 1] and the supremum is over only T distinct elements, we can apply
Massart’s Lemma (Massart, 2000) to obtain ˆ R ( F , S )
=
O ( (cid:112) log( T ) /N ) .
Taking logs and simplifying our bound on T , we have that log( T ) =
O (cid:0) ( L (cid:48)
+ L ) 2 L (cid:48)
log( Nn ) (cid:1) , giving the following bound on the empirical Rademacher complexity of F :
[Equation]
Next, from standard Rademacher complexity bounds (Bartlett and Mendelson, 2002), we are guaranteed that with probability at least 1 − δ we have that
[Equation]
where the last equality follows from the fact that for any x, y ≥
we have √ x + √ y ≤ (cid:112) 2( x + y ) .
Since the right hand side goes to zero as N grows, it remains to choose N sufﬁciently large that the right hand side is bounded by (cid:15) .
Let A =
( L (cid:48)
+ L ) 2 L (cid:48) and B =
( L (cid:48)
+ L ) 2 L (cid:48) log( n ) + log(1 /δ )
so that the error bound is given by O (cid:18)(cid:113)
A log( N )+ B N (cid:19) .
We are guaranteed that (cid:113) A log( N )+ B N ≤ (cid:15) whenever N ≥ 1 (cid:15) 2 ( A log( N ) + B ) .
Using the fact that for a ≥ 1 and b ≥we have that x ≥ 4 a log(2 a ) + 2 b implies that x ≥ a log( x ) + b (e.g., see Lemma A.2 in (Shalev-Shwartz and BenDavid, 2014)), it follows that when N ≥ 4 A(cid:15) 2 log 2 A(cid:15)
+ 2 B(cid:15)
2 =
O (cid:0) 1 (cid:15)
( A log A(cid:15) 2 + B ) (cid:1) , we also have (cid:113)
A log( N )+ B N ≤ (cid:15) .
Substituting A and B and simplifying the expression completes the proof.
B A PPENDIX FOR E FFICIENT A LGORITHM S ELECTION B. L EARNING THE M ERGE F UNCTION
In this section we provide details for learning the best combination of two merge functions.
We also give detailed pseudocode for our sweepline algorithm for ﬁnding the children of a node in the execution tree (see Algorithm 2) and for the complete algorithm (see Algorithm 3).
Algorithm 2 Find all merges for A merge (D 0 , D 1 )
Input: Set of clusters C 1 , . .
, C m , merge functions D 0 , D 1 , parameter interval [ α lo , α hi ) .
Let M = ∅ be the initially empty set of possible merges.
Let I = ∅ be the initially empty set of parameter intervals.
Let α = α lo . 4.
While α < α hi : (a) Let C i ,
C j be the pair of clusters minimizing (1 − α ) · D 0 ( C i , C j ) + α · D 1 ( C i , C j ) .
(b) For each k, l ∈ [ m ] , let c kl = ∆ 0 / (∆ 0 − ∆ 1 ) , where ∆ p =
D p ( C i , C j ) − D p ( C k , C l ) for p ∈ { 0 , 1 } .
(c) Let c = min (cid:0) { c kl | c kl > α } ∪ { α hi } (cid:1) .
(d
Add merge ( C i , C j ) to M and [ α, c ) to I .
(e
Set α = c . 5.
Return M and I .
Lemma 3.
For any merge functions D 0 and D 1 and any clustering instance S , the execution tree for A merge (D 0 , D 1 ) when run on S is well deﬁned.
That is, there exists a partition tree s.t.
for any node v at depth t , the same sequence of ﬁrst t merges is performed by A merge α for all α in node v ’s interval.
Proof.
The proof is by induction on the depth t .
The base case is for depth t = 0 , in which case we can use a single node whose interval is [0 , 1] .
Since all algorithms in the family start with an empty-sequence of merges, this satisﬁes the execution tree property.
Now suppose that there is a tree of depth t with the execution tree property.
If t = | S | − 1 then we are ﬁnished, since the algorithms in A merge (D 0 , D 1 ) make exactly | S | − 1 merges.
Otherwise, consider any leaf node v of the depth t tree with parameter interval I v .
It is sufﬁcient to show that we can partition I v into subintervals such that for α in each subinterval the next merge performed is constant.
By the inductive hypothesis, we know that the ﬁrst t merges made by A merge α are the same for all α ∈ I v .
After performing these merges, the algorithm will have arrived at some set of clusters C 1 , . . .
, C m with m = | S | − t .
For each pair of clusters C i and C j , the distance D α ( C i , C j ) =
(1 − α ) D
( C i , C j ) + α D 1 ( C i , C j ) is a linear function of the parameter α .
Therefore, for any clusters C i , C j , C k , and C l , the algorithm will prefer to merge C i and C j over C j and C k for a (possibly empty) sub-interval of I v , corresponding to the values of α ∈ I v where D α ( C i , C j ) <
D α ( C k , C l ) .
For any ﬁxed pair of clusters C i and C j , taking the intersection of these intervals over all other pairs C j and C k guarantees that clusters C i and C j will be merged exactly for parameter values in some subinterval of I v .
For each merge with a non-empty parameter interval, we can introduce a child node of v labeled by that parameter interval.
These children partition I v into intervals where the next merge is constant, as required.
Lemma 4.
Let C 1 , . .
, C m be a collection of clusters, D 0 and D 1 be any pair of merge functions, and [ α lo , α hi ) be a subset of the parameter space.
If there are M distinct cluster pairs C i , C j that minimize
D α
( C i , C j ) for values of α ∈ [ α lo , α hi ) , then the running time of Algorithm 2 is O
( Mm 2 K ) , where K is the cost of evaluating the merge functions D 0 and D 1 .
Proof.
The loop in step 4 of Algorithm 2 runs once for each possible merge, giving a total of M iterations.
Each iteration ﬁnds the closest pair of clusters according to D α using O ( m 2 ) evaluations of the merge functions D 0 and D 1 .
Calculating the critical parameter value c involves solving O ( m 2 ) linear equations whose coefﬁcients are determined by four evaluations of D 0 and D 1 .
It follows that the cost of each iteration is O ( m 2 K ) , where K is the cost of evaluating
D 0 and D 1 , and the overall running time is O
( Mm 2 K ) .
Theorem 2.
Let S = { x 1 , . . .
, x n } be a clustering instance and D 0 and D 1 be any two merge functions.
Suppose that the execution tree of A merge (D 0 , D 1 ) on S has E edges.
Then the total running time of Algorithm 3 is O
( En 2 K ) , where
K is the cost of evaluating D 0 and D 1 once.
Proof.
Fix any node v in the execution tree with m clusters C 1 , . .
, C m and M outgoing edges (i.e., M possible merges from the state represented by v ).
We run Algorithm 2 to determine the children of v , which by Lemma 4 costs
O ( Mn 2 K ) , since m ≤ n .
Summing over all non-leaves of the execution tree, the total cost is O
( En 2 K ) .
In addition to computing the children of a given node, we need to construct the children nodes, but this takes constant time per child.
B. L EARNING THE M ETRIC
In this section we provide details for learning the best combination of two metrics.
We also give detailed pseudocode for our sweepline algorithm for ﬁnding the children of a node in the execution tree (see Algorithm 4) and for the complete algorithm (see Algorithm 5).
Lemma 5.
For any metrics d 0 and d 1 and any clustering instance S , the execution tree for the family A metric (d 0 , d 1 ) when run on S is well deﬁned.
That is, there exists a partition tree s.t.
for any node v at depth t , the same sequence of ﬁrst t merges is performed by A metric β for all β in node v ’s interval.
Proof.
The proof is by induction on the depth t .
The base case is for depth t = 0 , in which case we can use a single node whose interval is [0 , 1] .
Since all algorithms in the family start with an empty-sequence of merges, this satisﬁes the execution tree property.
Now suppose that there is a tree of depth t with the execution tree property.
If t = | S | − 1 then we are ﬁnished, since the algorithms in A metric (d 0 , d 1 ) make exactly | S | − 1 merges.
Otherwise, consider any leaf node v of the depth t tree with parameter interval I v .
It is sufﬁcient to show that we can partition I v into subintervals such that for β in each subinterval the next merge performed is constant.
By the inductive hypothesis, we know that the ﬁrst t merges made by A metric β are the same for all β ∈
I v .
After performing these merges, the algorithm will have arrived at some set of clusters C 1 , . . .
, C m with m = | S | − t .
Recall that algorithms in the family A metric (d 0 , d 1 ) run complete linkage using the metric d β .
Complete linkage can be implemented in such a way that it only makes comparisons between pairwise point distances (i.e., is d β ( x, x (cid:48) ) larger or smaller than d β ( y, y (cid:48) ) ?).
To see this, for any pair of clusters, we can ﬁnd the farthest pair of points between them using only distance comparisons.
And, once we have the farthest pair of points between all pairs of clusters, we can ﬁnd the pair of clusters to merge by again making only pairwise comparisons.
It follows that if two parameters β and β (cid:48) have the same outcome for all pairwise distance comparisons, then the next merge to be performed must be the same.
We use this observation to partition the interval I v into subintervals where the next merge is constant.
For any pair of points x, x (cid:48) ∈ S , the distance d β ( x, x (cid:48) )
= (1 − β ) d 0 ( x, x (cid:48) )
+ β d 1 ( x, x (cid:48) ) is a linear function of the parameter β .
Therefore, for any points x, x (cid:48) , y, y (cid:48) ∈ S , there is at most one critical parameter value where the relative order of d β ( x, x (cid:48) ) and d β ( y, y (cid:48) ) changes.
Between these O ( | S | 4 ) critical parameter values, the ordering on all pairwise merges is constant, and the next merge performed by the algorithm will also be constant.
Therefore, there must exist a partitioning of I v into at most O ( | S | 4 ) sub-intervals such that the next merge is constant on each interval.
We let the children of v correspond to the coarsest such partition.
Lemma 6.
Let C 1 , . .
, C m be a collection of clusters, d 0 and d 1 be any pair of metrics, and [ β lo , β hi ) be a subset of the parameter space.
If there are M distinct cluster pairs C i , C j that complete linkage would merge when using the metric d β for β ∈ [ β lo , β hi ) , the running time of Algorithm 4 is O
( Mn 2 ) .
Proof.
The loop in step 4 of Algorithm 4 runs once for each possible merge, giving a total of M iterations.
Each iteration ﬁnds the merge performed by complete linkage using the d β metric, which takes O ( n 2 ) time, and then solves
O ( n 2 ) linear equations to determine the largest value of β (cid:48) such that the same merge is performed.
It follows that the cost of each iteration is O ( n 2 ) , leading to an overall running time of O
( Mn 2 ) .
Note, we assume that the pairwise distances d β ( x, x (cid:48) ) can be evaluated in constant time.
This can always be achieved by precomputing two n × n distance matrices for the base metrics d 0 and d 1 , respectively.
Theorem 3.
Let S = { x 1 , . . .
, x n } be a clustering instance and d 0 and d 1 be any two merge functions.
Suppose that the execution tree of A metric (d 0 , d 1 ) on S has E edges.
Then the total running time of Algorithm 5 is O
( En 2 ) .
Proof.
Fix any node v in the execution tree with m clusters C 1 , . .
, C m and M outgoing edges (i.e., M possible merges from the state represented by v ).
We run Algorithm 4 to determine the children of v , which by Lemma 6 costs
O ( Mn 2 ) .
Summing over all non-leaves of the execution tree, the total cost is O
( En 2 ) .
C A PPENDIX FOR E XPERIMENTS
Clustering distributions.
set
j
farthest
Let r be the root node of the execution tree with r. N = { ( x 1 ) , . . .
, ( x n ) } and r.I =
Let s be a stack of execution tree nodes, initially containing the root r . 3.
Let T = ∅ be the initially empty set of possible cluster trees.
Let I = ∅ be the initially empty set of intervals.
While the stack s is not empty: (a) Pop execution tree node e off stack s .
(b) If e. N has a single cluster, add e. N to T and e.I to I .
(c) Otherwise, for each merge ( C i , C j ) and interval I c returned by Algorithm 4 run on e. N and e.I : i. Let c be a new node with state given by e. N after merging C i and C j and c.
I =
I c .
ii.
Push c onto the stack s . 6.
Return T and I .
MNIST Subsets.
Our ﬁrst distribution over clustering tasks corresponds to clustering subsets of the MNIST dataset (LeCun et al., 1998), which contains 80,000 hand-written examples of the digits 0 through 9 .
We generate a random clustering instance from the MNIST data as follows:
ﬁrst, we select k = 5 digits from { 0 , . .
, 9 } at random, then we randomly select 200 examples belonging to each of the selected digits, giving a total of n = 1000 images.
The target clustering for this instance is given by the ground-truth digit labels.
We measure distances between any pair of digits in terms of the the Euclidean distance between their images represented as vectors of pixel intensities.
CIFAR-10 Subsets.
We also consider a distribution over clustering tasks that corresponds to clustering subsets of the
CIFAR-10 dataset (Krizhevsky, 2009).
This dataset contains 6000 images of each of the following classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck.
Each example is a 32 × 32 color image with 3 color channels.
We pre-process the data to obtain neural-network feature representations for each example.
We include 50 randomly rotated and cropped versions of each example and obtain feature representations from layer ‘in4d’ of a pre-trained Google inception network.
This gives a 144 -dimensional feature representation for each of theexamples (50 randomly rotated copies of the 6000 examples for each of the 10 classes).
We generate clustering tasks from CIFAR-10 as follows:
ﬁrst, select k = 5 classes at random, then choose 50 examples belonging to each of the selected classes, giving a total of n = 250 images.
The target clustering for this instance is given by the ground-truth class labels.
We measure distance between any pair of images as the distance between their feature embeddings.
Omniglot Subsets.
Next, we consider a distribution over clustering tasks corresponding to clustering subsets of the
Omniglot dataset (Lake et al., 2015).
The Omniglot dataset consists of written characters from 50 different alphabets with a total of 1623 different characters.
The dataset includes 20 examples of each character, leading to a total of 32, examples.
We generate a random clustering instance from the Omniglot data as follows:
ﬁrst, we choose one of the alphabets at random.
Next, we choose k uniformly in { 5 , . .
. , 10 } and choose k random characters from that alphabet.
The clustering instance includes 20 k examples and the target clustering is given by the ground-truth character labels.
We use two different distance metrics on the Omniglot dataset.
First, we use the cosine distance between neural network feature embeddings.
The neural network was trained to perform digit classiﬁcation on MNIST.
Second, each example has both an image of the written character, as well as the stroke trajectory (i.e., a time series of ( x, y ) coordinates of the tip of the pen when the character was written).
We also use the following distance deﬁned in terms of the strokes:
Given two trajectories s = ( x t , y t )
Tt =1 and s (cid:48)
=
( x (cid:48) t , y (cid:48) t )
Tt =1 , we deﬁne the distance between them by d ( s, s (cid:48) )
=
[Equation]
Tt =
[Equation]
d (cid:0) ( x t , y t ) , s (cid:48)
[Equation]
+ (cid:80) T
[Equation]
t =
[Equation]
d (cid:0) ( x (cid:48) t , y (cid:48) t ) , s (cid:1)(cid:17) , where d (cid:0) ( x t , y t ) , s (cid:48) (cid:1) denotes the Euclidean distance from the point ( x t , y t ) to the closest point in s (cid:48) .
This is the average distance from any point from either trajectory to the nearest point on the other trajectory.
This hand-designed metric provides a complementary notion of distance to the neural network feature embeddings.
Places2 Subsets.
The Places2 dataset consists of images of 365 different place categories, including “volcano”, “gift shop”, and “farm” (Zhou et al., 2017).
To generate a clustering instance from the places data, we choose k randomly from { 5 , . .
10 } , choose k random place categories, and then select 20 random examples from each chosen category.
We restrict ourselves to the ﬁrst 1000 images from each class.
We use two metrics for this data distribution.
First, we use cosine distances between feature embeddings generated by a VGG16 network pre-trained on imagenet.
In particular, we use the activations just before the fully connected layers, but after the max-pooling is performed, so that we have 512 -dimensional feature vectors.
Second, we compute color histograms in HSV space for each image and use the cosine distance between the histograms.
In more detail, we partition the hue space into 8 bins, the saturation space into 2 bins, and the value space into 4 bins, resulting in a 64-dimensional histogram counting how frequently each quantized color appears in the image.
Two images are close under this metric if they contain similar colors.
Places
Diverse Subsets.
We also construct an instance distribution from a subset of the Places2 classes which have diverse color histograms.
We expect the color histogram metric to perform better on this distribution.
To generate a clustering instance, we pick k = 4 classes from aquarium, discotheque, highway, iceberg, kitchen, lawn, stage-indoor, underwater ocean deep, volcano, and water tower.
We include 50 randomly sampled images from each chosen class, leading to a total of n = 200 points per instance.
Synthetic Rings and Disks.
We consider a two dimensional synthetic distribution where each clustering instance hasclusters, where two are ring-shaped and two are disk-shaped.
To generate each instance we sample 100 points uniformly at random from each ring or disk.
The two rings have radiuses 0 .
4 and 0 . 8 , respectively,
and are both centered at the origin.
The two disks have radius 0 .
and are centered at (1 . 5 , 0 . 4) and (1 . 5 , − 0 . 4) , respectively.
For this data, we measure distances between points in terms of the Euclidean distance between them.
Average Number of Discontinuities .
Next we report the average number of discontinuities in the loss function for a clustering instance sampled from each of the distributions described above for each of the learning tasks we consider.
In all cases, the average number of discontinuities is many orders of magnitude smaller than the upper bounds.
The metric learning problems tend to have more discontinuities than learning the best merge function.
Surprisingly, even though our only worst-case bound on the number of discontinuities when interpolating between average and complete linkage is exponential in n , the empirical number of discontinuities is always smaller than for interpolating between single and complete linkage.
The results are shown in Table 1.
[Table]