chore(README): unnecessary space
This commit is contained in:
parent
ace9b7f5f9
commit
44f2ae372a
56
README.md
56
README.md
@ -4,42 +4,42 @@ A simple Machine Learning library.
|
|||||||
|
|
||||||
## Simple neural network
|
## Simple neural network
|
||||||
```haskell
|
```haskell
|
||||||
import Numeric.Sibe
|
import Numeric.Sibe
|
||||||
|
|
||||||
let a = (sigmoid, sigmoid') -- activation function
|
let a = (sigmoid, sigmoid') -- activation function
|
||||||
-- random network, seed 0, values between -1 and 1,
|
-- random network, seed 0, values between -1 and 1,
|
||||||
-- two inputs, two nodes in hidden layer and a single output
|
-- two inputs, two nodes in hidden layer and a single output
|
||||||
rnetwork = randomNetwork 0 (-1, 1) 2 [(2, a)] (1, a)
|
rnetwork = randomNetwork 0 (-1, 1) 2 [(2, a)] (1, a)
|
||||||
|
|
||||||
-- inputs and labels
|
-- inputs and labels
|
||||||
inputs = [vector [0, 1], vector [1, 0], vector [1, 1], vector [0, 0]]
|
inputs = [vector [0, 1], vector [1, 0], vector [1, 1], vector [0, 0]]
|
||||||
labels = [vector [1], vector [1], vector [0], vector [0]]
|
labels = [vector [1], vector [1], vector [0], vector [0]]
|
||||||
|
|
||||||
-- define the session which includes parameters
|
-- define the session which includes parameters
|
||||||
session = def { network = rnetwork
|
session = def { network = rnetwork
|
||||||
, learningRate = 0.5
|
, learningRate = 0.5
|
||||||
, epochs = 1000
|
, epochs = 1000
|
||||||
, training = zip inputs labels
|
, training = zip inputs labels
|
||||||
, test = zip inputs labels
|
, test = zip inputs labels
|
||||||
, drawChart = True
|
, drawChart = True
|
||||||
, chartName = "nn.png" -- draws chart of loss over time
|
, chartName = "nn.png" -- draws chart of loss over time
|
||||||
} :: Session
|
} :: Session
|
||||||
|
|
||||||
initialCost = crossEntropy session
|
initialCost = crossEntropy session
|
||||||
|
|
||||||
-- run gradient descent
|
-- run gradient descent
|
||||||
-- you can also use `sgd`, see the notmnist example
|
-- you can also use `sgd`, see the notmnist example
|
||||||
newsession <- run gd session
|
newsession <- run gd session
|
||||||
|
|
||||||
let results = map (`forward` newsession) inputs
|
let results = map (`forward` newsession) inputs
|
||||||
rounded = map (map round . toList) results
|
rounded = map (map round . toList) results
|
||||||
|
|
||||||
cost = crossEntropy newsession
|
cost = crossEntropy newsession
|
||||||
|
|
||||||
putStrLn $ "- initial cost (cross-entropy): " ++ show initialCost
|
putStrLn $ "- initial cost (cross-entropy): " ++ show initialCost
|
||||||
putStrLn $ "- actual result: " ++ show results
|
putStrLn $ "- actual result: " ++ show results
|
||||||
putStrLn $ "- rounded result: " ++ show rounded
|
putStrLn $ "- rounded result: " ++ show rounded
|
||||||
putStrLn $ "- cost (cross-entropy): " ++ show cost
|
putStrLn $ "- cost (cross-entropy): " ++ show cost
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user