@ -16,84 +16,40 @@ defmodule P1 do
@res 50
def start ( _type , _args ) do
# zeros(10)
# |> set_graph(Tools.linspace(String.to_integer("-5"), 5, 10))
# |> heatmap(:color24bit)
# zeros(50)
# |> set_points(Dataset.points |> multiply(20) |> add(new(@rows, 2, fn -> 25 end)), Dataset.values)
# |> heatmap(:color24bit)
# IO.puts inspect Dataset.points
# loss_o = if rem(i, 25) == 0 do
# Enum.concat(loss, [Toolex.cost(a, transpose(Dataset.values))])
# else
# loss
# end
# z = [loss_o] |> new
# IO.puts inspect z
# if z[:columns] > 10 do
# zeros(z[:columns])
# |> set_graph(z)
# |> heatmap(:color24bit)
# #:timer.sleep(60)
# end
# IO.puts inspect random(1, 6) |> multiply(2) |> subtract(1)
# IO.puts inspect Toolex.mean(Dataset2.ab)
# IO.puts inspect Dataset2.aa |> subtract(Toolex.mean(Dataset2.bb)) |> multiply(0.5)
# IO.puts inspect Dataset2.ac |> subtract(Toolex.mean(Dataset2.ab)) |> multiply(0.5)
# IO.puts inspect Dataset2.ac - multiply(Toolex.mean(Dataset2.ab), 0.5)
IO . puts " starting "
loop_main ( create_nn ( @topology ) )
IO . puts " Ending "
:timer . sleep ( 1000 )
Task . start ( fn -> :timer . sleep ( 1000 ) ; IO . puts ( " done sleeping " ) end )
end
Enum . reduce ( 0 . . 2500 , create_nn ( @topology ) , fn i , neural_net_acc ->
{ _a , n } = train ( neural_net_acc , Dataset . points , Dataset . values )
def loop_main ( neural_net , n , 2500 ) do
neural_net
end
def loop_main ( neural_net , n , i ) do
loop_main ( n , i )
end
x0 = Tools . linspace ( String . to_float ( " -1.5 " ) , 1.5 , @res )
x1 = Tools . linspace ( String . to_float ( " -1.5 " ) , 1.5 , @res )
# IO.puts inspect x0
# IO.puts inspect x1
# IO.puts inspect a
def loop_main ( neural_net , i \\ 0 ) do
{ a , n } = train ( neural_net , Dataset . points , Dataset . values )
if rem ( i , 25 ) == 0 do
Enum . reduce ( Enum . with_index ( x0 ) , zeros ( @res ) , fn { i2 , i1 } , acc1 ->
Enum . reduce ( Enum . with_index ( x1 ) , acc1 , fn { j2 , j1 } , acc2 ->
set ( acc2 , i1 + 1 , j1 + 1 , elem ( train ( n , new ( [ [ i2 , j2 ] ] ) , Dataset . values , false ) , 0 ) [ 1 ] )
end )
end )
|> set_points ( Dataset . points |> multiply ( 20 ) |> add ( new ( @rows , 2 , fn -> 25 end ) ) , Dataset . values )
|> heatmap ( :color24bit , [ title : " ----------------------Pensando---------------------- " ] )
#|> inspect |> IO.puts
:timer . sleep ( 50 )
paint ( n )
end
n
end )
# a = [[0.49451709],
# [0.48813893],
# [0.47200026],
# [0.46428155],
# [0.4900677 ],
# [0.49409855]] |> new
# b = [[0], [1], [1], [0], [1], [0]] |> new
# #IO.puts inspect Toolex.cost_d(a, b)
# c = (1 - a)
# IO.puts inspect Toolex.sigm_d(a)
loop_main ( neural_net , n , i + 1 )
end
IO . puts " Ending "
:timer . sleep ( 1000 )
Task . start ( fn -> :timer . sleep ( 1000 ) ; IO . puts ( " done sleeping " ) end )
def paint ( nn ) do
x0 = Tools . linspace ( String . to_float ( " -1.5 " ) , 1.5 , @res )
x1 = Tools . linspace ( String . to_float ( " -1.5 " ) , 1.5 , @res )
Enum . reduce ( Enum . with_index ( x0 ) , zeros ( @res ) , fn { i2 , i1 } , acc1 ->
Enum . reduce ( Enum . with_index ( x1 ) , acc1 , fn { j2 , j1 } , acc2 ->
set ( acc2 , i1 + 1 , j1 + 1 , elem ( train ( nn , new ( [ [ i2 , j2 ] ] ) , Dataset . values , false ) , 0 ) [ 1 ] )
end )
end )
|> set_points ( Dataset . points |> multiply ( 20 ) |> add ( new ( @rows , 2 , fn -> 25 end ) ) , Dataset . values )
|> heatmap ( :color24bit , [ title : " ----------------------Solucion---------------------- " ] )
end
def train ( neural_net , x , y , train \\ true ) do
@ -138,15 +94,6 @@ defmodule P1 do
end )
end
def set_graph ( m , points ) do
size = points [ :columns ]
points = ( size + 1 ) - ( sigmoid ( points ) * size ) |> truncate
Enum . reduce ( 1 . . size , m , fn p , acc ->
set ( acc , trunc ( points [ p ] ) , p , 1 )
end )
end
def neural_layer ( n_conn , n_neur ) do
%{
b : random ( 1 , n_neur ) |> multiply ( 2 ) |> subtract ( 1 ) ,
@ -157,12 +104,4 @@ defmodule P1 do
def create_nn ( topology ) do
for n <- 1 . . Enum . count ( topology ) - 1 , do : neural_layer ( trunc ( topology [ n ] ) , trunc ( topology [ n + 1 ] ) )
end
def loop do
:timer . sleep ( 16 ) ;
zeros ( 50 )
|> set_points ( Dataset . points |> multiply ( 20 ) |> add ( new ( @rows , 2 , fn -> 25 end ) ) , Dataset . values )
|> heatmap ( :color24bit )
loop
end
end