|
|
@@ -12,7 +12,7 @@ const (
|
|
|
Hidden int = 64
|
|
|
Output int = 7
|
|
|
Sample int = 10000
|
|
|
- Batch int = 5
|
|
|
+ Batch int = 16
|
|
|
Dropout float64 = 0.5
|
|
|
Rate float64 = 0.01
|
|
|
)
|
|
|
@@ -122,9 +122,9 @@ func Train(G Graph) []Layer {
|
|
|
p2 := Parameter{MakeRandomMatrix(Hidden, Output), MakeRandomMatrix(Hidden, Output)}
|
|
|
l := []Layer{{d: Input}, {d: Hidden, f: ReLU, p: p1}, {d: Output, f: Softmax, p: p2}}
|
|
|
for i := 0; i < Sample; i++ {
|
|
|
- if i%1000 == 0 {
|
|
|
+ if i%100 == 0 {
|
|
|
Test(G, l, false)
|
|
|
- fmt.Println("sampling", i)
|
|
|
+ // fmt.Println("sampling", i)
|
|
|
}
|
|
|
var wg sync.WaitGroup
|
|
|
l[0].D, l[1].D = MakeDropoutVector(Input), MakeDropoutVector(Hidden)
|
|
|
@@ -148,7 +148,7 @@ func Train(G Graph) []Layer {
|
|
|
StartCalc(&wg, DB1, Matrix{G.E[0][u]}, deltaB)
|
|
|
deltaW := delta.Multiply(l[2].p.W.Transpose())
|
|
|
for v := range G.A[u] {
|
|
|
- delta = MakeMatrix(1, Hidden).Add(deltaW).Divide(float64(len(G.A[u])))
|
|
|
+ delta = MakeMatrix(1, Hidden).Add(deltaW)
|
|
|
for k := 0; k < Hidden; k++ {
|
|
|
if G.E[1][v][k] == 0 {
|
|
|
delta[0][k] = 0
|
|
|
@@ -159,6 +159,7 @@ func Train(G Graph) []Layer {
|
|
|
}
|
|
|
wg.Wait()
|
|
|
}
|
|
|
+ Rate := 0.2 * math.Exp(-float64(i)/1000)
|
|
|
StartRefine(&wg, l[2].p.W, DW2, 1/Rate)
|
|
|
StartRefine(&wg, l[2].p.B, DB2, 1/Rate)
|
|
|
StartRefine(&wg, l[1].p.W, DW1, 1/Rate)
|
|
|
@@ -169,7 +170,7 @@ func Train(G Graph) []Layer {
|
|
|
}
|
|
|
|
|
|
func Test(G Graph, l []Layer, detail bool) {
|
|
|
- cnt1, cnt2 := 0, 0
|
|
|
+ cnt1, cnt2, loss := 0, 0, 0.
|
|
|
for u := range G.X {
|
|
|
GetEmbedding(G, u, 2, l, false)
|
|
|
id, _ := G.E[2][u].Max()
|
|
|
@@ -182,7 +183,16 @@ func Test(G Graph, l []Layer, detail bool) {
|
|
|
if G.L[u] == id+Output {
|
|
|
cnt2++
|
|
|
}
|
|
|
+ loss -= math.Log(G.E[2][u][G.L[u]%Output])
|
|
|
+ }
|
|
|
+ if detail {
|
|
|
+ fmt.Println(cnt1, "/", len(nodeId), ",", cnt2, "/", Node-len(nodeId))
|
|
|
+ fmt.Println(
|
|
|
+ 100*float64(cnt1)/float64(len(nodeId)), ",",
|
|
|
+ 100*float64(cnt2)/float64((Node-len(nodeId))), ",",
|
|
|
+ loss/float64(len(G.X)),
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ fmt.Println(100*float64(cnt2)/float64((Node-len(nodeId))), loss/float64(len(G.X)))
|
|
|
}
|
|
|
- fmt.Println(cnt1, "/", len(nodeId), ",", cnt2, "/", Node-len(nodeId))
|
|
|
- fmt.Println(100.*cnt1/len(nodeId), ",", 100.*cnt2/(Node-len(nodeId)))
|
|
|
}
|