Constraints
Do you have rules that every row in the data must follow? Are these the same regardless of how much data there is? You can use constraints to describe this business logic to your synthesizer.
Adding Predefined Logic
The SDV library comes with some predefined constraint logic that is ready to use. You can define each constraint using a dictionary format.
(required)
'constraint_class
: A string with the name of the predefined constraint class(required)
'table_name'
: A string with the name of the table for the constraint(required)
'constraint_parameters'
: A dictionary with the parameters. Each class has different parameters.
For more details about the classes and parameters, browse the Predefined Constraint Classes.
add_constraints
Apply constraints by adding them to your synthesizer. Use this function to add your constraints to the synthesizer.
Parameters
(required)
constraints
: A list of dictionaries that describe your constraint. These can be predefined constraints or your own, custom constraint.
Output (None)
get_constraints
Use this function to inspect all of the constraints your synthesizer contains.
Parameters None
Output A list of dictionaries that describe all the constraints applied to your synthesizer
Note that the returned list is a representation of the constraints. Changing it will not modify the constraints in any way.
Training the synthesizer
After adding constraints, you'll need to (re)train the synthesizer with real data.
The synthesizer will now learn from your real data with the added constraints. All synthetic data it produces will be valid for the constraint.
Adding Custom Logic
In some cases, you may need to add some custom constraints. We recommend you define the logic in a separate Python file. See the Custom Logic Reference for more details.
load_custom_constraint_classes
Use this function to load your custom logic from a separate Python file.
Parameters
(required)
filepath
: A string describing the filepath of your Python file. If your constraints are defined in the current file, you can specifyNone
.(required)
class_names
: A list of strings, describing the class names to load
Output (None) After using this function, you can apply your custom constraints to your synthesizer.
Use a Custom Constraint
Once you have loaded your custom logic, you can define constraints using your custom name and parameters. Then you can apply it to your synthesizer just like any other constraint.
Last updated