rumale 0.12.9 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -8
- data/CHANGELOG.md +14 -0
- data/README.md +1 -1
- data/ext/rumale/rumale.c +7 -8
- data/lib/rumale/base/base_estimator.rb +17 -1
- data/lib/rumale/decomposition/pca.rb +25 -11
- data/lib/rumale/version.rb +1 -1
- data/rumale.gemspec +5 -4
- metadata +29 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdd9f655f3a1f95edc68476dd614deac7718ef65
|
4
|
+
data.tar.gz: f979c070a55fc8fb2afce0c04b1fa26bf92aa2af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a6aed271a2f0da786544aaef2dc81b62c357f7dbd552c5ebbdd6a67c39b3584b9b139a6ea8be269a030ca2c7ec0f5852ccc3990492d3f4aabf55ab46172d9a
|
7
|
+
data.tar.gz: b89de3059991cecfe92d492193287777cd8278715ee55e52868005a8df5489005f02ed862b8a782111e0cc8f76da67b1965b690e5a5876c7877025d7657f6be3
|
data/.travis.yml
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
sudo: false
|
2
2
|
os: linux
|
3
|
-
dist:
|
3
|
+
dist: xenial
|
4
4
|
language: ruby
|
5
5
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
- '2.4'
|
7
|
+
- '2.5'
|
8
|
+
- '2.6'
|
9
|
+
|
10
|
+
addons:
|
11
|
+
apt:
|
12
|
+
packages:
|
13
|
+
- libopenblas-dev
|
14
|
+
- liblapacke-dev
|
13
15
|
|
16
|
+
before_install:
|
17
|
+
- gem install bundler -v 2.0.2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.13.0
|
2
|
+
- Introduce [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) to use linear algebra algorithms on the optimization.
|
3
|
+
- Add the solver parameter that specifies the optimization algorithm to Rumale::Decomposition::PCA.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'rumale'
|
7
|
+
|
8
|
+
# Loading Numo::Linalg enables features based on linear algebra algorithms.
|
9
|
+
require 'numo/linalg/autoloader'
|
10
|
+
|
11
|
+
decomposer = Rumale::Decomposition::PCA.new(n_components: 2, solver: 'evd')
|
12
|
+
low_dimensional_samples = decomposer.fit_transform(samples)
|
13
|
+
```
|
14
|
+
|
1
15
|
# 0.12.9
|
2
16
|
- Add class for K-Medoids clustering.
|
3
17
|
- Fix extension codes of decision tree regressor for using Numo::NArray.
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/github/yoshoku/rumale/badge.svg?branch=master)](https://coveralls.io/github/yoshoku/rumale?branch=master)
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/rumale.svg)](https://badge.fury.io/rb/rumale)
|
8
8
|
[![BSD 2-Clause License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://github.com/yoshoku/rumale/blob/master/LICENSE.txt)
|
9
|
-
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/rumale/0.
|
9
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/rumale/0.13.0)
|
10
10
|
|
11
11
|
Rumale (**Ru**by **ma**chine **le**arning) is a machine learning library in Ruby.
|
12
12
|
Rumale provides machine learning algorithms with interfaces similar to Scikit-Learn in Python.
|
data/ext/rumale/rumale.c
CHANGED
@@ -459,14 +459,13 @@ iter_find_split_params_grad_reg(na_loop_t const* lp)
|
|
459
459
|
* Find for split point with maximum information gain.
|
460
460
|
*
|
461
461
|
* @overload find_split_params(order, features, gradients, hessians, sum_gradient, sum_hessian, reg_lambda) -> Array<Float>
|
462
|
-
*
|
463
|
-
*
|
464
|
-
*
|
465
|
-
*
|
466
|
-
*
|
467
|
-
*
|
468
|
-
*
|
469
|
-
* @param reg_lambda [Float] The L2 regularization term on weight.
|
462
|
+
* @param order [Numo::Int32] (shape: [n_elements]) The element indices sorted according to feature values.
|
463
|
+
* @param features [Numo::DFloat] (shape: [n_elements]) The feature values.
|
464
|
+
* @param gradients [Numo::DFloat] (shape: [n_elements]) The gradient values.
|
465
|
+
* @param hessians [Numo::DFloat] (shape: [n_elements]) The hessian values.
|
466
|
+
* @param sum_gradient [Float] The sum of gradient values.
|
467
|
+
* @param sum_hessian [Float] The sum of hessian values.
|
468
|
+
* @param reg_lambda [Float] The L2 regularization term on weight.
|
470
469
|
* @return [Array<Float>] The array consists of optimal parameters including threshold and gain.
|
471
470
|
*/
|
472
471
|
static VALUE
|
@@ -11,8 +11,24 @@ module Rumale
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
+
def enable_linalg?
|
15
|
+
if defined?(Numo::Linalg).nil?
|
16
|
+
warn('If you want to use features that depend on Numo::Linalg, you should install and load Numo::Linalg in advance.')
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
if Numo::Linalg::VERSION < '0.1.4'
|
20
|
+
warn('The loaded Numo::Linalg does not implement the methods required by Rumale. Please load Numo::Linalg version 0.1.4 or later.')
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
14
26
|
def enable_parallel?
|
15
|
-
return false if @params[:n_jobs].nil?
|
27
|
+
return false if @params[:n_jobs].nil?
|
28
|
+
if defined?(Parallel).nil?
|
29
|
+
warn('If you want to use parallel option, you should install and load Parallel in advance.')
|
30
|
+
return false
|
31
|
+
end
|
16
32
|
true
|
17
33
|
end
|
18
34
|
|
@@ -12,6 +12,11 @@ module Rumale
|
|
12
12
|
# decomposer = Rumale::Decomposition::PCA.new(n_components: 2)
|
13
13
|
# representaion = decomposer.fit_transform(samples)
|
14
14
|
#
|
15
|
+
# # If Numo::Linalg is installed, you can specify 'evd' for the solver option.
|
16
|
+
# require 'numo/linalg/autoloader'
|
17
|
+
# decomposer = Rumale::Decomposition::PCA.new(n_components: 2, solver: 'evd')
|
18
|
+
# representaion = decomposer.fit_transform(samples)
|
19
|
+
#
|
15
20
|
# *Reference*
|
16
21
|
# - A. Sharma and K K. Paliwal, "Fast principal component analysis using fixed-point algorithm," Pattern Recognition Letters, 28, pp. 1151--1155, 2007.
|
17
22
|
class PCA
|
@@ -23,7 +28,7 @@ module Rumale
|
|
23
28
|
attr_reader :components
|
24
29
|
|
25
30
|
# Returns the mean vector.
|
26
|
-
# @return [Numo::DFloat] (shape: [n_features]
|
31
|
+
# @return [Numo::DFloat] (shape: [n_features])
|
27
32
|
attr_reader :mean
|
28
33
|
|
29
34
|
# Return the random generator.
|
@@ -33,15 +38,19 @@ module Rumale
|
|
33
38
|
# Create a new transformer with PCA.
|
34
39
|
#
|
35
40
|
# @param n_components [Integer] The number of principal components.
|
36
|
-
# @param
|
37
|
-
#
|
41
|
+
# @param solver [String] The algorithm for the optimization ('fpt' or 'evd').
|
42
|
+
# 'fpt' uses the fixed-point algorithm. 'evd' performs eigen value decomposition of the covariance matrix of samples.
|
43
|
+
# @param max_iter [Integer] The maximum number of iterations. If solver = 'evd', this parameter is ignored.
|
44
|
+
# @param tol [Float] The tolerance of termination criterion. If solver = 'evd', this parameter is ignored.
|
38
45
|
# @param random_seed [Integer] The seed value using to initialize the random generator.
|
39
|
-
def initialize(n_components: 2, max_iter: 100, tol: 1.0e-4, random_seed: nil)
|
46
|
+
def initialize(n_components: 2, solver: 'fpt', max_iter: 100, tol: 1.0e-4, random_seed: nil)
|
40
47
|
check_params_integer(n_components: n_components, max_iter: max_iter)
|
48
|
+
check_params_string(solver: solver)
|
41
49
|
check_params_float(tol: tol)
|
42
50
|
check_params_type_or_nil(Integer, random_seed: random_seed)
|
43
51
|
check_params_positive(n_components: n_components, max_iter: max_iter, tol: tol)
|
44
52
|
@params = {}
|
53
|
+
@params[:solver] = solver != 'evd' ? 'fpt' : 'evd'
|
45
54
|
@params[:n_components] = n_components
|
46
55
|
@params[:max_iter] = max_iter
|
47
56
|
@params[:tol] = tol
|
@@ -69,14 +78,19 @@ module Rumale
|
|
69
78
|
centered_x = x - @mean
|
70
79
|
# optimization.
|
71
80
|
covariance_mat = centered_x.transpose.dot(centered_x) / (n_samples - 1)
|
72
|
-
@params[:
|
73
|
-
|
74
|
-
@
|
75
|
-
|
76
|
-
|
77
|
-
comp_vec =
|
81
|
+
if @params[:solver] == 'evd' && enable_linalg?
|
82
|
+
_, evecs = Numo::Linalg.eigh(covariance_mat, vals_range: (n_features - @params[:n_components])...n_features)
|
83
|
+
@components = evecs.reverse(1).transpose.dup
|
84
|
+
else
|
85
|
+
@params[:n_components].times do
|
86
|
+
comp_vec = Rumale::Utils.rand_uniform(n_features, sub_rng)
|
87
|
+
@params[:max_iter].times do
|
88
|
+
updated = orthogonalize(covariance_mat.dot(comp_vec))
|
89
|
+
break if (updated.dot(comp_vec) - 1).abs < @params[:tol]
|
90
|
+
comp_vec = updated
|
91
|
+
end
|
92
|
+
@components = @components.nil? ? comp_vec : Numo::NArray.vstack([@components, comp_vec])
|
78
93
|
end
|
79
|
-
@components = @components.nil? ? comp_vec : Numo::NArray.vstack([@components, comp_vec])
|
80
94
|
end
|
81
95
|
self
|
82
96
|
end
|
data/lib/rumale/version.rb
CHANGED
data/rumale.gemspec
CHANGED
@@ -37,10 +37,11 @@ Gem::Specification.new do |spec|
|
|
37
37
|
|
38
38
|
spec.add_runtime_dependency 'numo-narray', '>= 0.9.1'
|
39
39
|
|
40
|
-
spec.add_development_dependency 'bundler', '
|
41
|
-
spec.add_development_dependency 'coveralls', '
|
42
|
-
spec.add_development_dependency '
|
40
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
41
|
+
spec.add_development_dependency 'coveralls', '>= 0.8.23'
|
42
|
+
spec.add_development_dependency 'numo-linalg', '>= 0.1.4'
|
43
|
+
spec.add_development_dependency 'parallel', '>= 1.17.0'
|
43
44
|
spec.add_development_dependency 'rake', '~> 12.0'
|
44
|
-
spec.add_development_dependency 'rake-compiler'
|
45
|
+
spec.add_development_dependency 'rake-compiler', '~> 1.0'
|
45
46
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
46
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -26,46 +26,60 @@ dependencies:
|
|
26
26
|
version: 0.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 0.8.23
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 0.8.23
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: numo-linalg
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 0.1.4
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 0.1.4
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: parallel
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 1.17.0
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 1.17.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +98,16 @@ dependencies:
|
|
84
98
|
name: rake-compiler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
103
|
+
version: '1.0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
110
|
+
version: '1.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|