Class: Rumale::Clustering::PowerIteration
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Clustering::PowerIteration
- Includes:
- Base::ClusterAnalyzer
- Defined in:
- rumale-clustering/lib/rumale/clustering/power_iteration.rb
Overview
PowerIteration is a class that implements power iteration clustering.
Reference
-
Lin, F., and Cohen, W W., “Power Iteration Clustering,” Proc. ICML’10, pp. 655–662, 2010.
Instance Attribute Summary collapse
-
#embedding ⇒ Numo::DFloat
readonly
Return the data in embedded space.
-
#labels ⇒ Numo::Int32
readonly
Return the cluster labels.
-
#n_iter ⇒ Integer
readonly
Return the number of iterations run for optimization.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ PowerIteration
Analysis clusters with given training data.
-
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
-
#initialize(n_clusters: 8, affinity: 'rbf', gamma: nil, init: 'k-means++', max_iter: 1000, tol: 1.0e-8, eps: 1.0e-5, random_seed: nil) ⇒ PowerIteration
constructor
Create a new cluster analyzer with power iteration clustering.
Methods included from Base::ClusterAnalyzer
Constructor Details
#initialize(n_clusters: 8, affinity: 'rbf', gamma: nil, init: 'k-means++', max_iter: 1000, tol: 1.0e-8, eps: 1.0e-5, random_seed: nil) ⇒ PowerIteration
Create a new cluster analyzer with power iteration clustering.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 47 def initialize(n_clusters: 8, affinity: 'rbf', gamma: nil, init: 'k-means++', max_iter: 1000, tol: 1.0e-8, eps: 1.0e-5, random_seed: nil) super() @params = { n_clusters: n_clusters, affinity: affinity, gamma: gamma, init: (init == 'random' ? 'random' : 'k-means++'), max_iter: max_iter, tol: tol, eps: eps, random_seed: random_seed || srand } end |
Instance Attribute Details
#embedding ⇒ Numo::DFloat (readonly)
Return the data in embedded space.
26 27 28 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 26 def @embedding end |
#labels ⇒ Numo::Int32 (readonly)
Return the cluster labels.
30 31 32 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 30 def labels @labels end |
#n_iter ⇒ Integer (readonly)
Return the number of iterations run for optimization
34 35 36 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 34 def n_iter @n_iter end |
Instance Method Details
#fit(x) ⇒ PowerIteration
Analysis clusters with given training data.
68 69 70 71 72 73 74 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 68 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) raise ArgumentError, 'the input affinity matrix should be square' if check_invalid_array_shape(x) fit_predict(x) self end |
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
81 82 83 84 85 86 87 88 |
# File 'rumale-clustering/lib/rumale/clustering/power_iteration.rb', line 81 def fit_predict(x) x = ::Rumale::Validation.check_convert_sample_array(x) raise ArgumentError, 'the input affinity matrix should be square' if check_invalid_array_shape(x) affinity_mat = @params[:affinity] == 'precomputed' ? x : ::Rumale::PairwiseMetric.rbf_kernel(x, nil, @params[:gamma]) @embedding, @n_iter = (affinity_mat, @params[:max_iter], @params[:tol].fdiv(affinity_mat.shape[0])) @labels = line_kmeans_clustering(@embedding) end |