ruby-fann 2.0.0 → 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
  SHA256:
3
- metadata.gz: 1513ab175dd525a96a3846565c6b54a2d5bf44af679144a4f7e877dd8e948e03
4
- data.tar.gz: 9942ab1a6cd7112ec21fa4d7912f8f72e62a18ab429948cc507c73a8af5efb73
3
+ metadata.gz: bb0b5d885b26bc1f76362a4080cbd8ea2b9c5295ca3ace671a6180ca80ca2dff
4
+ data.tar.gz: 11a03ab942710b6fc5b0348a98c7d9905e1be28f43761b806ddb62586ab083da
5
5
  SHA512:
6
- metadata.gz: 5b0a6b6909f6d19b005454dfddf77570493ddf3618c7b51e6fd36c99b09bfa3858b489cfca80829253f1c1ed79c953cbae21b6f4a24eddd34cd37d31920d529d
7
- data.tar.gz: 8776e0c70509d821e032b2e9b1bf7c0a323609e3bf69a7cd294ebbb192c57236c06e5cffcb869f79291d3fabe5ef17f6553cd078419f88283cdff05f33ff17d4
6
+ metadata.gz: 899e20eab9c151a31d250e95028787dad46d43756d756696e8e2518b9c950b781ce3ac55a6e29f4103ae5dbf978b55bcf5bfb8a3c156ce57dea41caa728d2034
7
+ data.tar.gz: b2e938e9af9fb0c416a54742c6fd92d5684583b5417bbfeddc0e2d67df887f07ac9288ecdfc9c1c7212c0748fc1c787973d1da7c1fd6ee966f0f63e1f0af1706
data/README.md CHANGED
@@ -2,13 +2,14 @@
2
2
  _Fast_ **AI**
3
3
 
4
4
 
5
- ![NN eye candy](nn1.png)
6
-
7
5
  ---
8
6
  Neural Networks in `ruby`
9
7
 
10
8
  [![Gem Version](https://badge.fury.io/rb/ruby-fann.png)](http://badge.fury.io/rb/ruby-fann)
11
9
 
10
+ ![NN eye candy](ruby-fann.png)
11
+
12
+
12
13
  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
14
 
14
15
  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
@@ -1,22 +1,21 @@
1
1
  #include "ruby.h"
2
2
  #include "ruby_compat.h"
3
3
 
4
- FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary2(
5
- unsigned int num_data,
6
- unsigned int num_input,
7
- unsigned long num_output)
4
+ FANN_EXTERNAL struct fann_train_data *FANN_API fann_create_train_from_rb_ary2(
5
+ unsigned int num_data,
6
+ unsigned int num_input,
7
+ unsigned long num_output)
8
8
  {
9
- return 0;
9
+ return 0;
10
10
  }
11
11
 
12
12
  /*
13
13
  * Copied from fann_create_train_from_callback/file & modified to ease
14
14
  * allocating from ruby arrays:
15
15
  */
16
- FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
17
- VALUE inputs,
18
- VALUE outputs
19
- )
16
+ FANN_EXTERNAL struct fann_train_data *FANN_API fann_create_train_from_rb_ary(
17
+ VALUE inputs,
18
+ VALUE outputs)
20
19
  {
21
20
  unsigned int i, j;
22
21
  fann_type *data_input, *data_output;
@@ -24,89 +23,90 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
24
23
 
25
24
  long num_input = RARRAY_LEN(RARRAY_PTR(inputs)[0]);
26
25
  long num_output = RARRAY_LEN(RARRAY_PTR(outputs)[0]);
27
- long num_data = RARRAY_LEN(inputs);
26
+ long num_data = RARRAY_LEN(inputs);
28
27
 
29
-
30
- if(data == NULL) {
28
+ if (data == NULL)
29
+ {
31
30
  fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
32
31
  return NULL;
33
32
  }
34
33
 
35
- fann_init_error_data((struct fann_error *) data);
34
+ fann_init_error_data((struct fann_error *)data);
36
35
 
37
- data->num_data = num_data;
38
- data->num_input = num_input;
36
+ data->num_data = num_data;
37
+ data->num_input = num_input;
39
38
  data->num_output = num_output;
40
- data->input = (fann_type **) calloc(num_data, sizeof(fann_type *));
41
- if(data->input == NULL)
39
+ data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
40
+ if (data->input == NULL)
42
41
  {
43
42
  fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
44
43
  fann_destroy_train(data);
45
44
  return NULL;
46
45
  }
47
46
 
48
- data->output = (fann_type **) calloc(num_data, sizeof(fann_type *));
49
- if(data->output == NULL)
47
+ data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
48
+ if (data->output == NULL)
50
49
  {
51
50
  fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
52
51
  fann_destroy_train(data);
53
52
  return NULL;
54
53
  }
55
- data_input = (fann_type *) calloc(num_input * num_data, sizeof(fann_type));
56
- if(data_input == NULL)
54
+ data_input = (fann_type *)calloc(num_input * num_data, sizeof(fann_type));
55
+ if (data_input == NULL)
57
56
  {
58
57
  fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
59
58
  fann_destroy_train(data);
60
59
  return NULL;
61
60
  }
62
61
 
63
- data_output = (fann_type *) calloc(num_output * num_data, sizeof(fann_type));
64
- if(data_output == NULL)
62
+ data_output = (fann_type *)calloc(num_output * num_data, sizeof(fann_type));
63
+ if (data_output == NULL)
65
64
  {
66
65
  fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
67
66
  fann_destroy_train(data);
68
67
  return NULL;
69
68
  }
70
69
 
71
- VALUE inputs_i, outputs_i;
72
- for(i = 0; i != num_data; i++)
73
- {
74
- data->input[i] = data_input;
75
- data_input += num_input;
76
-
77
- inputs_i = RARRAY_PTR(inputs)[i];
78
- outputs_i = RARRAY_PTR(outputs)[i];
79
-
80
- if(RARRAY_LEN(inputs_i) != num_input)
81
- {
82
- rb_raise (
83
- rb_eRuntimeError,
84
- "Number of inputs at [%d] is inconsistent: (%du != %d)",
85
- i,RARRAY_LEN(inputs_i)), num_input;
86
- }
87
-
88
- if(RARRAY_LEN(outputs_i) != num_output)
89
- {
90
- rb_raise (
91
- rb_eRuntimeError,
92
- "Number of outputs at [%d] is inconsistent: (%d != %d)",
93
- i, RARRAY_LEN(outputs_i)), num_output;
94
- }
95
-
96
-
97
- for(j = 0; j != num_input; j++)
98
- {
99
- data->input[i][j]=NUM2DBL(RARRAY_PTR(inputs_i)[j]);
100
- }
101
-
102
- data->output[i] = data_output;
103
- data_output += num_output;
104
-
105
- for(j = 0; j != num_output; j++)
106
- {
107
- data->output[i][j]=NUM2DBL(RARRAY_PTR(outputs_i)[j]);
108
- }
109
- }
70
+ VALUE inputs_i, outputs_i;
71
+ for (i = 0; i != num_data; i++)
72
+ {
73
+ data->input[i] = data_input;
74
+ data_input += num_input;
75
+
76
+ inputs_i = RARRAY_PTR(inputs)[i];
77
+ outputs_i = RARRAY_PTR(outputs)[i];
78
+
79
+ if (RARRAY_LEN(inputs_i) != num_input)
80
+ {
81
+ rb_raise(
82
+ rb_eRuntimeError,
83
+ "Number of inputs at [%d] is inconsistent: (%du != %d)",
84
+ i, RARRAY_LEN(inputs_i)),
85
+ num_input;
86
+ }
87
+
88
+ if (RARRAY_LEN(outputs_i) != num_output)
89
+ {
90
+ rb_raise(
91
+ rb_eRuntimeError,
92
+ "Number of outputs at [%d] is inconsistent: (%d != %d)",
93
+ i, RARRAY_LEN(outputs_i)),
94
+ num_output;
95
+ }
96
+
97
+ for (j = 0; j != num_input; j++)
98
+ {
99
+ data->input[i][j] = NUM2DBL(RARRAY_PTR(inputs_i)[j]);
100
+ }
101
+
102
+ data->output[i] = data_output;
103
+ data_output += num_output;
104
+
105
+ for (j = 0; j != num_output; j++)
106
+ {
107
+ data->output[i][j] = NUM2DBL(RARRAY_PTR(outputs_i)[j]);
108
+ }
109
+ }
110
110
 
111
111
  return data;
112
112
  }