rumale-svm 0.9.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/rumale/svm/clustered_svc.rb +171 -0
- data/lib/rumale/svm/random_recursive_svc.rb +145 -0
- data/lib/rumale/svm/version.rb +1 -1
- data/lib/rumale/svm.rb +2 -0
- data/sig/rumale/svm/clustered_svc.rbs +29 -0
- data/sig/rumale/svm/locally_linear_svc.rbs +32 -0
- data/sig/rumale/svm/random_recursive_svc.rbs +27 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e355b5a28902d6452614e8c667fd5d8ad192320e8b9f32d3410c3ec8bf37cff1
|
4
|
+
data.tar.gz: ec0c545c306df2ab8146f105d55c6565ba119efbd7f2c3a276da1f1e0d127727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c864deab7055371b9afc3372ee21cccc81164f8eadf75cdc110657a0dcf2f922fc5e5bfbe332759fbbbb952496df2ab417235e3dbed68b956d0380c8558bc7f3
|
7
|
+
data.tar.gz: 31cbab3030f09ab7bf6cef223d374bbffbd4d91bf8be65696e7b3542fecc6efb6626f38dd56e4594034bc4d4b0cc6c0a9b5586d7f680cc797733e490f7c21c02
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [[0.11.0](https://github.com/yoshoku/rumale-svm/compare/v0.10.0...v0.11.0)]
|
2
|
+
- Add Rumale::SVM::ClusteredSVC that is classifier with clustered support vector machine.
|
3
|
+
|
4
|
+
# 0.10.0
|
5
|
+
- Add Rumale::SVM::RandomRecursiveSVC that is classifier with random recursive support vector machine.
|
6
|
+
- Add type declaration files for RandomRecursiveSVC and LocallyLinearSVC.
|
7
|
+
|
1
8
|
# 0.9.0
|
2
9
|
- Add Rumale::SVM::LocallyLinearSVC that is classifier with locally linear support vector machine.
|
3
10
|
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rumale/base/estimator'
|
4
|
+
require 'rumale/base/classifier'
|
5
|
+
require 'rumale/pairwise_metric'
|
6
|
+
require 'rumale/validation'
|
7
|
+
require 'rumale/svm/linear_svc'
|
8
|
+
|
9
|
+
module Rumale
|
10
|
+
module SVM
|
11
|
+
# ClusteredSVC is a class that implements Clustered Support Vector Classifier.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# require 'rumale/svm'
|
15
|
+
#
|
16
|
+
# estimator = Rumale::SVM::ClusteredSVC.new(n_clusters: 16, reg_param_global: 1.0, random_seed: 1)
|
17
|
+
# estimator.fit(training_samples, training_labels)
|
18
|
+
# results = estimator.predict(testing_samples)
|
19
|
+
#
|
20
|
+
# *Reference*
|
21
|
+
# - Gu, Q., and Han, J., "Clustered Support Vector Machines," In Proc. AISTATS'13, pp. 307--315, 2013.
|
22
|
+
class ClusteredSVC < Rumale::Base::Estimator
|
23
|
+
include Rumale::Base::Classifier
|
24
|
+
|
25
|
+
# Return the classifier.
|
26
|
+
# @return [LinearSVC]
|
27
|
+
attr_reader :model
|
28
|
+
|
29
|
+
# Return the centroids.
|
30
|
+
# @return [Numo::DFloat] (shape: [n_clusters, n_features])
|
31
|
+
attr_accessor :cluster_centers
|
32
|
+
|
33
|
+
# Create a new classifier with Random Recursive Support Vector Machine.
|
34
|
+
#
|
35
|
+
# @param n_clusters [Integer] The number of clusters.
|
36
|
+
# @param reg_param_global [Float] The regularization parameter for global reference vector.
|
37
|
+
# @param max_iter_kmeans [Integer] The maximum number of iterations for k-means clustering.
|
38
|
+
# @param tol_kmeans [Float] The tolerance of termination criterion for k-means clustering.
|
39
|
+
# @param penalty [String] The type of norm used in the penalization ('l2' or 'l1').
|
40
|
+
# @param loss [String] The type of loss function ('squared_hinge' or 'hinge').
|
41
|
+
# This parameter is ignored if penalty = 'l1'.
|
42
|
+
# @param dual [Boolean] The flag indicating whether to solve dual optimization problem.
|
43
|
+
# When n_samples > n_features, dual = false is more preferable.
|
44
|
+
# This parameter is ignored if loss = 'hinge'.
|
45
|
+
# @param reg_param [Float] The regularization parameter.
|
46
|
+
# @param fit_bias [Boolean] The flag indicating whether to fit the bias term.
|
47
|
+
# @param bias_scale [Float] The scale of the bias term.
|
48
|
+
# This parameter is ignored if fit_bias = false.
|
49
|
+
# @param tol [Float] The tolerance of termination criterion.
|
50
|
+
# @param verbose [Boolean] The flag indicating whether to output learning process message
|
51
|
+
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
52
|
+
def initialize(n_clusters: 8, reg_param_global: 1.0, max_iter_kmeans: 100, tol_kmeans: 1e-6, # rubocop:disable Metrics/ParameterLists
|
53
|
+
penalty: 'l2', loss: 'squared_hinge', dual: true, reg_param: 1.0,
|
54
|
+
fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil)
|
55
|
+
super()
|
56
|
+
@params = {
|
57
|
+
n_clusters: n_clusters,
|
58
|
+
reg_param_global: reg_param_global,
|
59
|
+
max_iter_kmeans: max_iter_kmeans,
|
60
|
+
tol_kmeans: tol_kmeans,
|
61
|
+
penalty: penalty == 'l1' ? 'l1' : 'l2',
|
62
|
+
loss: loss == 'hinge' ? 'hinge' : 'squared_hinge',
|
63
|
+
dual: dual,
|
64
|
+
reg_param: reg_param.to_f,
|
65
|
+
fit_bias: fit_bias,
|
66
|
+
bias_scale: bias_scale.to_f,
|
67
|
+
tol: tol.to_f,
|
68
|
+
verbose: verbose,
|
69
|
+
random_seed: random_seed || Random.rand(4_294_967_295)
|
70
|
+
}
|
71
|
+
@rng = Random.new(@params[:random_seed])
|
72
|
+
@cluster_centers = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# Fit the model with given training data.
|
76
|
+
#
|
77
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
|
78
|
+
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
79
|
+
# @return [ClusteredSVC] The learned classifier itself.
|
80
|
+
def fit(x, y)
|
81
|
+
z = transform(x)
|
82
|
+
@model = LinearSVC.new(**linear_svc_params).fit(z, y)
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
# Calculate confidence scores for samples.
|
87
|
+
#
|
88
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
|
89
|
+
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
90
|
+
def decision_function(x)
|
91
|
+
z = transform(x)
|
92
|
+
@model.decision_function(z)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Predict class labels for samples.
|
96
|
+
#
|
97
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
|
98
|
+
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
99
|
+
def predict(x)
|
100
|
+
z = transform(x)
|
101
|
+
@model.predict(z)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Transform the given data with the learned model.
|
105
|
+
#
|
106
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
|
107
|
+
# @return [Numo::DFloat] (shape: [n_samples, n_features + n_features * n_clusters]) The transformed data.
|
108
|
+
def transform(x)
|
109
|
+
clustering(x) if @cluster_centers.nil?
|
110
|
+
|
111
|
+
cluster_ids = assign_cluster_id(x)
|
112
|
+
|
113
|
+
x = expand_feature(x) if fit_bias?
|
114
|
+
|
115
|
+
n_samples, n_features = x.shape
|
116
|
+
z = Numo::DFloat.zeros(n_samples, n_features * (1 + @params[:n_clusters]))
|
117
|
+
z[true, 0...n_features] = 1.fdiv(Math.sqrt(@params[:reg_param_global])) * x
|
118
|
+
@params[:n_clusters].times do |n|
|
119
|
+
assigned_bits = cluster_ids.eq(n)
|
120
|
+
z[assigned_bits.where, n_features * (n + 1)...n_features * (n + 2)] = x[assigned_bits.where, true]
|
121
|
+
end
|
122
|
+
|
123
|
+
z
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def linear_svc_params
|
129
|
+
@params.reject { |key, _| CLUSTERED_SVC_BINARY_PARAMS.include?(key) }.merge(fit_bias: false)
|
130
|
+
end
|
131
|
+
|
132
|
+
def clustering(x)
|
133
|
+
n_samples = x.shape[0]
|
134
|
+
sub_rng = @rng.dup
|
135
|
+
rand_id = Array.new(@params[:n_clusters]) { |_v| sub_rng.rand(0...n_samples) }
|
136
|
+
@cluster_centers = x[rand_id, true].dup
|
137
|
+
|
138
|
+
@params[:max_iter_kmeans].times do |_t|
|
139
|
+
center_ids = assign_cluster_id(x)
|
140
|
+
old_centers = @cluster_centers.dup
|
141
|
+
@params[:n_clusters].times do |n|
|
142
|
+
assigned_bits = center_ids.eq(n)
|
143
|
+
@cluster_centers[n, true] = x[assigned_bits.where, true].mean(axis: 0) if assigned_bits.count.positive?
|
144
|
+
end
|
145
|
+
error = Numo::NMath.sqrt(((old_centers - @cluster_centers)**2).sum(axis: 1)).mean
|
146
|
+
break if error <= @params[:tol_kmeans]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def assign_cluster_id(x)
|
151
|
+
distance_matrix = ::Rumale::PairwiseMetric.euclidean_distance(x, @cluster_centers)
|
152
|
+
distance_matrix.min_index(axis: 1) - Numo::Int32[*0.step(distance_matrix.size - 1, @cluster_centers.shape[0])]
|
153
|
+
end
|
154
|
+
|
155
|
+
def expand_feature(x)
|
156
|
+
n_samples = x.shape[0]
|
157
|
+
Numo::NArray.hstack([x, Numo::DFloat.ones([n_samples, 1]) * @params[:bias_scale]])
|
158
|
+
end
|
159
|
+
|
160
|
+
def fit_bias?
|
161
|
+
return false if @params[:fit_bias].nil? || @params[:fit_bias] == false
|
162
|
+
|
163
|
+
true
|
164
|
+
end
|
165
|
+
|
166
|
+
CLUSTERED_SVC_BINARY_PARAMS = %i[n_clusters reg_param_global max_iter_kmeans tol_kmeans].freeze
|
167
|
+
|
168
|
+
private_constant :CLUSTERED_SVC_BINARY_PARAMS
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rumale/utils'
|
4
|
+
require 'rumale/base/estimator'
|
5
|
+
require 'rumale/base/classifier'
|
6
|
+
require 'rumale/svm/linear_svc'
|
7
|
+
|
8
|
+
module Rumale
|
9
|
+
module SVM
|
10
|
+
# RandomRecursiveSVC is a class that implements Random Recursive Support Vector Classifier.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# require 'rumale/svm'
|
14
|
+
#
|
15
|
+
# estimator = Rumale::SVM::RandomRecursiveSVC.new(n_hidden_layers: 2, beta: 0.5, random_seed: 1)
|
16
|
+
# estimator.fit(training_samples, training_labels)
|
17
|
+
# results = estimator.predict(testing_samples)
|
18
|
+
#
|
19
|
+
# *Reference*
|
20
|
+
# - Vinyals, O., Jia, Y., Deng, L., and Darrell, T., "Learning with Recursive Perceptual Representations," In Proc. NIPS'12, pp. 2825--2833, 2012.
|
21
|
+
class RandomRecursiveSVC < Rumale::Base::Estimator
|
22
|
+
include Rumale::Base::Classifier
|
23
|
+
|
24
|
+
# Return the classifiers for each layer.
|
25
|
+
# @return [Array<LinearSVC>]
|
26
|
+
attr_reader :classifiers
|
27
|
+
|
28
|
+
# Return the random matrices for each hidden layer.
|
29
|
+
# @return [Array<Numo::DFloat>] (shape: [n_classes, n_features])
|
30
|
+
attr_reader :random_matrices
|
31
|
+
|
32
|
+
# Create a new classifier with Random Recursive Support Vector Machine.
|
33
|
+
#
|
34
|
+
# @param n_hidden_layers [Integer] The number of hidden layers.
|
35
|
+
# @param beta [Float] The weight parameter for the degree of moving the original data.
|
36
|
+
# @param penalty [String] The type of norm used in the penalization ('l2' or 'l1').
|
37
|
+
# @param loss [String] The type of loss function ('squared_hinge' or 'hinge').
|
38
|
+
# This parameter is ignored if penalty = 'l1'.
|
39
|
+
# @param dual [Boolean] The flag indicating whether to solve dual optimization problem.
|
40
|
+
# When n_samples > n_features, dual = false is more preferable.
|
41
|
+
# This parameter is ignored if loss = 'hinge'.
|
42
|
+
# @param reg_param [Float] The regularization parameter.
|
43
|
+
# @param fit_bias [Boolean] The flag indicating whether to fit the bias term.
|
44
|
+
# @param bias_scale [Float] The scale of the bias term.
|
45
|
+
# This parameter is ignored if fit_bias = false.
|
46
|
+
# @param tol [Float] The tolerance of termination criterion.
|
47
|
+
# @param verbose [Boolean] The flag indicating whether to output learning process message
|
48
|
+
# @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
|
49
|
+
def initialize(n_hidden_layers: 2, beta: 0.5, penalty: 'l2', loss: 'squared_hinge', dual: true, reg_param: 1.0,
|
50
|
+
fit_bias: true, bias_scale: 1.0, tol: 1e-3, verbose: false, random_seed: nil)
|
51
|
+
super()
|
52
|
+
@params = {
|
53
|
+
n_hidden_layers: n_hidden_layers,
|
54
|
+
beta: beta,
|
55
|
+
penalty: penalty == 'l1' ? 'l1' : 'l2',
|
56
|
+
loss: loss == 'hinge' ? 'hinge' : 'squared_hinge',
|
57
|
+
dual: dual,
|
58
|
+
reg_param: reg_param.to_f,
|
59
|
+
fit_bias: fit_bias,
|
60
|
+
bias_scale: bias_scale.to_f,
|
61
|
+
tol: tol.to_f,
|
62
|
+
verbose: verbose,
|
63
|
+
random_seed: random_seed || Random.rand(4_294_967_295)
|
64
|
+
}
|
65
|
+
@rng = Random.new(@params[:random_seed])
|
66
|
+
end
|
67
|
+
|
68
|
+
# Fit the model with given training data.
|
69
|
+
#
|
70
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
|
71
|
+
# @param y [Numo::Int32] (shape: [n_samples]) The labels to be used for fitting the model.
|
72
|
+
# @return [RandomRecursiveSVC] The learned classifier itself.
|
73
|
+
def fit(x, y)
|
74
|
+
partial_fit(x, y)
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# Calculate confidence scores for samples.
|
79
|
+
#
|
80
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
|
81
|
+
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
|
82
|
+
def decision_function(x)
|
83
|
+
@classifiers.last.decision_function(transform(x))
|
84
|
+
end
|
85
|
+
|
86
|
+
# Predict class labels for samples.
|
87
|
+
#
|
88
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
|
89
|
+
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
|
90
|
+
def predict(x)
|
91
|
+
@classifiers.last.predict(transform(x))
|
92
|
+
end
|
93
|
+
|
94
|
+
# Transform the given data with the learned model.
|
95
|
+
#
|
96
|
+
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The data to be transformed with the learned model.
|
97
|
+
# @return [Numo::DFloat] (shape: [n_samples, n_features]) The output of last hidden layer.
|
98
|
+
def transform(x)
|
99
|
+
d = x
|
100
|
+
s = Numo::DFloat.zeros(x.shape)
|
101
|
+
@random_matrices.each_with_index do |w, n|
|
102
|
+
o = @classifiers[n].predict_proba(d)
|
103
|
+
s += o.dot(w)
|
104
|
+
d = sigmoid(x + @params[:beta] * s)
|
105
|
+
end
|
106
|
+
d
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def partial_fit(x, y)
|
112
|
+
@classifiers = []
|
113
|
+
@random_matrices = []
|
114
|
+
sub_rng = @rng.dup
|
115
|
+
n_classes = y.to_a.uniq.size
|
116
|
+
n_features = x.shape[1]
|
117
|
+
d = x
|
118
|
+
s = Numo::DFloat.zeros(x.shape)
|
119
|
+
@params[:n_hidden_layers].times do
|
120
|
+
svc = LinearSVC.new(**linear_svc_params).fit(d, y)
|
121
|
+
o = svc.predict_proba(d)
|
122
|
+
w = ::Rumale::Utils.rand_normal([n_classes, n_features], sub_rng)
|
123
|
+
s += o.dot(w)
|
124
|
+
d = sigmoid(x + @params[:beta] * s)
|
125
|
+
@classifiers << svc
|
126
|
+
@random_matrices << w
|
127
|
+
end
|
128
|
+
svc = LinearSVC.new(**linear_svc_params).fit(d, y)
|
129
|
+
@classifiers << svc
|
130
|
+
end
|
131
|
+
|
132
|
+
def linear_svc_params
|
133
|
+
@params.reject { |key, _| RRSVC_PARAMS.include?(key) }.merge(probability: true)
|
134
|
+
end
|
135
|
+
|
136
|
+
def sigmoid(x)
|
137
|
+
0.5 * (Numo::NMath.tanh(0.5 * x) + 1.0)
|
138
|
+
end
|
139
|
+
|
140
|
+
RRSVC_PARAMS = %i[n_hidden_layers beta].freeze
|
141
|
+
|
142
|
+
private_constant :RRSVC_PARAMS
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/lib/rumale/svm/version.rb
CHANGED
data/lib/rumale/svm.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TypeProf 0.21.8
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Rumale
|
5
|
+
module SVM
|
6
|
+
class ClusteredSVC
|
7
|
+
@params: {n_clusters: Integer, reg_param_global: Float, max_iter_kmeans: Integer, tol_kmeans: Float, penalty: String, loss: String, dual: bool, reg_param: Float, fit_bias: bool, bias_scale: Float, tol: Float, verbose: bool, random_seed: Integer}
|
8
|
+
@rng: Random
|
9
|
+
|
10
|
+
attr_reader model: Rumale::SVM::LinearSVC
|
11
|
+
attr_accessor cluster_centers: Numo::DFloat
|
12
|
+
def initialize: (?n_clusters: Integer, ?reg_param_global: Float, ?max_iter_kmeans: Integer, ?tol_kmeans: Float, ?penalty: String, ?loss: String, ?dual: bool, ?reg_param: Float, ?fit_bias: bool, ?bias_scale: Float, ?tol: Float, ?verbose: bool, ?random_seed: (nil | Integer)) -> void
|
13
|
+
def fit: (Numo::DFloat x, Numo::Int32 y) -> ClusteredSVC
|
14
|
+
def decision_function: (Numo::DFloat x) -> Numo::DFloat
|
15
|
+
def predict: (Numo::DFloat x) -> Numo::Int32
|
16
|
+
def transform: (Numo::DFloat x) -> Numo::DFloat
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def linear_svc_params: -> (Hash[:bias_scale | :dual | :fit_bias | :loss | :max_iter_kmeans | :n_clusters | :penalty | :random_seed | :reg_param | :reg_param_global | :tol | :tol_kmeans | :verbose, Float | Integer | String | bool])
|
21
|
+
def clustering: (Numo::DFloat x) -> void
|
22
|
+
def assign_cluster_id: (Numo::DFloat x) -> Numo::Int32
|
23
|
+
def expand_feature: (Numo::DFloat x) -> Numo::DFloat
|
24
|
+
def fit_bias?: -> bool
|
25
|
+
|
26
|
+
CLUSTERED_SVC_BINARY_PARAMS: [:n_clusters, :reg_param_global, :max_iter_kmeans, :tol_kmeans]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# TypeProf 0.21.8
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Rumale
|
5
|
+
module SVM
|
6
|
+
class LocallyLinearSVC
|
7
|
+
@params: {reg_param: Float, reg_param_local: Float, max_iter: Integer, n_anchors: Integer, tol: Float, n_neighbors: Integer, fit_bias: bool, bias_scale: Float, random_seed: Integer}
|
8
|
+
@rng: Random
|
9
|
+
@coeff: Numo::DFloat
|
10
|
+
|
11
|
+
attr_reader classes: Numo::Int32
|
12
|
+
attr_reader anchors: Numo::DFloat
|
13
|
+
attr_reader weight_vec: Numo::DFloat
|
14
|
+
attr_reader bias_term: Numo::DFloat
|
15
|
+
def initialize: (?reg_param: Float, ?reg_param_local: Float, ?max_iter: Integer, ?tol: Float, ?n_anchors: Integer, ?n_neighbors: Integer, ?fit_bias: bool, ?bias_scale: Float, ?random_seed: (nil | Integer)) -> void
|
16
|
+
def fit: (Numo::DFloat x, Numo::Int32 y) -> LocallyLinearSVC
|
17
|
+
def decision_function: (Numo::DFloat x) -> Numo::DFloat
|
18
|
+
def predict: (Numo::DFloat x) -> Numo::Int32
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def partial_fit: (Numo::DFloat base_x, Numo::Int32 bin_y) -> [Numo::DFloat, Numo::DFloat]
|
23
|
+
def local_coordinates: (Numo::DFloat xi) -> Numo::DFloat
|
24
|
+
def find_neighbors: (Numo::DFloat xi) -> Numo::Int32
|
25
|
+
def find_anchors: (Numo::DFloat x) -> void
|
26
|
+
def assign_anchors: (Numo::DFloat x) -> Integer
|
27
|
+
def fit_bias?: -> bool
|
28
|
+
def expand_feature: (Numo::DFloat x) -> Numo::DFloat
|
29
|
+
def multiclass_problem?: -> bool
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# TypeProf 0.21.8
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Rumale
|
5
|
+
module SVM
|
6
|
+
class RandomRecursiveSVC
|
7
|
+
@params: {n_hidden_layers: Integer, beta: Float, penalty: String, loss: String, dual: bool, reg_param: Float, fit_bias: bool, bias_scale: Float, tol: Float, verbose: bool, random_seed: Integer}
|
8
|
+
@rng: Random
|
9
|
+
|
10
|
+
attr_reader classifiers: Array[Rumale::SVM::LinearSVC]
|
11
|
+
attr_reader random_matrices: Array[Numo::DFloat]
|
12
|
+
def initialize: (?n_hidden_layers: Integer, ?beta: Float, ?penalty: String, ?loss: String, ?dual: bool, ?reg_param: Float, ?fit_bias: bool, ?bias_scale: Float, ?tol: Float, ?verbose: bool, ?random_seed: (nil | Integer)) -> void
|
13
|
+
def fit: (Numo::DFloat x, Numo::Int32 y) -> RandomRecursiveSVC
|
14
|
+
def decision_function: (Numo::DFloat x) -> Numo::DFloat
|
15
|
+
def predict: (Numo::DFloat x) -> Numo::Int32
|
16
|
+
def transform: (Numo::DFloat x) -> Numo::DFloat
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def partial_fit: (Numo::DFloat x, Numo::DFloat y) -> void
|
21
|
+
def linear_svc_params: -> (Hash[:beta | :bias_scale | :dual | :fit_bias | :loss | :n_hidden_layers | :penalty | :random_seed | :reg_param | :tol | :verbose, Float | Integer | String | bool])
|
22
|
+
def sigmoid: (Numo::DFloat x) -> Numo::DFloat
|
23
|
+
|
24
|
+
RRSVC_PARAMS: [:n_hidden_layers, :beta]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumale-svm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-liblinear
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
68
68
|
- lib/rumale/svm.rb
|
69
|
+
- lib/rumale/svm/clustered_svc.rb
|
69
70
|
- lib/rumale/svm/linear_one_class_svm.rb
|
70
71
|
- lib/rumale/svm/linear_svc.rb
|
71
72
|
- lib/rumale/svm/linear_svr.rb
|
@@ -74,17 +75,21 @@ files:
|
|
74
75
|
- lib/rumale/svm/nu_svc.rb
|
75
76
|
- lib/rumale/svm/nu_svr.rb
|
76
77
|
- lib/rumale/svm/one_class_svm.rb
|
78
|
+
- lib/rumale/svm/random_recursive_svc.rb
|
77
79
|
- lib/rumale/svm/svc.rb
|
78
80
|
- lib/rumale/svm/svr.rb
|
79
81
|
- lib/rumale/svm/version.rb
|
80
82
|
- sig/rumale/svm.rbs
|
83
|
+
- sig/rumale/svm/clustered_svc.rbs
|
81
84
|
- sig/rumale/svm/linear_one_class_svm.rbs
|
82
85
|
- sig/rumale/svm/linear_svc.rbs
|
83
86
|
- sig/rumale/svm/linear_svr.rbs
|
87
|
+
- sig/rumale/svm/locally_linear_svc.rbs
|
84
88
|
- sig/rumale/svm/logistic_regression.rbs
|
85
89
|
- sig/rumale/svm/nu_svc.rbs
|
86
90
|
- sig/rumale/svm/nu_svr.rbs
|
87
91
|
- sig/rumale/svm/one_class_svm.rbs
|
92
|
+
- sig/rumale/svm/random_recursive_svc.rbs
|
88
93
|
- sig/rumale/svm/svc.rbs
|
89
94
|
- sig/rumale/svm/svr.rbs
|
90
95
|
homepage: https://github.com/yoshoku/rumale-svm
|
@@ -111,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
116
|
- !ruby/object:Gem::Version
|
112
117
|
version: '0'
|
113
118
|
requirements: []
|
114
|
-
rubygems_version: 3.4.
|
119
|
+
rubygems_version: 3.4.22
|
115
120
|
signing_key:
|
116
121
|
specification_version: 4
|
117
122
|
summary: Rumale::SVM provides support vector machine algorithms using LIBSVM and LIBLINEAR
|