LoginSignup
2
0

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
ニューラルネットワークで、xor推定したけど、浮動小数点使わないで、int8でやる。
構想編

方針

  • 量子化を用いて、変数を浮動小数点から、-127から127のint8に変更する。
  • 活性化関数、tanhとsigmoidをint8に変更する。

量子化は、以下の式でやる。
weight * x + bias
具体的には、以下を選択した。
10 * x + 0

tanh

a = :math.exp(i/10)
b = :math.exp(-1 * i/10)
floor((a - b) / (a + b) * 10)

sigmoid

floor((1 / (1 + :math.exp(-1 * i/10))) * 10)

サンプルコード

w10 = [-3.4681022, 0.379121, -1.4711456, 2.2247136, 2.3135107, 2.7624693, -1.83576, -1.1545312]
w11 = [2.1978209, 0.2895245, 2.0881913, -1.3450832, -1.4154571, 1.9255028, 3.2867477, 1.956522]
b1 = [-0.6591252, 0.3864409, 0.4982838, 0.3707547, 0.3982254, -0.3612466, 0.4284867, 0.2701645]
w2 = [1.4324994, 0.7911373, -2.3011343, -1.7614117, -2.4442003, 3.9701838, -1.837263, -1.3641325]
b2 = 0.9285715

Enum.map(w10, fn x ->
    floor(10 * x)
end)
|> IO.inspect
Enum.map(w11, fn x ->
    floor(10 * x)
end)
|> IO.inspect
Enum.map(b1, fn x ->
    floor(10 * x)
end)
|> IO.inspect
Enum.map(w2, fn x ->
    floor(10 * x)
end)
|> IO.inspect
floor(10 * b2)
|> IO.inspect





実行結果

[-35, 3, -15, 22, 23, 27, -19, -12]
[21, 2, 20, -14, -15, 19, 32, 19]
[-7, 3, 4, 3, 3, -4, 4, 2]
[14, 7, -24, -18, -25, 39, -19, -14]
9

成果物

以上。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0