ruby-fann 1.4.0 → 1.4.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
  SHA256:
3
- metadata.gz: 5f69931c60a95be5f61615040e3f17707fb55fc973927c4fc2923a175074ca69
4
- data.tar.gz: 713eae27835fa17800ccb988b6c10bdcfef71dff2efa8022a1e6f1176d848c25
3
+ metadata.gz: 1c291587d1ebb0faf402b6d8dfa9e7629c5fc02e14b43c138c641945b899f434
4
+ data.tar.gz: ea97a950c60a26d63dbaecc12bf79ac3ecd8ed9b4a27d12e87c39add9228a5c2
5
5
  SHA512:
6
- metadata.gz: 405e429b1e74019c26c04a62ac0723666776c6d953ccb900e48d382493b325dfa2b75ac97f073da09bd0715b140f3403a33378aa905141a7146a278f66fed2ec
7
- data.tar.gz: e6b67dcd28e795afc1e2cab87a1270aa06032dba06fda0030163acb97ea2ca3f1ae6db1859028575607ff3246fb35a365b84d932784793dacd4cddb7c2440e16
6
+ metadata.gz: a309c2c124032e56f5532608d3979f4c039902a8ab31f05422c8385b8975baca1dce3596c7ffa8b0a2f125d4f78691699509a6bb2ecbb22278ff8d0a032e2fca
7
+ data.tar.gz: 4a3e11465e2d660bb09442cb7dab7ef572c21aea8427b18fc6bdb70afad986e213703cac02b43bed9fa4d59d0e40f9958e91610c6261ff56e87aa340d85edc84
data/README.md CHANGED
@@ -9,7 +9,7 @@ Neural Networks in `ruby`
9
9
 
10
10
  [![Gem Version](https://badge.fury.io/rb/ruby-fann.png)](http://badge.fury.io/rb/ruby-fann)
11
11
 
12
- RubyFann, or "ruby-fann" is a ruby gem that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free (native) open source neural network library, which implements multilayer artificial neural networks, supporting both fully-connected and sparsely-connected networks. It is easy to use, versatile, well documented, and fast. `RubyFann` makes working with neural networks a breeze using `ruby`, with the added benefit that most of the heavy lifting is done natively.
12
+ RubyFann, or "ruby-fann" is a Ruby Gem (no Rails required) that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free native open source neural network library, which implements multilayer artificial neural networks, supporting both fully-connected and sparsely-connected networks. It is easy to use, versatile, well documented, and fast. `RubyFann` makes working with neural networks a breeze using `ruby`, with the added benefit that most of the heavy lifting is done natively.
13
13
 
14
14
  A talk given by our friend Ethan from Big-Oh Studios at Lone Star Ruby 2013: http://confreaks.com/videos/2609-lonestarruby2013-neural-networks-with-rubyfann
15
15
 
@@ -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 long i, j;
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
- unsigned int num_data = RARRAY_LEN(inputs);
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(outputs)[i];
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, RARRAY_LEN(inputs_i), num_input);
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
 
@@ -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
- unsigned int first_con;
417
- unsigned int last_con;
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 */
@@ -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, const enum fann_errno_enum errno_f, ...)
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
@@ -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]));
@@ -2,7 +2,7 @@ module RubyFann
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 4
5
- TINY = 0
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.0
4
+ version: 1.4.2
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-14 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Bindings to use FANN from within ruby/rails environment
14
14
  email:
@@ -47,9 +47,10 @@ files:
47
47
  - lib/ruby_fann/neurotica.rb
48
48
  - lib/ruby_fann/version.rb
49
49
  homepage: http://github.com/tangledpath/ruby-fann
50
- licenses: []
50
+ licenses:
51
+ - MIT
51
52
  metadata: {}
52
- post_install_message:
53
+ post_install_message:
53
54
  rdoc_options: []
54
55
  require_paths:
55
56
  - lib
@@ -65,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
68
  requirements: []
68
- rubygems_version: 3.2.3
69
- signing_key:
69
+ rubygems_version: 3.1.4
70
+ signing_key:
70
71
  specification_version: 4
71
72
  summary: Bindings to use FANN from within ruby/rails environment. Fann is a is a
72
73
  free open source neural network library, which implements multilayer artificial