Skip to content

Commit

Permalink
Use Elixir 1.3.4
Browse files Browse the repository at this point in the history
- use :rand module instead of deprecated :random
- move test modules on top of test files
- fix compile warnings
- TODO: remove all HashDicts
  • Loading branch information
zampino committed Jan 7, 2017
1 parent 85d2a21 commit 8379fa8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: elixir
otp_release:
- 18.2
- 19.0
elixir:
- 1.2.2
- 1.3.4
2 changes: 1 addition & 1 deletion lib/exnn/dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule EXNN.DSL do
nodes = Module.get_attribute(env.module, :nodes) |> Macro.escape
pattern = Module.get_attribute(env.module, :initial_pattern) |> Macro.escape
fitness = Module.get_attribute(env.module, :fitness)
mode = Module.get_attribute(env.module, :mode)
# mode = Module.get_attribute(env.module, :mode)

quote do
def initial_pattern, do: unquote(pattern)
Expand Down
5 changes: 1 addition & 4 deletions lib/exnn/pattern.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ defmodule EXNN.Pattern do
end

def label(type, int, prefix) do
front = type
if prefix do
front = "#{front}_#{prefix}"
end
front = if prefix, do: "#{type}_#{prefix}", else: type
:"#{front}_#{int}"
end
end
3 changes: 2 additions & 1 deletion lib/exnn/strategies/trainer_strategy_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ defmodule EXNN.Strategies.TrainerStrategyBuilder do
}
import EXNN.Strategies.TrainerStrategyBuilder,
only: [impl_for: 2]
IO.puts "what the hell is #{inspect {__MODULE__, unquote(mode)}}"

# IO.puts "what the hell is #{inspect {__MODULE__, unquote(mode)}}"

impl_for unquote(mode), unquote(options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/exnn/utils/math.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule EXNN.Utils.Math do

def sin(x), do: :math.sin(x)

def sigmoid(x, k)
def sigmoid(_x, _k), do: nil # TODO

def labelled_scalar_product({id, weight}, {memo, acc}) do
{val, acc} = Keyword.pop_first acc, id
Expand Down
6 changes: 3 additions & 3 deletions lib/exnn/utils/random.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ defmodule EXNN.Utils.Random do
import EXNN.Utils.Math, only: [pi: 0]

def seed do
:random.seed :os.timestamp
:rand.seed :exs1024, :os.timestamp
end

def uniform do
:random.uniform
:rand.uniform
end

def coefficient(value) do
value * pi * (:random.uniform - 0.5)
value * pi * (:rand.uniform - 0.5)
end

def take(list) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule EXNN.Mixfile do
[
app: :exnn,
version: "0.1.0",
elixir: "~> 1.2",
elixir: "~> 1.3",
deps: deps,
name: "EXNN",
description: ~s(Elixir Evolutive Neural Networks "<> <<224::utf8>> <>" la G.Sher),
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
%{"earmark": {:hex, :earmark, "0.2.1"},
"ex_doc": {:hex, :ex_doc, "0.11.4"}}
%{"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.4", "a064bdb720594c3745b94709b17ffb834fd858b4e0c1f48f37c0d92700759e02", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]}}
49 changes: 24 additions & 25 deletions test/examples/xor.exs
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
defmodule XORTest do
require Logger
use ExUnit.Case, async: true

setup do
{:ok, _pid} = XORApp.start(:normal, [])
IO.puts "starting app"

on_exit fn ->
XORApp.stop(:normal)
IO.puts "terminating app: XOR"
end

{:ok, []}
end

test "X or runs!" do
:ok = EXNN.Trainer.start reporter: self

assert_receive {:report, state}, 5_000
Logger.info "\nTrained stably to #{inspect state.fitness} in #{state.fit_after} ms\n"
Logger.info inspect state
end
end

defmodule XORApp do
use EXNN.Application

Expand Down Expand Up @@ -117,5 +92,29 @@ defmodule XORApp.Fitness do
trigger = List.delete state.trigger, x
%{state | trigger: trigger, acc: acc}
end
end

defmodule XORTest do
require Logger
use ExUnit.Case, async: true

setup do
{:ok, _pid} = XORApp.start(:normal, [])
IO.puts "starting app"

on_exit fn ->
XORApp.stop(:normal)
IO.puts "terminating app: XOR"
end

{:ok, []}
end

test "X or runs!" do
:ok = EXNN.Trainer.start reporter: self

assert_receive {:report, state}, 5_000
Logger.info "\nTrained stably to #{inspect state.fitness} in #{state.fit_after} ms\n"
Logger.info inspect state
end
end
28 changes: 14 additions & 14 deletions test/exnn/nodes_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
defmodule EXNN.NodesTest do
use ExUnit.Case, async: true

defmodule TestSensor do
use GenServer

def start_link(genome) do
send :test_pid, genome.message
GenServer.start_link(__MODULE__, genome, [name: genome.id])
end

def handle_cast :foo, state do
IO.puts "foo!!!"
{:noreply, state}
end
end

setup do #_all do
{status, node_sup} = EXNN.NodeSupervisor.start_link
IO.puts "/////////////////////////////// exnn test node superv tries to start: #{status}"
Expand Down Expand Up @@ -58,17 +72,3 @@ restarted", %{genome: genome} do
end

end

defmodule TestSensor do
use GenServer

def start_link(genome) do
send :test_pid, genome.message
GenServer.start_link(__MODULE__, genome, [name: genome.id])
end

def handle_cast :foo, state do
IO.puts "foo!!!"
{:noreply, state}
end
end

0 comments on commit 8379fa8

Please sign in to comment.