Skip to content

Commit

Permalink
Allow connections keys in config to be ranges. More Rubish config.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwilk committed Oct 19, 2012
1 parent 3b0e430 commit 0459c0e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -5,5 +5,6 @@ gem 'rake-compiler'
group :test do
gem "rspec"
gem "rake"
gem "fakefs", :require => "fakefs/safe"
end

2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
fakefs (0.4.0)
rake (0.9.2.2)
rake-compiler (0.8.1)
rake
Expand All @@ -18,6 +19,7 @@ PLATFORMS
ruby

DEPENDENCIES
fakefs
rake
rake-compiler
rspec
12 changes: 6 additions & 6 deletions Rakefile
Expand Up @@ -21,12 +21,12 @@ if tlearn_extension_present?
namespace :example do
require File.dirname(__FILE__) + '/lib/tlearn'

neural_network_config = {:nodes => {:nodes => 86},
:connections => [{'1-81' => '0'},
{'1-40' => 'i1-i77'},
{'41-46' => '1-40'},
{'1-40' => '47-86'},
{'47-86' => ' 1-40 = 1. & 1. fixed one-to-one'}],
neural_network_config = {:nodes => {:nodes => 86},
:connections => [{1..81 => '0'},
{1..40 => 'i1-i77'},
{41..46 => '1-40'},
{1..40 => '47-86'},
{47..86 => ' 1-40 = 1. & 1. fixed one-to-one'}],
:special => {:linear => '47-86',
:weight_limit => '1.00',
:selected => '1-86'}}
Expand Down
11 changes: 9 additions & 2 deletions lib/tlearn/config.rb
Expand Up @@ -29,19 +29,26 @@ def number_of_sweeps
DEFAULT_NUMBER_OF_SWEEPS
end

private
def file_root
"#{WORKING_DIR}/#{TLEARN_NAMESPACE}"
end

private

def connections_ranges_to_strings(connections_config)
connections_config.map{|hash| {hash.keys[0].to_s.gsub('..','-') => hash.values[0]}}
end

def evaulator_config(training_data)
nodes_config = {
:nodes => @nodes_config[:nodes],
:inputs => training_data.no_of_inputs,
:outputs => training_data.no_of_outputs,
:output_nodes => '41-46'
}


@connections_config = connections_ranges_to_strings(@connections_config)

output_nodes = nodes_config.delete(:output_nodes)
node_config_strings = nodes_config.map{|key,value| "#{key.to_s.gsub('_',' ')} = #{value}" }
node_config_strings << "output nodes are #{output_nodes}"
Expand Down
44 changes: 44 additions & 0 deletions spec/tlearn/config_spec.rb
@@ -0,0 +1,44 @@
require 'spec_helper'
require 'fakefs/spec_helpers'

module TLearn
describe Config do
include FakeFS::SpecHelpers

before(:each) do
@config = Config.new(settings)
FileUtils.mkdir_p @config.file_root
end

let(:settings){
{ :nodes => {:nodes => 5},
:connections => [{1..81 => '0'},
{1..40 => 'i1-i77'},
{1..40 => '47-86'},
{47..86 => ' 1-40 = 1. & 1. fixed one-to-one'}]}
}

let(:training_data){
TrainingData.new([[{[1] * 77 => [0, 0, 0, 0, 0, 1]}],[{[0] * 77 => [1, 0, 0, 0, 0, 0]}]])
}

def config_file
File.read("#{@config.file_root}.cf")
end

describe "generating *.cf file" do
it "should convert ranges to strings" do
@config.setup_config(training_data)

config_file.should include "1-81"
end

it "should allow multiple values for a single range" do
@config.setup_config(training_data)

config_file.scan(/^1-40/).should == ["1-40", "1-40"]
end
end

end
end
10 changes: 5 additions & 5 deletions spec_integration/spec_helper.rb
Expand Up @@ -5,11 +5,11 @@

def example_config
{:nodes => {:nodes => 86},
:connections => [{'1-81' => '0'},
{'1-40' => 'i1-i77'},
{'41-46' => '1-40'},
{'1-40' => '47-86'},
{'47-86' => ' 1-40 = 1. & 1. fixed one-to-one'}],
:connections => [{1..81 => '0'},
{1..40 => 'i1-i77'},
{41..46 => '1-40'},
{1..40 => '47-86'},
{47..86 => ' 1-40 = 1. & 1. fixed one-to-one'}],
:special => {:linear => '47-86',
:weight_limit => '1.00',
:selected => '1-86'}}
Expand Down

0 comments on commit 0459c0e

Please sign in to comment.