csys: a second test with just 1 neuron, linked to itself, + 1 effector
This commit is contained in:
parent
046f518289
commit
3a9d281f65
4 changed files with 39 additions and 16 deletions
|
|
@ -29,6 +29,7 @@ defmodule Scopes.CSys do
|
|||
end
|
||||
|
||||
def forward(msg, scope) do
|
||||
#for s <- syns(scope), reduce: 0, do: (acc -> s.(msg); acc + 1)
|
||||
for s <- syns(scope), reduce: false, do: (_acc -> s.(msg))
|
||||
#Enum.reduce(syns(scope), false, fn s, _acc -> s.(msg); true end)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ defmodule Scopes.CSys.Environ do
|
|||
alias Scopes.Shape
|
||||
|
||||
defmodule State do
|
||||
defstruct [neurons: [], init_seq: []]
|
||||
defstruct [neurons: [], names: %{}, init_seq: []]
|
||||
end
|
||||
|
||||
def setup({state, proc}, seq \\ []) do
|
||||
|
|
@ -23,10 +23,12 @@ defmodule Scopes.CSys.Environ do
|
|||
end
|
||||
|
||||
def process_creation(msg, {state, proc, syns, env}) do
|
||||
new = Shape.data(msg).new
|
||||
data = Shape.data(msg)
|
||||
new = data.new
|
||||
neurons = [new | state.neurons]
|
||||
names = data[:name] && Map.put(state.names, data.name, new) || state.names
|
||||
{step, seq} = List.pop_at(state.init_seq, 0)
|
||||
CSys.update({%State{neurons: neurons, names: names, init_seq: seq}, proc, syns, env})
|
||||
if step, do: step.(neurons)
|
||||
CSys.update({%{state | neurons: neurons, init_seq: seq}, proc, syns, env})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@ alias Scopes.CSys
|
|||
alias Scopes.Shape
|
||||
|
||||
defmodule State do
|
||||
defstruct [:value, :threshold, :bias, :stage, :prog]
|
||||
defstruct [:value, :count, :bias, :threshold, :stage, :prog]
|
||||
end
|
||||
|
||||
def prepare(prog, args) do
|
||||
state = %State{
|
||||
value: args[:bias],
|
||||
threshold: args[:threshold],
|
||||
count: 0,
|
||||
bias: args[:bias],
|
||||
threshold: args[:threshold],
|
||||
stage: :initial,
|
||||
prog: prog
|
||||
}
|
||||
|
|
@ -132,15 +133,15 @@ alias Scopes.CSys
|
|||
# demo init sequences
|
||||
|
||||
def init_seq_b1() do [
|
||||
fn [zero | _ns] -> CSys.send_message(zero, [:csys, :create, :pred],
|
||||
%{op: [CSys.data_only(), negate()]}) end,
|
||||
fn [one | _ns] -> CSys.send_message(one, [:csys, :create, :succ],
|
||||
%{op: CSys.data_only()}) end,
|
||||
fn [two | _ns] -> CSys.send_message(two, [:csys, :create, :pred]) end,
|
||||
fn [three | others] ->
|
||||
zero = List.last(others)
|
||||
CSys.send_message(three, [:csys, :connect], %{target: zero})
|
||||
end
|
||||
]
|
||||
fn [zero | _ns] -> CSys.send_message(zero, [:csys, :create, :pred],
|
||||
%{op: [CSys.data_only(), negate()]}) end,
|
||||
fn [one | _ns] -> CSys.send_message(one, [:csys, :create, :succ],
|
||||
%{op: CSys.data_only()}) end,
|
||||
fn [two | _ns] -> CSys.send_message(two, [:csys, :create, :pred]) end,
|
||||
fn [three | others] ->
|
||||
zero = List.last(others)
|
||||
CSys.send_message(three, [:csys, :connect], %{target: zero})
|
||||
end
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,14 +25,33 @@ defmodule Scopes.CSysTest do
|
|||
one = receive_data([:csys, :created]).new
|
||||
_two = receive_data([:csys, :created]).new
|
||||
three = receive_data([:csys, :created]).new
|
||||
Process.sleep(5)
|
||||
Process.sleep(50)
|
||||
CSys.send_value(one, 1)
|
||||
assert receive_data().value == 1
|
||||
#assert receive_data().value in [-1, 1]
|
||||
CSys.send_value(three, 3)
|
||||
assert receive_data().value in [2, 3]
|
||||
assert receive_data().value in [2, 3]
|
||||
refute_received msg, "unhandled message(s): #{inspect(msg)}"
|
||||
end
|
||||
end
|
||||
|
||||
def init_recursive_1() do [
|
||||
fn [zero] ->
|
||||
CSys.send_message(zero, [:csys, :connect], %{target: zero, op: Program.negate()})
|
||||
CSys.send_message(zero, [:csys, :create, :succ])
|
||||
end
|
||||
]
|
||||
end
|
||||
|
||||
describe "recursive:" do
|
||||
test "zero + effector" do
|
||||
_env = Environ.setup(Program.prepare_basic(), init_recursive_1())
|
||||
zero = receive_data([:csys, :created]).new
|
||||
_eff = receive_data([:csys, :created]).new
|
||||
Process.sleep(50)
|
||||
CSys.send_value(zero, 42)
|
||||
assert receive_data().value == 42
|
||||
refute_received msg, "unhandled message(s): #{inspect(msg)}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue