Quickstart: Tabular Compression with the python API#

This tutorial uses Heaviside provided with NeurEco installation.

To work with the Tabular NeurEco models in Python, import NeurEcoTabular library:

from NeurEco import NeurEcoTabular as Tabular

Import numpy to handle the data sets:

import numpy as np

Load the data sets(see Data preparation for NeurEco Compression with python API and Heaviside):

x_train = np.genfromtxt("x_train.csv", delimiter=";", skip_header=True)
    x_test = np.genfromtxt("x_test.csv", delimiter=";", skip_header=True)

To initialize a NeurEco object to handle the Compression problem:

compression_model = Tabular.Compressor()

To build the model, call method build with the parameters set for the problem under consideration (see Build NeurEco Compression model with the Python API):

compression_model.build(x_train,  # the rest of the parameters are optional
                      write_model_to='./HeavisideModel/Heaviside.ednn',
                      write_compression_model_to='./HeavisideModel/HeavisideCompressor.ednn',
                      write_decompression_model_to='./HeavisideModel/HeavisideUncompressor.ednn',
                      compress_tolerance=0.02,
                      checkpoint_address='./HeavisideModel/Heaviside.checkpoint')

Note

For detailed documentation on build, see Build NeurEco Compression model with the Python API

To evaluate the NeurEco Model on the testing data, call evaluate method:

neureco_test_outputs = compression_model.evaluate(x_test)

Note

For detailed documentation on evaluate, see Evaluate NeurEco Compression model with the Python API

To export the model to the chosen format (embed license is required), run one of the following commands:

compression_model.export_c("./HeavisideModel/Heaviside.h", precision="double")
compression_model.export_onnx("./HeavisideModel/Heaviside.onnx", precision="float16")
compression_model.export_fmu("./HeavisideModel/Heaviside.fmu")
compression_model.export_vba("./HeavisideModel/Heaviside.bas", precision="float")

Export to these formats requires embed license.

Note

For detailed documentation on export, see Export NeurEco Compression model with the Python API

When the model is not needed any more, delete it from the memory:

compression_model.delete()

Note

For detailed documentation on Tabular Compression with the python API, see Tabular Compression with the Python API.