rumale-svm 0.3.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2fa12724b67f4cc5be042e64a8d29284e2292f23a5b13031e4b2ee33397285a
4
- data.tar.gz: 453907d44a6113bf65531ec39e9d6da219bd1c2d0822cc6c72a1188e1b1e0b5e
3
+ metadata.gz: f0000e7a25f4aaf36f645a7860d13bed3ca06ea7d99bc15469cd7c9ea0a57288
4
+ data.tar.gz: 0db6f53cabe1a84493d20bf9e0822057dca4ec92042bdefb6fda15f794aba9aa
5
5
  SHA512:
6
- metadata.gz: 490675646f497293d10112605ab1d5dcbc1a69a21e67f2712b304b89d7e542e9894358e536dec4811e04ead3bb94fbd77c5273a7e3464cc883e9e50e8212af0b
7
- data.tar.gz: 9ccac4d7d7cf56deac34f9c9c731e3b6c455df65ca7349ed0634c37106ea0e6fe42dec243459f966e87c3aadf72525211fa4c365925c59f6089024689968c9be
6
+ metadata.gz: af0433aacb57daa0b9bf81dfe961f71ef71751215749201c18c1c81aa592d55050e4ed6d65605809ff6c36153cbbeb45e200181675dec23e13f884b70185ccab
7
+ data.tar.gz: c97c4a38ccdfabd869e6f5196eae73f32371d7bd12ff8e9612ede2cbfe89bb3bc563505429590ef65d928ba84d76cc06cf9c5f9eee0e79b161cbfd470da80cc0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.5.1
2
+ - Refator specs and config files.
3
+
4
+ # 0.5.0
5
+ - Add type declaration files.
6
+
7
+ # 0.4.0
8
+ - Add linear one-class support vector machine.
9
+
1
10
  # 0.3.0
2
11
  - Fix to raise error when calling prediction method before training model.
3
12
  - Fix some config files.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2020 Atsushi Tatsuma
1
+ Copyright (c) 2019-2022 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Rumale::SVM
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/rumale-svm.svg?branch=master)](https://travis-ci.org/yoshoku/rumale-svm)
4
- [![Coverage Status](https://coveralls.io/repos/github/yoshoku/rumale-svm/badge.svg?branch=master)](https://coveralls.io/github/yoshoku/rumale-svm?branch=master)
3
+ [![Build Status](https://github.com/yoshoku/rumale-svm/workflows/build/badge.svg)](https://github.com/yoshoku/rumale-svm/actions?query=workflow%3Abuild)
4
+ [![Coverage Status](https://coveralls.io/repos/github/yoshoku/rumale-svm/badge.svg?branch=main)](https://coveralls.io/github/yoshoku/rumale-svm?branch=main)
5
5
  [![Gem Version](https://badge.fury.io/rb/rumale-svm.svg)](https://badge.fury.io/rb/rumale-svm)
6
- [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/rumale-svm/blob/master/LICENSE.txt)
7
- [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/rumale-svm/doc/)
6
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/rumale-svm/blob/main/LICENSE.txt)
7
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/rumale-svm/doc/)
8
8
 
9
9
  Rumale::SVM provides support vector machine algorithms in
10
10
  [LIBSVM](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) and [LIBLINEAR](https://www.csie.ntu.edu.tw/~cjlin/liblinear/)
@@ -77,20 +77,10 @@ $ ruby rumale_svm_test.rb
77
77
  Accuracy: 0.835
78
78
  ```
79
79
 
80
- ## Development
81
-
82
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
-
84
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
-
86
80
  ## Contributing
87
81
 
88
- Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/rumale-svm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/rumale-svm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
89
83
 
90
84
  ## License
91
85
 
92
86
  The gem is available as open source under the terms of the [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause).
93
-
94
- ## Code of Conduct
95
-
96
- Everyone interacting in the Rumale::Svm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/rumale-svm/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'numo/liblinear'
4
+ require 'rumale/base/base_estimator'
5
+ require 'rumale/validation'
6
+
7
+ module Rumale
8
+ module SVM
9
+ # LinearOneClassSVM is a class that provides linear One-class Support Vector Machine in LIBLINEAR with Rumale interface.
10
+ #
11
+ # @example
12
+ # estimator = Rumale::SVM::LinearOneClassSVM.new(nu: 0.05, random_seed: 1)
13
+ # estimator.fit(training_samples, traininig_labels)
14
+ # results = estimator.predict(testing_samples)
15
+ class LinearOneClassSVM
16
+ include Base::BaseEstimator
17
+ include Validation
18
+
19
+ # Return the weight vector for LinearOneClassSVM.
20
+ # @return [Numo::DFloat] (shape: [n_features])
21
+ attr_reader :weight_vec
22
+
23
+ # Return the bias term (a.k.a. intercept) for LinearOneClassSVM.
24
+ # @return [Float]
25
+ attr_reader :bias_term
26
+
27
+ # Create a new estimator with linear One-class Support Vector Machine.
28
+ #
29
+ # @param nu [Float] The fraction of data as outliers. The interval of nu is (0, 1].
30
+ # @param reg_param [Float] The regularization parameter.
31
+ # @param tol [Float] The tolerance of termination criterion.
32
+ # @param verbose [Boolean] The flag indicating whether to output learning process message
33
+ # @param random_seed [Integer/Nil] The seed value using to initialize the random generator.
34
+ def initialize(nu: 0.05, reg_param: 1.0, tol: 1e-3, verbose: false, random_seed: nil)
35
+ check_params_numeric(nu: nu, reg_param: reg_param, tol: tol)
36
+ check_params_boolean(verbose: verbose)
37
+ check_params_numeric_or_nil(random_seed: random_seed)
38
+ @params = {}
39
+ @params[:nu] = nu.to_f
40
+ @params[:reg_param] = reg_param.to_f
41
+ @params[:tol] = tol.to_f
42
+ @params[:verbose] = verbose
43
+ @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
44
+ end
45
+
46
+ # Fit the model with given training data.
47
+ #
48
+ # @overload fit(x) -> LinearOneClassSVM
49
+ # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
50
+ #
51
+ # @return [LinearOneClassSVM] The learned estimator itself.
52
+ def fit(x, _y = nil)
53
+ x = check_convert_sample_array(x)
54
+ dummy = Numo::DFloat.ones(x.shape[0])
55
+ @model = Numo::Liblinear.train(x, dummy, liblinear_params)
56
+ @weight_vec = @model[:w].dup
57
+ @bias_term = @model[:rho]
58
+ self
59
+ end
60
+
61
+ # Calculate confidence scores for samples.
62
+ #
63
+ # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
64
+ # @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence score per sample.
65
+ def decision_function(x)
66
+ raise "#{self.class.name}\##{__method__} expects to be called after training the model with the fit method." unless trained?
67
+ x = check_convert_sample_array(x)
68
+ Numo::Liblinear.decision_function(x, liblinear_params, @model)
69
+ end
70
+
71
+ # Predict class labels for samples.
72
+ #
73
+ # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
74
+ # @return [Numo::Int32] (shape: [n_samples]) Predicted label per sample.
75
+ def predict(x)
76
+ raise "#{self.class.name}\##{__method__} expects to be called after training the model with the fit method." unless trained?
77
+ x = check_convert_sample_array(x)
78
+ Numo::Int32.cast(Numo::Liblinear.predict(x, liblinear_params, @model))
79
+ end
80
+
81
+ # Dump marshal data.
82
+ # @return [Hash] The marshal data about LinearOneClassSVM.
83
+ def marshal_dump
84
+ { params: @params,
85
+ model: @model,
86
+ weight_vec: @weight_vec,
87
+ bias_term: @bias_term }
88
+ end
89
+
90
+ # Load marshal data.
91
+ # @return [nil]
92
+ def marshal_load(obj)
93
+ @params = obj[:params]
94
+ @model = obj[:model]
95
+ @weight_vec = obj[:weight_vec]
96
+ @bias_term = obj[:bias_term]
97
+ nil
98
+ end
99
+
100
+ private
101
+
102
+ def liblinear_params
103
+ res = {}
104
+ res[:solver_type] = Numo::Liblinear::SolverType::ONECLASS_SVM
105
+ res[:eps] = @params[:tol]
106
+ res[:C] = @params[:reg_param]
107
+ res[:nu] = @params[:nu]
108
+ res[:verbose] = @params[:verbose]
109
+ res[:random_seed] = @params[:random_seed]
110
+ res
111
+ end
112
+
113
+ def trained?
114
+ !@model.nil?
115
+ end
116
+ end
117
+ end
118
+ end
@@ -58,10 +58,6 @@ module Rumale
58
58
  @params[:tol] = tol.to_f
59
59
  @params[:verbose] = verbose
60
60
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
61
- @model = nil
62
- @weight_vec = nil
63
- @bias_term = nil
64
- @prob_param = nil
65
61
  end
66
62
 
67
63
  # Fit the model with given training data.
@@ -54,9 +54,6 @@ module Rumale
54
54
  @params[:tol] = tol.to_f
55
55
  @params[:verbose] = verbose
56
56
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
57
- @model = nil
58
- @weight_vec = nil
59
- @bias_term = nil
60
57
  end
61
58
 
62
59
  # Fit the model with given training data.
@@ -52,9 +52,6 @@ module Rumale
52
52
  @params[:tol] = tol.to_f
53
53
  @params[:verbose] = verbose
54
54
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
55
- @model = nil
56
- @weight_vec = nil
57
- @bias_term = nil
58
55
  end
59
56
 
60
57
  # Fit the model with given training data.
@@ -47,7 +47,6 @@ module Rumale
47
47
  @params[:tol] = tol.to_f
48
48
  @params[:verbose] = verbose
49
49
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
50
- @model = nil
51
50
  end
52
51
 
53
52
  # Fit the model with given training data.
@@ -45,7 +45,6 @@ module Rumale
45
45
  @params[:tol] = tol.to_f
46
46
  @params[:verbose] = verbose
47
47
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
48
- @model = nil
49
48
  end
50
49
 
51
50
  # Fit the model with given training data.
@@ -45,7 +45,6 @@ module Rumale
45
45
  @params[:tol] = tol.to_f
46
46
  @params[:verbose] = verbose
47
47
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
48
- @model = nil
49
48
  end
50
49
 
51
50
  # Fit the model with given training data.
@@ -47,7 +47,6 @@ module Rumale
47
47
  @params[:tol] = tol.to_f
48
48
  @params[:verbose] = verbose
49
49
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
50
- @model = nil
51
50
  end
52
51
 
53
52
  # Fit the model with given training data.
@@ -48,7 +48,6 @@ module Rumale
48
48
  @params[:tol] = tol.to_f
49
49
  @params[:verbose] = verbose
50
50
  @params[:random_seed] = random_seed.nil? ? nil : random_seed.to_i
51
- @model = nil
52
51
  end
53
52
 
54
53
  # Fit the model with given training data.
@@ -5,6 +5,6 @@ module Rumale
5
5
  # This module consists of Rumale interfaces for suppor vector machine algorithms with LIBSVM and LIBLINEAR.
6
6
  module SVM
7
7
  # The version of Rumale-SVM you are using.
8
- VERSION = '0.3.0'
8
+ VERSION = '0.5.1'
9
9
  end
10
10
  end
data/lib/rumale/svm.rb CHANGED
@@ -9,3 +9,4 @@ require 'rumale/svm/one_class_svm'
9
9
  require 'rumale/svm/linear_svc'
10
10
  require 'rumale/svm/linear_svr'
11
11
  require 'rumale/svm/logistic_regression'
12
+ require 'rumale/svm/linear_one_class_svm'
@@ -0,0 +1,24 @@
1
+ module Rumale
2
+ module SVM
3
+ class LinearOneClassSVM
4
+ include Base::BaseEstimator
5
+ include Validation
6
+
7
+ attr_reader weight_vec: Numo::DFloat
8
+ attr_reader bias_term: Float
9
+
10
+ def initialize: (?nu: Float nu, ?reg_param: Float reg_param, ?tol: Float tol,
11
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
12
+ def fit: (Numo::DFloat x, ?untyped? _y) -> LinearOneClassSVM
13
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
14
+ def predict: (Numo::DFloat x) -> Numo::Int32
15
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped, weight_vec: Numo::DFloat, bias_term: Float }
16
+ def marshal_load: (untyped obj) -> void
17
+
18
+ private
19
+
20
+ def liblinear_params: () -> untyped
21
+ def trained?: () -> bool
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module Rumale
2
+ module SVM
3
+ class LinearSVC
4
+ include Base::BaseEstimator
5
+ include Base::Classifier
6
+
7
+ attr_reader weight_vec: Numo::DFloat
8
+ attr_reader bias_term: Numo::DFloat
9
+
10
+ def initialize: (?penalty: String penalty, ?loss: String loss, ?dual: bool dual, ?reg_param: Float reg_param,
11
+ ?fit_bias: bool fit_bias, ?bias_scale: Float bias_scale, ?probability: bool probability,
12
+ ?tol: Float tol, ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
13
+ def fit: (Numo::DFloat x, Numo::Int32 y) -> LinearSVC
14
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
15
+ def predict: (Numo::DFloat x) -> Numo::Int32
16
+ def predict_proba: (Numo::DFloat x) -> Numo::DFloat
17
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped, weight_vec: Numo::DFloat, bias_term: Numo::DFloat, prob_param: Numo::DFloat }
18
+ def marshal_load: (Hash[Symbol, untyped] obj) -> void
19
+
20
+ private
21
+
22
+ def expand_feature: (Numo::DFloat x) -> Numo::DFloat
23
+ def weight_and_bias: (Numo::DFloat base_weight) -> [Numo::DFloat, Numo::DFloat]
24
+ def proba_model: (Numo::DFloat df, Numo::Int32 y) -> Numo::DFloat
25
+ def liblinear_params: () -> untyped
26
+ def solver_type: () -> Integer
27
+ def binary_class?: () -> bool
28
+ def fit_probability?: () -> bool
29
+ def fit_bias?: () -> bool
30
+ def bias_scale: () -> Float
31
+ def n_classes: () -> Integer
32
+ def n_features: () -> Integer
33
+ def labels: () -> Numo::Int32
34
+ def trained?: () -> bool
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module Rumale
2
+ module SVM
3
+ class LinearSVR
4
+ include Base::BaseEstimator
5
+ include Base::Regressor
6
+
7
+ attr_reader weight_vec: Numo::DFloat
8
+ attr_reader bias_term: Numo::DFloat
9
+
10
+ def initialize: (?loss: String loss, ?dual: bool dual, ?reg_param: Float reg_param, ?epsilon: Float epsilon,
11
+ ?fit_bias: bool fit_bias, ?bias_scale: Float bias_scale, ?tol: Float tol,
12
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
13
+ def fit: (Numo::DFloat x, Numo::DFloat y) -> LinearSVR
14
+ def predict: (Numo::DFloat x) -> Numo::DFloat
15
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped, weight_vec: Numo::DFloat, bias_term: Numo::DFloat }
16
+ def marshal_load: (Hash[Symbol, untyped] obj) -> void
17
+
18
+ private
19
+
20
+ def expand_feature: (Numo::DFloat x) -> Numo::DFloat
21
+ def weight_and_bias: (Numo::DFloat base_weight) -> [Numo::DFloat, Numo::DFloat]
22
+ def liblinear_params: () -> untyped
23
+ def solver_type: () -> Integer
24
+ def fit_bias?: () -> bool
25
+ def bias_scale: () -> Float
26
+ def trained?: () -> bool
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ module Rumale
2
+ module SVM
3
+ class LogisticRegression
4
+ include Base::BaseEstimator
5
+ include Base::Classifier
6
+
7
+ attr_reader weight_vec: Numo::DFloat
8
+ attr_reader bias_term: Numo::DFloat
9
+
10
+ def initialize: (?penalty: String penalty, ?dual: bool dual, ?reg_param: Float reg_param,
11
+ ?fit_bias: bool fit_bias, ?bias_scale: Float bias_scale, ?tol: Float tol,
12
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
13
+ def fit: (Numo::DFloat x, Numo::Int32 y) -> LogisticRegression
14
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
15
+ def predict: (Numo::DFloat x) -> Numo::Int32
16
+ def predict_proba: (Numo::DFloat x) -> Numo::DFloat
17
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped, weight_vec: Numo::DFloat, bias_term: Numo::DFloat }
18
+ def marshal_load: (untyped obj) -> void
19
+
20
+ private
21
+
22
+ def expand_feature: (Numo::DFloat x) -> Numo::DFloat
23
+ def weight_and_bias: (Numo::DFloat base_weight) -> [Numo::DFloat, Numo::DFloat]
24
+ def liblinear_params: () -> untyped
25
+ def solver_type: () -> Integer
26
+ def binary_class?: () -> bool
27
+ def fit_bias?: () -> bool
28
+ def bias_scale: () -> Float
29
+ def n_classes: () -> Integer
30
+ def n_features: () -> Integer
31
+ def trained?: () -> bool
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Rumale
2
+ module SVM
3
+ class NuSVC
4
+ include Base::BaseEstimator
5
+ include Base::Classifier
6
+
7
+ def initialize: (?nu: Float nu, ?kernel: String kernel, ?degree: Integer degree, ?gamma: Float gamma, ?coef0: Float coef0,
8
+ ?shrinking: bool shrinking, ?probability: bool probability,
9
+ ?cache_size: Float cache_size, ?tol: Float tol,
10
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
11
+ def fit: (Numo::DFloat x, Numo::Int32 y) -> NuSVC
12
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
13
+ def predict: (Numo::DFloat x) -> Numo::Int32
14
+ def predict_proba: (Numo::DFloat x) -> Numo::DFloat
15
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped }
16
+ def marshal_load: (untyped obj) -> void
17
+ def support: () -> Numo::Int32
18
+ def support_vectors: () -> Numo::DFloat
19
+ def n_support: () -> Numo::Int32
20
+ def duel_coef: () -> Numo::DFloat
21
+ def intercept: () -> Numo::DFloat
22
+ def prob_a: () -> Numo::DFloat
23
+ def prob_b: () -> Numo::DFloat
24
+
25
+ private
26
+
27
+ def add_index_col: (Numo::DFloat x) -> Numo::DFloat
28
+ def del_index_col: (Numo::DFloat x) -> Numo::DFloat
29
+ def precomputed_kernel?: () -> bool
30
+ def libsvm_params: () -> untyped
31
+ def trained?: () -> bool
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Rumale
2
+ module SVM
3
+ class NuSVR
4
+ include Base::BaseEstimator
5
+ include Base::Regressor
6
+
7
+ def initialize: (?nu: Float nu, ?kernel: String kernel, ?degree: Integer degree, ?gamma: Float gamma, ?coef0: Float coef0,
8
+ ?shrinking: bool shrinking, ?cache_size: Float cache_size, ?tol: Float tol,
9
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
10
+ def fit: (Numo::DFloat x, Numo::DFloat y) -> NuSVR
11
+ def predict: (Numo::DFloat x) -> Numo::DFloat
12
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped }
13
+ def marshal_load: (Hash[Symbol, untyped] obj) -> void
14
+ def support: () -> Numo::Int32
15
+ def support_vectors: () -> Numo::DFloat
16
+ def n_support: () -> Integer
17
+ def duel_coef: () -> Numo::DFloat
18
+ def intercept: () -> Numo::DFloat
19
+
20
+ private
21
+
22
+ def add_index_col: (Numo::DFloat x) -> Numo::DFloat
23
+ def del_index_col: (Numo::DFloat x) -> Numo::DFloat
24
+ def precomputed_kernel?: () -> bool
25
+ def libsvm_params: () -> untyped
26
+ def trained?: () -> bool
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ module Rumale
2
+ module SVM
3
+ class OneClassSVM
4
+ include Base::BaseEstimator
5
+ include Validation
6
+
7
+ def initialize: (?nu: Float nu, ?kernel: String kernel, ?degree: Integer degree, ?gamma: Float gamma, ?coef0: Float coef0,
8
+ ?shrinking: bool shrinking, ?cache_size: Float cache_size, ?tol: Float tol,
9
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
10
+ def fit: (Numo::DFloat x, ?untyped? _y) -> OneClassSVM
11
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
12
+ def predict: (Numo::DFloat x) -> Numo::Int32
13
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped }
14
+ def marshal_load: (Hash[Symbol, untyped] obj) -> void
15
+ def support: () -> Numo::Int32
16
+ def support_vectors: () -> Numo::DFloat
17
+ def n_support: () -> Integer
18
+ def duel_coef: () -> Numo::DFloat
19
+ def intercept: () -> Numo::DFloat
20
+
21
+ private
22
+
23
+ def libsvm_params: () -> untyped
24
+ def trained?: () -> bool
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module Rumale
2
+ module SVM
3
+ class SVC
4
+ include Base::BaseEstimator
5
+ include Base::Classifier
6
+
7
+ def initialize: (?reg_param: Float reg_param, ?kernel: String kernel, ?degree: Integer degree, ?gamma: Float gamma,
8
+ ?coef0: Float coef0, ?shrinking: bool shrinking, ?probability: bool probability,
9
+ ?cache_size: Float cache_size, ?tol: Float tol,
10
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
11
+ def fit: (Numo::DFloat x, Numo::Int32 y) -> SVC
12
+ def decision_function: (Numo::DFloat x) -> Numo::DFloat
13
+ def predict: (Numo::DFloat x) -> Numo::Int32
14
+ def predict_proba: (Numo::DFloat x) -> Numo::DFloat
15
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped }
16
+ def marshal_load: (Hash[Symbol, untyped] obj) -> nil
17
+ def support: () -> Numo::Int32
18
+ def support_vectors: () -> Numo::DFloat
19
+ def n_support: () -> Numo::Int32
20
+ def duel_coef: () -> Numo::DFloat
21
+ def intercept: () -> Numo::DFloat
22
+ def prob_a: () -> Numo::DFloat
23
+ def prob_b: () -> Numo::DFloat
24
+
25
+ private
26
+
27
+ def add_index_col: (Numo::DFloat x) -> Numo::DFloat
28
+ def del_index_col: (Numo::DFloat x) -> Numo::DFloat
29
+ def precomputed_kernel?: () -> bool
30
+ def libsvm_params: () -> untyped
31
+ def trained?: () -> bool
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ module Rumale
2
+ module SVM
3
+ class SVR
4
+ include Base::BaseEstimator
5
+ include Base::Regressor
6
+
7
+ def initialize: (?reg_param: Float reg_param, ?epsilon: Float epsilon, ?kernel: String kernel, ?degree: Integer degree,
8
+ ?gamma: Float gamma, ?coef0: Float coef0, ?shrinking: bool shrinking,
9
+ ?cache_size: Float cache_size, ?tol: Float tol,
10
+ ?verbose: bool verbose, ?random_seed: untyped? random_seed) -> void
11
+ def fit: (Numo::DFloat x, Numo::DFloat y) -> SVR
12
+ def predict: (Numo::DFloat x) -> Numo::DFloat
13
+ def marshal_dump: () -> { params: Hash[Symbol, untyped], model: untyped }
14
+ def marshal_load: (Hash[Symbol, untyped] obj) -> void
15
+ def support: () -> Numo::Int32
16
+ def support_vectors: () -> Numo::DFloat
17
+ def n_support: () -> Integer
18
+ def duel_coef: () -> Numo::DFloat
19
+ def intercept: () -> Numo::DFloat
20
+
21
+ private
22
+
23
+ def add_index_col: (Numo::DFloat x) -> Numo::DFloat
24
+ def del_index_col: (Numo::DFloat x) -> Numo::DFloat
25
+ def precomputed_kernel?: () -> bool
26
+ def libsvm_params: () -> untyped
27
+ def trained?: () -> bool
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Rumale
2
+ module SVM
3
+ VERSION: String
4
+ end
5
+ 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.3.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-06 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-liblinear
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: numo-libsvm
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,6 +45,9 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.14'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '0.24'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,6 +55,9 @@ dependencies:
52
55
  - - "~>"
53
56
  - !ruby/object:Gem::Version
54
57
  version: '0.14'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.24'
55
61
  description: 'Rumale-SVM provides support vector machine algorithms of LIBSVM and
56
62
  LIBLINEAR with Rumale interface.
57
63
 
@@ -62,21 +68,11 @@ executables: []
62
68
  extensions: []
63
69
  extra_rdoc_files: []
64
70
  files:
65
- - ".coveralls.yml"
66
- - ".github/workflows/build.yml"
67
- - ".gitignore"
68
- - ".rspec"
69
- - ".rubocop.yml"
70
- - ".travis.yml"
71
71
  - CHANGELOG.md
72
- - CODE_OF_CONDUCT.md
73
- - Gemfile
74
72
  - LICENSE.txt
75
73
  - README.md
76
- - Rakefile
77
- - bin/console
78
- - bin/setup
79
74
  - lib/rumale/svm.rb
75
+ - lib/rumale/svm/linear_one_class_svm.rb
80
76
  - lib/rumale/svm/linear_svc.rb
81
77
  - lib/rumale/svm/linear_svr.rb
82
78
  - lib/rumale/svm/logistic_regression.rb
@@ -86,15 +82,25 @@ files:
86
82
  - lib/rumale/svm/svc.rb
87
83
  - lib/rumale/svm/svr.rb
88
84
  - lib/rumale/svm/version.rb
89
- - rumale-svm.gemspec
85
+ - sig/rumale/svm.rbs
86
+ - sig/rumale/svm/linear_one_class_svm.rbs
87
+ - sig/rumale/svm/linear_svc.rbs
88
+ - sig/rumale/svm/linear_svr.rbs
89
+ - sig/rumale/svm/logistic_regression.rbs
90
+ - sig/rumale/svm/nu_svc.rbs
91
+ - sig/rumale/svm/nu_svr.rbs
92
+ - sig/rumale/svm/one_class_svm.rbs
93
+ - sig/rumale/svm/svc.rbs
94
+ - sig/rumale/svm/svr.rbs
90
95
  homepage: https://github.com/yoshoku/rumale-svm
91
96
  licenses:
92
97
  - BSD-3-Clause
93
98
  metadata:
94
99
  homepage_uri: https://github.com/yoshoku/rumale-svm
95
100
  source_code_uri: https://github.com/yoshoku/rumale-svm
96
- changelog_uri: https://github.com/yoshoku/rumale-svm/blob/master/CHANGELOG.md
101
+ changelog_uri: https://github.com/yoshoku/rumale-svm/blob/main/CHANGELOG.md
97
102
  documentation_uri: https://yoshoku.github.io/rumale-svm/doc/
103
+ rubygems_mfa_required: 'true'
98
104
  post_install_message:
99
105
  rdoc_options: []
100
106
  require_paths:
@@ -110,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
116
  - !ruby/object:Gem::Version
111
117
  version: '0'
112
118
  requirements: []
113
- rubygems_version: 3.1.2
119
+ rubygems_version: 3.2.33
114
120
  signing_key:
115
121
  specification_version: 4
116
122
  summary: Rumale-SVM provides support vector machine algorithms of LIBSVM and LIBLINEAR
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
@@ -1,24 +0,0 @@
1
- name: build
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- strategy:
11
- matrix:
12
- ruby: ['2.4.x', '2.5.x', '2.6.x']
13
-
14
- steps:
15
- - uses: actions/checkout@master
16
- - name: Set up Ruby
17
- uses: actions/setup-ruby@master
18
- with:
19
- ruby-version: ${{ matrix.ruby }}
20
- - name: Build and test with Rake
21
- run: |
22
- gem install bundler
23
- bundle install --jobs 4 --retry 3
24
- bundle exec rake
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
13
-
14
- *.swp
15
- *.bundle
16
- tags
17
- .DS_Store
18
- .ruby-version
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,107 +0,0 @@
1
- require:
2
- - rubocop-performance
3
- - rubocop-rspec
4
-
5
- AllCops:
6
- TargetRubyVersion: 2.4
7
- DisplayCopNames: true
8
- DisplayStyleGuide: true
9
- Exclude:
10
- - 'bin/*'
11
- - 'rumale-svm.gemspec'
12
- - 'Rakefile'
13
- - 'Gemfile'
14
-
15
- Layout/EmptyLineAfterGuardClause:
16
- Enabled: false
17
-
18
- Layout/EmptyLinesAroundAttributeAccessor:
19
- Enabled: true
20
-
21
- Layout/LineLength:
22
- Max: 145
23
- IgnoredPatterns: ['(\A|\s)#']
24
-
25
- Layout/SpaceAroundMethodCallOperator:
26
- Enabled: true
27
-
28
- Lint/DeprecatedOpenSSLConstant:
29
- Enabled: true
30
-
31
- Lint/RaiseException:
32
- Enabled: true
33
-
34
- Lint/StructNewOverride:
35
- Enabled: true
36
-
37
- Metrics/ModuleLength:
38
- Max: 200
39
-
40
- Metrics/ClassLength:
41
- Max: 200
42
-
43
- Metrics/MethodLength:
44
- Max: 40
45
-
46
- Metrics/AbcSize:
47
- Max: 60
48
-
49
- Metrics/CyclomaticComplexity:
50
- Max: 16
51
-
52
- Metrics/PerceivedComplexity:
53
- Max: 16
54
-
55
- Metrics/BlockLength:
56
- Max: 40
57
- Exclude:
58
- - 'spec/**/*'
59
-
60
- Metrics/ParameterLists:
61
- Max: 12
62
-
63
- Naming/MethodParameterName:
64
- Enabled: false
65
-
66
- Naming/ConstantName:
67
- Enabled: false
68
-
69
- Security/MarshalLoad:
70
- Enabled: false
71
-
72
- Style/Documentation:
73
- Enabled: false
74
-
75
- Style/ExponentialNotation:
76
- Enabled: true
77
-
78
- Style/HashEachMethods:
79
- Enabled: true
80
-
81
- Style/HashTransformKeys:
82
- Enabled: true
83
-
84
- Style/HashTransformValues:
85
- Enabled: true
86
-
87
- Style/SlicingWithRange:
88
- Enabled: true
89
-
90
- Style/FormatStringToken:
91
- Enabled: false
92
-
93
- Style/NumericLiterals:
94
- Enabled: false
95
-
96
- RSpec/MultipleExpectations:
97
- Enabled: false
98
-
99
- RSpec/ExampleLength:
100
- Max: 40
101
-
102
- RSpec/InstanceVariable:
103
- Enabled: false
104
-
105
- RSpec/LeakyConstantDeclaration:
106
- Enabled: false
107
-
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- sudo: false
3
- os: linux
4
- dist: bionic
5
- language: ruby
6
- cache: bundler
7
- rvm:
8
- - '2.4'
9
- - '2.5'
10
- - '2.6'
11
- - '2.7'
12
-
13
- before_install:
14
- - gem install bundler -v 2.0.2
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at yoshoku@outlook.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rumale-svm.gemspec
4
- gemspec
5
-
6
- gem 'coveralls', '~> 0.8'
7
- gem 'rake', '~> 12.0'
8
- gem 'rspec', '~> 3.0'
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rumale/svm"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/rumale-svm.gemspec DELETED
@@ -1,37 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'rumale/svm/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'rumale-svm'
7
- spec.version = Rumale::SVM::VERSION
8
- spec.authors = ['yoshoku']
9
- spec.email = ['yoshoku@outlook.com']
10
-
11
- spec.summary = <<~MSG
12
- Rumale-SVM provides support vector machine algorithms of LIBSVM and LIBLINEAR with Rumale interface.
13
- MSG
14
- spec.description = <<~MSG
15
- Rumale-SVM provides support vector machine algorithms of LIBSVM and LIBLINEAR with Rumale interface.
16
- MSG
17
- spec.homepage = 'https://github.com/yoshoku/rumale-svm'
18
- spec.license = 'BSD-3-Clause'
19
-
20
- spec.metadata['homepage_uri'] = spec.homepage
21
- spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/rumale-svm'
22
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/rumale-svm/blob/master/CHANGELOG.md'
23
- spec.metadata['documentation_uri'] = 'https://yoshoku.github.io/rumale-svm/doc/'
24
-
25
- # Specify which files should be added to the gem when it is released.
26
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
- end
30
- spec.bindir = 'exe'
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ['lib']
33
-
34
- spec.add_runtime_dependency 'numo-liblinear', '~> 1.0'
35
- spec.add_runtime_dependency 'numo-libsvm', '~> 1.0'
36
- spec.add_runtime_dependency 'rumale', '~> 0.14'
37
- end