yinspire 0.1.0 → 0.2.0

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.
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # TODO: Dump at the end.
4
-
5
3
  begin
6
4
  require 'rubygems'
7
5
  rescue LoadError
@@ -23,15 +21,24 @@ LOADERS = {
23
21
  }
24
22
 
25
23
  DUMPERS = {
26
- :dot => Dumper_Dot
24
+ :dot => Dumper_Dot,
25
+ :yin => Dumper_Yin
27
26
  }
28
27
 
28
+ def parse_file_format(str, formats)
29
+ file, format = str.split(":")
30
+ format ||= File.extname(file)[1..-1]
31
+ raise "invalid FORMAT #{format}" unless format
32
+ klass = formats[format.to_sym]
33
+ raise "invalid FORMAT #{format}" unless klass
34
+ return file, klass
35
+ end
36
+
29
37
  def parse_cmdline
30
38
  require 'optparse'
31
39
  require 'ostruct'
32
40
 
33
41
  options = OpenStruct.new
34
- options.current_format = :yin
35
42
  options.stop_at = Infinity
36
43
  options.tolerance = 0.0
37
44
  options.output = nil
@@ -45,7 +52,7 @@ def parse_cmdline
45
52
  options.loads = []
46
53
 
47
54
  opts = OptionParser.new do |opts|
48
- opts.banner = "Usage: yinspire [options] [file] [options] [file] ..."
55
+ opts.banner = "Usage: yinspire [options]"
49
56
 
50
57
  opts.on("-s", "--stop-at N", Float, "Stop simulation at N (default: #{options.stop_at})") do |n|
51
58
  options.stop_at = n
@@ -55,21 +62,15 @@ def parse_cmdline
55
62
  options.tolerance = n
56
63
  end
57
64
 
58
- opts.on("-f", "--format FORMAT", LOADERS.keys,
59
- "Select format type of files to load",
60
- " (#{LOADERS.keys.join(', ')})") do |t|
61
- options.current_format = t
62
- end
63
-
64
- opts.on("-l", "--load FILE", "Load file") do |ld|
65
- options.loads << [options.current_format, ld]
65
+ opts.on("-l", "--load FILE[:FORMAT]", "Load file",
66
+ " (formats: #{LOADERS.keys.join(', ')})") do |ld|
67
+
68
+ options.loads << parse_file_format(ld, LOADERS)
66
69
  end
67
70
 
68
- opts.on("-d", "--dump FILE:FORMAT", "Dump net to file (after simulation)",
69
- " (formats: #{DUMPERS.keys.join(', ')})") do |t|
70
- file, format = t.split(":")
71
- raise "invalid FORMAT" if format.nil? or !DUMPERS.include?(format.to_sym)
72
- options.dumps << [file, format.to_sym]
71
+ opts.on("-d", "--dump FILE[:FORMAT]", "Dump net to file (after simulation)",
72
+ " (formats: #{DUMPERS.keys.join(', ')})") do |d|
73
+ options.dumps << parse_file_format(d, DUMPERS)
73
74
  end
74
75
 
75
76
  opts.on("-o", "--output FILE", "Filename to write output to",
@@ -107,9 +108,7 @@ def parse_cmdline
107
108
  end
108
109
  end
109
110
 
110
- unparsed = opts.order(ARGV.dup) {|arg|
111
- options.loads << [options.current_format, arg]
112
- }
111
+ unparsed = opts.parse!(ARGV.dup)
113
112
  if !unparsed.empty? or options.loads.empty?
114
113
  puts opts
115
114
  exit
@@ -164,8 +163,8 @@ def run
164
163
  sim = Simulator.new
165
164
  sim.stimuli_tolerance = options.tolerance
166
165
 
167
- options.loads.each do |format, file|
168
- LOADERS[format].new(sim).load(file)
166
+ options.loads.each do |file, klass|
167
+ klass.new(sim).load(file)
169
168
  end
170
169
 
171
170
  sim.run(options.stop_at) unless options.do_not_simulate
@@ -173,8 +172,8 @@ def run
173
172
  $yinspire_out.close if options.output and options.output != "-"
174
173
 
175
174
  # dump nets
176
- options.dumps.each do |file, format|
177
- dumper = DUMPERS[format].new(sim)
175
+ options.dumps.each do |file, klass|
176
+ dumper = klass.new(sim)
178
177
  if file == "-"
179
178
  dumper.dump(STDOUT)
180
179
  else
@@ -8,3 +8,4 @@ require 'Yinspire/Loaders/Loader_GraphML'
8
8
  require 'Yinspire/Loaders/Loader_Yin'
9
9
  require 'Yinspire/Loaders/Loader_Spike'
10
10
  require 'Yinspire/Dumpers/Dumper_Dot'
11
+ require 'Yinspire/Dumpers/Dumper_Yin'
@@ -0,0 +1,80 @@
1
+ require 'Yinspire/Dumpers/Dumper'
2
+ require 'enumerator'
3
+
4
+ class Dumper_Yin < Dumper
5
+
6
+ def initialize(*args)
7
+ super
8
+ @verbose = true
9
+ end
10
+
11
+ def dump(out)
12
+ ekeys = @entities.keys.sort
13
+ ekeys.each {|key|
14
+ entity = @entities[key]
15
+ out << "ENTITY " if @verbose
16
+ out << to_yin_str(entity.id)
17
+ out << " = #{to_yin_str(entity.entity_type)} "
18
+ out << to_yin_str(entity.dump)
19
+ out << "\n"
20
+ }
21
+
22
+ ekeys.each {|key|
23
+ entity = @entities[key]
24
+ targets = []; entity.each_connection {|t| targets << to_yin_str(t.id)}
25
+ next if targets.empty?
26
+
27
+ out << "CONNECT " if @verbose
28
+ out << "#{to_yin_str(entity.id)} -> #{targets.join(', ')}\n"
29
+ }
30
+
31
+ ekeys.each {|key|
32
+ entity = @entities[key]
33
+ next unless entity.respond_to?(:stimuli_pq_to_a)
34
+ stimuli = entity.stimuli_pq_to_a
35
+ next if stimuli.empty?
36
+
37
+ out << "\n"
38
+ out << "STIMULATE " if @verbose
39
+ out << "#{to_yin_str(entity.id)} ! {\n "
40
+
41
+ out << stimuli.to_enum(:each_slice, 2).
42
+ map {|at, weight|
43
+ if weight == Infinity
44
+ to_yin_str(at)
45
+ else
46
+ "#{to_yin_str(weight)}@#{to_yin_str(at)}"
47
+ end
48
+ }.to_enum(:each_slice, 5).map {|arr| arr.join(" ")}.join("\n ")
49
+
50
+ out << "\n}\n"
51
+ }
52
+ end
53
+
54
+ def to_yin_str(obj)
55
+ case obj
56
+ when String
57
+ if obj =~ /^\w+$/
58
+ obj
59
+ else
60
+ '"' + obj + '"'
61
+ end
62
+ when Symbol
63
+ to_yin_str(obj.to_s)
64
+ when Hash
65
+ out = ""
66
+ out << "{\n"
67
+ obj.keys.sort_by {|k| k.to_s}.each do |k|
68
+ out << " " if @verbose
69
+ out << "#{to_yin_str(k)} = #{to_yin_str(obj[k])}\n"
70
+ end
71
+ out << "}\n"
72
+ out
73
+ when TrueClass, FalseClass, Float, Fixnum, Bignum
74
+ obj.to_s
75
+ else
76
+ raise "#{obj.class}"
77
+ end
78
+ end
79
+
80
+ end
@@ -2,10 +2,10 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = "yinspire"
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
  s.summary = "An efficient Spiking Neural Net Simulator"
7
7
  s.files = Dir['**/*']
8
- s.add_dependency('cplus2ruby', '>= 1.1.1')
8
+ s.add_dependency('cplus2ruby', '>= 1.1.2')
9
9
  s.executables = ['yinspire']
10
10
 
11
11
  s.author = "Michael Neumann"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yinspire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Neumann
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-31 00:00:00 +02:00
12
+ date: 2008-04-01 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.1.1
22
+ version: 1.1.2
23
23
  version:
24
24
  description:
25
25
  email: mneumann@ntecs.de
@@ -30,102 +30,103 @@ extensions: []
30
30
  extra_rdoc_files: []
31
31
 
32
32
  files:
33
- - bench
34
- - bench/pq
35
- - bench/pq/bench_pairingheap.h
36
- - bench/pq/bench_binaryheap.h
37
- - bench/pq/bench.rb
38
- - bench/pq/bench_calendarqueue.h
39
- - bench/pq/Makefile
40
- - bench/pq/distribution.h
41
- - bench/pq/make.rb
42
- - bench/pq/bench_stlpq.h
43
- - bench/pq/bench.cc
44
- - bench/pq/benchmark.h
45
- - yinspire.gemspec
46
- - pure_cpp
47
- - pure_cpp/src
48
- - pure_cpp/src/algo
49
- - pure_cpp/src/algo/indexed_binary_heap.h
50
- - pure_cpp/src/algo/binary_heap.h
51
- - pure_cpp/src/neuron.cc
52
- - pure_cpp/src/neural_entity.cc
53
- - pure_cpp/src/neuron.h
54
- - pure_cpp/src/simulator.h
55
- - pure_cpp/src/neuron_srm_01.h
56
- - pure_cpp/src/neural_entity.h
57
- - pure_cpp/src/memory_allocator.h
58
- - pure_cpp/src/synapse.h
59
- - pure_cpp/src/main.cc
60
- - pure_cpp/src/synapse.cc
61
- - pure_cpp/src/json
62
- - pure_cpp/src/json/json_parser.rl
63
- - pure_cpp/src/json/json_parser.h
64
- - pure_cpp/src/json/json.cc
65
- - pure_cpp/src/json/json.h
66
- - pure_cpp/src/json/json_parser.cc
67
- - pure_cpp/src/neuron_srm_01.cc
68
- - pure_cpp/src/simulator.cc
69
- - pure_cpp/src/types.h
70
- - pure_cpp/Makefile
71
- - pure_cpp/README
72
33
  - lib
73
- - lib/Allocators
74
- - lib/Allocators/MemoryAllocator.h
75
- - lib/Allocators/ChunkedFreelistAllocator.h
76
- - lib/Allocators/RubyMemoryAllocator.h
77
- - lib/Yinspire.rb
34
+ - lib/Algorithms
35
+ - lib/Algorithms/CalendarQueue.h
36
+ - lib/Algorithms/BinaryHeap.h
37
+ - lib/Algorithms/Array.h
38
+ - lib/Algorithms/IndexedBinaryHeap.h
39
+ - lib/Algorithms/PairingHeap.h
78
40
  - lib/Yinspire
79
- - lib/Yinspire/Models
80
- - lib/Yinspire/Models/Neuron_Base.rb
81
- - lib/Yinspire/Models/Synapse_Hebb.rb
82
- - lib/Yinspire/Models/Neuron_Input.rb
83
- - lib/Yinspire/Models/Neuron_Output.rb
84
- - lib/Yinspire/Models/Neuron_InputOutput.rb
85
- - lib/Yinspire/Models/Neuron_SRM01.rb
86
- - lib/Yinspire/Models/Neuron_SRM02.rb
41
+ - lib/Yinspire/Dumpers
42
+ - lib/Yinspire/Dumpers/Dumper_Yin.rb
43
+ - lib/Yinspire/Dumpers/Dumper.rb
44
+ - lib/Yinspire/Dumpers/Dumper_Dot.rb
45
+ - lib/Yinspire/All.rb
87
46
  - lib/Yinspire/Core
88
- - lib/Yinspire/Core/StimuliMixin.rb
47
+ - lib/Yinspire/Core/Stimulus.rb
48
+ - lib/Yinspire/Core/Simulator.rb
49
+ - lib/Yinspire/Core/Synapse.rb
89
50
  - lib/Yinspire/Core/NeuralEntity.rb
51
+ - lib/Yinspire/Core/Neuron.rb
52
+ - lib/Yinspire/Core/StimuliMixin.rb
90
53
  - lib/Yinspire/Core/Scheduling
91
- - lib/Yinspire/Core/Scheduling/Simulator.rb
92
54
  - lib/Yinspire/Core/Scheduling/NeuralEntity.rb
93
- - lib/Yinspire/Core/Synapse.rb
94
- - lib/Yinspire/Core/Neuron.rb
95
- - lib/Yinspire/Core/Simulator.rb
96
- - lib/Yinspire/Core/Stimulus.rb
97
- - lib/Yinspire/Dumpers
98
- - lib/Yinspire/Dumpers/Dumper.rb
99
- - lib/Yinspire/Dumpers/Dumper_Dot.rb
55
+ - lib/Yinspire/Core/Scheduling/Simulator.rb
100
56
  - lib/Yinspire/Loaders
101
57
  - lib/Yinspire/Loaders/Loader_Yin.rb
102
58
  - lib/Yinspire/Loaders/Loader_GraphML.rb
103
- - lib/Yinspire/Loaders/Loader.rb
104
- - lib/Yinspire/Loaders/YinScanner.rb
105
59
  - lib/Yinspire/Loaders/GraphML.rb
60
+ - lib/Yinspire/Loaders/YinScanner.rb
61
+ - lib/Yinspire/Loaders/Loader.rb
106
62
  - lib/Yinspire/Loaders/Loader_Spike.rb
107
63
  - lib/Yinspire/Loaders/Loader_JSON.rb
108
- - lib/Yinspire/All.rb
109
- - lib/Algorithms
110
- - lib/Algorithms/IndexedBinaryHeap.h
111
- - lib/Algorithms/Array.h
112
- - lib/Algorithms/PairingHeap.h
113
- - lib/Algorithms/CalendarQueue.h
114
- - lib/Algorithms/BinaryHeap.h
64
+ - lib/Yinspire/Models
65
+ - lib/Yinspire/Models/Neuron_Input.rb
66
+ - lib/Yinspire/Models/Neuron_Base.rb
67
+ - lib/Yinspire/Models/Neuron_InputOutput.rb
68
+ - lib/Yinspire/Models/Synapse_Hebb.rb
69
+ - lib/Yinspire/Models/Neuron_SRM02.rb
70
+ - lib/Yinspire/Models/Neuron_Output.rb
71
+ - lib/Yinspire/Models/Neuron_SRM01.rb
72
+ - lib/Yinspire.rb
73
+ - lib/Allocators
74
+ - lib/Allocators/RubyMemoryAllocator.h
75
+ - lib/Allocators/ChunkedFreelistAllocator.h
76
+ - lib/Allocators/MemoryAllocator.h
77
+ - tools
78
+ - tools/json_writer.rb
79
+ - tools/conv_jsonc_to_yin.rb
80
+ - tools/converter.rb
81
+ - pure_cpp
82
+ - pure_cpp/src
83
+ - pure_cpp/src/algo
84
+ - pure_cpp/src/algo/binary_heap.h
85
+ - pure_cpp/src/algo/indexed_binary_heap.h
86
+ - pure_cpp/src/synapse.h
87
+ - pure_cpp/src/main.cc
88
+ - pure_cpp/src/memory_allocator.h
89
+ - pure_cpp/src/simulator.h
90
+ - pure_cpp/src/neuron_srm_01.h
91
+ - pure_cpp/src/neuron.cc
92
+ - pure_cpp/src/neural_entity.h
93
+ - pure_cpp/src/simulator.cc
94
+ - pure_cpp/src/json
95
+ - pure_cpp/src/json/json_parser.cc
96
+ - pure_cpp/src/json/json.h
97
+ - pure_cpp/src/json/json_parser.h
98
+ - pure_cpp/src/json/json.cc
99
+ - pure_cpp/src/json/json_parser.rl
100
+ - pure_cpp/src/neural_entity.cc
101
+ - pure_cpp/src/types.h
102
+ - pure_cpp/src/neuron.h
103
+ - pure_cpp/src/neuron_srm_01.cc
104
+ - pure_cpp/src/synapse.cc
105
+ - pure_cpp/README
106
+ - pure_cpp/Makefile
115
107
  - bin
116
108
  - bin/yinspire
117
- - README
118
- - run.rb
109
+ - yinspire.gemspec
119
110
  - examples
120
111
  - examples/nets
121
- - examples/nets/gereon2005.c.json
122
112
  - examples/nets/spiketrains_angle_180.txt
123
- - examples/nets/skorpion.graphml
124
113
  - examples/nets/gereon2005.yin
125
- - tools
126
- - tools/converter.rb
127
- - tools/json_writer.rb
128
- - tools/conv_jsonc_to_yin.rb
114
+ - examples/nets/gereon2005.c.json
115
+ - examples/nets/skorpion.graphml
116
+ - README
117
+ - run.rb
118
+ - bench
119
+ - bench/pq
120
+ - bench/pq/distribution.h
121
+ - bench/pq/make.rb
122
+ - bench/pq/bench.cc
123
+ - bench/pq/benchmark.h
124
+ - bench/pq/bench_calendarqueue.h
125
+ - bench/pq/bench_pairingheap.h
126
+ - bench/pq/bench.rb
127
+ - bench/pq/bench_stlpq.h
128
+ - bench/pq/bench_binaryheap.h
129
+ - bench/pq/Makefile
129
130
  has_rdoc: false
130
131
  homepage: http://www.ntecs.de/projects/yinspire/
131
132
  post_install_message: