Skip to content
Luis Carbonell edited this page Dec 22, 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.activate(Math.random(), function(error, conclusion) {
  console.log(results) // 0.4254387327
  n.learn(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.connect(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)

.connect(object[, callback])

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

.inputs([callback])

  • .inputs(): Returns a list of incoming connections to neuron; Invokes _ callback(error, inputs)_

.outputs([callback])

  • .outputs(): Returns a list of outgoing connections from neuron; Invokes callback(error, outputs)

.activate(inputs[,callback])

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

forward([callback])

  • .forward(): Propagates the last result of .activate() to all outgoing connections; Invokes callback(error, connections)

.learn(feedback[,callback])

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

.backward([callback])

  • .backward(): Propagates the last results of .learn() to all incoming connections; Invokes callback(error, connections)

Appendix

Properties

Key Type Default Description
connections [Connection] [] All neuron connections
actions [Number] [] An array of neuron's past outputs
bias Number Math.random() Check Out:
learning_rate Number 0.3 Check Out:
activation "relu"|"sigmoid"|"tanh"|"step"|"linear"|"leaky-relu"|"softmax"|Function "sigmoid" Check Out:

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.connect() Connects to another neuron, layer, or group
Neuron.prototype.inputs() List of incoming connections
Neuron.prototype.outputs() List of outgoing connections
Neuron.prototype.activate() Activation function of neuron
Neuron.prototype.forward() Forward propagates results of Neuron.prototype.activate()
Neuron.prototype.learn() Updating function of neuron
Neuron.prototype.backward() Backward propagates results of Neuron.prototype.activate()

Class Constants

Key Description
Neuron.activation An object of typical activation/squash functions
Neuron.activation.SIGMOID sigmoid Squash Function
Neuron.activation.ReLU ReLU Squash Function
Neuron.activation.TANH tanh Squash Function
Neuron.activation.IDENTITY identity Squash Function
Neuron.activation.PERCEPTRON perceptron Squash Function
Neuron.update An object of typical activation/squash function derivatives
Neuron.activation.SIGMOID sigmoid Squash Function Partial Derivative
Neuron.activation.ReLU ReLU Squash Function Partial Derivative
Neuron.activation.TANH tanh Squash Function Partial Derivative
Neuron.activation.IDENTITY identity Squash Function Partial Derivative
Neuron.activation.PERCEPTRON perceptron Squash Function Partial Derivative