Class: Loader_Yin
Overview
This is a human readable data format for describing neural nets as well as stimulations.
Note that it is a streaming scanner/parser, i.e. it’s important to put the template definitions before you actually use them. The same applies to stimulations and connections!
Instance Method Summary collapse
Methods inherited from Loader
Constructor Details
This class inherits a constructor from Loader
Instance Method Details
#load(filename) ⇒ Object
15 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/Yinspire/Loaders/Loader_Yin.rb', line 15 def load(filename) templates = {} hash = Hash.new YinScanner.new(File.read(filename)).scan do |cmd| case cmd.shift when :entity ids, type, prop_list = *cmd hash.clear if t = templates[type] type, template_data = *t hash.update(template_data) if template_data end hash.update(prop_list) if prop_list ids.each {|id| create_entity(type, id, hash) } when :connect cmd.first.each_cons(2) do |from, to| from.each {|f| entity = @entities[f] to.each {|t| entity.connect(@entities[t]) } } end when :stimulate ids, stimuls = *cmd ids.map! {|id| @entities[id] } stimuls.each do |sti| at, weight = *sti weight ||= Infinity ids.each {|entity| entity.stimulate(at, weight, nil) } end when :template ids, base_type, prop_list = *cmd ids.each do |id| raise if templates[id] templates[id] = [base_type, prop_list] end else raise end end end |