wslのtensorflowでkerasのbackend その11

# 概要
wslのtensorflowでkerasのbackendを試す。
練習問題、やってみた。

# 練習問題
kerasのbackendでxorを学習したウェイトとバイアスを量子化して、elixirで再現せよ。

# サンプルコード

```

defmodule Nn do
	def mul(a, b) do
	    Enum.map(a, fn i -> 
    	    i * b
        end)
	end
	def add(a, b) do
	    for x <- 0..7 do
		    Enum.at(a, x) + Enum.at(b, x)
	    end
	end
	def sum(a, b) do
	    for x <- 0..7 do
		    Enum.at(a, x) * Enum.at(b, x)
	    end
	    |> Enum.sum
	end
	def tanh(v) do
		Enum.map(v, fn i -> 
		    y = [-10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -9, -9, -9, -9, -8, -8, -7, -7, -6, -5, -4, -3, -2, -1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, ]
		    Enum.at(y, i + 126)
		end)
	end
	def sigmoid(v) do
	    Enum.map(v, fn i -> 
	        if i < -126 do
		        0
	        else
    	        if i > 126 do
    		        10
                else    	       
    	       	    y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
    	    	    Enum.at(y, i + 126)
    		    end
    		end
		end)
	end
end


w10 = [-35, 3, -15, 22, 23, 27, -19, -12]
w11 = [21, 2, 20, -14, -15, 19, 32, 19]
b1 = [-7, 3, 4, 3, 3, -4, 4, 2]
w2 = [14, 7, -24, -18, -25, 39, -19, -14]
b2 = 9
for i <- 0..1, j <- 0..1 do
    h = Nn.mul(w10, i)
    #|> IO.inspect
    l = Nn.mul(w11, j)
    #|> IO.inspect
    h = Nn.add(h, l)
    #|> IO.inspect
    h = Nn.add(h, b1)
    #|> IO.inspect
    h = Nn.tanh(h)
    #|> IO.inspect
    y = Nn.sum(h, w2)
    #|> IO.inspect
    y = y + b2
    #|> IO.inspect
    y = Nn.sigmoid([y])
    #|> IO.inspect
    y = Enum.at(y, 0)
    IO.puts "#{i}, #{j} = #{y}"
end



```

# 実行結果

```
0, 0 = 0
0, 1 = 10
1, 0 = 10
1, 1 = 0


```

# 成果物

https://paiza.io/projects/Au-xxlZsqE3wXhPzoQ2Ggw


以上。