538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
# File 'ext/tlearn/tlearn_ext.c', line 538
static VALUE tlearn_fitness(VALUE self, VALUE config) {
int tlearn_args_count = 4;
char *tlearn_args[tlearn_args_count];
VALUE ruby_array = rb_ary_new();
VALUE file_root_value = rb_hash_aref(config, ID2SYM(rb_intern("file_root")));
VALUE sweeps_value = rb_hash_aref(config, ID2SYM(rb_intern("sweeps")));
long nsweeps = NUM2DBL(sweeps_value);
char *file_root = StringValueCStr(file_root_value);
char weights[strlen(file_root) + strlen(".wts")];
float *result_weights;
strcpy(weights, file_root);
tlearn_args[0] = "tlearn_fitness";
tlearn_args[1] = "-l";
tlearn_args[2] = strcat(weights, ".wts");
tlearn_args[3] = "-V";
float current_weights_output[6];
int failure = run_fitness(tlearn_args_count, tlearn_args, nsweeps, file_root, current_weights_output);
if(failure == 0){
float weight;
int result_index;
for(result_index = 0; result_index < 6; result_index++){
weight = current_weights_output[result_index];
rb_ary_store(ruby_array, result_index, rb_float_new(weight));
}
return(ruby_array);
}
else{
return(rb_int_new(failure));
}
}
|