Sign inSign up

synchronicityiot/estimation-generic

By synchronicityiot

Updated over 6 years ago

Image
0

345

synchronicityiot/estimation-generic repository overview

Deploying the models

The estimator is defined as a microservice so that it is easy to be run and deployed in any use case and infrastructure. In addition, it is fully configurable and adaptable for scenario Moreover, it can be run just to obtain a prediction, or it can be configured to deploy a REST API to access the predictions at any time.

With the data produced by the sensors every day, a database is collected for every entity/id so that a predictive model can be produced for each entity. This model will recognize and detect the patterns in the data so that it is able to forecast (predict), considering some context input data, the next value(s) of the time series; or to estimate the value of a specific target feature. This model is trained by the trainer-estimation, and then stored in Elasticsearch to be deployed in the inference-estimators microservices.

Configuration

There are several parameters that can be modified to change how the system predicts. These parameters are enclosed in the file ./config/config.ini, and are explained here:

Note: It is very important that these parameters match the ones specified in the configuration file of the trainer used to train the models that are deployed in this estimator.

ESTIMATION section:

  • data_type: can be timeseries or features and stands for the type of the data (used to train the model). If the datatype is features, the next two parameters are ignored.
  • num_forecasts: Number of values that the system will output when a prediction is requested, when the data_type is timeseries.
  • num_previous_measures: This parameter affects the learning algorithm itself, it stands for the length of the time series, which is the number of previous values considered for the learning.

ML section:

  • algorithm: Name of the algorithm to be used as Neural Network, currently 'lstm' (default), 'phasedlstm' and 'dense' models are available.
  • training_size: Number of samples which will be used to train the model
  • time_window_to: Period of time for looking back for data in elasticsearch. One week is 1w. One month would be 1M
  • time_window_from: Time to start looking back to for data in elasticsearch. Default is now

The format for time_window parameters follows Date Math from elasticsearch API.

ELASTIC section:

  • index_entities: Name of the index that stores the entities
  • index_data: Name of the index that stores the data
  • index_scalers: Name of the index that stores the scalers
  • index_predictions: Name of the index that stores the predictions
  • index_models: Name of the index that stores the models
  • mapping_data: Name of the mapping that defines the format in the index of data
  • mapping_entities: Name of the mapping that defines the format in the index of entities
  • mapping_models: Name of the mapping that defines the format in the index of models
  • mapping_predictions: Name of the mapping that defines the format in the index of predictions

DATA section:

  • time_index: Column label used for indexing data (timestamp column), typically timestamp
  • inference_features: Name of the feature(s) that is/are going to be forecasted
  • dataset_features: Name of the other features used only for training

ELK section

  • elastic_host: Hostname of elasticsearch. Example: localhost
  • elastic_port: Port of communication with elasticsearch. Example: 9200 (default of elasticsearch)

MINIO section

  • minio_host: Hostname of MINIO. Example: minio
  • minio_port: Port of communication with MINIO (default is '9000')

DEFAULT section

  • endpoint: If True open a REST API for asking for inference in localhost (True || False)
  • port: Port where the endpoint will listen (default 5005)
  • schedule: Schedule the predictions (True || False) every day or every X minutes (only one of both when True).
  • schedule_every_day: Schedule the predictions every day at a certain time (ex: 04:37). Leave blank if you do not want to schedule by day.
  • schedule_every_minutes: Schedule the predictions every X minutes (ex: 360). Leave blank if you do not want to schedule by minutes.

Instructions

Use this command to launch the container:

docker run synchronicityiot/estimation-generic:@tag -e MINIO_HOST='@minio_host' -e MINIO_PORT='@minio_port' -e MINIO_ACCESS_KEY='@minio_access' -e MINIO_SECRET_KEY='@minio_secret' -e ELASTIC_HOST='@elastic_host' -e ELASTIC_PORT='@elastic_port' -v ./config/:/usr/src/app/config/config.ini -p 5005:5005

Note that you must specify at least @tag (for example :v1.0) and the folder that contains the configuration file as a volume. You can specify environment variables for the elasticsearch host (@elastic_host) and the elasticsearch port (@elastic_port), if you do not provide them, the ones in the config.ini file will be used. You should also open the port used in the estimator (5005).

In case you might want to include the engine in your docker-compose file, we provide here the code needed to launch it (please configure properly the docker image tag and the elasticsearch environment variables and the MINIO secret and access key):

networks:
  ioelab-network:
    driver: bridge

volumes:
  aimodelsdata:
    driver: local

services:

  iot-ai-engine:
    image: ioelab/estimation-generic:v1.0
    container_name: estimation-generic
    hostname: estimation-generic_host
    volumes:
      - ./config/config.ini:/usr/src/app/config/config.ini
    environment:
      NODE_ENV: development
      ELASTIC_HOST: 127.0.0.1
      ELASTIC_PORT: 9200
      MINIO_HOST: 127.0.0.1
      MINIO_PORT: 9200
      ESTIMATION_PORT: 5005
      MINIO_ACCESS_KEY: {MINIO_ACCESS_KEY}
      MINIO_SECRET_KEY: {MINIO_SECRET_KEY} 
    ports:
      - 5005:5005
    networks:
      ioelab-network:
        aliases:
          - estimation-generic_host

With the model loaded, predictions can be done either by request (from the REST endpoint or from the execution) or periodically (if you launch the estimator with the scheduler). You can access those predictions in elasticsearch at the index and mapping that you have indicated in the config file. An example of the format of the predictions stored in elasticsearch is:

{
    "model_file": "Q7NwDWsB2UYPRYj1IUbr",
    "timestamp": "2019-05-31T10:30:30.737034Z",
    "algorithm": "lstm",
    "id": "urn:ngsi-ld:OnStreetParking:santander:parking:onStreet:StaLuciaEast",
    "values": [
        17.101938247680664,
        16.920570373535156,
        16.93316650390625,
        16.768169403076172
    ],
    "prediction_times": [
        "2019-05-31T10:45:30.737034Z",
        "2019-05-31T11:00:30.737034Z",
        "2019-05-31T11:15:30.737034Z",
        "2019-05-31T11:30:30.737034Z"
    ],
    "latency": "0.45788"
}

If you run the estimator as a REST API, ask for a prediction via a GET method to the estimator with:

curl -X GET http://127.0.0.1:5000/predict/id

Notice that it is necessary to indicate the id of the entity corresponding to the estimations. This will return a JSON object with the format (if id = urn:ngsi-ld:OnStreetParking:santander:parking:onStreet:StaLuciaEast):

{
    "timestamp": "2019-05-31T10:30:30.737034Z",
    "id": "urn:ngsi-ld:OnStreetParking:santander:parking:onStreet:StaLuciaEast",
    "prediction": [
        17.101938247680664,
        16.920570373535156,
        16.93316650390625,
        16.768169403076172
    ],
    "prediction_times": [
        "2019-05-31T10:45:30.737034Z",
        "2019-05-31T11:00:30.737034Z",
        "2019-05-31T11:15:30.737034Z",
        "2019-05-31T11:30:30.737034Z"
    ],
    "latency": "0.1",
    "status": "success"
}

Tag summary

Content type

Image

Digest

Size

497.3 MB

Last updated

over 6 years ago

docker pull synchronicityiot/estimation-generic:2.1