Soletta machine learning
Machine learning for IoT devices
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
sml.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
165 #define SML_INTERNAL_ERROR 3
167 #define SML_VARIABLE_NAME_MAX_LEN (127)
176 struct sml_object;
177 
185 
192 struct sml_variables_list;
193 
203 typedef bool (*sml_read_state_cb) (struct sml_object *sml, void *data);
204 
212 typedef void (*sml_change_cb)(struct sml_object *sml, struct sml_variables_list *changed, void *data);
213 
214 
229 bool sml_load_fll_file(struct sml_object *sml, const char *filename);
230 
236 void sml_free(struct sml_object *sml);
237 
254 bool sml_set_read_state_callback(struct sml_object *sml, sml_read_state_cb read_state_cb, void *data);
255 
270 bool sml_set_output_state_changed_callback(struct sml_object *sml, sml_change_cb output_state_changed_cb, void *data);
271 
272 
286 bool sml_set_learn_disabled(struct sml_object *sml, bool disable);
287 
301 int sml_process(struct sml_object *sml);
302 
334 bool sml_predict(struct sml_object *sml);
335 
351 bool sml_set_stabilization_hits(struct sml_object *sml, uint16_t hits);
352 
363 bool sml_erase_knowledge(struct sml_object *sml);
364 
374 bool sml_save(struct sml_object *sml, const char *path);
375 
385 bool sml_load(struct sml_object *sml, const char *path);
386 
393 void sml_print_debug(struct sml_object *sml, bool full);
394 
413 bool sml_set_debug_log_file(struct sml_object *sml, const char *str);
414 
431 bool sml_load_debug_log_file(struct sml_object *sml, const char *str);
432 
442 bool sml_set_max_memory_for_observations(struct sml_object *sml, unsigned int max_size);
443 
462 
471 
483 struct sml_variable *sml_new_input(struct sml_object *sml, const char *name);
484 
497 struct sml_variable *sml_new_output(struct sml_object *sml, const char *name);
498 
507 struct sml_variable *sml_get_input(struct sml_object *sml, const char *name);
508 
517 struct sml_variable *sml_get_output(struct sml_object *sml, const char *name);
518 
528 bool sml_variable_set_value(struct sml_object *sml, struct sml_variable *sml_variable, float value);
529 
538 float sml_variable_get_value(struct sml_object *sml, struct sml_variable *sml_variable);
539 
549 int sml_variable_get_name(struct sml_object *sml, struct sml_variable *sml_variable, char *var_name, size_t var_name_size);
550 
565 int sml_variable_set_enabled(struct sml_object *sml, struct sml_variable *variable, bool enabled);
566 
575 bool sml_variable_is_enabled(struct sml_object *sml, struct sml_variable *variable);
576 
589 bool sml_remove_variable(struct sml_object *sml, struct sml_variable *variable);
590 
598 uint16_t sml_variables_list_get_length(struct sml_object *sml, struct sml_variables_list *list);
599 
609 struct sml_variable *sml_variables_list_index(struct sml_object *sml, struct sml_variables_list *list, uint16_t index);
610 
620 bool sml_variables_list_contains(struct sml_object *sml, struct sml_variables_list *list, struct sml_variable *var);
621 
637 bool sml_variable_set_range(struct sml_object *sml, struct sml_variable *sml_variable, float min, float max);
638 
649 bool sml_variable_get_range(struct sml_object *sml, struct sml_variable *sml_variable, float *min, float *max);
650 
651 #define SML_VARIABLES_LIST_FOREACH(sml, list, len, var, i) \
652  for (i = 0, len = sml_variables_list_get_length(sml, list); \
653  i < len && ((var = sml_variables_list_index(sml, list, i))); \
654  i++)
655 
660 #ifdef __cplusplus
661 }
662 #endif
bool sml_variable_set_value(struct sml_object *sml, struct sml_variable *sml_variable, float value)
Set the variable value.
bool sml_set_output_state_changed_callback(struct sml_object *sml, sml_change_cb output_state_changed_cb, void *data)
Register a change callback.
uint16_t sml_variables_list_get_length(struct sml_object *sml, struct sml_variables_list *list)
Get the sml_variables_list size.
bool sml_set_max_memory_for_observations(struct sml_object *sml, unsigned int max_size)
Set maximum memory that can be used to store observation history data.
int sml_variable_get_name(struct sml_object *sml, struct sml_variable *sml_variable, char *var_name, size_t var_name_size)
Get sml_variable name.
bool sml_set_stabilization_hits(struct sml_object *sml, uint16_t hits)
Set the stabilization hits.
struct sml_variables_list * sml_get_output_list(struct sml_object *sml)
Return the output variables list.
struct sml_variable * sml_new_input(struct sml_object *sml, const char *name)
Create a new input variable.
bool(* sml_read_state_cb)(struct sml_object *sml, void *data)
A user defined callback to read the variables values.
Definition: sml.h:203
Definition: sml.h:176
bool sml_variables_list_contains(struct sml_object *sml, struct sml_variables_list *list, struct sml_variable *var)
Check if sml_variable is present in a sml_variables_list.
void sml_print_debug(struct sml_object *sml, bool full)
Prints SML debug information.
bool sml_load(struct sml_object *sml, const char *path)
Load the SML state from the disk.
bool sml_remove_variable(struct sml_object *sml, struct sml_variable *variable)
Remove a variable from the engine.
Definition: sml.h:184
struct sml_variable * sml_new_output(struct sml_object *sml, const char *name)
Create a new output variable.
bool sml_variable_is_enabled(struct sml_object *sml, struct sml_variable *variable)
Check if a sml_variable is enabled.
struct sml_variables_list * sml_get_input_list(struct sml_object *sml)
Return the input variables list.
bool sml_predict(struct sml_object *sml)
Make a prediction based on the most recent observations.
void(* sml_change_cb)(struct sml_object *sml, struct sml_variables_list *changed, void *data)
Called every time the SML made a prediction.
Definition: sml.h:212
float sml_variable_get_value(struct sml_object *sml, struct sml_variable *sml_variable)
Get the variable current value.
bool sml_variable_get_range(struct sml_object *sml, struct sml_variable *sml_variable, float *min, float *max)
Get variable range.
bool sml_set_learn_disabled(struct sml_object *sml, bool disable)
Disable the SML learning.
struct sml_variable * sml_get_output(struct sml_object *sml, const char *name)
Get input variable by name.
bool sml_variable_set_range(struct sml_object *sml, struct sml_variable *sml_variable, float min, float max)
Set variable range.
struct sml_variable * sml_variables_list_index(struct sml_object *sml, struct sml_variables_list *list, uint16_t index)
Get sml_variable by index.
bool sml_load_fll_file(struct sml_object *sml, const char *filename)
Reads a FLL file.
int sml_process(struct sml_object *sml)
Process variables and make predictions.
bool sml_set_read_state_callback(struct sml_object *sml, sml_read_state_cb read_state_cb, void *data)
Register a read callblack.
void sml_free(struct sml_object *sml)
Frees the SML engine.
bool sml_set_debug_log_file(struct sml_object *sml, const char *str)
Set the file to be used to debug data changes in this engine.
int sml_variable_set_enabled(struct sml_object *sml, struct sml_variable *variable, bool enabled)
Enable or disable a variable.
struct sml_variable * sml_get_input(struct sml_object *sml, const char *name)
Get input variable by name.
bool sml_save(struct sml_object *sml, const char *path)
Save the SML state on the disk.
bool sml_load_debug_log_file(struct sml_object *sml, const char *str)
Load to current engine the debug data logged to a file.
bool sml_erase_knowledge(struct sml_object *sml)
Erase all previous knowledge.