-
Notifications
You must be signed in to change notification settings - Fork 108
Soletta Machine Learning
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 Soletta Machine Learning: Light Sensor Tutorial for a complete tutorial.
See Running SML in Galileo or Edison for more information about SML support in Galileo and Edison boards.
Its code is hosted at solettaproject/soletta-machine-learning under BSD 3-clauses license.
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 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:
- http://www.faqs.org/faqs/ai-faq/neural-nets/
- https://en.wikipedia.org/wiki/Artificial_neural_network
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:
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.
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 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.
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
A ramp term uses a mathematical function defined by its start and end points. Start parameters is the coordinate in X axis where the ramp is in its minimum value (zero). End parameter is the coordinate in Y axis where the ramp is in its maximum value (1.0). If start < end we will have a positive ramp. If end < start we will have a negative ramp.
-
Triangle
A triangle term uses a mathematical function defined by 3 vertex (a, b c). For X coordinates between vertex a and b, function value is obtained by the linear function connecting points (vertex_a; 0) to (vertex_b; 1). In vertex_b, function value will 1.0 and from vertex_b to vertex_c, function value is obtained by the linear function connecting opints (vertex_b; 1.0) to (vertex_c; 0). For all other X values, the function value will be zero.
-
Rectangle
A rectangle term uses a mathematical function defined by its start and end points. For any X value from start to end, the function value will be 1.0. For all other X values, the function value will be zero.
- Cosine
Cosine term value is obtained by the function value from a cosine function centered in X coordinate center and with width defined by width parameter. The maximum value (1.0) of the cosine function is in X coordinate center.
- Gaussian
Gaussian term value is obtained by the function value from a gaussian function defined by the parameters mean, standard_deviation. The maximum value in Y axis of the gaussian function is 1.0.
More information about each term in the online API
- 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
- Training takes longer and training time is unpredictable
- It does not work while not collect enough data
- Tends to forget old events
- Better results when using id fields as inputs or outputs
- Training is faster
- Start to provide prediction just after first read
- 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.