forked from CorticalComputer/DXNN2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epitopes.erl
178 lines (170 loc) · 5.9 KB
/
epitopes.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This source code and work is provided and developed by Gene I. Sher & DXNN Research Group WWW.DXNNResearch.COM
%
%The original release of this source code and the DXNN MK2 system was introduced and explained in my book: Handbook of Neuroevolution Through Erlang. Springer 2012, print ISBN: 978-1-4614-4462-6 ebook ISBN: 978-1-4614-4463-6.
%
%Copyright (C) 2009 by Gene Sher, DXNN Research Group CorticalComputer@gmail.com
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%%%%%%%%%%%%%%%%%%%% Deus Ex Neural Network :: DXNN %%%%%%%%%%%%%%%%%%%%
-module(epitopes).
-compile(export_all).
-include("records.hrl").
start()->
spawn(epitopes,db,[]).
db()->
ets:file2tab(abc_pred10),
ets:file2tab(abc_pred12),
ets:file2tab(abc_pred14),
ets:file2tab(abc_pred16),
ets:file2tab(abc_pred18),
ets:file2tab(abc_pred20),
receive
terminate ->
ok
end.
sim(ExoSelf)->
receive
{From,sense,OpMode,Parameters}->
%[TableName,StartIndex,EndIndex,StartBenchIndex,EndBenchIndex] = [abc_pred16,841,1120,841,1120],%%TODO
[TableName,StartIndex,EndIndex,StartBenchIndex,EndBenchIndex] = Parameters,
Out=case get(abc_pred) of
undefined ->
case OpMode of
gt ->
put(abc_pred,StartIndex),
Sequence = ets:lookup_element(TableName,StartIndex,2),
lists:flatten([translate_seq(Char) || Char <- Sequence]);
benchmark ->
put(abc_pred,StartBenchIndex),
Sequence = ets:lookup_element(TableName,StartBenchIndex,2),
lists:flatten([translate_seq(Char) || Char <- Sequence])
end;
Ind ->
Index = case Ind == 0 of
true -> 1;
false -> Ind
end,
Sequence = ets:lookup_element(TableName,Index,2),
lists:flatten([translate_seq(Char) || Char <- Sequence])
end,
From ! {self(),percept,Out},
sim(ExoSelf);
{From,classify,OpMode,Parameters,Output}->
%[TableName,StartIndex,EndIndex,StartBenchIndex,EndBenchIndex] = [abc_pred16,841,1120,841,1120],%%TODO
[TableName,StartIndex,EndIndex,StartBenchIndex,EndBenchIndex] = Parameters,
case get(abc_pred) of
undefined ->
exit("Exit with error from sim epitopes~n");
Ind ->
Index = case Ind == 0 of
true -> 1;
false -> Ind
end,
Classification = ets:lookup_element(TableName,Index,3),
HaltFlag = case OpMode of
gt ->
case Index == EndIndex of
true -> erase(abc_pred),1;
false -> put(abc_pred,(Index+1) rem 1401),0
end;
benchmark ->
case Index == EndBenchIndex of
true -> erase(abc_pred),1;
false -> put(abc_pred,(Index+1) rem 1401),0
end
end,
case (Classification == functions:bin(Output)) of%%TODO
%case (Classification==0) and (0==functions:bin(Output)) of
true ->
From ! {self(),1,HaltFlag};
false ->
From ! {self(),0,HaltFlag}
end
end,
sim(ExoSelf);
{ExoSelf,terminate} ->
ok
%after 10000 ->
%io:format("Exiting with error from epitopes sim~n")
end.
translate_seq1(Char)->
case Char of
65 -> -1;
82 -> -0.9;
78 -> -0.8;
68 -> -0.7;
67 -> -0.6;
69 -> -0.5;
81 -> -0.4;
71 -> -0.3;
72 -> -0.2;
73 -> -0.1;
76 -> 0;
75 -> 0.1;
77 -> 0.2;
70 -> 0.3;
80 -> 0.4;
83 -> 0.5;
84 -> 0.6;
87 -> 0.7;
89 -> 0.8;
86 -> 0.9;
88 -> 1
end.
translate_seq(Char)->
case Char of
65 -> [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
82 -> [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
78 -> [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
68 -> [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
67 -> [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
69 -> [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
81 -> [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
71 -> [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0];
72 -> [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0];
73 -> [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0];
76 -> [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0];
75 -> [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0];
77 -> [0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0];
70 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0];
80 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0];
83 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0];
84 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0];
87 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0];
89 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0];
86 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];
88 -> [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
end.
test(ExperimentName)->
ets:new(testing,[named_table,set,public]),
[E] = mnesia:dirty_read({experiment,ExperimentName}),
io:format("E:~p~n",[E]),
Traces = E#experiment.trace_acc,
BestGen_Champions = [get_best(Trace) || Trace <- Traces],
[{BOTB_F,BOTB_Id}|_] = lists:reverse(lists:sort(BestGen_Champions)),
[exoself:start(ExoselfId,void,benchmark) || {GenFitness,ExoselfId} <- BestGen_Champions],
timer:sleep(5000),
get_avg(ets:first(potato),[]),
exoself:start(BOTB_Id,void,benchmark),
ets:delete(testing).
get_best(T)->
Stats = T#trace.stats,
GenTest_Champions=[Stat#stat.validation_fitness || [Stat] <- Stats],
[Best|_]=lists:reverse(lists:sort(GenTest_Champions)),
Best.
get_avg('$end_of_table',Acc)->
io:format("~p~n",[{functions:avg(Acc),functions:std(Acc),lists:max(Acc),lists:min(Acc),functions:avg(Acc)/280}]);
get_avg(Key,Acc)->
Val = ets:lookup_element(testing,Key,2),
get_avg(ets:next(testing,Key),[Val|Acc]).