knn_cv 0.1.2 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82ad55344b760f5b5fc48453c165ac225f943b5d
4
- data.tar.gz: f95e098c3a20dae28375f3e61df444aa054daf33
3
+ metadata.gz: ae7308b1dc9b6844bfe35f260b0112db5200a1cd
4
+ data.tar.gz: 6d299e33cd783d6ef734728e50c440d7ab108536
5
5
  SHA512:
6
- metadata.gz: aeeba2a91ea65ec5ce46c68c6050ccaf67579b0ae80428b4b5484c7df2b0d035e76c6246b08ec3758babd4c48df41462c133faaaf231303ef8d6ce8579d38eb7
7
- data.tar.gz: ea440252cf2b59f64671ffff77bd48df5544d66c4b691d77c5720ee84664e1e6f2ce5ad39ad3a8b4161dc4f49b7987199ef094f9b714c46d3c0ce1b384355c6c
6
+ metadata.gz: b716e72c5029a23262b6c41c6e0bafa5fcf53357bbb89876a7e181e13200b61174ee705f64a84399eb94895251f34af46ae5e655b68e89aba0dbbb7ed6ae29c6
7
+ data.tar.gz: da2335e2a1d07010ef7a0827d3078314925569c7bdc62a5e6e82297f504edcba7d5f1fd1ef1821d64720a797fca7ba362ead7a80f35f9e114d6bc7873f088faf
data/.gitignore CHANGED
File without changes
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
File without changes
File without changes
@@ -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 rb_dataset, VALUE rb_random_par) {
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
- rb_iv_set(self, "@nrow", INT2NUM(nrow));
202
- ncol = RARRAY_LEN(rb_ary_entry(data, 0));
203
- rb_iv_set(self, "@ncol", INT2NUM(ncol));
204
- rb_iv_set(self, "@nclass", rb_funcall(rb_dataset, rb_intern("class_count"), 0));
205
- FLOAT_MAX = NUM2DBL(rb_intern("Float::MAX"));
206
- rb_iv_set(self, "@rng", rb_random_par);
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
- instances = (double*) malloc(sizeof(double) * nrow * ncol);
221
+ classes = (int*) malloc(sizeof(int) * nrow);
209
222
 
210
- int i, j;
211
- for (i = 0; i < nrow; i++) {
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
- classes = (int*) malloc(sizeof(int) * nrow);
227
+ which_numeric = (int*) malloc(sizeof(int) * ncol);
221
228
 
222
- for (i = 0; i < nrow; i++) {
223
- classes[i] = NUM2INT(rb_ary_entry(rb_class, i));
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
- for (j = 0; j < ncol; j++) {
229
- which_numeric[j] = NUM2INT(rb_ary_entry(rb_numeric, j));
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, 3);
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
  }
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module KnnCv
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2"
3
3
  end
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.1.2
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-04-07 00:00:00.000000000 Z
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler