This namespace contains all the functions that are related to the neural networks.
(require '[clj-synapses.net :as net])
There are four ways to create a neural network:
(def network
(net/->net
[3 4 2]))
(net/->net
[2 3 1]
1000)
(net/json->
"[[{"activationF":"sigmoid","weights":[-0.4,-0.1,-0.8]}]]")
(require '[clj-synapses.fun :as fun])
(net/->net
[2 3 1]
(fn [_] fun/sigmoid)
(fn [_] (rand)))
EXAMPLES
Get the prediction for an input:
(net/predict
network
[0.4 0.05 0.2])
Fit network to a single observation:
(net/fit
network
0.1
[0.4 0.05 0.2]
[0.03 0.8])
Get the JSON representation of the network:
(net/->json
rand-network)
This namespace contains all the functions that are related to the neural networks. ```clojure (require '[clj-synapses.net :as net]) ``` There are four ways to create a neural network: 1. By providing its layer sizes, a random sigmoid neural network is created. ```clojure (def network (net/->net [3 4 2])) ``` 2. By providing its layer sizes and a seed, a non-random sigmoid neural network is created. ```clojure (net/->net [2 3 1] 1000) ``` 3. By providing its JSON representation. ```clojure (net/json-> "[[{"activationF":"sigmoid","weights":[-0.4,-0.1,-0.8]}]]") ``` 4. By providing the size, the activation function and the weights for each layer. ```clojure (require '[clj-synapses.fun :as fun]) (net/->net [2 3 1] (fn [_] fun/sigmoid) (fn [_] (rand))) ``` EXAMPLES Get the prediction for an input: ```clojure (net/predict network [0.4 0.05 0.2]) ``` Fit network to a single observation: ```clojure (net/fit network 0.1 [0.4 0.05 0.2] [0.03 0.8]) ``` Get the JSON representation of the network: ```clojure (net/->json rand-network) ```
(->json network)
Returns the JSON representation of the neural network.
Returns the JSON representation of the neural network.
(->net layer-sizes)
(->net layer-sizes seed)
(->net layer-sizes activation-f weight-init-f)
Returns a neural network by accepting:
(net/->net
[3 4 2])
(net/->net
[2 3 1]
1000)
(net/->net
[2 3 1]
(fn [_] fun/sigmoid)
(fn [_] (rand)))
Returns a neural network by accepting: * its layer sizes ```clojure (net/->net [3 4 2]) ``` * its layer sizes and a seed ```clojure (net/->net [2 3 1] 1000) ``` * the size, the activation function and the weights for each layer ```clojure (net/->net [2 3 1] (fn [_] fun/sigmoid) (fn [_] (rand))) ```
(->svg network)
Returns the SVG representation of the neural network.
The color of each neuron depends on its activation function while the transparency of the synapses depends on their weight.
(net/->svg
custom-network)
Returns the SVG representation of the neural network. The color of each neuron depends on its activation function while the transparency of the synapses depends on their weight. ```clojure (net/->svg custom-network) ```
(fit network learning-rate input-values expected-output)
Returns the neural network with its weights adjusted to the provided observation.
In order for it to be trained, it should fit with multiple observations, usually by reducing over a collection.
learning-rate
is a number that controls how much the weights are adjusted to the observation.
input-values
is the feature values of the observation
and its size should be equal to the size of the input layer.
expected-output
is the expected output of the observation
and its size should be equal to the size of the output layer.
(net/fit
network
0.1
[0.2 0.6]
[0.9])
Returns the neural network with its weights adjusted to the provided observation. In order for it to be trained, it should fit with multiple observations, usually by reducing over a collection. `learning-rate` is a number that controls how much the weights are adjusted to the observation. `input-values` is the feature values of the observation and its size should be equal to the size of the input layer. `expected-output` is the expected output of the observation and its size should be equal to the size of the output layer. ```clojure (net/fit network 0.1 [0.2 0.6] [0.9]) ```
(json-> json)
Parses and returns a neural network.
(net/json->
"[[{"activationF":"sigmoid","weights":[-0.4,-0.1,-0.8]}]]")
Parses and returns a neural network. ```clojure (net/json-> "[[{"activationF":"sigmoid","weights":[-0.4,-0.1,-0.8]}]]") ```
(par-fit network learning-rate input-values expected-output)
Returns a neural network that has the same shape of the original, but it has learned from the provided observation.
The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
Returns a neural network that has the same shape of the original, but it has learned from the provided observation. The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
(par-predict network input-values)
Returns a prediction made for the provided input.
The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
Returns a prediction made for the provided input. The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
(predict network input-values)
Returns a prediction made for the provided input.
The size of the returned vector should be equal to the size of the output layer.
input-values
is the values of the features.
The size of the accepted vector should be equal to the size of the input layer.
(net/predict
network
[0.2 0.6])
Returns a prediction made for the provided input. The size of the returned vector should be equal to the size of the output layer. `input-values` is the values of the features. The size of the accepted vector should be equal to the size of the input layer. ```clojure (net/predict network [0.2 0.6]) ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close