Skip to content
Nuno Aguiar edited this page Dec 29, 2017 · 2 revisions

ow.ai.network

ow.ai.network(aMap) : ow.ai.network

Creates a neural network given the parameters in aMap. aMap should contain a "type" parameter to indicate the type of network (perceptron, lstm, liquid or hopfield). Then aMap should contain a "args" parameter to provide each network inialization parameters. Please see "help ow.ai.network.[type of network]" for more details about each one.


ow.ai.network.fromJson

ow.ai.network.fromJson(aMap)

Tries to rebuild the network from aMap returned previously by a toJson function.


ow.ai.network.get

ow.ai.network.get(inputArray) : Array

Given an inputArray of decimal values, normalize between 0 and 1, will activate the current network and  return an output array of decimal values between 0 and 1.


ow.ai.network.hopfield

ow.ai.network.hopfield(args) : ow.ai.network

Hopfield serves as a content-addressable memory remembering patterns and when feed with new patterns the network returns the most similar one from the patterns it was trained to remember. You need to provide then number of input patterns args = [ 10 ].


ow.ai.network.liquid

ow.ai.network.liquid(args) : ow.ai.network

Liquid state machines are neural networks where neurons are randomly connected to each other. The recurrent nature of the connections turns the time varying input into a spatio-temporal pattern of activations in the network nodes. You need to provide args = [number of inputs, size of pool of neurons, number of outputs, number of random connections, number of random gates] (e.g. 2, 20, 1, 30, 10).


ow.ai.network.lstm

ow.ai.network.lstm(args) : ow.ai.network

LSTM (Long short-term memory) are well-suited to learn from experience to classify, process and predict time series when there are very long time lags of unknown size between important events. There is a minimum of 3 layers (input, memory block (input, memory cell, forget gate, output gate), output). args = [2, 6, 1] means 2 input, 6 memory blocks, 1 output; args = [2, 4, 4, 4, 1] means 2 input neurons, 3 memory blocks and 1 output.


ow.ai.network.perceptron

ow.ai.network.perceptron(args) : ow.ai.network

Perceptron or feed-forward neural networks. There is a minimum of 3 layers (input, hidden and output) and a any nmumber of hidden layers. args = [2, 3, 1] means 2 input neurons, 3 hidden neurons and 1 output neuron; args = [2, 10, 10, 10, 10, 1] means 2 input neurons, 4 layers of 10 neurons and 1 output neuron.


ow.ai.network.readFile

ow.ai.network.readFile(aFile)

Rebuilds a network from a map stored in aFile previously with ow.ai.network.writeFile.


ow.ai.network.toJson

ow.ai.network.toJson() : Map

Returns a map representation of the current network to be later rebuilt with the fromJson function.


ow.ai.network.train

ow.ai.network.train(trainingData, trainArgs)

Trains the current network with the trainingData provided. trainingData should be an array of maps. Each  map entry should have a input and output keys. Each input and output entries should be an array for the  entry values and output values normalized to a decimal number between 0 and 1. Example:
[{input: [0,0], output: [0]}, {input: [0,1], output: [1]}, {input: [1,0], output: [1]}, {input: [1,1], output :[0]}].


ow.ai.network.writeFile

ow.ai.network.writeFile(aFile)

Writes a compressed file with the map representation of the current network.


ow.ai.normalize.intArray

ow.ai.normalize.intArray(anArray) : Array

Returns anArray where all numbers have been rounded to an integer value.


ow.ai.normalize.scaleArray

ow.ai.normalize.scaleArray(anArray, aMax, aMin) : Array

Given anArray of numbers tries to normalize returning an array of values between 0 and 1. If aMax or aMin are not provided they will be infered from the provided anArray.


ow.ai.normalize.withSchema

ow.ai.normalize.withSchema(aSimpleMapOfData, aMapSchema) : Array

Tries to normalize and return aSimpleMapOfData normalized according with aMapSchema provided. Each element of aMapSchema should be a map describing how to normalize aSimpleMapOfData. Example:

var ar = [
  {name:'workout', duration:'120', enjoy: true, time:1455063275, tags:['gym', 'weights'], crucial: false },
  {name:'lunch', duration:'45', enjoy: false, time:1455063275, tags:['salad', 'wine'], crucial: true },
  {name:'sleep', duration:'420', enjoy: true, time:1455063275, tags:['bed', 'romance'], crucial: true}
];

var sar = {
  name    : { col: 0, oneOf: [ 'workout', 'lunch', 'sleep' ] },
  duration: { col: 1, min: 0, max: 1000 },
  enjoy   : { col: 2 },
  tags    : { col: 3, anyOf: [ 'gym', 'weights', 'salad', 'wine', 'bed', 'romance' ] },
  crucial : { col: 4, scaleOf: [
    { val: true,  weight: 0.85 },
    { val: false, weight: 0.15 }
  ]},
};

$from(ar).sort("time").select((r) => { return normalize(r, sar); });

Clone this wiki locally