csys: put proc metadata in State struct, use for preparing zero neuron via setup()
This commit is contained in:
parent
d13962c02b
commit
36dae3885c
4 changed files with 27 additions and 13 deletions
|
|
@ -23,9 +23,12 @@ defmodule Scopes.CSys do
|
||||||
proc(scope).(msg, scope)
|
proc(scope).(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_message(rcvr, head, data) do
|
||||||
|
Actor.send(rcvr, Shape.create(head, data: data))
|
||||||
|
end
|
||||||
|
|
||||||
def send_value(rcvr, val) do
|
def send_value(rcvr, val) do
|
||||||
msg = Shape.create([:csys, :data], data: %{value: val})
|
send_message(rcvr, [:csys, :data], %{value: val})
|
||||||
Actor.send(rcvr, msg)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def state(scope), do: elem(scope, 0)
|
def state(scope), do: elem(scope, 0)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
defmodule Scopes.CSys.Environ do
|
defmodule Scopes.CSys.Environ do
|
||||||
use Agent
|
|
||||||
|
|
||||||
alias Scopes.CSys
|
alias Scopes.CSys
|
||||||
|
|
||||||
def setup(proc) do
|
def setup({state, proc}) do
|
||||||
env = CSys.neuron({[], &proc_env/2, [], self()})
|
env = CSys.neuron({[], &proc_env/2, [], self()})
|
||||||
CSys.neuron({[], proc, [], env})
|
CSys.neuron({state, proc, [], env})
|
||||||
end
|
end
|
||||||
|
|
||||||
def proc_env(msg, scope) do
|
def proc_env(msg, scope) do
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,17 @@ defmodule Scopes.CSys.Program do
|
||||||
neuron: 1, update_neuron: 1, synapse: 3,
|
neuron: 1, update_neuron: 1, synapse: 3,
|
||||||
syns: 1, env: 1
|
syns: 1, env: 1
|
||||||
]
|
]
|
||||||
|
|
||||||
alias Scopes.Core.Actor
|
alias Scopes.Core.Actor
|
||||||
|
|
||||||
# programs
|
defmodule State do
|
||||||
|
defstruct [:value, :stage, :prog]
|
||||||
|
end
|
||||||
|
|
||||||
|
def prepare(prog) do
|
||||||
|
{%State{value: 0, stage: :initial, prog: prog}, elem(prog, 0)[:initial]}
|
||||||
|
end
|
||||||
|
|
||||||
|
# basic program
|
||||||
|
|
||||||
def basic_prog() do
|
def basic_prog() do
|
||||||
default = &basic_active/2
|
default = &basic_active/2
|
||||||
|
|
@ -24,26 +31,32 @@ defmodule Scopes.CSys.Program do
|
||||||
{stages, transitions}
|
{stages, transitions}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_basic() do
|
||||||
|
prepare(basic_prog())
|
||||||
|
end
|
||||||
|
|
||||||
# basic processors
|
# basic processors
|
||||||
|
|
||||||
def basic_initial(msg, scope) do
|
def basic_initial(msg, scope) do
|
||||||
basic(msg, scope, {:initial, basic_prog()})
|
basic(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
def basic_active(msg, scope) do
|
def basic_active(msg, scope) do
|
||||||
basic(msg, scope, {:active, basic_prog()})
|
basic(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
def basic(msg = {head, _info}, scope, _meta) do
|
def basic(msg = {head, _info}, scope) do
|
||||||
case head do
|
case head do
|
||||||
[:csys, :create, :pred | _rest] -> create_pred(scope)
|
[:csys, :create, :pred | _rest] -> create_pred(scope)
|
||||||
[:csys, :create, :succ | _rest] -> create_succ(scope)
|
[:csys, :create, :succ | _rest] -> create_succ(scope)
|
||||||
#[:csys, :next | _rest] -> next(scope, meta)
|
#[:csys, :next | _rest] -> next(scope, meta)
|
||||||
|
#[:csys, :data | rest] -> process_data(rest, Shape.data(msg), scope)
|
||||||
|
#[:csys, action | rest] -> transition(action, scope)
|
||||||
_ -> forward(msg, scope) || notify(msg, scope)
|
_ -> forward(msg, scope) || notify(msg, scope)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def basic(msg, scope, _meta) do
|
def basic(msg, scope) do
|
||||||
forward(msg, scope) || notify(msg, scope)
|
forward(msg, scope) || notify(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ defmodule Scopes.CSysTest do
|
||||||
|
|
||||||
describe "basic:" do
|
describe "basic:" do
|
||||||
test "minimal-neural-net" do
|
test "minimal-neural-net" do
|
||||||
{stages, _trans} = Program.basic_prog()
|
zero = Environ.setup(Program.prepare_basic())
|
||||||
zero = Environ.setup(stages[:initial])
|
|
||||||
#Actor.send(zero, "Hello Zero!")
|
#Actor.send(zero, "Hello Zero!")
|
||||||
CSys.send_value(zero, "Hello Zero!")
|
CSys.send_value(zero, "Hello Zero!")
|
||||||
assert "Hello Zero!" = receive_data().value
|
assert "Hello Zero!" = receive_data().value
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue