Skip to content

Soletta Machine Learning

Otávio edited this page Aug 7, 2015 · 17 revisions

Soletta Machine Learning (SML)

SML is an open source machine learning library for development of IoT devices. It provides APIs to handle with client side AI and an easy to use flow-based Soletta module.

Initially supporting neural networks and fuzzy logic learning, using well established open source libraries it could be easily extended to support others.

See Getting Started on SML for a tutorial.

See Running SML in Galileo or Edison for more information about SML support in Galileo and Edison boards.

Introduction to Machine Learning

Machine learning is a subfield of Artificial Inteligence that aims in creating computer software that take actions without being strictly programmed to do them. To achieve this, the software needs to be trained using example data, so predictions can be made and decisions can be taken.

Neural Networks

Neural Networks is a short name for Artificial Neural Networks, statistical learning models inspired by biological neural networks. Neural Network models are composed by interconnected simple units, called neurons, with a small local memory.

Each neuron process only their local inputs and data, and the combination of several neurons can be used to represent complex functions to produce outputs from input data.

Training a neural network is the process of adjust the neuron's local data in order to have the expected outputs to example inputs.

To learn mode about artificial neural networks:

Fuzzy Logic

Fuzzy logic is a form of mathematical logic opposed to boolean logic. Instead of having only two possible values (True or False), a fuzzy variable can have any intermediate value between True and False, from completely True to completely False. This way, we can represent a partially true value.

In a simple example, we have a fruit and we want to have a variable to show if the fruit is ok to be eaten. Instead of having a boolean variable, with Yes/No options we could represent each possible state (called in fuzzy logic, terms) of the fruit.

A fruit can be unripe, ripe or rotten. But the transitions between each state is not discrete. There is a small overlap in each transition, a state where the fruit is ok to be eaten, but not completely ripe. Or it is ripe, but it the beginning of the rotten process.

Fuzzy logic uses the concept of membership value of each term to represent each state. An unripe fruit would be 100% unripe, 0% ripe and 0% rotten. As time goes by, the unripe membership starts to decrease, so we would have something like 20% unripe, 80% ripe and 0% rotten. Then the fruit will move to a completely ripe state, where unripe is 0%, ripe is 100% and rotten is 0%. Then the rotten process would begun in, for example, 0% unripe, 30% ripe and 70% rotten. Finally we would have a 0% unripe, 0% ripe, 100% rotten state.

As shown, fuzzy logic is a good tool to represent transitions between states, so SML Fuzzy Engine uses an algorithm based in Fuzzy logic to divide each input and output variable in overlapped terms, looking for recurring patterns in inputs to predict output values.

To learn mode about fuzzy logic:

Introduction to Soletta Machine Learning

First of all we need to understand the concept of inputs and outputs used in SML.

Inputs are all variables that provides information about the current state of the environment being monitored, such as sensors attached to IoT devices. It may be a light sensor, a device that monitors the Bluetooth activity or even a simple switch. Outputs are devices that are operated by users and that are expected to be controlled.

SML works by learning how the current inputs values affect user changes in outputs. Using this knowledge, SML can read current input values to create a scenario, predict expected outputs values and control an output device. This way, devices will be adapted to users need, without expecting him to set a configuration or even knowing his own behavior.

Neural Network

SML Neural Network engine keep record of input and output values, and use them to train an Artificial Neural Network. After training, SML will use current input values as the input for the trained neural network to predict output values.

As users behavior changes, the neural network is retrained periodically.

Fuzzy Logic

Fuzzy Logic Engine uses a Fuzzy Logic model to represent inputs and outputs. In each iteration, the engine will create fuzzy rules to represent the current state and keep them to predict future states. When inputs are read and they fit any previous record rule, the engine will use fuzzy math to compute the expected outputs values.

To keep SML always updated with users needs, Fuzzy engine assigns higher weights to frequent rules and non recurring rules tend to be forgotten.

Fuzzy Terms

In Fuzzy Logic Engine, fuzzy terms are created using mathematical functions. The membership of a fuzzy value to a term is defined by the function applied to that value. Fuzzy Logic Engine supports 5 different terms:

  • Ramp
  • Triangle
  • Rectangle
  • Cosine
  • Gaussian

More information about each term in the online API

Engines Comparison

Neural Network

Pros:

  • Better when interpolation is needed
  • Low memory consumption
  • Prediction is faster
  • For neural network previously trained and where there is no need for retraining, memory consumption is even lower.
  • Always provide a prediction, even if the state is completely new

Cons:

  • Training takes longer and training time is unpredictable
  • It does not work while not collect enough data
  • Tends to forget old events

Fuzzy Logic

Pros:

  • Better results when using id fields as inputs or outputs
  • Training is faster
  • Start to provide prediction just after first read

Cons:

  • Higher memory consumption
  • Tends to forget non recurring events
  • only it provides prediction when the state is similar to state already previously read. This is only a problem when there is a need for prediction in all iterations.

Code

Code is hosted at GitHub under BSD 3-clauses license.