Skip to main content

COIM

Constrain Operator for Inferential Models is a simple tool for pre and pos processing of data to eliminate redunduncy in datasets caused by dependency rules between the variables/columns.

Status

PyPI - Version PyPI - License PyPI - Status GitHub commits since tagged version GitHub milestone details PyPI - Downloads GitHub repo size Static Badge

Usage

To start using COIM, import into your code the operator class, which orquestrates the constrains, and define an instance of it.

from COIM import ConstrainOperator
operator=ConstrainOperator()

To add a new constrain, use the add_rule method from ConstrainOperator class.

from COIM import SomeConstrain
contraint_some_rule=SomeConstrain(**parameters)
operator.add_rule(contraint_some_rule)

Each constrain will require their own specific set of parameters, refer to section Available constrains to know each of them. However, all constrains receive the parameter "labels", which is a list with the new names to be used on the encoded columns, and a parameter "precision", which indicates the precision for dataset validation (default to 1e-10).

Then you can encode your dataframe to use the new corrected variables to feed your model.

encoded_df=operator.encode_dataframe(df)

After running your model, you can regenerate the data in the original format, decoding the acquired values and errors.

decoded_df, decoded_errors=operator.decode_dataframe(predicted_df, errors)

That will yield the predictions for the original variables as if they had been fed to the model themselves, but with rather more consistent results.

Also, the errors for these corrected variables will be adjusted according to their mathematical rules.

Available constrains

  1. "add_scalar":
    • $a+K=b$
    • base_variable = a
    • target_variable = b
    • constant = K
  2. "mul_scalar":
    • $a*K=b$
    • base_variable = a
    • target_variable = b
    • constant = K
  3. "const_sum":
    • $\sum W_i\cdot a_i=K$
    • variables = $[a_1, a_2, \cdots, a_n]$
    • reference_variable = $a_j$
    • constant_sum = K
    • weights = $[W_1, W_2, \cdots, W_n]$ or $W$ if $W_1=W_2= \cdots= W_n$ or fixed value $W$ if weights do not differ between columns
  4. "custom_func":
    • to be used when none of the above is applicable and you have to develop your own functions to operate the dataframe
    • variables : list of the variables to be used
    • validate_function: Function to assert if the received dataframe follows the given constrain.
    • format_function: Write a string that describes the constrain equation.
    • encode_dataframe: Create the new custom columns in the dataframe.
    • decode_dataframe: Restore the original columns in the dataframe and calculate the propagated errors.

Future additions

In the foreseeable future, some new constrains will be implemented, those are:

  1. Variable sum
  2. Constant and variable products
  3. Conditionals

Theoretical foundation

All of the worked out mathematics for the developed constrains can be found at the calculations pdf

Metadata

Release files for COIM 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for COIM 0.0.3
File Size Uploaded
coim-0.0.3.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for COIM 0.0.3
File Interpreter ABI Platform
coim-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.7 kB

Release files / coim-0.0.3.tar.gz

Download URL coim-0.0.3.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
42a84dbc6dfb1a9226a662ca596747a4a4eaa67c12b1bb6391e1bd5dceab48a1
BLAKE2b-256 checksum
How to use checksums
fa37aecb8c9206fb6dc4d57257a0cd1e88b911cd8b32f89e649a1fe60a70261f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.13

Release files / coim-0.0.3-py3-none-any.whl

Download URL coim-0.0.3-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcc320fc45427bbfb8b45cef9ea6e12c5bf04e7b192dabf6b8287ef1ce624250
BLAKE2b-256 checksum
How to use checksums
4b3a080316bbff5554f9a2a4ad8a0e71c7667b615154d8c2c5762d16a94862f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page