umappp 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/umappp/umappp.cpp +23 -28
- data/lib/umappp/version.rb +1 -1
- data/lib/umappp.rb +15 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 652d8cf10c9054b45a567638d8f04f42f8915944bc980c6e28b9e71f0a0f76af
|
4
|
+
data.tar.gz: 2d9f36babd30db2554e6e02753d16d777dabcb2c163f1558f369035317fd1398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45fe9afc8e8a0917429901ee7cfca09596a4ec6d3e292717aa2035f0ba992e570da604bd22879abfc924ff75e200e2d37513ed82ab7b8d547df9234d025a8429
|
7
|
+
data.tar.gz: 267b65e8883f039e1876a4b4b629cd77b506212641d602bf97f1787103b99457148618188dd6aafdb5c8d96df1e22fa2a2dc0d73a052d4375c6b731288532784
|
data/ext/umappp/umappp.cpp
CHANGED
@@ -18,7 +18,7 @@ using namespace Rice;
|
|
18
18
|
|
19
19
|
// This function is used to view default parameters from Ruby.
|
20
20
|
|
21
|
-
Hash
|
21
|
+
Hash umappp_default_parameters(Object self)
|
22
22
|
{
|
23
23
|
Hash d;
|
24
24
|
d[Symbol("local_connectivity")] = Umap::Defaults::local_connectivity;
|
@@ -42,7 +42,7 @@ Hash umap_default_parameters(Object self)
|
|
42
42
|
|
43
43
|
// Function to perform umap.
|
44
44
|
|
45
|
-
Object
|
45
|
+
Object umappp_run(
|
46
46
|
Object self,
|
47
47
|
Hash params,
|
48
48
|
numo::SFloat data,
|
@@ -51,120 +51,115 @@ Object umap_run(
|
|
51
51
|
int tick = 0)
|
52
52
|
{
|
53
53
|
// Parameters are taken from a Ruby Hash object.
|
54
|
-
// If there is
|
54
|
+
// If there is key, set the value.
|
55
55
|
|
56
|
+
auto umap_ptr = new Umap;
|
57
|
+
|
56
58
|
double local_connectivity = Umap::Defaults::local_connectivity;
|
57
59
|
if (RTEST(params.call("has_key?", Symbol("local_connectivity"))))
|
58
60
|
{
|
59
61
|
local_connectivity = params.get<double>(Symbol("local_connectivity"));
|
62
|
+
umap_ptr->set_local_connectivity(local_connectivity);
|
60
63
|
}
|
61
64
|
|
62
65
|
double bandwidth = Umap::Defaults::bandwidth;
|
63
66
|
if (RTEST(params.call("has_key?", Symbol("bandwidth"))))
|
64
67
|
{
|
65
68
|
bandwidth = params.get<double>(Symbol("bandwidth"));
|
69
|
+
umap_ptr->set_bandwidth(bandwidth);
|
66
70
|
}
|
67
71
|
|
68
72
|
double mix_ratio = Umap::Defaults::mix_ratio;
|
69
73
|
if (RTEST(params.call("has_key?", Symbol("mix_ratio"))))
|
70
74
|
{
|
71
75
|
mix_ratio = params.get<double>(Symbol("mix_ratio"));
|
76
|
+
umap_ptr->set_mix_ratio(mix_ratio);
|
72
77
|
}
|
73
78
|
|
74
79
|
double spread = Umap::Defaults::spread;
|
75
80
|
if (RTEST(params.call("has_key?", Symbol("spread"))))
|
76
81
|
{
|
77
82
|
spread = params.get<double>(Symbol("spread"));
|
83
|
+
umap_ptr->set_spread(spread);
|
78
84
|
}
|
79
85
|
|
80
86
|
double min_dist = Umap::Defaults::min_dist;
|
81
87
|
if (RTEST(params.call("has_key?", Symbol("min_dist"))))
|
82
88
|
{
|
83
89
|
min_dist = params.get<double>(Symbol("min_dist"));
|
90
|
+
umap_ptr->set_min_dist(min_dist);
|
84
91
|
}
|
85
92
|
|
86
93
|
double a = Umap::Defaults::a;
|
87
94
|
if (RTEST(params.call("has_key?", Symbol("a"))))
|
88
95
|
{
|
89
96
|
a = params.get<double>(Symbol("a"));
|
97
|
+
umap_ptr->set_a(a);
|
90
98
|
}
|
91
99
|
|
92
100
|
double b = Umap::Defaults::b;
|
93
101
|
if (RTEST(params.call("has_key?", Symbol("b"))))
|
94
102
|
{
|
95
103
|
b = params.get<double>(Symbol("b"));
|
104
|
+
umap_ptr->set_b(b);
|
96
105
|
}
|
97
106
|
|
98
107
|
double repulsion_strength = Umap::Defaults::repulsion_strength;
|
99
108
|
if (RTEST(params.call("has_key?", Symbol("repulsion_strength"))))
|
100
109
|
{
|
101
110
|
repulsion_strength = params.get<double>(Symbol("repulsion_strength"));
|
111
|
+
umap_ptr->set_repulsion_strength(repulsion_strength);
|
102
112
|
}
|
103
113
|
|
104
114
|
int num_epochs = Umap::Defaults::num_epochs;
|
105
115
|
if (RTEST(params.call("has_key?", Symbol("num_epochs"))))
|
106
116
|
{
|
107
117
|
num_epochs = params.get<int>(Symbol("num_epochs"));
|
118
|
+
umap_ptr->set_num_epochs(num_epochs);
|
108
119
|
}
|
109
120
|
|
110
121
|
double learning_rate = Umap::Defaults::learning_rate;
|
111
122
|
if (RTEST(params.call("has_key?", Symbol("learning_rate"))))
|
112
123
|
{
|
113
124
|
learning_rate = params.get<double>(Symbol("learning_rate"));
|
125
|
+
umap_ptr->set_learning_rate(learning_rate);
|
114
126
|
}
|
115
127
|
|
116
128
|
double negative_sample_rate = Umap::Defaults::negative_sample_rate;
|
117
129
|
if (RTEST(params.call("has_key?", Symbol("negative_sample_rate"))))
|
118
130
|
{
|
119
131
|
negative_sample_rate = params.get<double>(Symbol("negative_sample_rate"));
|
132
|
+
umap_ptr->set_negative_sample_rate(negative_sample_rate);
|
120
133
|
}
|
121
134
|
|
122
135
|
int num_neighbors = Umap::Defaults::num_neighbors;
|
123
136
|
if (RTEST(params.call("has_key?", Symbol("num_neighbors"))))
|
124
137
|
{
|
125
138
|
num_neighbors = params.get<int>(Symbol("num_neighbors"));
|
139
|
+
umap_ptr->set_num_neighbors(num_neighbors);
|
126
140
|
}
|
127
141
|
|
128
142
|
int seed = Umap::Defaults::seed;
|
129
143
|
if (RTEST(params.call("has_key?", Symbol("seed"))))
|
130
144
|
{
|
131
145
|
seed = params.get<int>(Symbol("seed"));
|
146
|
+
umap_ptr->set_seed(seed);
|
132
147
|
}
|
133
148
|
|
134
149
|
bool batch = Umap::Defaults::batch;
|
135
150
|
if (RTEST(params.call("has_key?", Symbol("batch"))))
|
136
151
|
{
|
137
152
|
batch = params.get<bool>(Symbol("batch"));
|
153
|
+
umap_ptr->set_batch(batch);
|
138
154
|
}
|
139
155
|
|
140
156
|
int num_threads = Umap::Defaults::num_threads;
|
141
157
|
if (RTEST(params.call("has_key?", Symbol("num_threads"))))
|
142
158
|
{
|
143
159
|
num_threads = params.get<int>(Symbol("num_threads"));
|
160
|
+
umap_ptr->set_num_threads(num_threads);
|
144
161
|
}
|
145
|
-
|
146
|
-
// setup_parameters
|
147
|
-
|
148
|
-
auto umap_ptr = new Umap;
|
149
|
-
umap_ptr->set_local_connectivity(local_connectivity);
|
150
|
-
umap_ptr->set_bandwidth(bandwidth);
|
151
|
-
umap_ptr->set_mix_ratio(mix_ratio);
|
152
|
-
umap_ptr->set_spread(spread);
|
153
|
-
umap_ptr->set_min_dist(min_dist);
|
154
|
-
umap_ptr->set_a(a);
|
155
|
-
umap_ptr->set_b(b);
|
156
|
-
|
157
|
-
umap_ptr->set_repulsion_strength(repulsion_strength);
|
158
|
-
umap_ptr->set_num_epochs(num_epochs);
|
159
|
-
umap_ptr->set_learning_rate(learning_rate);
|
160
|
-
umap_ptr->set_negative_sample_rate(negative_sample_rate);
|
161
|
-
|
162
|
-
umap_ptr->set_num_neighbors(num_neighbors);
|
163
|
-
umap_ptr->set_seed(seed);
|
164
|
-
umap_ptr->set_batch(batch);
|
165
|
-
|
166
|
-
umap_ptr->set_num_threads(num_threads);
|
167
|
-
|
162
|
+
|
168
163
|
// initialize_from_matrix
|
169
164
|
|
170
165
|
const float *y = data.read_ptr();
|
@@ -220,6 +215,6 @@ extern "C" void Init_umappp()
|
|
220
215
|
{
|
221
216
|
Module rb_mUmappp =
|
222
217
|
define_module("Umappp")
|
223
|
-
.define_singleton_method("
|
224
|
-
.define_singleton_method("
|
218
|
+
.define_singleton_method("umappp_run", &umappp_run)
|
219
|
+
.define_singleton_method("umappp_default_parameters", &umappp_default_parameters);
|
225
220
|
}
|
data/lib/umappp/version.rb
CHANGED
data/lib/umappp.rb
CHANGED
@@ -7,7 +7,18 @@ require_relative "umappp/umappp"
|
|
7
7
|
# Uniform Manifold Approximation and Projection
|
8
8
|
module Umappp
|
9
9
|
|
10
|
-
#
|
10
|
+
# Make wrapper methods for the C++ function generated by Rice private
|
11
|
+
private_class_method :umappp_run
|
12
|
+
private_class_method :umappp_default_parameters
|
13
|
+
|
14
|
+
# View the default parameters defined within the Umappp C++ library structure.
|
15
|
+
def self.default_parameters
|
16
|
+
# {method: :annoy, ndim: 2, tick: 0}.merge
|
17
|
+
umappp_default_parameters
|
18
|
+
end
|
19
|
+
|
20
|
+
# Runs the Uniform Manifold Approximation and Projection (UMAP) dimensional
|
21
|
+
# reduction technique.
|
11
22
|
# @param embedding [Array, Numo::SFloat]
|
12
23
|
# @param method [Symbol]
|
13
24
|
# @param ndim [Integer]
|
@@ -28,14 +39,14 @@ module Umappp
|
|
28
39
|
# @param batch [Boolean]
|
29
40
|
# @param num_threads [Integer]
|
30
41
|
|
31
|
-
def self.run(
|
42
|
+
def self.run(embedding, method: :annoy, ndim: 2, tick: 0, **params)
|
32
43
|
unless (u = (params.keys - default_parameters.keys)).empty?
|
33
44
|
raise ArgumentError, "[umappp.rb] unknown option : #{u.inspect}"
|
34
45
|
end
|
35
46
|
|
36
47
|
nnmethod = %i[annoy vptree].index(method.to_sym)
|
37
|
-
data = Numo::SFloat.cast(
|
48
|
+
data = Numo::SFloat.cast(embedding)
|
38
49
|
|
39
|
-
|
50
|
+
umappp_run(params, data, ndim, nnmethod, tick)
|
40
51
|
end
|
41
52
|
end
|