-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.jl~
More file actions
49 lines (39 loc) · 814 Bytes
/
test.jl~
File metadata and controls
49 lines (39 loc) · 814 Bytes
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
f = open("test.txt")
input = [5.0;3.0;-1.0;2.5;-0.5;0.3;0.7;1.9;3.5;-0.3]
hiddenSizes=[25,9];
action=1;
qtarget = 0.5;
weights = readlines(f);
counter = 1;
W = Any[]
x = length(input)
for h in hiddenSizes
params = split(weights[counter],",")
w = parse.(Float64,params)
w = reshape(w,h,x)
push!(W,w)
counter += 1
params = split(weights[counter],",")
b = parse.(Float64,params)
b = reshape(b,h,1)
push!(W,b)
counter += 1
x = h
end
function forward(w,x)
for i=1:2:length(w)
x = w[i]*x .+ w[i+1]
if i<length(w)-1
x = relu.(x)
end
end
return x
end
function loss(w,x,action,target)
x3 = forward(w,x);
loss = x3[action]-target
return loss^2
end
using Knet
gradloss = grad(loss);
gradloss(W,input,1,qtarget)