knn_cv 0.1.2 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/ext/c_knn/Makefile +0 -0
- data/ext/c_knn/extconf.rb +0 -0
- data/ext/c_knn/knn.c +37 -33
- data/knn_cv.gemspec +0 -0
- data/lib/knn_cv.rb +0 -0
- data/lib/knn_cv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae7308b1dc9b6844bfe35f260b0112db5200a1cd
|
4
|
+
data.tar.gz: 6d299e33cd783d6ef734728e50c440d7ab108536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b716e72c5029a23262b6c41c6e0bafa5fcf53357bbb89876a7e181e13200b61174ee705f64a84399eb94895251f34af46ae5e655b68e89aba0dbbb7ed6ae29c6
|
7
|
+
data.tar.gz: da2335e2a1d07010ef7a0827d3078314925569c7bdc62a5e6e82297f504edcba7d5f1fd1ef1821d64720a797fca7ba362ead7a80f35f9e114d6bc7873f088faf
|
data/.gitignore
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/ext/c_knn/Makefile
CHANGED
File without changes
|
data/ext/c_knn/extconf.rb
CHANGED
File without changes
|
data/ext/c_knn/knn.c
CHANGED
@@ -184,55 +184,59 @@ VALUE method_c_knn_leaveoneout(VALUE self, VALUE rb_features) {
|
|
184
184
|
return rb_float_new(fitness);
|
185
185
|
}
|
186
186
|
|
187
|
-
VALUE method_c_knn_initialize(VALUE self, VALUE rb_k, VALUE
|
188
|
-
int ncol, nrow;
|
187
|
+
VALUE method_c_knn_initialize(VALUE self, VALUE rb_k, VALUE data, VALUE rb_class, VALUE rb_numeric, VALUE rb_random_par) {
|
188
|
+
long int ncol, nrow;
|
189
189
|
|
190
190
|
double * instances = NULL;
|
191
191
|
int * classes = NULL;
|
192
192
|
int * which_numeric = NULL;
|
193
193
|
|
194
|
-
VALUE data = rb_funcall(rb_dataset, rb_intern("instances"), 0);
|
195
|
-
VALUE rb_class = rb_funcall(rb_dataset, rb_intern("classes"), 0);
|
196
|
-
VALUE rb_numeric = rb_funcall(rb_dataset, rb_intern("numeric_attrs"), 0);
|
194
|
+
// VALUE data = rb_funcall(rb_dataset, rb_intern("instances"), 0);
|
195
|
+
// VALUE rb_class = rb_funcall(rb_dataset, rb_intern("classes"), 0);
|
196
|
+
// VALUE rb_numeric = rb_funcall(rb_dataset, rb_intern("numeric_attrs"), 0);
|
197
197
|
|
198
198
|
// Define global variables
|
199
199
|
rb_iv_set(self, "@num_neighbors", rb_k);
|
200
200
|
nrow = RARRAY_LEN(data);
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
201
|
+
if (nrow > 0) {
|
202
|
+
rb_iv_set(self, "@nrow", INT2NUM(nrow));
|
203
|
+
ncol = RARRAY_LEN(rb_ary_entry(data, 0));
|
204
|
+
rb_iv_set(self, "@ncol", INT2NUM(ncol));
|
205
|
+
rb_iv_set(self, "@nclass", rb_funcall(rb_funcall(rb_class, rb_intern("uniq"), 0), rb_intern("length"), 0));
|
206
|
+
FLOAT_MAX = NUM2DBL(rb_intern("Float::MAX"));
|
207
|
+
rb_iv_set(self, "@rng", rb_random_par);
|
208
|
+
|
209
|
+
instances = (double*) malloc(sizeof(double) * nrow * ncol);
|
210
|
+
|
211
|
+
int i, j;
|
212
|
+
for (i = 0; i < nrow; i++) {
|
213
|
+
for (j = 0; j < ncol; j++) {
|
214
|
+
if (TYPE(rb_ary_entry(rb_ary_entry(data, i), j)) == T_STRING) {
|
215
|
+
rb_raise(rb_eArgError, "A string was found within the dataset. Aborting...");
|
216
|
+
} else
|
217
|
+
instances[i * ncol + j] = NUM2DBL(rb_ary_entry(rb_ary_entry(data, i), j));
|
218
|
+
}
|
219
|
+
}
|
207
220
|
|
208
|
-
|
221
|
+
classes = (int*) malloc(sizeof(int) * nrow);
|
209
222
|
|
210
|
-
|
211
|
-
|
212
|
-
for (j = 0; j < ncol; j++) {
|
213
|
-
if (TYPE(rb_ary_entry(rb_ary_entry(data, i), j)) == T_STRING) {
|
214
|
-
rb_raise(rb_eStandardError, "A string was found within the dataset. Aborting...");
|
215
|
-
} else
|
216
|
-
instances[i * ncol + j] = NUM2DBL(rb_ary_entry(rb_ary_entry(data, i), j));
|
223
|
+
for (i = 0; i < nrow; i++) {
|
224
|
+
classes[i] = NUM2INT(rb_ary_entry(rb_class, i));
|
217
225
|
}
|
218
|
-
}
|
219
226
|
|
220
|
-
|
227
|
+
which_numeric = (int*) malloc(sizeof(int) * ncol);
|
221
228
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
which_numeric = (int*) malloc(sizeof(int) * ncol);
|
229
|
+
for (j = 0; j < ncol; j++) {
|
230
|
+
which_numeric[j] = NUM2INT(rb_ary_entry(rb_numeric, j));
|
231
|
+
}
|
227
232
|
|
228
|
-
|
229
|
-
|
233
|
+
rb_iv_set(self, "@instances", Data_Wrap_Struct(C_instances, NULL, c_knn_free, instances));
|
234
|
+
rb_iv_set(self, "@classes", Data_Wrap_Struct(C_classes, NULL, c_knn_free, classes));
|
235
|
+
rb_iv_set(self, "@which_numeric", Data_Wrap_Struct(C_numerics, NULL, c_knn_free, which_numeric));
|
236
|
+
} else {
|
237
|
+
rb_raise(rb_eArgError, "Attempted to create a classifier for an empty dataset. Aborting...");
|
230
238
|
}
|
231
239
|
|
232
|
-
rb_iv_set(self, "@instances", Data_Wrap_Struct(C_instances, NULL, c_knn_free, instances));
|
233
|
-
rb_iv_set(self, "@classes", Data_Wrap_Struct(C_classes, NULL, c_knn_free, classes));
|
234
|
-
rb_iv_set(self, "@which_numeric", Data_Wrap_Struct(C_numerics, NULL, c_knn_free, which_numeric));
|
235
|
-
|
236
240
|
return self;
|
237
241
|
}
|
238
242
|
|
@@ -245,6 +249,6 @@ void Init_c_knn(void) {
|
|
245
249
|
C_classes = rb_define_class_under(Classifier, "Classes", rb_cObject);
|
246
250
|
C_numerics = rb_define_class_under(Classifier, "Numerics", rb_cObject);
|
247
251
|
|
248
|
-
rb_define_method(Classifier, "initialize", method_c_knn_initialize,
|
252
|
+
rb_define_method(Classifier, "initialize", method_c_knn_initialize, 5);
|
249
253
|
rb_define_method(Classifier, "fitness_for", method_c_knn_leaveoneout, 1);
|
250
254
|
}
|
data/knn_cv.gemspec
CHANGED
File without changes
|
data/lib/knn_cv.rb
CHANGED
File without changes
|
data/lib/knn_cv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knn_cv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Charte
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|