ruby-fann 1.4.0 → 1.4.1
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 +4 -4
- data/ext/ruby_fann/fann_augment.h +8 -8
- data/ext/ruby_fann/fann_data.h +2 -2
- data/ext/ruby_fann/fann_error.c +5 -3
- data/ext/ruby_fann/ruby_fann.c +16 -16
- data/lib/ruby_fann/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b41957229e899b6498641c04163610daeecd8d7bc989262915ed5284128172
|
4
|
+
data.tar.gz: 4be842a49ec6b57d1e1b7489302b874427faec3e06d439ccc9976be49419287e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 753f3252b1e3c9500d455b1d25f72d7ca99935739f18c5c6226cc034c55cb7e0354820b995511690eaca39da9e685e4e6883cb7a5c527ffadee92d729267e171
|
7
|
+
data.tar.gz: a904cd8752595018693c65b996aaf9d6b58917cac4cde6943ca5b847e744269b4224cdd79cb1abc63be169d999ea5f8c9f9ef4e215c5f0a2626427a8c577eb86
|
@@ -18,12 +18,12 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
|
|
18
18
|
VALUE outputs
|
19
19
|
)
|
20
20
|
{
|
21
|
-
unsigned
|
21
|
+
unsigned int i, j;
|
22
22
|
fann_type *data_input, *data_output;
|
23
23
|
struct fann_train_data *data = (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
|
24
|
-
unsigned int num_input = RARRAY_LEN(RARRAY_PTR(inputs)[0]);
|
25
|
-
unsigned int num_output =RARRAY_LEN(RARRAY_PTR(outputs)[0]);
|
26
|
-
|
24
|
+
unsigned int num_input = NUM2UINT(RARRAY_LEN(RARRAY_PTR(inputs)[0]));
|
25
|
+
unsigned int num_output = NUM2UINT(RARRAY_LEN(RARRAY_PTR(outputs)[0]));
|
26
|
+
unsigned int num_data = NUM2UINT(RARRAY_LEN(inputs));
|
27
27
|
|
28
28
|
if(data == NULL) {
|
29
29
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
@@ -74,15 +74,15 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
|
|
74
74
|
data->input[i] = data_input;
|
75
75
|
data_input += num_input;
|
76
76
|
|
77
|
-
inputs_i = RARRAY_PTR(inputs)[i];
|
78
|
-
outputs_i = RARRAY_PTR(
|
77
|
+
inputs_i = NUM2UINT(RARRAY_PTR(inputs)[i]);
|
78
|
+
outputs_i = NUM2UINT(RARRAY_PTR(inputs)[i]);
|
79
79
|
|
80
80
|
if(RARRAY_LEN(inputs_i) != num_input)
|
81
81
|
{
|
82
82
|
rb_raise (
|
83
83
|
rb_eRuntimeError,
|
84
84
|
"Number of inputs at [%d] is inconsistent: (%d != %d)",
|
85
|
-
i,
|
85
|
+
i,NUM2UINT(RARRAY_LEN(inputs_i)), num_input);
|
86
86
|
}
|
87
87
|
|
88
88
|
if(RARRAY_LEN(outputs_i) != num_output)
|
@@ -90,7 +90,7 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
|
|
90
90
|
rb_raise (
|
91
91
|
rb_eRuntimeError,
|
92
92
|
"Number of outputs at [%d] is inconsistent: (%d != %d)",
|
93
|
-
i, RARRAY_LEN(outputs_i), num_output);
|
93
|
+
i, NUM2UINT(RARRAY_LEN(outputs_i)), num_output);
|
94
94
|
}
|
95
95
|
|
96
96
|
|
data/ext/ruby_fann/fann_data.h
CHANGED
@@ -413,8 +413,8 @@ struct fann_neuron
|
|
413
413
|
/* Index to the first and last connection
|
414
414
|
* (actually the last is a past end index)
|
415
415
|
*/
|
416
|
-
|
417
|
-
|
416
|
+
long first_con;
|
417
|
+
long last_con;
|
418
418
|
/* The sum of the inputs multiplied with the weights */
|
419
419
|
fann_type sum;
|
420
420
|
/* The value of the activation function applied to the sum */
|
data/ext/ruby_fann/fann_error.c
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
#include <stdarg.h>
|
23
23
|
#include <string.h>
|
24
24
|
|
25
|
+
#include "ruby.h"
|
25
26
|
#include "config.h"
|
26
27
|
#include "fann.h"
|
27
28
|
|
@@ -90,7 +91,7 @@ FANN_EXTERNAL void FANN_API fann_print_error(struct fann_error *errdat)
|
|
90
91
|
/* INTERNAL FUNCTION
|
91
92
|
Populate the error information
|
92
93
|
*/
|
93
|
-
void fann_error(struct fann_error *errdat,
|
94
|
+
void fann_error(struct fann_error *errdat, enum fann_errno_enum errno_f, ...)
|
94
95
|
{
|
95
96
|
va_list ap;
|
96
97
|
char *errstr;
|
@@ -191,12 +192,13 @@ void fann_error(struct fann_error *errdat, const enum fann_errno_enum errno_f, .
|
|
191
192
|
|
192
193
|
if(error_log == (FILE *)-1) /* This is the default behavior and will give stderr */
|
193
194
|
{
|
194
|
-
fprintf(stderr, "FANN Error %d: %s", errno_f, errstr);
|
195
|
+
fprintf(stderr, "FANN Error %d: %s, ", errno_f, errstr);
|
195
196
|
}
|
196
197
|
else if(error_log != NULL)
|
197
198
|
{
|
198
|
-
fprintf(error_log, "FANN Error %d: %s", errno_f, errstr);
|
199
|
+
fprintf(error_log, "FANN Error %d: %s, ", errno_f, errstr);
|
199
200
|
}
|
201
|
+
rb_raise (rb_eRuntimeError, errstr);
|
200
202
|
}
|
201
203
|
|
202
204
|
/* INTERNAL FUNCTION
|
data/ext/ruby_fann/ruby_fann.c
CHANGED
@@ -278,7 +278,7 @@ static VALUE fann_initialize(VALUE self, VALUE hash)
|
|
278
278
|
Check_Type(num_outputs, T_FIXNUM);
|
279
279
|
|
280
280
|
// Initialize layers:
|
281
|
-
unsigned int num_layers=RARRAY_LEN(hidden_neurons) + 2;
|
281
|
+
unsigned int num_layers=NUM2UINT(RARRAY_LEN(hidden_neurons)) + 2;
|
282
282
|
unsigned int layers[num_layers];
|
283
283
|
|
284
284
|
// Input:
|
@@ -286,7 +286,7 @@ static VALUE fann_initialize(VALUE self, VALUE hash)
|
|
286
286
|
// Output:
|
287
287
|
layers[num_layers-1]=NUM2INT(num_outputs);
|
288
288
|
// Hidden:
|
289
|
-
int i;
|
289
|
+
unsigned int i;
|
290
290
|
for (i=1; i<=num_layers-2; i++) {
|
291
291
|
layers[i]=NUM2UINT(RARRAY_PTR(hidden_neurons)[i-1]);
|
292
292
|
}
|
@@ -691,7 +691,7 @@ static VALUE get_bias_array(VALUE self)
|
|
691
691
|
// Create ruby array & set outputs:
|
692
692
|
VALUE arr;
|
693
693
|
arr = rb_ary_new();
|
694
|
-
int i;
|
694
|
+
unsigned int i;
|
695
695
|
for (i=0; i<num_layers; i++)
|
696
696
|
{
|
697
697
|
rb_ary_push(arr, INT2NUM(layers[i]));
|
@@ -803,7 +803,7 @@ static VALUE get_layer_array(VALUE self)
|
|
803
803
|
// Create ruby array & set outputs:
|
804
804
|
VALUE arr;
|
805
805
|
arr = rb_ary_new();
|
806
|
-
int i;
|
806
|
+
unsigned int i;
|
807
807
|
for (i=0; i<num_layers; i++)
|
808
808
|
{
|
809
809
|
rb_ary_push(arr, INT2NUM(layers[i]));
|
@@ -1017,7 +1017,7 @@ static VALUE get_train_stop_function(VALUE self)
|
|
1017
1017
|
{
|
1018
1018
|
ret_val = ID2SYM(rb_intern("mse")); // (rb_str_new2("FANN_NETTYPE_LAYER"));
|
1019
1019
|
}
|
1020
|
-
else if(train_stop==FANN_STOPFUNC_BIT)
|
1020
|
+
else // if(train_stop==FANN_STOPFUNC_BIT)
|
1021
1021
|
{
|
1022
1022
|
ret_val = ID2SYM(rb_intern("bit")); // (rb_str_new2("FANN_NETTYPE_SHORTCUT"));
|
1023
1023
|
}
|
@@ -1066,11 +1066,11 @@ static VALUE run (VALUE self, VALUE inputs)
|
|
1066
1066
|
Check_Type(inputs, T_ARRAY);
|
1067
1067
|
|
1068
1068
|
struct fann* f;
|
1069
|
-
int i;
|
1069
|
+
unsigned int i;
|
1070
1070
|
fann_type* outputs;
|
1071
1071
|
|
1072
1072
|
// Convert inputs to type needed for NN:
|
1073
|
-
unsigned int len = RARRAY_LEN(inputs);
|
1073
|
+
unsigned int len = NUM2UINT(RARRAY_LEN(inputs));
|
1074
1074
|
fann_type fann_inputs[len];
|
1075
1075
|
for (i=0; i<len; i++)
|
1076
1076
|
{
|
@@ -1124,12 +1124,12 @@ static VALUE train(VALUE self, VALUE input, VALUE expected_output)
|
|
1124
1124
|
struct fann* f;
|
1125
1125
|
Data_Get_Struct(self, struct fann, f);
|
1126
1126
|
|
1127
|
-
unsigned int num_input = RARRAY_LEN(input);
|
1128
|
-
unsigned int num_output = RARRAY_LEN(expected_output);
|
1127
|
+
unsigned int num_input = NUM2UINT(RARRAY_LEN(input));
|
1128
|
+
unsigned int num_output = NUM2UINT(RARRAY_LEN(expected_output));
|
1129
1129
|
|
1130
1130
|
fann_type data_input[num_input], data_output[num_output];
|
1131
1131
|
|
1132
|
-
int i;
|
1132
|
+
unsigned int i;
|
1133
1133
|
|
1134
1134
|
for (i = 0; i < num_input; i++) {
|
1135
1135
|
data_input[i] = NUM2DBL(RARRAY_PTR(input)[i]);
|
@@ -1425,9 +1425,9 @@ static VALUE set_cascade_activation_functions(VALUE self, VALUE cascade_activati
|
|
1425
1425
|
struct fann* f;
|
1426
1426
|
Data_Get_Struct (self, struct fann, f);
|
1427
1427
|
|
1428
|
-
unsigned int cnt = RARRAY_LEN(cascade_activation_functions);
|
1428
|
+
unsigned int cnt = NUM2UINT(RARRAY_LEN(cascade_activation_functions));
|
1429
1429
|
enum fann_activationfunc_enum fann_activation_functions[cnt];
|
1430
|
-
int i;
|
1430
|
+
unsigned int i;
|
1431
1431
|
for (i=0; i<cnt; i++)
|
1432
1432
|
{
|
1433
1433
|
fann_activation_functions[i] = sym_to_activation_function(RARRAY_PTR(cascade_activation_functions)[i]);
|
@@ -1449,7 +1449,7 @@ static VALUE get_cascade_activation_functions(VALUE self)
|
|
1449
1449
|
// Create ruby array & set outputs:
|
1450
1450
|
VALUE arr;
|
1451
1451
|
arr = rb_ary_new();
|
1452
|
-
int i;
|
1452
|
+
unsigned int i;
|
1453
1453
|
for (i=0; i<cnt; i++)
|
1454
1454
|
{
|
1455
1455
|
rb_ary_push(arr, activation_function_to_sym(fann_functions[i]));
|
@@ -1489,9 +1489,9 @@ static VALUE set_cascade_activation_steepnesses(VALUE self, VALUE cascade_activa
|
|
1489
1489
|
struct fann* f;
|
1490
1490
|
Data_Get_Struct (self, struct fann, f);
|
1491
1491
|
|
1492
|
-
unsigned int cnt = RARRAY_LEN(cascade_activation_steepnesses);
|
1492
|
+
unsigned int cnt = NUM2UINT(RARRAY_LEN(cascade_activation_steepnesses));
|
1493
1493
|
fann_type fann_activation_steepnesses[cnt];
|
1494
|
-
int i;
|
1494
|
+
unsigned int i;
|
1495
1495
|
for (i=0; i<cnt; i++)
|
1496
1496
|
{
|
1497
1497
|
fann_activation_steepnesses[i] = NUM2DBL(RARRAY_PTR(cascade_activation_steepnesses)[i]);
|
@@ -1513,7 +1513,7 @@ static VALUE get_cascade_activation_steepnesses(VALUE self)
|
|
1513
1513
|
// Create ruby array & set outputs:
|
1514
1514
|
VALUE arr;
|
1515
1515
|
arr = rb_ary_new();
|
1516
|
-
int i;
|
1516
|
+
unsigned int i;
|
1517
1517
|
for (i=0; i<cnt; i++)
|
1518
1518
|
{
|
1519
1519
|
rb_ary_push(arr, rb_float_new(fann_steepnesses[i]));
|
data/lib/ruby_fann/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-fann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tangledpath
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Bindings to use FANN from within ruby/rails environment
|
14
14
|
email:
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
homepage: http://github.com/tangledpath/ruby-fann
|
50
50
|
licenses: []
|
51
51
|
metadata: {}
|
52
|
-
post_install_message:
|
52
|
+
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
@@ -65,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
69
|
-
signing_key:
|
68
|
+
rubygems_version: 3.1.4
|
69
|
+
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: Bindings to use FANN from within ruby/rails environment. Fann is a is a
|
72
72
|
free open source neural network library, which implements multilayer artificial
|