lib/rumale/clustering/hdbscan.rb in rumale-0.13.8 vs lib/rumale/clustering/hdbscan.rb in rumale-0.14.0
- old
+ new
@@ -32,12 +32,12 @@
# @param min_cluster_size [Integer/Nil] The minimum size of cluster. If nil is given, it is set equal to min_samples.
# @param metric [String] The metric to calculate the distances.
# If metric is 'euclidean', Euclidean distance is calculated for distance between points.
# If metric is 'precomputed', the fit and fit_transform methods expect to be given a distance matrix.
def initialize(min_samples: 10, min_cluster_size: nil, metric: 'euclidean')
- check_params_integer(min_samples: min_samples)
- check_params_type_or_nil(Integer, min_cluster_size: min_cluster_size)
+ check_params_numeric(min_samples: min_samples)
+ check_params_numeric_or_nil(min_cluster_size: min_cluster_size)
check_params_string(metric: metric)
check_params_positive(min_samples: min_samples)
@params = {}
@params[:min_samples] = min_samples
@params[:min_cluster_size] = min_cluster_size || min_samples
@@ -51,11 +51,11 @@
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for cluster analysis.
# If the metric is 'precomputed', x must be a square distance matrix (shape: [n_samples, n_samples]).
# @return [HDBSCAN] The learned cluster analyzer itself.
def fit(x, _y = nil)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
fit_predict(x)
self
end
@@ -63,10 +63,10 @@
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to be used for cluster analysis.
# If the metric is 'precomputed', x must be a square distance matrix (shape: [n_samples, n_samples]).
# @return [Numo::Int32] (shape: [n_samples]) Predicted cluster label per sample.
def fit_predict(x)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
distance_mat = @params[:metric] == 'precomputed' ? x : Rumale::PairwiseMetric.euclidean_distance(x)
@labels = partial_fit(distance_mat)
end