Class: Loader_Spike

Inherits:
Loader show all
Defined in:
lib/Yinspire/Loaders/Loader_Spike.rb

Overview

Loader for spikes in the format:

Id1 weight1@time1 time2 time3 ...
Id2 time1 time2 time3 ...
...

Weight values (e.g. 1.0@time1) are optional.

Lines beginning with “#” are comments.

Instance Method Summary collapse

Methods inherited from Loader

#initialize

Constructor Details

This class inherits a constructor from Loader

Instance Method Details

#load(filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/Yinspire/Loaders/Loader_Spike.rb', line 16

def load(filename)
  File.open(filename, 'r') do |f|
    while line = f.gets
      line.strip!
      next if line =~ /^#/ # comment

      #
      # The following code is to help Matlab to generate spike trains
      # more easily and allows spaces before and after the "@", e.g.
      # "123 @ 444".
      #
      line.gsub!(/\s+@\s+/, '')

      id, *spikes = line.split
      raise if spikes.empty?
      entity = @entities[id] || raise

      spikes.each do |spike|
        weight, at = spike.split("@") 
        weight, at = Infinity, weight if at.nil? # spike is a pure time-value
        entity.stimulate(at.to_f, weight.to_f, nil)
      end
    end
  end
end