Created
November 24, 2017 14:01
-
-
Save nakamkaz/8cd9ff25b7fec5c029a45f6bc4c58e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* ゼロから作るDeepLearning 3.4.3 実装のまとめ より */ | |
import ( | |
"github.com/nakamkaz/np00" | |
"fmt" | |
) | |
func InitNetwork() np00.NNetwork { | |
nn := make(map[string]np00.NParray) | |
nn["W1"] = np00.NParray{ | |
[]float64{0.1, 0.3, 0.5}, | |
[]float64{0.2, 0.4, 0.6}, | |
} | |
nn["B1"] = np00.NParray{ | |
[]float64{0.1, 0.2, 0.3}, | |
} | |
nn["W2"] = np00.NParray{ | |
[]float64{0.1, 0.4}, | |
[]float64{0.2, 0.5}, | |
[]float64{0.3, 0.6}, | |
} | |
nn["B2"] = np00.NParray{ | |
[]float64{0.1, 0.2}, | |
} | |
nn["W3"] = np00.NParray{ | |
[]float64{0.1, 0.3}, | |
[]float64{0.2, 0.4}, | |
} | |
nn["B3"] = np00.NParray{ | |
[]float64{0.1, 0.2}, | |
} | |
return nn | |
} | |
func Forward(nn np00.NNetwork, npa np00.NParray) (npr np00.NParray) { | |
W1, W2, W3 := nn["W1"], nn["W2"], nn["W3"] | |
b1, b2, b3 := nn["B1"], nn["B2"], nn["B3"] | |
a1 := np00.Add(np00.Dot(npa, W1), b1) | |
z1 := np00.Sigmoid(a1) | |
fmt.Println("z1: ",z1) | |
a2 := np00.Add(np00.Dot(z1, W2), b2) | |
z2 := np00.Sigmoid(a2) | |
fmt.Println("z2: ",z2) | |
fmt.Println("W3: ",W3) | |
_ = b3 | |
a3 := np00.Add(np00.Dot(z2, W3), b3) | |
y := np00.IdentityFunction(a3) | |
return y | |
} | |
func main(){ | |
nn := InitNetwork() | |
X := np00.NParray{ | |
[]float64{1.0,0.5}, | |
} | |
Y := Forward(nn,X) | |
fmt.Println(Y) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Numpy版と精度はちがうけど大体あってる
z1: ([1 3]){
[ 0.574442516811659 0.6681877721681662 0.7502601055951177 ]
}
z2: ([1 2]){
[ 0.6262493703990729 0.7710106968556123 ]
}
W3: ([2 2]){
[ 0.1 0.3 ]
[ 0.2 0.4 ]
}
([1 2]){
[ 0.3168270764110298 0.6962790898619668 ]
}