@@ -17,7 +17,7 @@ abstract type AbstractSplitter end
1717
1818Determine whether or not a `ClusterTree` should be further divided.
1919"""
20- function should_split (clt,splitter:: AbstractSplitter )
20+ function should_split (clt, splitter:: AbstractSplitter )
2121 abstract_method (splitter)
2222end
2323
2626
2727Divide `clt` using the strategy implemented by `splitter`.
2828"""
29- function split! (clt,splitter:: AbstractSplitter )
29+ function split! (clt, splitter:: AbstractSplitter )
3030 abstract_method (splitter)
3131end
3232
@@ -37,24 +37,24 @@ Used to split an `N` dimensional `ClusterTree` into `2^N` children until at most
3737`nmax` points are contained in node.
3838"""
3939Base. @kwdef struct DyadicSplitter <: AbstractSplitter
40- nmax:: Int = typemax (Int)
40+ nmax:: Int = typemax (Int)
4141end
4242
43- function should_split (node:: ClusterTree ,splitter:: DyadicSplitter )
43+ function should_split (node:: ClusterTree , splitter:: DyadicSplitter )
4444 return length (node) > splitter. nmax
4545end
4646
47- function split! (parentcluster:: ClusterTree ,:: DyadicSplitter )
48- d = ambient_dimension (parentcluster)
47+ function split! (parentcluster:: ClusterTree , :: DyadicSplitter )
48+ d = ambient_dimension (parentcluster)
4949 clusters = [parentcluster]
5050 rec = container (parentcluster)
5151 rec_center = center (rec)
52- for i in 1 : d
52+ for i = 1 : d
5353 pos = rec_center[i]
5454 nel = length (clusters) # 2^(i-1)
55- for _ in 1 : nel
55+ for _ = 1 : nel
5656 clt = popfirst! (clusters)
57- append! (clusters,_binary_split! (clt,i, pos;parentcluster))
57+ append! (clusters, _binary_split! (clt, i, pos; parentcluster))
5858 end
5959 end
6060 return clusters
6565
6666Used to split a `ClusterTree` in half along the largest axis.
6767"""
68- @ Base. kwdef struct GeometricSplitter <: AbstractSplitter
69- nmax:: Int = 50
68+ Base. @ kwdef struct GeometricSplitter <: AbstractSplitter
69+ nmax:: Int = 50
7070end
7171
72- should_split (node:: ClusterTree ,splitter:: GeometricSplitter ) = length (node) > splitter. nmax
72+ should_split (node:: ClusterTree , splitter:: GeometricSplitter ) = length (node) > splitter. nmax
7373
74- function split! (cluster:: ClusterTree ,:: GeometricSplitter )
75- rec = cluster. container
76- wmax, imax = findmax (high_corner (rec) - low_corner (rec))
77- left_node, right_node = _binary_split! (cluster, imax, low_corner (rec)[imax]+ wmax/ 2 )
74+ function split! (cluster:: ClusterTree , :: GeometricSplitter )
75+ rec = cluster. container
76+ wmax, imax = findmax (high_corner (rec) - low_corner (rec))
77+ left_node, right_node = _binary_split! (cluster, imax, low_corner (rec)[imax] + wmax / 2 )
7878 return [left_node, right_node]
7979end
8080
8383
8484Like [`GeometricSplitter`](@ref), but shrinks the children's containters.
8585"""
86- @ Base. kwdef struct GeometricMinimalSplitter <: AbstractSplitter
87- nmax:: Int = 50
86+ Base. @ kwdef struct GeometricMinimalSplitter <: AbstractSplitter
87+ nmax:: Int = 50
8888end
8989
90- should_split (node:: ClusterTree ,splitter:: GeometricMinimalSplitter ) = length (node) > splitter. nmax
90+ should_split (node:: ClusterTree , splitter:: GeometricMinimalSplitter ) = length (node) > splitter. nmax
9191
92- function split! (cluster:: ClusterTree ,:: GeometricMinimalSplitter )
93- rec = cluster. container
94- wmax, imax = findmax (high_corner (rec) - low_corner (rec))
95- mid = low_corner (rec)[imax]+ wmax/ 2
92+ function split! (cluster:: ClusterTree , :: GeometricMinimalSplitter )
93+ rec = cluster. container
94+ wmax, imax = findmax (high_corner (rec) - low_corner (rec))
95+ mid = low_corner (rec)[imax] + wmax / 2
9696 predicate = (x) -> x[imax] < mid
97- left_node,right_node = _binary_split! (cluster,predicate)
97+ left_node, right_node = _binary_split! (cluster, predicate)
9898 return [left_node, right_node]
9999end
100100
101101"""
102102 struct PrincipalComponentSplitter <: AbstractSplitter
103103"""
104- @ Base. kwdef struct PrincipalComponentSplitter <: AbstractSplitter
105- nmax:: Int = 50
104+ Base. @ kwdef struct PrincipalComponentSplitter <: AbstractSplitter
105+ nmax:: Int = 50
106106end
107107
108- should_split (node:: ClusterTree ,splitter:: PrincipalComponentSplitter ) = length (node) > splitter. nmax
108+ should_split (node:: ClusterTree , splitter:: PrincipalComponentSplitter ) = length (node) > splitter. nmax
109109
110- function split! (cluster:: ClusterTree ,:: PrincipalComponentSplitter )
111- pts = cluster. _elements
112- irange = cluster. index_range
113- xc = center_of_mass (cluster)
110+ function split! (cluster:: ClusterTree , :: PrincipalComponentSplitter )
111+ pts = cluster. _elements
112+ irange = cluster. index_range
113+ xc = center_of_mass (cluster)
114114 # compute covariance matrix for principal direction
115- cov = sum (irange) do i
115+ cov = sum (irange) do i
116116 x = coords (pts[i])
117- (x - xc)* transpose (x - xc)
117+ (x - xc) * transpose (x - xc)
118118 end
119- v = eigvecs (cov)[:,end ]
120- predicate = (x) -> dot (x- xc,v) < 0
121- left_node, right_node = _binary_split! (cluster,predicate)
119+ v = eigvecs (cov)[:, end ]
120+ predicate = (x) -> dot (x - xc, v) < 0
121+ left_node, right_node = _binary_split! (cluster, predicate)
122122 return [left_node, right_node]
123123end
124124
125125function center_of_mass (clt:: ClusterTree )
126- pts = clt. _elements
127- loc_idxs = clt. index_range
126+ pts = clt. _elements
127+ loc_idxs = clt. index_range
128128 # w = clt.weights
129- n = length (loc_idxs)
129+ n = length (loc_idxs)
130130 # M = isempty(w) ? n : sum(i->w[i],glob_idxs)
131131 # xc = isempty(w) ? sum(i->pts[i]/M,glob_idxs) : sum(i->w[i]*pts[i]/M,glob_idxs)
132- M = n
133- xc = sum (i-> coords (pts[i])/ M, loc_idxs)
132+ M = n
133+ xc = sum (i -> coords (pts[i]) / M, loc_idxs)
134134 return xc
135135end
136136
@@ -141,19 +141,19 @@ Used to split a `ClusterTree` along the largest dimension if
141141`length(tree)>nmax`. The split is performed so the `data` is evenly distributed
142142amongst all children.
143143"""
144- @ Base. kwdef struct CardinalitySplitter <: AbstractSplitter
145- nmax:: Int = 50
144+ Base. @ kwdef struct CardinalitySplitter <: AbstractSplitter
145+ nmax:: Int = 50
146146end
147147
148- should_split (node:: ClusterTree ,splitter:: CardinalitySplitter ) = length (node) > splitter. nmax
148+ should_split (node:: ClusterTree , splitter:: CardinalitySplitter ) = length (node) > splitter. nmax
149149
150- function split! (cluster:: ClusterTree ,:: CardinalitySplitter )
151- points = cluster. _elements
152- irange = cluster. index_range
153- rec = container (cluster)
154- _, imax = findmax (high_corner (rec) - low_corner (rec))
155- med = median (coords (points[i])[imax] for i in irange) # the median along largest axis `imax`
150+ function split! (cluster:: ClusterTree , :: CardinalitySplitter )
151+ points = cluster. _elements
152+ irange = cluster. index_range
153+ rec = container (cluster)
154+ _, imax = findmax (high_corner (rec) - low_corner (rec))
155+ med = median (coords (points[i])[imax] for i in irange) # the median along largest axis `imax`
156156 predicate = (x) -> x[imax] < med
157- left_node, right_node = _binary_split! (cluster,predicate)
157+ left_node, right_node = _binary_split! (cluster, predicate)
158158 return [left_node, right_node]
159159end
0 commit comments