-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubstrate_cep.erl
50 lines (44 loc) · 2.26 KB
/
substrate_cep.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
%% This source code and work is provided and developed by DXNN Research Group WWW.DXNNResearch.COM
%%
%Copyright (C) 2012 by Gene Sher, DXNN Research Group, [email protected]
%All rights reserved.
%
%This code is licensed under the version 3 of the GNU General Public License. Please see the LICENSE file that accompanies this project for the terms of use.
-module(substrate_cep).
-compile(export_all).
-include("records.hrl").
gen(ExoSelf_PId,Node)->
spawn(Node,?MODULE,prep,[ExoSelf_PId]).
prep(ExoSelf_PId) ->
receive
{ExoSelf_PId,{Id,Cx_PId,Substrate_PId,CEPName,Parameters,Fanin_PIds}} ->
loop(Id,ExoSelf_PId,Cx_PId,Substrate_PId,CEPName,Parameters,{Fanin_PIds,Fanin_PIds},[])
end.
%When gen/2 is executed it spawns the actuator element and immediately begins to wait for its initial state message.
loop(Id,ExoSelf_PId,Cx_PId,Substrate_PId,CEPName,Parameters,{[From_PId|Fanin_PIds],MFanin_PIds},Acc) ->
receive
{From_PId,forward,Input} ->
loop(Id,ExoSelf_PId,Cx_PId,Substrate_PId,CEPName,Parameters,{Fanin_PIds,MFanin_PIds},lists:append(Input,Acc));
{ExoSelf_PId,terminate} ->
%io:format("Substrate_CEP:~p is terminating.~n",[self()])
ok
end;
loop(Id,ExoSelf_PId,Cx_PId,Substrate_PId,CEPName,Parameters,{[],MFanin_PIds},Acc)->
ProperlyOrdered_Input=lists:reverse(Acc),
substrate_cep:CEPName(ProperlyOrdered_Input,Parameters,Substrate_PId),
loop(Id,ExoSelf_PId,Cx_PId,Substrate_PId,CEPName,Parameters,{MFanin_PIds,MFanin_PIds},[]).
%The substrate_cep process gathers the control signals from the neurons, appending them to the accumulator. The order in which the signals are accumulated into a vector is in the same order that the neuron ids are stored within NIds. Once all the signals have been gathered, the substrate_cep executes its function, forwards the processed signal to the substrate, and then again begins to wait for the neural signals from the output layer by reseting the Fanin_PIds from the second copy of the list.
%%%%%%%% Substrate_CEPs %%%%%%%%
set_weight(Output,_Parameters,Substrate_PId)->
[Val] = Output,
Threshold = 0.33,
Weight = if
Val > Threshold ->
(functions:scale(Val,1,Threshold)+1)/2;
Val < -Threshold ->
(functions:scale(Val,-Threshold,-1)-1)/2;
true ->
0
end,
Substrate_PId ! {self(),set_weight,[Weight]}.
%