Synthesis Validation
For synthesis validation we have only feature based evaluation metrics. To access the
Feature-based
Quality
pymdma.tabular.measures.synthesis_val.ImprovedPrecision
Improved Precision Metric for accessing fidelity of generative models.
Objective: Fidelity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of nearest neighbors to consider in the hypersphere estimation. Defaults to 5. |
5
|
metric
|
str
|
The metric to use when calculating distance between instances.
For the available metrics, see the documentation of |
"euclidean"
|
n_workers
|
int
|
Number of workers for computing pairwise distances. Defaults to 4. |
4
|
**kwargs
|
Additional keyword arguments for compatiblilty. |
{}
|
References
Kynkaanniemi et al., Improved Precision and Recall Metric for Assessing Generative Models (2019). https://arxiv.org/abs/1904.06991
Code adapted from: improved-precision-and-recall-metric: Improved Precision and Recall Metric for Assessing Generative Models — Official TensorFlow Implementation. https://github.com/kynkaat/improved-precision-and-recall-metric
Hypersphere estimation code was taken from: generative-evaluation-prdc, Reliable Fidelity and Diversity Metrics for Generative Models. https://github.com/clovaai/generative-evaluation-prdc
Examples:
>>> improved_precision = ImprovedPrecision()
>>> real_features = np.random.rand(100, 100)
>>> fake_features = np.random.rand(100, 100)
>>> result: MetricResult = improved_precision.compute(real_features, fake_features)
Source code in src/pymdma/general/measures/prdc.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
pymdma.tabular.measures.synthesis_val.ImprovedRecall
Improved Recall Metric for accessing diversity of generative models.
Objective: Diversity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of nearest neighbors to consider in the hypersphere estimation. Defaults to 5. |
5
|
metric
|
str
|
The metric to use when calculating distance between instances.
For the available metrics, see the documentation of |
"euclidean"
|
n_workers
|
int
|
Number of workers for computing pairwise distances. Defaults to 4. |
4
|
**kwargs
|
Additional keyword arguments for compatiblilty. |
{}
|
References
Kynkaanniemi et al., Improved Precision and Recall Metric for Assessing Generative Models (2019). https://arxiv.org/abs/1904.06991
Code adapted from: improved-precision-and-recall-metric: Improved Precision and Recall Metric for Assessing Generative Models — Official TensorFlow Implementation. https://github.com/kynkaat/improved-precision-and-recall-metric
Hypersphere estimation code was taken from: generative-evaluation-prdc, Reliable Fidelity and Diversity Metrics for Generative Models. https://github.com/clovaai/generative-evaluation-prdc
Examples:
>>> improved_recall = ImprovedRecall()
>>> real_features = np.random.rand(100, 100)
>>> fake_features = np.random.rand(100, 100)
>>> result: MetricResult = improved_recall.compute(real_features, fake_features)
Source code in src/pymdma/general/measures/prdc.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
pymdma.tabular.measures.synthesis_val.Density
Density Metric for accessing fidelity of the generated samples. Unlike Improved Precision, it is robust towards outliers in the real/reference data.
Objective: Fidelity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of nearest neighbors to consider in the hypersphere estimation. Defaults to 5. |
5
|
metric
|
str
|
The metric to use when calculating distance between instances.
For the available metrics, see the documentation of |
"euclidean"
|
n_workers
|
int
|
Number of workers for computing pairwise distances. Defaults to 4. |
4
|
**kwargs
|
Additional keyword arguments for compatibility. |
{}
|
References
Naeem et al., Reliable Fidelity and Diversity Metrics for Generative Models (2020). https://arxiv.org/abs/2002.09797
Code was adapted from: generative-evaluation-prdc, Reliable Fidelity and Diversity Metrics for Generative Models. https://github.com/clovaai/generative-evaluation-prdc
Examples:
>>> density = Density()
>>> real_features = np.random.rand(100, 100)
>>> fake_features = np.random.rand(100, 100)
>>> result: MetricResult = density.compute(real_features, fake_features)
Source code in src/pymdma/general/measures/prdc.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
pymdma.tabular.measures.synthesis_val.Coverage
Coverage Metric for accessing diversity of the generated samples. Unlike Improved Recall, it is robust towards outliers in the real/reference data.
Objective: Diversity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of nearest neighbors to consider in the hypersphere estimation. Defaults to 5. |
5
|
metric
|
str
|
The metric to use when calculating distance between instances.
For the available metrics, see the documentation of |
"euclidean"
|
n_workers
|
int
|
Number of workers for computing pairwise distances. Defaults to 4. |
4
|
**kwargs
|
Additional keyword arguments for compatibility. |
{}
|
References
Naeem et al., Reliable Fidelity and Diversity Metrics for Generative Models (2020). https://arxiv.org/abs/2002.09797
Code was adapted from: generative-evaluation-prdc, Reliable Fidelity and Diversity Metrics for Generative Models. https://github.com/clovaai/generative-evaluation-prdc
Examples:
>>> coverage = Coverage()
>>> real_features = np.random.rand(100, 100)
>>> fake_features = np.random.rand(100, 100)
>>> result: MetricResult = coverage.compute(real_features, fake_features)
Source code in src/pymdma/general/measures/prdc.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
pymdma.tabular.measures.synthesis_val.StatisticalSimScore
Computes a dataset-level statistical similarity score between real and synthetic data.
This metric assesses how closely the statistical properties of the synthetic dataset resemble those of the real dataset, providing a fidelity measure for synthetic data generation.
Objective: Fidelity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_map
|
dict
|
A mapping of column names to their types and properties. This is used to determine how to compute similarity for each column. |
None
|
**kwargs
|
dict
|
Additional keyword arguments passed to the parent class. |
{}
|
References
Yang et al., Structured evaluation of synthetic tabular data (2024). https://arxiv.org/abs/2403.10424
Returns:
| Type | Description |
|---|---|
MetricResult
|
A MetricResult object containing the similarity scores and their statistics. |
Examples:
>>> # Example 1: Evaluating statistical similarity for a dataset with discrete and continuous variables
>>> import numpy as np
>>> real_data = np.array([
... [1, 2.5],
... [1, 3.0],
... [2, 3.5],
... [2, 4.0]
... ])
>>> syn_data = np.array([
... [1, 2.6],
... [1, 3.1],
... [2, 3.4],
... [2, 4.2]
... ])
>>> col_map = {
... "column1": {"type": {"tag": "discrete"}},
... "column2": {"type": {"tag": "continuous"}},
... }
>>> sim_score = StatisticalSimScore(col_map=col_map)
>>> result: MetricResult = sim_score.compute(real_data, syn_data)
>>> dataset_level, _ = result.value # Output: similarity scores for each column
>>> # Example 2: Evaluating similarity with mismatched column types
>>> real_data = np.array([
... [1, 2],
... [2, 3],
... [3, 4]
... ])
>>> syn_data = np.array([
... [1, 2],
... [2, 3],
... [3, 5]
... ])
>>> col_map = {
... "column1": {"type": {"tag": "discrete"}},
... "column2": {"type": {"tag": "discrete"}},
... }
>>> sim_score = StatisticalSimScore(col_map=col_map)
>>> result: MetricResult = sim_score.compute(real_data, syn_data)
>>> dataset_level, _ = result.value # Output: similarity scores for each column
>>> dataset_stats, _ = result.stats # Output: mean and std of similarity scores
Source code in src/pymdma/tabular/measures/synthesis_val/data/similarity.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
pymdma.tabular.measures.synthesis_val.StatisticalDivergenceScore
Computes a statistical divergence score for each column, specifically the Jensen-Shannon (JS) and Kullback-Leibler (KL) divergence scores.
Objective: Fidelity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_names
|
list of str
|
List of the names of the columns (features) in the dataset. |
None
|
score
|
str
|
Specifies the divergence score to compute ('js' for Jensen-Shannon, 'kl' for Kullback-Leibler, 'all' for both). By default, it is set to 'kl'. |
'kl'
|
**kwargs
|
dict
|
Additional keyword arguments passed to the parent class. |
{}
|
References
Fonseca and Bacao, Tabular and latent space synthetic data generation: a literature review (2023). https://doi.org/10.1186/s40537-023-00792-7
Returns:
| Type | Description |
|---|---|
MetricResult
|
A MetricResult object containing the divergence scores and their statistics. |
Examples:
>>> # Example 1: Evaluating statistical divergence for a dataset
>>> import numpy as np
>>> real_data = np.array([
... [1, 2, 3],
... [2, 3, 4],
... [3, 4, 5]
... ])
>>> syn_data = np.array([
... [1, 2, 2],
... [2, 2, 3],
... [3, 3, 4]
... ])
>>> col_map = {
... "column1": {"type": {"tag": "continuous"}},
... "column2": {"type": {"tag": "continuous"}},
... "column3": {"type": {"tag": "continuous"}},
... }
>>> divergence_score = StatisticalDivergenceScore(col_map=col_map, score='kl')
>>> result: MetricResult = divergence_score.compute(real_data, syn_data)
>>> dataset_level, _ = result.value # Output: divergence scores for each column
>>> # Example 2: Using JS divergence instead of KL
>>> divergence_score_js = StatisticalDivergenceScore(col_map=col_map, score='js')
>>> result_js: MetricResult = divergence_score_js.compute(real_data, syn_data)
>>> dataset_level_js, _ = result_js.value # Output: JS divergence scores for each column
>>> dataset_stats_js, _ = result_js.stats # Output: mean and std of JS divergence scores
Source code in src/pymdma/tabular/measures/synthesis_val/data/similarity.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
pymdma.tabular.measures.synthesis_val.CoherenceScore
Computes the coherence score between the correlation matrices of the target and synthetic datasets. A higher coherence score indicates better fidelity between the datasets in terms of their correlation structures.
Objective: Fidelity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
Weights for the correlations, allowing for weighted contributions to the coherence score. If None, uniform weights are applied. |
None
|
corr_type
|
str
|
The type of correlation to compute ('pearson' by default). Other types like 'spearman' may be supported depending on the implementation. |
'pearson'
|
**kwargs
|
dict
|
Additional keyword arguments passed to the parent class. |
{}
|
References
Yang et al., Structured evaluation of synthetic tabular data (2024). https://arxiv.org/abs/2403.10424
Returns:
| Type | Description |
|---|---|
MetricResult
|
A MetricResult object containing the coherence score. |
Examples:
>>> # Example 1: Evaluating coherence score for a dataset
>>> import numpy as np
>>> real_data = np.array([
... [1, 2, 3],
... [2, 3, 4],
... [3, 4, 5]
... ])
>>> syn_data = np.array([
... [1, 2, 3],
... [1, 2, 3],
... [3, 4, 5]
... ])
>>> coherence_score = CoherenceScore(corr_type='pearson')
>>> result: MetricResult = coherence_score.compute(real_data, syn_data)
>>> dataset_level, _ = result.value # Output: coherence score
>>> # Example 2: Evaluating with custom weights
>>> weights = np.array([0.5, 1.0, 1.5]) # Example weights
>>> coherence_score_weighted = CoherenceScore(weights=weights, corr_type='spearman')
>>> result_weighted: MetricResult = coherence_score_weighted.compute(real_data, syn_data)
>>> dataset_level, _ = result_weighted.value # Output: weighted coherence score
Source code in src/pymdma/tabular/measures/synthesis_val/data/similarity.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
Privacy
pymdma.tabular.measures.synthesis_val.Authenticity
Authenticity Metric for assessing the authenticity of the generated samples. A synthetic sample is considered authentic if it is signficantly distinct from any real sample.
Objective: Privacy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
The metric to use when calculating distance between instances.
For the available metrics, see the documentation of |
"euclidean"
|
**kwargs
|
Additional keyword arguments for compatibility. |
{}
|
Notes
The authenticity metric is computed by checking if any fake sample is closer to a real sample than the real sample is to any other real sample.
References
Alaa et al., How Faithful Is Your Synthetic Data? Sample-Level Metrics for Evaluating and Auditing Generative Models. (2022) https://doi.org/10.48550/arXiv.2102.08921.
Hypersphere estimation code was adapted from: generative-evaluation-prdc, Reliable Fidelity and Diversity Metrics for Generative Models. https://github.com/clovaai/generative-evaluation-prdc
Examples:
>>> authenticity = Authenticity()
>>> real_features = np.random.rand(100, 100)
>>> fake_features = np.random.rand(100, 100)
>>> result: MetricResult = authenticity.compute(real_features, fake_features)
Source code in src/pymdma/general/measures/prdc.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |