Last active
August 6, 2017 05:22
-
-
Save eiel/0afd9833ea875ed5f27511e2527ee573 to your computer and use it in GitHub Desktop.
Rustで「ゼロからつくるDeep Learning」 p26 2.3.2 重みとバイアスの導入
This file contains hidden or 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] | |
name = "rust-nn" | |
version = "0.1.0" | |
authors = ["Tomohiko Himura <[email protected]>"] | |
[dependencies] | |
nalgebra = "0.12.3" |
This file contains hidden or 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
extern crate nalgebra as na; | |
use na::{Matrix1x2, Vector2, Vector1}; | |
// p26 2.3.2 重みとバイアスの導入 | |
// 行列同士の内積 | |
fn main() { | |
// Vector2 は Matrix2x1 のエイリアスとなっているので内積をとるためには transposeされた値を用意しないといけない。 | |
// let x = Vector2::new(0.0, 1.0).transpose(); // としてもよい | |
let x = Matrix1x2::new(0.0, 1.0); | |
let w = Vector2::new(0.5, 0.5); | |
let b = Vector1::new(-0.7); // x * w の結果はVector1になる。プリミティブ型を直接演算はできないので、Vector1に持ち上げておく。 | |
let sum = x * w + b; | |
println!("{} * {} + {} = {}", x, w, b, sum); | |
} |
This file contains hidden or 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
┌ ┐ | |
│ 0.000 1.000 │ | |
└ ┘ | |
* ┌ ┐ | |
│ 0.500 │ | |
│ 0.500 │ | |
└ ┘ | |
+ ┌ ┐ | |
│ -0.700 │ | |
└ ┘ | |
= ┌ ┐ | |
│ -0.200 │ | |
└ ┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment