Liking cljdoc? Tell your friends :D

clj-synapses.codec

A codec can encode and decode every data point.

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0. Minmax normalization scales continuous attributes into values between 0.0 and 1.0.

(require '[clj-synapses.codec :as codec])

There are two ways to create a codec:

  1. By providing a list of pairs that define the name and the type of each attribute:
(def preprocessor
  (codec/->codec
    [["petal_length" false]
     ["species" true]]
    [{"petal_length" "1.5"
      "species"      "setosa"}
     {"petal_length" "3.8"
      "species"      "versicolor"}]))
  1. By providing its JSON representation.
(def preprocessor
  (codec/json->
    "[{"Case" : "SerializableContinuous",
        "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
       {"Case" : "SerializableDiscrete",
        "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]"))

EXAMPLES

Encode a data point:

(codec/encode
  preprocessor
  {"petal_length" "1.5"
   "species" "setosa"})
;;=> [0.0, 1.0, 0.0]

Decode a data point:

(codec/decode
  preprocessor
  [0.0, 1.0, 0.0])
;;=> {"petal_length" "1.5", "species" "setosa"}

Get the JSON representation of the codec:

(codec/->json
  preprocessor)
A codec can encode and decode every data point.

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0.
Minmax normalization scales continuous attributes into values between 0.0 and 1.0.

```clojure
(require '[clj-synapses.codec :as codec])
```

There are two ways to create a codec:

1. By providing a list of pairs that define the name and the type of each attribute:

```clojure
(def preprocessor
  (codec/->codec
    [["petal_length" false]
     ["species" true]]
    [{"petal_length" "1.5"
      "species"      "setosa"}
     {"petal_length" "3.8"
      "species"      "versicolor"}]))
```

2. By providing its JSON representation.

```clojure
(def preprocessor
  (codec/json->
    "[{"Case" : "SerializableContinuous",
        "Fields" : [{"key" : "petal_length","min" : 1.5,"max" : 3.8}]},
       {"Case" : "SerializableDiscrete",
        "Fields" : [{"key" : "species","values" : ["setosa","versicolor"]}]}]"))
```

EXAMPLES

Encode a data point:

```clojure
(codec/encode
  preprocessor
  {"petal_length" "1.5"
   "species" "setosa"})
;;=> [0.0, 1.0, 0.0]
```

Decode a data point:

```clojure
(codec/decode
  preprocessor
  [0.0, 1.0, 0.0])
;;=> {"petal_length" "1.5", "species" "setosa"}
```

Get the JSON representation of the codec:

```clojure
(codec/->json
  preprocessor)
```
raw docstring

clj-synapses.fun

The activation functions a neuron can have.

They can be used in the arguments of neural network's creation.

(require '[clj-synapses.net :as net]
         '[clj-synapses.fun :as fun])
(net/->net
  [2 3 1]
  (fn [_] fun/sigmoid)
  (fn [_] (rand)))
(net/->net
  [4 6 8 5 3]
  (fn [_] fun/identity)
  (fn [_] (rand)))
(net/->net
  [4 8 3]
  (fn [_] fun/leaky-re-lu)
  (fn [_] (rand)))
(net/->net
  [2 1]
  (fn [_] fun/tanh)
  (fn [_] (rand)))
The activation functions a neuron can have.

They can be used in the arguments of neural network's creation.

```clojure
(require '[clj-synapses.net :as net]
         '[clj-synapses.fun :as fun])
```

```clojure
(net/->net
  [2 3 1]
  (fn [_] fun/sigmoid)
  (fn [_] (rand)))
```

```clojure
(net/->net
  [4 6 8 5 3]
  (fn [_] fun/identity)
  (fn [_] (rand)))
```

```clojure
(net/->net
  [4 8 3]
  (fn [_] fun/leaky-re-lu)
  (fn [_] (rand)))
```

```clojure
(net/->net
  [2 1]
  (fn [_] fun/tanh)
  (fn [_] (rand)))
```
raw docstring

clj-synapses.net

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:

  1. By providing its layer sizes, a random sigmoid neural network is created.
(def network
  (net/->net
    [3 4 2]))
  1. By providing its layer sizes and a seed, a non-random sigmoid neural network is created.
(net/->net
  [2 3 1]
  1000)
  1. By providing its JSON representation.
(net/json->
  "[[{"activationF":"sigmoid","weights":[-0.4,-0.1,-0.8]}]]")
  1. By providing the size, the activation function and the weights for each layer.
(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)
```
raw docstring

clj-synapses.stats

Measure the difference between the values predicted by a neural network and the observed values.

(require '[clj-synapses.stats :as stats])

Calculate the root mean square error:

(stats/rmse
  [[[0.0, 0.0, 1.0] [0.0, 0.0, 1.0]]
   [[0.0, 0.0, 1.0] [0.0, 1.0, 1.0]]])
;;=> 0.7071067811865476

Calculate the score of the classification accuracy:

(stats/score
  [[[0.0, 0.0, 1.0], [0.0, 0.1, 0.9]]
   [[0.0, 1.0, 0.0], [0.8, 0.2, 0.0]]
   [[1.0, 0.0, 0.0], [0.7, 0.1, 0.2]]
   [[1.0, 0.0, 0.0], [0.3, 0.3, 0.4]]
   [[0.0, 0.0, 1.0], [0.2, 0.2, 0.6]]])
;;=> 0.6
Measure the difference between the values predicted by a neural network and the observed values.

```clojure
(require '[clj-synapses.stats :as stats])
```

Calculate the root mean square error:

```clojure
(stats/rmse
  [[[0.0, 0.0, 1.0] [0.0, 0.0, 1.0]]
   [[0.0, 0.0, 1.0] [0.0, 1.0, 1.0]]])
;;=> 0.7071067811865476
```

Calculate the score of the classification accuracy:

```clojure
(stats/score
  [[[0.0, 0.0, 1.0], [0.0, 0.1, 0.9]]
   [[0.0, 1.0, 0.0], [0.8, 0.2, 0.0]]
   [[1.0, 0.0, 0.0], [0.7, 0.1, 0.2]]
   [[1.0, 0.0, 0.0], [0.3, 0.3, 0.4]]
   [[0.0, 0.0, 1.0], [0.2, 0.2, 0.6]]])
;;=> 0.6
```
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close