rumale 0.18.6 → 0.19.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +80 -3
  3. data/CHANGELOG.md +45 -0
  4. data/Gemfile +2 -0
  5. data/README.md +5 -36
  6. data/lib/rumale.rb +5 -0
  7. data/lib/rumale/base/base_estimator.rb +2 -0
  8. data/lib/rumale/clustering/dbscan.rb +4 -0
  9. data/lib/rumale/clustering/gaussian_mixture.rb +2 -0
  10. data/lib/rumale/clustering/hdbscan.rb +3 -1
  11. data/lib/rumale/clustering/k_means.rb +2 -1
  12. data/lib/rumale/clustering/k_medoids.rb +5 -1
  13. data/lib/rumale/clustering/mini_batch_k_means.rb +139 -0
  14. data/lib/rumale/clustering/power_iteration.rb +2 -0
  15. data/lib/rumale/clustering/single_linkage.rb +2 -0
  16. data/lib/rumale/dataset.rb +5 -3
  17. data/lib/rumale/decomposition/factor_analysis.rb +2 -0
  18. data/lib/rumale/decomposition/pca.rb +24 -5
  19. data/lib/rumale/ensemble/ada_boost_classifier.rb +3 -0
  20. data/lib/rumale/ensemble/ada_boost_regressor.rb +3 -0
  21. data/lib/rumale/evaluation_measure/function.rb +2 -1
  22. data/lib/rumale/evaluation_measure/normalized_mutual_information.rb +2 -0
  23. data/lib/rumale/evaluation_measure/precision_recall.rb +5 -0
  24. data/lib/rumale/evaluation_measure/roc_auc.rb +3 -0
  25. data/lib/rumale/evaluation_measure/silhouette_score.rb +2 -0
  26. data/lib/rumale/feature_extraction/feature_hasher.rb +14 -1
  27. data/lib/rumale/feature_extraction/hash_vectorizer.rb +1 -0
  28. data/lib/rumale/feature_extraction/tfidf_transformer.rb +113 -0
  29. data/lib/rumale/kernel_approximation/nystroem.rb +1 -1
  30. data/lib/rumale/kernel_machine/kernel_ridge.rb +2 -0
  31. data/lib/rumale/kernel_machine/kernel_svc.rb +1 -1
  32. data/lib/rumale/linear_model/base_linear_model.rb +3 -1
  33. data/lib/rumale/linear_model/base_sgd.rb +1 -1
  34. data/lib/rumale/linear_model/linear_regression.rb +1 -0
  35. data/lib/rumale/linear_model/ridge.rb +1 -0
  36. data/lib/rumale/manifold/mds.rb +2 -0
  37. data/lib/rumale/manifold/tsne.rb +4 -0
  38. data/lib/rumale/metric_learning/neighbourhood_component_analysis.rb +14 -1
  39. data/lib/rumale/model_selection/cross_validation.rb +3 -2
  40. data/lib/rumale/model_selection/grid_search_cv.rb +1 -0
  41. data/lib/rumale/model_selection/k_fold.rb +1 -1
  42. data/lib/rumale/model_selection/shuffle_split.rb +1 -1
  43. data/lib/rumale/multiclass/one_vs_rest_classifier.rb +2 -2
  44. data/lib/rumale/nearest_neighbors/k_neighbors_classifier.rb +1 -0
  45. data/lib/rumale/nearest_neighbors/k_neighbors_regressor.rb +2 -0
  46. data/lib/rumale/nearest_neighbors/vp_tree.rb +1 -1
  47. data/lib/rumale/neural_network/adam.rb +1 -1
  48. data/lib/rumale/neural_network/base_mlp.rb +2 -1
  49. data/lib/rumale/optimizer/ada_grad.rb +3 -0
  50. data/lib/rumale/optimizer/adam.rb +3 -0
  51. data/lib/rumale/optimizer/nadam.rb +5 -0
  52. data/lib/rumale/optimizer/rmsprop.rb +3 -0
  53. data/lib/rumale/optimizer/sgd.rb +3 -0
  54. data/lib/rumale/optimizer/yellow_fin.rb +3 -0
  55. data/lib/rumale/pipeline/pipeline.rb +3 -0
  56. data/lib/rumale/polynomial_model/base_factorization_machine.rb +6 -1
  57. data/lib/rumale/polynomial_model/factorization_machine_classifier.rb +5 -0
  58. data/lib/rumale/polynomial_model/factorization_machine_regressor.rb +5 -0
  59. data/lib/rumale/preprocessing/binarizer.rb +60 -0
  60. data/lib/rumale/preprocessing/l1_normalizer.rb +62 -0
  61. data/lib/rumale/preprocessing/l2_normalizer.rb +2 -1
  62. data/lib/rumale/preprocessing/max_normalizer.rb +62 -0
  63. data/lib/rumale/preprocessing/one_hot_encoder.rb +3 -0
  64. data/lib/rumale/preprocessing/ordinal_encoder.rb +2 -0
  65. data/lib/rumale/preprocessing/polynomial_features.rb +1 -0
  66. data/lib/rumale/probabilistic_output.rb +2 -0
  67. data/lib/rumale/tree/base_decision_tree.rb +2 -0
  68. data/lib/rumale/tree/decision_tree_classifier.rb +1 -0
  69. data/lib/rumale/tree/gradient_tree_regressor.rb +1 -0
  70. data/lib/rumale/utils.rb +1 -0
  71. data/lib/rumale/validation.rb +7 -0
  72. data/lib/rumale/version.rb +1 -1
  73. data/rumale.gemspec +1 -3
  74. metadata +11 -34
@@ -69,7 +69,7 @@ module Rumale
69
69
  n_components = [1, [@params[:n_components], n_samples].min].max
70
70
 
71
71
  # random sampling.
72
- @component_indices = Numo::Int32.cast([*0...n_samples].shuffle(random: sub_rng)[0...n_components])
72
+ @component_indices = Numo::Int32.cast(Array(0...n_samples).shuffle(random: sub_rng)[0...n_components])
73
73
  @components = x[@component_indices, true]
74
74
 
75
75
  # calculate normalizing factor.
@@ -30,6 +30,7 @@ module Rumale
30
30
  def initialize(reg_param: 1.0)
31
31
  raise TypeError, 'Expect class of reg_param to be Float or Numo::DFloat' unless reg_param.is_a?(Float) || reg_param.is_a?(Numo::DFloat)
32
32
  raise ArgumentError, 'Expect reg_param array to be 1-D arrray' if reg_param.is_a?(Numo::DFloat) && reg_param.shape.size != 1
33
+
33
34
  @params = {}
34
35
  @params[:reg_param] = reg_param
35
36
  @weight_vec = nil
@@ -55,6 +56,7 @@ module Rumale
55
56
  @weight_vec = Numo::Linalg.solve(reg_kernel_mat, y, driver: 'sym')
56
57
  else
57
58
  raise ArgumentError, 'Expect y and reg_param to have the same number of elements.' unless y.shape[1] == @params[:reg_param].shape[0]
59
+
58
60
  n_outputs = y.shape[1]
59
61
  @weight_vec = Numo::DFloat.zeros(n_samples, n_outputs)
60
62
  n_outputs.times do |n|
@@ -172,7 +172,7 @@ module Rumale
172
172
  # Start optimization.
173
173
  @params[:max_iter].times do |t|
174
174
  # random sampling
175
- rand_ids = [*0...n_training_samples].shuffle(random: sub_rng) if rand_ids.empty?
175
+ rand_ids = Array(0...n_training_samples).shuffle(random: sub_rng) if rand_ids.empty?
176
176
  target_id = rand_ids.shift
177
177
  # update the weight vector
178
178
  func = (weight_vec * bin_y).dot(x[target_id, true].transpose).to_f
@@ -8,6 +8,7 @@ module Rumale
8
8
  # @note
9
9
  # In version 0.17.0, a new linear model abstract class called BaseSGD is introduced.
10
10
  # BaseLienarModel is deprecated and will be removed in the future.
11
+ # @deprecated Use BaseSGD class instead. This class will be deleted in version 0.20.0.
11
12
  #
12
13
  # BaseLinearModel is an abstract class for implementation of linear estimator
13
14
  # with mini-batch stochastic gradient descent optimization.
@@ -55,7 +56,7 @@ module Rumale
55
56
  samples = @params[:fit_bias] ? expand_feature(x) : x
56
57
  # Initialize some variables.
57
58
  n_samples, n_features = samples.shape
58
- rand_ids = [*0...n_samples].shuffle(random: @rng.dup)
59
+ rand_ids = Array(0...n_samples).shuffle(random: @rng.dup)
59
60
  weight = Numo::DFloat.zeros(n_features)
60
61
  optimizer = @params[:optimizer].dup
61
62
  # Optimization.
@@ -68,6 +69,7 @@ module Rumale
68
69
  # Update weight.
69
70
  loss_gradient = calc_loss_gradient(sub_samples, sub_targets, weight)
70
71
  next if loss_gradient.ne(0.0).count.zero?
72
+
71
73
  weight = calc_new_weight(optimizer, sub_samples, weight, loss_gradient)
72
74
  end
73
75
  split_weight(weight)
@@ -209,7 +209,7 @@ module Rumale
209
209
  l1_penalty = LinearModel::Penalty::L1Penalty.new(reg_param: l1_reg_param) if apply_l1_penalty?
210
210
  # Optimization.
211
211
  @params[:max_iter].times do |t|
212
- sample_ids = [*0...n_samples]
212
+ sample_ids = Array(0...n_samples)
213
213
  sample_ids.shuffle!(random: sub_rng)
214
214
  until (subset_ids = sample_ids.shift(@params[:batch_size])).empty?
215
215
  # sampling
@@ -162,6 +162,7 @@ module Rumale
162
162
  def load_linalg?
163
163
  return false if defined?(Numo::Linalg).nil?
164
164
  return false if Numo::Linalg::VERSION < '0.1.4'
165
+
165
166
  true
166
167
  end
167
168
  end
@@ -164,6 +164,7 @@ module Rumale
164
164
  def load_linalg?
165
165
  return false if defined?(Numo::Linalg).nil?
166
166
  return false if Numo::Linalg::VERSION < '0.1.4'
167
+
167
168
  true
168
169
  end
169
170
  end
@@ -83,6 +83,7 @@ module Rumale
83
83
  def fit(x, _not_used = nil)
84
84
  x = check_convert_sample_array(x)
85
85
  raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
86
+
86
87
  # initialize some varibales.
87
88
  n_samples = x.shape[0]
88
89
  hi_distance_mat = @params[:metric] == 'precomputed' ? x : Rumale::PairwiseMetric.euclidean_distance(x)
@@ -142,6 +143,7 @@ module Rumale
142
143
  def terminate?(old_stress, new_stress)
143
144
  return false if @params[:tol].nil?
144
145
  return false if old_stress.nil?
146
+
145
147
  (old_stress - new_stress).abs <= @params[:tol]
146
148
  end
147
149
 
@@ -89,6 +89,7 @@ module Rumale
89
89
  def fit(x, _not_used = nil)
90
90
  x = check_convert_sample_array(x)
91
91
  raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
92
+
92
93
  # initialize some varibales.
93
94
  @n_iter = 0
94
95
  distance_mat = @params[:metric] == 'precomputed' ? x**2 : Rumale::PairwiseMetric.squared_error(x)
@@ -99,6 +100,7 @@ module Rumale
99
100
  one_vec = Numo::DFloat.ones(x.shape[0]).expand_dims(1)
100
101
  @params[:max_iter].times do |t|
101
102
  break if terminate?(hi_prob_mat, lo_prob_mat)
103
+
102
104
  a = hi_prob_mat * lo_prob_mat
103
105
  b = lo_prob_mat * lo_prob_mat
104
106
  y = (b.dot(one_vec) * y + (a - b).dot(y)) / a.dot(one_vec)
@@ -170,6 +172,7 @@ module Rumale
170
172
  entropy, probs = gaussian_distributed_probability_vector(sample_id, distance_vec, beta)
171
173
  diff_entropy = entropy - init_entropy
172
174
  break if diff_entropy.abs <= 1e-5
175
+
173
176
  if diff_entropy.positive?
174
177
  betamin = beta
175
178
  if betamax == Float::MAX
@@ -211,6 +214,7 @@ module Rumale
211
214
 
212
215
  def terminate?(p, q)
213
216
  return false if @params[:tol].nil?
217
+
214
218
  cost(p, q) <= @params[:tol]
215
219
  end
216
220
  end
@@ -2,13 +2,15 @@
2
2
 
3
3
  require 'rumale/base/base_estimator'
4
4
  require 'rumale/base/transformer'
5
- require 'mopti/scaled_conjugate_gradient'
6
5
 
7
6
  module Rumale
8
7
  module MetricLearning
9
8
  # NeighbourhoodComponentAnalysis is a class that implements Neighbourhood Component Analysis.
10
9
  #
11
10
  # @example
11
+ # require 'mopti'
12
+ # require 'rumale'
13
+ #
12
14
  # transformer = Rumale::MetricLearning::NeighbourhoodComponentAnalysis.new
13
15
  # transformer.fit(training_samples, traininig_labels)
14
16
  # low_samples = transformer.transform(testing_samples)
@@ -63,6 +65,8 @@ module Rumale
63
65
  # @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
64
66
  # @return [NeighbourhoodComponentAnalysis] The learned classifier itself.
65
67
  def fit(x, y)
68
+ raise 'NeighbourhoodComponentAnalysis#fit requires Mopti but that is not loaded.' unless enable_mopti?
69
+
66
70
  x = check_convert_sample_array(x)
67
71
  y = check_convert_label_array(y)
68
72
  check_sample_label_size(x, y)
@@ -98,6 +102,14 @@ module Rumale
98
102
 
99
103
  private
100
104
 
105
+ def enable_mopti?
106
+ if defined?(Mopti).nil?
107
+ warn('NeighbourhoodComponentAnalysis#fit requires Mopti but that is not loaded. You should intall and load mopti gem in advance.')
108
+ return false
109
+ end
110
+ true
111
+ end
112
+
101
113
  def init_components(x, n_features, n_components)
102
114
  if @params[:init] == 'pca'
103
115
  pca = Rumale::Decomposition::PCA.new(n_components: n_components, solver: 'evd')
@@ -126,6 +138,7 @@ module Rumale
126
138
  res = prm
127
139
  puts "[NeighbourhoodComponentAnalysis] The value of objective function after #{res[:n_iter]} epochs: #{x.shape[0] - res[:fnc]}" if @params[:verbose]
128
140
  break if (fold - res[:fnc]).abs <= @params[:tol] && (dold - res[:jcb]).abs <= @params[:tol]
141
+
129
142
  fold = res[:fnc]
130
143
  dold = res[:jcb]
131
144
  end
@@ -69,10 +69,11 @@ module Rumale
69
69
  # the return_train_score is false.
70
70
  def perform(x, y)
71
71
  x = check_convert_sample_array(x)
72
- if @estimator.is_a?(Rumale::Base::Classifier)
72
+ case @estimator
73
+ when Rumale::Base::Classifier
73
74
  y = check_convert_label_array(y)
74
75
  check_sample_label_size(x, y)
75
- elsif @estimator.is_a?(Rumale::Base::Regressor)
76
+ when Rumale::Base::Regressor
76
77
  y = check_convert_tvalue_array(y)
77
78
  check_sample_tvalue_size(x, y)
78
79
  else
@@ -156,6 +156,7 @@ module Rumale
156
156
 
157
157
  def valid_param_grid(grid)
158
158
  raise TypeError, 'Expect class of param_grid to be Hash or Array' unless grid.is_a?(Hash) || grid.is_a?(Array)
159
+
159
160
  grid = [grid] if grid.is_a?(Hash)
160
161
  grid.each do |h|
161
162
  raise TypeError, 'Expect class of elements in param_grid to be Hash' unless h.is_a?(Hash)
@@ -62,7 +62,7 @@ module Rumale
62
62
  end
63
63
  sub_rng = @rng.dup
64
64
  # Splits dataset ids to each fold.
65
- dataset_ids = [*0...n_samples]
65
+ dataset_ids = Array(0...n_samples)
66
66
  dataset_ids.shuffle!(random: sub_rng) if @shuffle
67
67
  fold_sets = Array.new(@n_splits) do |n|
68
68
  n_fold_samples = n_samples / @n_splits
@@ -74,7 +74,7 @@ module Rumale
74
74
  end
75
75
  sub_rng = @rng.dup
76
76
  # Returns array consisting of the training and testing ids for each fold.
77
- dataset_ids = [*0...n_samples]
77
+ dataset_ids = Array(0...n_samples)
78
78
  Array.new(@n_splits) do
79
79
  test_ids = dataset_ids.sample(n_test_samples, random: sub_rng)
80
80
  train_ids = if @train_size.nil?
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rumale/base/base_estimator.rb'
4
- require 'rumale/base/classifier.rb'
3
+ require 'rumale/base/base_estimator'
4
+ require 'rumale/base/classifier'
5
5
 
6
6
  module Rumale
7
7
  # This module consists of the classes that implement multi-class classification strategy.
@@ -67,6 +67,7 @@ module Rumale
67
67
  y = check_convert_label_array(y)
68
68
  check_sample_label_size(x, y)
69
69
  raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
70
+
70
71
  @prototypes = if @params[:metric] == 'euclidean'
71
72
  if @params[:algorithm] == 'vptree'
72
73
  VPTree.new(x)
@@ -61,6 +61,7 @@ module Rumale
61
61
  y = check_convert_tvalue_array(y)
62
62
  check_sample_tvalue_size(x, y)
63
63
  raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1]
64
+
64
65
  @prototypes = if @params[:metric] == 'euclidean'
65
66
  if @params[:algorithm] == 'vptree'
66
67
  VPTree.new(x)
@@ -82,6 +83,7 @@ module Rumale
82
83
  if @params[:metric] == 'precomputed' && x.shape[1] != @values.shape[0]
83
84
  raise ArgumentError, 'Expect the size input matrix to be n_testing_samples-by-n_training_samples.'
84
85
  end
86
+
85
87
  # Initialize some variables.
86
88
  n_samples = x.shape[0]
87
89
  n_prototypes, n_outputs = @values.shape
@@ -30,7 +30,7 @@ module Rumale
30
30
  @params = {}
31
31
  @params[:min_samples_leaf] = min_samples_leaf
32
32
  @data = x
33
- @tree = build_tree(Numo::Int32.cast([*0...@data.shape[0]]))
33
+ @tree = build_tree(Numo::Int32.cast(Array(0...@data.shape[0])))
34
34
  end
35
35
 
36
36
  # Search k-nearest neighbors of given query point.
@@ -32,7 +32,7 @@ module Rumale
32
32
  end
33
33
 
34
34
  # @!visibility private
35
- # Calculate the updated weight with Nadam adaptive learning rate.
35
+ # Calculate the updated weight with Adam adaptive learning rate.
36
36
  #
37
37
  # @param weight [Numo::DFloat] (shape: [n_features]) The weight to be updated.
38
38
  # @param gradient [Numo::DFloat] (shape: [n_features]) The gradient for updating the weight.
@@ -222,7 +222,7 @@ module Rumale
222
222
  n_samples = x.shape[0]
223
223
 
224
224
  @params[:max_iter].times do |t|
225
- sample_ids = [*0...n_samples]
225
+ sample_ids = Array(0...n_samples)
226
226
  sample_ids.shuffle!(random: srng)
227
227
  until (subset_ids = sample_ids.shift(@params[:batch_size])).empty?
228
228
  # random sampling
@@ -233,6 +233,7 @@ module Rumale
233
233
  # calc loss function
234
234
  loss, dout = loss_func.call(out, sub_y)
235
235
  break if loss < @params[:tol]
236
+
236
237
  # backward
237
238
  backward.call(dout)
238
239
  end
@@ -7,6 +7,8 @@ module Rumale
7
7
  module Optimizer
8
8
  # AdaGrad is a class that implements AdaGrad optimizer.
9
9
  #
10
+ # @deprecated AdaGrad will be deleted in version 0.20.0.
11
+ #
10
12
  # *Reference*
11
13
  # - Duchi, J., Hazan, E., and Singer, Y., "Adaptive Subgradient Methods for Online Learning and Stochastic Optimization," J. Machine Learning Research, vol. 12, pp. 2121--2159, 2011.
12
14
  class AdaGrad
@@ -17,6 +19,7 @@ module Rumale
17
19
  #
18
20
  # @param learning_rate [Float] The initial value of learning rate.
19
21
  def initialize(learning_rate: 0.01)
22
+ warn 'warning: AdaGrad is deprecated. This class will be deleted in version 0.20.0.'
20
23
  check_params_numeric(learning_rate: learning_rate)
21
24
  check_params_positive(learning_rate: learning_rate)
22
25
  @params = {}
@@ -7,6 +7,8 @@ module Rumale
7
7
  module Optimizer
8
8
  # Adam is a class that implements Adam optimizer.
9
9
  #
10
+ # @deprecated Adam will be deleted in version 0.20.0.
11
+ #
10
12
  # *Reference*
11
13
  # - Kingma, D P., and Ba, J., "Adam: A Method for Stochastic Optimization," Proc. ICLR'15, 2015.
12
14
  class Adam
@@ -19,6 +21,7 @@ module Rumale
19
21
  # @param decay1 [Float] The smoothing parameter for the first moment.
20
22
  # @param decay2 [Float] The smoothing parameter for the second moment.
21
23
  def initialize(learning_rate: 0.001, decay1: 0.9, decay2: 0.999)
24
+ warn 'warning: Adam is deprecated. This class will be deleted in version 0.20.0.'
22
25
  check_params_numeric(learning_rate: learning_rate, decay1: decay1, decay2: decay2)
23
26
  check_params_positive(learning_rate: learning_rate, decay1: decay1, decay2: decay2)
24
27
  @params = {}
@@ -5,9 +5,13 @@ require 'rumale/base/base_estimator'
5
5
 
6
6
  module Rumale
7
7
  # This module consists of the classes that implement optimizers adaptively tuning hyperparameters.
8
+ #
9
+ # @deprecated Optimizer module will be deleted in version 0.20.0.
8
10
  module Optimizer
9
11
  # Nadam is a class that implements Nadam optimizer.
10
12
  #
13
+ # @deprecated Nadam will be deleted in version 0.20.0.
14
+ #
11
15
  # *Reference*
12
16
  # - Dozat, T., "Incorporating Nesterov Momentum into Adam," Tech. Repo. Stanford University, 2015.
13
17
  class Nadam
@@ -20,6 +24,7 @@ module Rumale
20
24
  # @param decay1 [Float] The smoothing parameter for the first moment.
21
25
  # @param decay2 [Float] The smoothing parameter for the second moment.
22
26
  def initialize(learning_rate: 0.01, decay1: 0.9, decay2: 0.999)
27
+ warn 'warning: Nadam is deprecated. This class will be deleted in version 0.20.0.'
23
28
  check_params_numeric(learning_rate: learning_rate, decay1: decay1, decay2: decay2)
24
29
  check_params_positive(learning_rate: learning_rate, decay1: decay1, decay2: decay2)
25
30
  @params = {}
@@ -7,6 +7,8 @@ module Rumale
7
7
  module Optimizer
8
8
  # RMSProp is a class that implements RMSProp optimizer.
9
9
  #
10
+ # @deprecated RMSProp will be deleted in version 0.20.0.
11
+ #
10
12
  # *Reference*
11
13
  # - Sutskever, I., Martens, J., Dahl, G., and Hinton, G., "On the importance of initialization and momentum in deep learning," Proc. ICML' 13, pp. 1139--1147, 2013.
12
14
  # - Hinton, G., Srivastava, N., and Swersky, K., "Lecture 6e rmsprop," Neural Networks for Machine Learning, 2012.
@@ -20,6 +22,7 @@ module Rumale
20
22
  # @param momentum [Float] The initial value of momentum.
21
23
  # @param decay [Float] The smooting parameter.
22
24
  def initialize(learning_rate: 0.01, momentum: 0.9, decay: 0.9)
25
+ warn 'warning: RMSProp is deprecated. This class will be deleted in version 0.20.0.'
23
26
  check_params_numeric(learning_rate: learning_rate, momentum: momentum, decay: decay)
24
27
  check_params_positive(learning_rate: learning_rate, momentum: momentum, decay: decay)
25
28
  @params = {}
@@ -6,6 +6,8 @@ require 'rumale/base/base_estimator'
6
6
  module Rumale
7
7
  module Optimizer
8
8
  # SGD is a class that implements SGD optimizer.
9
+ #
10
+ # @deprecated SGD will be deleted in version 0.20.0.
9
11
  class SGD
10
12
  include Base::BaseEstimator
11
13
  include Validation
@@ -16,6 +18,7 @@ module Rumale
16
18
  # @param momentum [Float] The initial value of momentum.
17
19
  # @param decay [Float] The smooting parameter.
18
20
  def initialize(learning_rate: 0.01, momentum: 0.0, decay: 0.0)
21
+ warn 'warning: SGD is deprecated. This class will be deleted in version 0.20.0.'
19
22
  check_params_numeric(learning_rate: learning_rate, momentum: momentum, decay: decay)
20
23
  check_params_positive(learning_rate: learning_rate, momentum: momentum, decay: decay)
21
24
  @params = {}
@@ -7,6 +7,8 @@ module Rumale
7
7
  module Optimizer
8
8
  # YellowFin is a class that implements YellowFin optimizer.
9
9
  #
10
+ # @deprecated YellowFin will be deleted in version 0.20.0.
11
+ #
10
12
  # *Reference*
11
13
  # - Zhang, J., and Mitliagkas, I., "YellowFin and the Art of Momentum Tuning," CoRR abs/1706.03471, 2017.
12
14
  class YellowFin
@@ -20,6 +22,7 @@ module Rumale
20
22
  # @param decay [Float] The smooting parameter.
21
23
  # @param window_width [Integer] The sliding window width for searching curvature range.
22
24
  def initialize(learning_rate: 0.01, momentum: 0.9, decay: 0.999, window_width: 20)
25
+ warn 'warning: YellowFin is deprecated. This class will be deleted in version 0.20.0.'
23
26
  check_params_numeric(learning_rate: learning_rate, momentum: momentum, decay: decay, window_width: window_width)
24
27
  check_params_positive(learning_rate: learning_rate, momentum: momentum, decay: decay, window_width: window_width)
25
28
  @params = {}
@@ -119,6 +119,7 @@ module Rumale
119
119
  @steps.keys.reverse_each do |name|
120
120
  transformer = @steps[name]
121
121
  next if transformer.nil?
122
+
122
123
  itrans_z = transformer.inverse_transform(itrans_z)
123
124
  end
124
125
  itrans_z
@@ -140,6 +141,7 @@ module Rumale
140
141
  steps.keys[0...-1].each do |name|
141
142
  transformer = steps[name]
142
143
  next if transformer.nil? || %i[fit transform].all? { |m| transformer.class.method_defined?(m) }
144
+
143
145
  raise TypeError,
144
146
  'Class of intermediate step in pipeline should be implemented fit and transform methods: ' \
145
147
  "#{name} => #{transformer.class}"
@@ -158,6 +160,7 @@ module Rumale
158
160
  @steps.keys[0...-1].each do |name|
159
161
  transformer = @steps[name]
160
162
  next if transformer.nil?
163
+
161
164
  transformer.fit(trans_x, y) if fit
162
165
  trans_x = transformer.transform(trans_x)
163
166
  end
@@ -5,9 +5,13 @@ require 'rumale/optimizer/nadam'
5
5
 
6
6
  module Rumale
7
7
  # This module consists of the classes that implement polynomial models.
8
+ #
9
+ # @deprecated PolynomialModel module will be deleted in version 0.20.0.
8
10
  module PolynomialModel
9
11
  # BaseFactorizationMachine is an abstract class for implementation of Factorization Machine-based estimators.
10
12
  # This class is used internally.
13
+ #
14
+ # @deprecated BaseFactorizationMachine will be deleted in version 0.20.0.
11
15
  class BaseFactorizationMachine
12
16
  include Base::BaseEstimator
13
17
 
@@ -65,7 +69,7 @@ module Rumale
65
69
  factor_optimizers = Array.new(@params[:n_factors]) { @params[:optimizer].dup }
66
70
  # Start optimization.
67
71
  @params[:max_iter].times do |t|
68
- sample_ids = [*0...n_samples]
72
+ sample_ids = Array(0...n_samples)
69
73
  sample_ids.shuffle!(random: sub_rng)
70
74
  until (subset_ids = sample_ids.shift(@params[:batch_size])).empty?
71
75
  # Sampling.
@@ -75,6 +79,7 @@ module Rumale
75
79
  # Calculate gradients for loss function.
76
80
  loss_grad = loss_gradient(sub_x, ex_sub_x, sub_y, factor_mat, weight_vec)
77
81
  next if loss_grad.ne(0.0).count.zero?
82
+
78
83
  # Update each parameter.
79
84
  weight_vec = weight_optimizer.call(weight_vec, weight_gradient(loss_grad, ex_sub_x, weight_vec))
80
85
  @params[:n_factors].times do |n|