Class: Neuron

Inherits:
NeuralEntity show all
Defined in:
lib/Yinspire.rb,
lib/Yinspire/Core/Neuron.rb

Overview

Base class of all Neurons. Defines the structure that is special for a Neuron, i.e. that a Neuron has pre- and post-Synapses.

Direct Known Subclasses

Neuron_Base

Instance Method Summary collapse

Methods inherited from NeuralEntity

class_from_name, #disconnect_all, #dump, entity_ann_dump_cache, entity_ann_load_cache, #entity_type, entity_type_map, entity_type_map_reverse, #initialize, #load, new_from_name

Constructor Details

This class inherits a constructor from NeuralEntity

Instance Method Details

#add_post_synapse(syn) ⇒ Object Also known as: connect

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/Yinspire/Core/Neuron.rb', line 31

def add_post_synapse(syn)
  raise ArgumentError, "Synapse expected" unless syn.kind_of?(Synapse)
  raise "Synapse already connected" if syn.pre_neuron || syn.next_post_synapse

  if last = self.last_post_synapse
    assert(last.next_post_synapse == nil)
    last.next_post_synapse = syn
    self.last_post_synapse = syn # advance tail pointer
  else
    assert(self.first_post_synapse == nil)
    self.first_post_synapse = self.last_post_synapse = syn
  end

  syn.pre_neuron = self
end

#add_pre_synapse(syn) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/Yinspire/Core/Neuron.rb', line 15

def add_pre_synapse(syn)
  raise ArgumentError, "Synapse expected" unless syn.kind_of?(Synapse)
  raise "Synapse already connected" if syn.post_neuron || syn.next_pre_synapse

  if last = self.last_pre_synapse
    assert(last.next_pre_synapse == nil) # missing method: neuron instead of synapse
    last.next_pre_synapse = syn
    self.last_pre_synapse = syn # advance tail pointer
  else
    assert(self.first_pre_synapse == nil)
    self.first_pre_synapse = self.last_pre_synapse = syn
  end

  syn.post_neuron = self
end

#delete_post_synapse(syn) ⇒ Object Also known as: disconnect



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/Yinspire/Core/Neuron.rb', line 73

def delete_post_synapse(syn)
  # FIXME
  raise "target must be Synapse" unless target.kind_of?(Synapse)
  raise "Synapse not connected to this Neuron" if target.pre_neuron != self 

  #
  # Find the synapse in the linked list that precedes +target+.
  #
  prev = nil
  curr = self.first_post_synapse

  while true
    break if curr == target
    break unless curr
    prev = curr
    curr = curr.next_post_synapse
  end

  raise "Synapse not in post synapse list" if curr != target

  #
  # Remove +target+ from linked list.
  #
  if prev
    prev.next_post_synapse = target.next_post_synapse
    self.last_post_synapse = prev if self.last_post_synapse == target 
  else
    #
    # target is the only synapse in the post synapse list.
    #
    assert self.first_post_synapse == target
    assert self.last_post_synapse == target
    self.first_post_synapse = nil
    self.last_post_synapse = nil
  end

  target.pre_neuron = nil
  target.next_post_synapse = nil
end

#delete_pre_synapse(syn) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/Yinspire/Core/Neuron.rb', line 47

def delete_pre_synapse(syn)
  raise ArgumentError, "Synapse expected" unless syn.kind_of?(Synapse)
  raise "Synapse not connected to this Neuron" if syn.post_neuron != self

  prev = find_preceding_synapse(syn, first_pre_synapse(), :next_pre_syapse)

  #
  # Remove +target+ from linked list.
  #
  if prev
    prev.next_pre_synapse = target.next_post_synapse
    self.last_post_synapse = prev if self.last_post_synapse == target 
  else
    #
    # target is the only synapse in the post synapse list.
    #
    assert self.first_post_synapse == target
    assert self.last_post_synapse == target
    self.first_post_synapse = nil
    self.last_post_synapse = nil
  end

  target.pre_neuron = nil
  target.next_post_synapse = nil
end

#each_connectionObject

Iterates over each outgoing connection (post synapses).



119
120
121
122
123
124
125
# File 'lib/Yinspire/Core/Neuron.rb', line 119

def each_connection
  syn = self.first_post_synapse
  while syn
    yield syn
    syn = syn.next_post_synapse
  end
end