❖ UniqueBridgeTable
Last updated
Last updated
Use the UniqueBridgeTable constraint when you have a bridge table that records a many-to-many relationship between multiple tables, and the connections have to be unique. That is to say, the combinations of keys in the bridge tables must be unique.
Create a UniqueBridgeTable
constraint.
Parameters:
(required) table_name
: A string with the name of the bridge table
(required) foreign_key_columns
: A list of strings with the names of the foreign key columns. The combination of values in these columns must be unique.
from sdv.cag import UniqueBridgeTable
my_constraint = UniqueBridgeTable(
table_name='Author-Book',
foreign_key_columns=['Author ID', 'Book ID'])
Make sure that all the tables and columns you provide are listed in your Metadata, as well as all foreign key connections.
Apply the constraint to any SDV synthesizer. Then fit and sample as usual.
synthesizer = HSASynthesizer(metadata)
synthesizer.add_constraints([my_constraint])
synthesizer.fit(data)
synthetic_data = synthesizer.sample()
For more information about using predefined constraints, please see the Constraint-Augmented Generation tutorial.