README.md

# ExNeuralNetwork

A very simple implementation of a neural network in elixir with a sigmoid activation function and optionally multiple hidden layers. You can use this project for classification.

## Installation

Since this module uses [Matrex](https://github.com/versilov/matrex#installation) you have to consider its installation instruction as well.

```elixir
def deps do
  [
   {:ex_neural_network, "~> 0.1.0"},
  ]
end
```

## Usage

You can use this project in your module as seen below. In addition you can see an example implementation [here](#example).

```elixir
defmodule YourModule do
  use ExNeuralNetwork

  def init() do
    # creates network with
    # 3 input nodes,
    # 1 hidden_layer with 10 nodes,
    # 2 output nodes
    # and a learning rate # of 10 %
    start_link(3, [10], 2, 0.1)
  end

end

iex> YourModule.train([0.5, 0.1, 1], [0.99, 0.01])
:ok

iex> YourModule.query([0.5, 0.1, 1])
[0.6072454452514648, 0.4708364009857178]

iex> YourModule.get_network()
[
  [
    [-0.4642568826675415, 0.32747191190719604, 0.47093304991722107],
    [0.2627932131290436, 0.03314032033085823, 0.2971944808959961],
    [0.3352765142917633, -0.33794283866882324, -0.2254313975572586],
    [-0.006374203599989414, 0.25249508023262024, -0.43000200390815735],
    [-0.12729819118976593, 0.3885648548603058, 0.24821318686008453],
    [-0.00284160696901381, -0.4020627737045288, 0.4009591042995453],
    [-0.02663102000951767, -0.16462339460849762, -0.476892352104187],
    [0.24168038368225098, 0.007184899412095547, 0.21450108289718628],
    [-0.21997787058353424, -0.454841673374176, -0.4043811857700348],
    [-0.4514453411102295, -0.4835187494754791, -0.2895463705062866]
  ],
  [
    [0.36193764209747314, -0.4462336599826813, -0.4621596336364746,
     0.32381609082221985, 0.3180595636367798, 0.0723995789885521,
     0.12477762997150421, 0.15863820910453796, 0.23335273563861847,
     0.4093025326728821],
    [-0.3611955940723419, -0.024936040863394737, 0.4674941897392273,
     0.011199625208973885, -0.1361985206604004, 0.20991763472557068,
     -0.4904402792453766, -0.038411326706409454, 0.11535274982452393,
     -0.02014654129743576]
  ]
]

iex> YourModule.set_network(network)
:ok

```

## Example

### (MNIST handwritten digits)

The MNIST database of handwritten digits has a training set of 60,000 examples, and a test set of 10,000 examples. This database will commonly used to test implementations of neural networks.

```elixir
iex> ExNeuralNetwork.Examples.Mnist.init
{:ok, #PID<0.215.0>}

iex> for _ <- 1..5, do: ExNeuralNetwork.Examples.Mnist.train_with_file("./mnist_train.csv")
# print -> Training time in seconds: 59.283
# print -> Training time in seconds: 60.093
# print -> Training time in seconds: 59.84
# print -> Training time in seconds: 61.861
# print -> Training time in seconds: 58.918
[:ok, :ok, :ok, :ok, :ok]

iex> ExNeuralNetwork.Examples.Mnist.score_with_file("./mnist_test.csv")
# print -> Error rate in percent: 2.629999999999999 - Query time in seconds: 5.335
:ok
```