cerebrum 0.1.2 → 0.1.3

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: 8ad9f879fedc9edbdb4898c23ac34c774ce96d93
4
- data.tar.gz: e69a64b6c1cb78e474f7223cebc3879588511e37
3
+ metadata.gz: 822cf99b99f8c49d058c2d1ff99fec93cc910228
4
+ data.tar.gz: 0ace6aab3806f1344a73af0300c25992e8753d96
5
5
  SHA512:
6
- metadata.gz: 5f0fafaae68fd966304f3ef83b8a8b4b124931132693ffe2a53607f37c3f1b79966d9f32172b093200467c9801cff505c14bac8af3a668f1d88b6c71e432c4ab
7
- data.tar.gz: d0fc8ce6021dc2262cb6e4bb12f34aceb1fae9408aeb4b0e3918ecf12f2f557217d1bf07082fa5fae8153108ca8fc17562df474fa30e55c4152ba1ac4b3a2092
6
+ metadata.gz: ceca1caa39e8bc1866de84ef9047c431badc913cbaa8c178d78426095e4455d21727d03e03a28b2a5dcdc1b82c33865e9f7a26f147e6ce175785455a0d731e8a
7
+ data.tar.gz: 3e1e98735a3731120e029bf13aeaeb78469c89c7c39d941805bf9ccc93de61272a013e5f61aaff160c1691979fb75f63059b8f20dadf9d9befef9c5710095f1a
data/README.md CHANGED
@@ -62,7 +62,7 @@ network.train([
62
62
  ]);
63
63
 
64
64
  result = network.run({ r: 1, g: 0.4, b: 0 })
65
- # => { :black=>0.011967728530458011, :white=>0.9871010273923573 }
65
+ # => { black: 0.011967728530458011, white: 0.9871010273923573 }
66
66
  ```
67
67
 
68
68
  #### Cerebrum Options
@@ -115,6 +115,22 @@ The output of `Cerebrum#train` is a hash of information about how the training w
115
115
  network.train(data, options)
116
116
  # => { error: 0.005324233132423, iterations: 9001 }
117
117
  ```
118
+
119
+ #### JSON
120
+
121
+ Serialize or load in the state of a trained network with JSON:
122
+
123
+ ``` ruby
124
+ saved_state = network.save_state
125
+ nn = Cerebrum.new
126
+ nn.load_state(saved_state)
127
+
128
+ nn.run({ r: 1, g: 0.4, b: 0 })
129
+ # => { black: 0.011967728530458011, white: 0.9871010273923573 }
130
+ ```
131
+
132
+ Additionally the new network can be separately trained whilst retaining all
133
+ previous training from the other network.
118
134
  ## Development
119
135
 
120
136
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -1,5 +1,6 @@
1
1
  require_relative "data_scrubber"
2
2
  require_relative "cerebrum_helper"
3
+ require 'json'
3
4
 
4
5
  class Cerebrum
5
6
  include CerebrumHelper
@@ -25,8 +26,8 @@ class Cerebrum
25
26
  end
26
27
 
27
28
  def train(training_set, options = Hash.new)
28
- @input_lookup_table ||= get_input_lookup_table(training_set)
29
- @output_lookup_table ||= get_output_lookup_table(training_set)
29
+ @input_lookup_table ||= get_input_lookup_table(training_set)
30
+ @output_lookup_table ||= get_output_lookup_table(training_set)
30
31
  training_set = scrub_dataset(training_set)
31
32
 
32
33
  iterations = options[:iterations] || 20000
@@ -62,6 +63,44 @@ class Cerebrum
62
63
  @output_lookup_table ? to_features_given_vector(output, @output_lookup_table) : output
63
64
  end
64
65
 
66
+ def save_state
67
+ {
68
+ biases: @biases,
69
+ binary_thresh: @binary_thresh,
70
+ changes: @changes,
71
+ deltas: @deltas,
72
+ errors: @errors,
73
+ hidden_layers: @hidden_layers,
74
+ input_lookup_table: @input_lookup_table,
75
+ layer_sizes: @layer_sizes,
76
+ layers: @layers,
77
+ learning_rate: @learning_rate,
78
+ momentum: @momentum,
79
+ output_lookup_table: @output_lookup_table,
80
+ outputs: @outputs,
81
+ weights: @weights
82
+ }.to_json
83
+ end
84
+
85
+ def load_state(saved_state)
86
+ state = JSON.parse(saved_state, symbolize_names: true)
87
+
88
+ @biases = state[:biases]
89
+ @binary_thresh = state[:binary_thresh]
90
+ @changes = state[:changes]
91
+ @deltas = state[:deltas]
92
+ @errors = state[:errors]
93
+ @hidden_layers = state[:hidden_layers]
94
+ @input_lookup_table = state[:input_lookup_table]
95
+ @layer_sizes = state[:layer_sizes]
96
+ @layers = state[:layers]
97
+ @learning_rate = state[:learning_rate]
98
+ @momentum = state[:momentum]
99
+ @output_lookup_table = state[:output_lookup_table]
100
+ @outputs = state[:outputs]
101
+ @weights = state[:weights]
102
+ end
103
+
65
104
  private
66
105
 
67
106
  def construct_network(layer_sizes)
@@ -1,3 +1,3 @@
1
1
  class Cerebrum
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cerebrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Irfan Sharif
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-05-22 00:00:00.000000000 Z
12
+ date: 2016-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler