❖ ColumnFormula
Use the ColumnFormula constraint when one of the columns in your table can be directly, formulaically determined based on the values in some other columns.

total_rate column can be formulaically determined from the room_rate + amenities_fee.Formula Definition
To use the constraint, you would first need to define a formula function.
Input: This function should take as input a pandas DataFrame containing all the columns that are needed for for the formula.
Output: It should output a pandas Series object containing the formulaically-determined column.
In the example below, we're showing a simple example where the total_rate = room_rate + amenities_fee.
Yo can write and save this function in a separate file, for example my_formulas.py. Or alternatively, you can also define it in the same script as your main SDV modeling and sampling.
Constraint API
Create a ColumnFormula constraint.
Parameters:
(required)
input_column_names: A list of strings that describe all the column names that should be inputs into the formula. In the previous SDV Enterprise version 0.47, this was calledinput_columns.(required)
output_column_name: A string that describes the final output column name. This is the column that is formulaically determined. In the previous SDV Enterprise version 0.47, this was calledoutput_column.(required)
formula_function_name: A string that contains the name of the formula function. This should be defined within the Python file specified above.module_name: A string with the name of the Python module where the formula function is written. (This is typically the name of the Python file without the.pysuffix.) In the previous SDV Enterprise version 0.47, this was calledmodule.(default)
"__main__": The currently active module. Use this if the function is defined in the same file as the constraint.
table_name: The name of the table that contains the columns. This is required if you have multi-table data.
Make sure that all the tables and columns you provide are in your Metadata.
Usage
Apply the constraint to any SDV synthesizer. Then fit and sample as usual.
For more information about using predefined constraints, please see the Constraint-Augmented Generation tutorial.
Auto-Detection
Auto-detection not available for this constraint. Please create the constraint object and add it to the synthesizer using the API described above.
FAQs
Last updated