Skip to content
Luis Carbonell edited this page Dec 27, 2018 · 6 revisions

Neurons

Useful Links

Usage

Getting Started

Creating a Neuron

let Neuron = require('@liquid-carrot/carrot').Neuron

let n = new Neuron()

Activating a Neuron

let Neuron = require('@liquid-carrot/carrot').Neuron

let n = new Neuron()

n.activate(Math.random(), function(error, results) {
  console.log(results) // 0.4254387327
})

Teaching a Neuron

let Neuron = require('@liquid-carrot/carrot').Neuron

let n = new Neuron()

n.propagate(0, function(error, fault) {
  console.log(results) // 0.124511366
})

Connecting two Neurons

let Neuron = require('@liquid-carrot/carrot').Neuron

let n0 = new Neuron()
let n1 = new Neuron()

n0.project(n1, function(error, connection) {
  console.log(connection)
})

Reference

new Neuron()

  • new Neuron(): Creates a new neuron.
  • new Neuron({ inputs: [n0, n1], outputs: [n2] }): Creates a new neuron with n0 and n1 as incoming connections, and n2 as an outgoing connection.
  • new Neuron(n0): Creates a new neuron with the same connections as n0

.is.input([callback])

  • neuron.is.input(): Returns true if neuron has no incoming connections; Invokes callback(error, isInput)

.is.output([callback])

  • neuron.is.output(): Returns true if neuron has no outgoing connections; Invokes callback(error, isOutput)

.project(object[, callback])

  • neuron.project(other_neuron): Connects neuron to other_neuron; Invokes callback(error, connections)
  • neuron.project(layer): Connects neuron to every neuron in layer; Invokes callback(error, connections)
  • neuron.project(group): Connects neuron to every neuron in group; Invokes callback(error, connections)

.activate(inputs[,callback])

  • .activate([0, 1, 0, 1]): Activates neuron with the given inputs; inputs.length must equal connections.length; Invokes callback(error, results)

.propagate(feedback[,callback])

  • .propagate([1, 0, 1, 0]): Calculates incoming connection errors; Invokes callback(error, results)

Appendix

Instance Functions

Key Description
Neuron.prototype.is.input() Tests whether neuron has no input connections
Neuron.prototype.is.output() Tests whether neuron has no output connections
Neuron.prototype.project() Connects to another neuron, layer, or group
Neuron.prototype.activate() Activates neuron and forward propagates results
Neuron.prototype.learn() Calculates error, updates weights, and backward propagates error

Class Constants

Key Description
Neuron.activations An object of typical activation/squash functions
Neuron.activations.SIGMOID sigmoid Squash Function
Neuron.activations.RELU ReLU Squash Function
Neuron.activations.TANH tanh Squash Function
Neuron.activations.LINEAR identity Squash Function

Properties

Key Type Default Description
connections Object [] All neuron connections
connections.incoming [Connection] [] All incoming neuron connections
connections.outgoing [Connection] [] All outgoing neuron connections
bias Number Math.random() Check Out:
rate Number 0.3 Check Out:
activation "relu"|"sigmoid"|"tanh"|"linear"|Function "sigmoid" Check Out: