Evaluating generators: FID, KID, Inception Score, precision and recall
How generated images are scored, what each number rewards and misses, and how the same questions apply to the synthetic tables CodeSplash makes. No single number says a generator is good.
What runs in CodeSplash
- EVA021Fréchet Inception Distance Needs a data type CodeSplash doesn't load yet
- EVA022Kernel Inception Distance Needs a data type CodeSplash doesn't load yet
- EVA023Inception Score Needs a data type CodeSplash doesn't load yet
- EVA024Generative precision, recall, density, and coverage Runs as a notebook
- Synthetic data — tabular GAN (WGAN-GP) Experimental
- Synthetic data — tabular diffusion (TabDDPM-style) Experimental
- Synthetic data — flow matching Experimental
- Synthetic data — tabular VAE (TVAE) Experimental
You will be able to
- Compute FID from feature means and covariances and say what it depends on
- Explain why KID is unbiased and can come out below zero
- Say what the Inception Score rewards and why it ignores real data
- Separate precision (fidelity) from recall and coverage (diversity)
- Read a synthetic-table scorecard where different metrics rank generators differently
Compare features, not pixels
ReadImage generators are scored in a feature space: each real and generated image is passed through a fixed pretrained network, classically Inception-v3, and compared by its feature vector. Every score below inherits that choice. Change the network, the resizing or the image count and the number changes, so scores are comparable only under the same protocol.
FID
ReadThe Fréchet inception distanceFréchet inception distance (FID)Distance between Gaussians fit to real and generated images' features; lower is closer, and it depends on the feature network. fits a Gaussian to each set of features and measures the distance between the two Gaussians:
Lower is closer. In the reference's two-feature example with diagonal covariances it is 0.302. FID is biased upward for small samples, so two models must be compared at the same image count, and it summarizes fidelity and diversity in one number you can't take apart.
Reference · EVA021 · Needs a data type CodeSplash doesn't load yetFréchet Inception DistanceCompares Gaussian approximations to real and generated image-feature distributions.KID
ReadThe kernel inception distanceKernel inception distanceAn unbiased squared kernel distance (MMD) between real and generated image features; small samples can give values below 0. is the squared MMDMaximum mean discrepancyThe distance between two distributions' average kernel embeddings; zero when they are equal. between the two feature sets, with a cubic polynomial kernel. Its estimator is unbiased: on average it equals the true distance at any sample size, which makes small-sample comparisons fairer than FID's.
Unbiased has a price: for close distributions and few images it can come out below zero. In the reference's three-image example it is −1.410. A negative KID isn't a bug; it means the two sets are indistinguishable at that sample size. Report it with its spread over subsets.
Reference · EVA022 · Needs a data type CodeSplash doesn't load yetKernel Inception DistanceUses an unbiased squared MMD estimator with a polynomial kernel on Inception features.Inception Score
ReadThe Inception ScoreInception scoreRewards generated images a classifier labels confidently and that spread over many classes; it never looks at real images. runs a classifier on generated images only. It is high when each image gets a confident label and the labels spread over many classes:
In the reference's four-image example it is 1.324, out of a maximum of 2 for two classes. It never looks at real images, so it can't tell whether the images resemble your data, and it rewards whatever the classifier finds confident.
Reference · EVA023 · Needs a data type CodeSplash doesn't load yetInception ScoreRewards confident classifier predictions for individual generated images and diversity of predicted classes across images.Precision, recall, density and coverage
ReadOne number mixes two failures: unrealistic samples and missing kinds of data. Precision and recall for generatorsPrecision and recall for generatorsPrecision asks whether generated rows fall where real rows live; recall or coverage asks whether real rows are reached. split them, using balls around each point's k-th nearest neighbor in feature space:
- precision: the share of generated points inside some real point's ball (are samples realistic?);
- recall, or the sturdier coverage: the share of real points whose ball holds a generated point (is every kind of real data reached?).
In the reference's example two of three generated points fall in a real ball and both real points are reached: precision 0.667, coverage 1.0. Mode collapseMode collapseA generator that covers only some of the data's kinds of rows, often switching between them, while its loss looks fine. shows up as high precision with low coverage.
DExplorable · Scoring generators: FID, precision and recall
Can one number say how good generated samples are?
How will this generator's precision and recall come out?
Generator
The real data is a ring of 8 clusters. Each generator gets something different wrong.
Feature extractor
FID and the k-NN scores compare features, not raw samples. Real FID uses a vision network; here, four simple maps.
How many real and how many generated samples are compared.
Each sample's ball reaches its k-th nearest neighbor in its own set.
Commit your prediction above to see the result
Make your prediction to see the result.
One table, several generators
ExploreCodeSplash's synthetic scorecard asks the same questions of tables, column by column. On the customer table, mean KS distances per column (lower is closer):
320 synthetic rows over 8 columns from 320 training rows with flow matching. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.049 and categories by a mean total variation of 0.093.
- Synthetic rows
- 320
- Mean KS distance
- 0.0492
- Mean TV distance
- 0.0928
- Rows copied from the data
- 0
Plots
View data
| Density | Source | age |
|---|---|---|
| 0.0230 | real | 18.950 |
| 0.0016 | real | 20.850 |
| 0.0049 | real | 22.750 |
| 0.0148 | real | 24.650 |
| 0.0148 | real | 26.550 |
| 0.0181 | real | 28.450 |
| 0.0197 | real | 30.350 |
| 0.0296 | real | 32.250 |
| 0.0362 | real | 34.150 |
| 0.0115 | real | 36.050 |
| 0.0362 | real | 37.950 |
| 0.0313 | real | 39.850 |
| 0.0296 | real | 41.750 |
| 0.0280 | real | 43.650 |
| 0.0280 | real | 45.550 |
| 0.0181 | real | 47.450 |
| 0.0164 | real | 49.350 |
| 0.0197 | real | 51.250 |
| 0.0362 | real | 53.150 |
| 0.0148 | real | 55.050 |
| 0.0164 | real | 56.950 |
| 0.0181 | real | 58.850 |
| 0.0082 | real | 60.750 |
| 0.0164 | real | 62.650 |
| 0.0049 | real | 64.550 |
| 0.0115 | real | 66.450 |
| 0.0066 | real | 68.350 |
| 0.0049 | real | 70.250 |
| 0.0016 | real | 72.150 |
| 0.0049 | real | 74.050 |
| 0.0461 | synthetic | 18.950 |
| 0.0016 | synthetic | 20.850 |
| 0.0033 | synthetic | 22.750 |
| 0.0230 | synthetic | 24.650 |
| 0.0115 | synthetic | 26.550 |
| 0.0164 | synthetic | 28.450 |
| 0.0214 | synthetic | 30.350 |
| 0.0296 | synthetic | 32.250 |
| 0.0247 | synthetic | 34.150 |
| 0.0115 | synthetic | 36.050 |
| 0.0362 | synthetic | 37.950 |
| 0.0280 | synthetic | 39.850 |
| 0.0148 | synthetic | 41.750 |
| 0.0345 | synthetic | 43.650 |
| 0.0197 | synthetic | 45.550 |
| 0.0148 | synthetic | 47.450 |
| 0.0214 | synthetic | 49.350 |
| 0.0148 | synthetic | 51.250 |
| 0.0411 | synthetic | 53.150 |
| 0.0082 | synthetic | 55.050 |
| 0.0197 | synthetic | 56.950 |
| 0.0132 | synthetic | 58.850 |
| 0.0115 | synthetic | 60.750 |
| 0.0132 | synthetic | 62.650 |
| 0.0049 | synthetic | 64.550 |
| 0.0066 | synthetic | 66.450 |
| 0.0099 | synthetic | 68.350 |
| 0.0115 | synthetic | 70.250 |
| 0.0049 | synthetic | 72.150 |
| 0.0082 | synthetic | 74.050 |
View data
| Density | Source | annual income |
|---|---|---|
| 3.010e-6 | real | 6851.93 |
| 1.605e-5 | real | 10141.74 |
| 2.107e-5 | real | 13431.55 |
| 2.408e-5 | real | 16721.36 |
| 3.511e-5 | real | 20011.17 |
| 4.113e-5 | real | 23300.98 |
| 2.809e-5 | real | 26590.79 |
| 2.408e-5 | real | 29880.60 |
| 2.508e-5 | real | 33170.41 |
| 1.605e-5 | real | 36460.22 |
| 1.605e-5 | real | 39750.03 |
| 1.505e-5 | real | 43039.84 |
| 1.003e-5 | real | 46329.65 |
| 5.016e-6 | real | 49619.46 |
| 6.019e-6 | real | 52909.27 |
| 4.013e-6 | real | 56199.07 |
| 4.013e-6 | real | 59488.88 |
| 4.013e-6 | real | 62778.69 |
| 1.003e-6 | real | 66068.50 |
| 1.003e-6 | real | 69358.31 |
| 1.003e-6 | real | 72648.12 |
| 0 | real | 75937.93 |
| 1.003e-6 | real | 79227.74 |
| 1.003e-6 | real | 82517.55 |
| 0 | real | 85807.36 |
| 0 | real | 89097.17 |
| 0 | real | 92386.98 |
| 0 | real | 95676.79 |
| 0 | real | 98966.60 |
| 1.003e-6 | real | 102256.41 |
| 3.010e-6 | synthetic | 6851.93 |
| 1.705e-5 | synthetic | 10141.74 |
| 2.006e-5 | synthetic | 13431.55 |
| 2.207e-5 | synthetic | 16721.36 |
| 3.612e-5 | synthetic | 20011.17 |
| 3.812e-5 | synthetic | 23300.98 |
| 2.207e-5 | synthetic | 26590.79 |
| 2.608e-5 | synthetic | 29880.60 |
| 2.307e-5 | synthetic | 33170.41 |
| 1.705e-5 | synthetic | 36460.22 |
| 1.705e-5 | synthetic | 39750.03 |
| 2.207e-5 | synthetic | 43039.84 |
| 7.022e-6 | synthetic | 46329.65 |
| 6.019e-6 | synthetic | 49619.46 |
| 9.029e-6 | synthetic | 52909.27 |
| 4.013e-6 | synthetic | 56199.07 |
| 6.019e-6 | synthetic | 59488.88 |
| 4.013e-6 | synthetic | 62778.69 |
| 1.003e-6 | synthetic | 66068.50 |
| 0 | synthetic | 69358.31 |
| 1.003e-6 | synthetic | 72648.12 |
| 0 | synthetic | 75937.93 |
| 0 | synthetic | 79227.74 |
| 0 | synthetic | 82517.55 |
| 0 | synthetic | 85807.36 |
| 0 | synthetic | 89097.17 |
| 0 | synthetic | 92386.98 |
| 1.003e-6 | synthetic | 95676.79 |
| 1.003e-6 | synthetic | 98966.60 |
| 0 | synthetic | 102256.41 |
View data
| Density | Source | tenure_months |
|---|---|---|
| 0.0938 | real | 0.7667 |
| 0.0224 | real | 2.300 |
| 0.0183 | real | 3.833 |
| 0.0306 | real | 5.367 |
| 0.0204 | real | 6.900 |
| 0.0265 | real | 8.433 |
| 0.0204 | real | 9.967 |
| 0.0530 | real | 11.500 |
| 0.0183 | real | 13.033 |
| 0.0510 | real | 14.567 |
| 0.0183 | real | 16.100 |
| 0.0367 | real | 17.633 |
| 0.0224 | real | 19.167 |
| 0.0448 | real | 20.700 |
| 0.0469 | real | 22.233 |
| 0.0082 | real | 23.767 |
| 0.0306 | real | 25.300 |
| 0.0061 | real | 26.833 |
| 0.0183 | real | 28.367 |
| 0.0041 | real | 29.900 |
| 0.0143 | real | 31.433 |
| 0.0061 | real | 32.967 |
| 0.0183 | real | 34.500 |
| 0.0020 | real | 36.033 |
| 0.0041 | real | 37.567 |
| 0 | real | 39.100 |
| 0.0061 | real | 40.633 |
| 0.0041 | real | 42.167 |
| 0.0020 | real | 43.700 |
| 0.0041 | real | 45.233 |
| 0.1121 | synthetic | 0.7667 |
| 0.0265 | synthetic | 2.300 |
| 0.0143 | synthetic | 3.833 |
| 0.0245 | synthetic | 5.367 |
| 0.0122 | synthetic | 6.900 |
| 0.0163 | synthetic | 8.433 |
| 0.0102 | synthetic | 9.967 |
| 0.0530 | synthetic | 11.500 |
| 0.0102 | synthetic | 13.033 |
| 0.0367 | synthetic | 14.567 |
| 0.0143 | synthetic | 16.100 |
| 0.0367 | synthetic | 17.633 |
| 0.0285 | synthetic | 19.167 |
| 0.0448 | synthetic | 20.700 |
| 0.0510 | synthetic | 22.233 |
| 0.0102 | synthetic | 23.767 |
| 0.0346 | synthetic | 25.300 |
| 0.0020 | synthetic | 26.833 |
| 0.0285 | synthetic | 28.367 |
| 0.0061 | synthetic | 29.900 |
| 0.0346 | synthetic | 31.433 |
| 0.0082 | synthetic | 32.967 |
| 0.0183 | synthetic | 34.500 |
| 0 | synthetic | 36.033 |
| 0.0061 | synthetic | 37.567 |
| 0 | synthetic | 39.100 |
| 0.0041 | synthetic | 40.633 |
| 0.0020 | synthetic | 42.167 |
| 0.0041 | synthetic | 43.700 |
| 0.0020 | synthetic | 45.233 |
View data
| Density | Source | signup |
|---|---|---|
| 0.0005 | real | 17582.23 |
| 0.0007 | real | 17654.70 |
| 0.0005 | real | 17727.17 |
| 0.0005 | real | 17799.63 |
| 0.0004 | real | 17872.10 |
| 0.0005 | real | 17944.57 |
| 0.0006 | real | 18017.03 |
| 0.0004 | real | 18089.50 |
| 0.0005 | real | 18161.97 |
| 0.0005 | real | 18234.43 |
| 0.0001 | real | 18306.90 |
| 0.0009 | real | 18379.37 |
| 0.0006 | real | 18451.83 |
| 0.0003 | real | 18524.30 |
| 0.0005 | real | 18596.77 |
| 0.0004 | real | 18669.23 |
| 0.0002 | real | 18741.70 |
| 0.0005 | real | 18814.17 |
| 0.0006 | real | 18886.63 |
| 0.0005 | real | 18959.10 |
| 0.0005 | real | 19031.57 |
| 0.0005 | real | 19104.03 |
| 0.0003 | real | 19176.50 |
| 0.0006 | real | 19248.97 |
| 0.0004 | real | 19321.43 |
| 0.0003 | real | 19393.90 |
| 0.0002 | real | 19466.37 |
| 0.0005 | real | 19538.83 |
| 0.0003 | real | 19611.30 |
| 0.0004 | real | 19683.77 |
| 0.0003 | synthetic | 17582.23 |
| 0.0006 | synthetic | 17654.70 |
| 0.0006 | synthetic | 17727.17 |
| 0.0008 | synthetic | 17799.63 |
| 0.0005 | synthetic | 17872.10 |
| 0.0007 | synthetic | 17944.57 |
| 0.0005 | synthetic | 18017.03 |
| 0.0002 | synthetic | 18089.50 |
| 0.0006 | synthetic | 18161.97 |
| 0.0004 | synthetic | 18234.43 |
| 0.0002 | synthetic | 18306.90 |
| 0.0007 | synthetic | 18379.37 |
| 0.0003 | synthetic | 18451.83 |
| 0.0003 | synthetic | 18524.30 |
| 0.0007 | synthetic | 18596.77 |
| 0.0005 | synthetic | 18669.23 |
| 0.0004 | synthetic | 18741.70 |
| 0.0005 | synthetic | 18814.17 |
| 0.0007 | synthetic | 18886.63 |
| 0.0005 | synthetic | 18959.10 |
| 0.0006 | synthetic | 19031.57 |
| 0.0004 | synthetic | 19104.03 |
| 0.0005 | synthetic | 19176.50 |
| 0.0006 | synthetic | 19248.97 |
| 0.0003 | synthetic | 19321.43 |
| 0.0003 | synthetic | 19393.90 |
| 0.0001 | synthetic | 19466.37 |
| 0.0004 | synthetic | 19538.83 |
| 0.0003 | synthetic | 19611.30 |
| 0.0003 | synthetic | 19683.77 |
View data
| plan | Share | Source |
|---|---|---|
| basic | 0.3563 | real |
| plus | 0.3969 | real |
| premium | 0.2469 | real |
| basic | 0.3750 | synthetic |
| plus | 0.3344 | synthetic |
| premium | 0.2906 | synthetic |
View data
| region | Share | Source |
|---|---|---|
| east | 0.2848 | real |
| north | 0.2718 | real |
| south | 0.3042 | real |
| west | 0.1392 | real |
| east | 0.3514 | synthetic |
| north | 0.2204 | synthetic |
| south | 0.2428 | synthetic |
| west | 0.1853 | synthetic |
View data
| churned | Share | Source |
|---|---|---|
| false | 0.7688 | real |
| true | 0.2313 | real |
| false | 0.6656 | synthetic |
| true | 0.3344 | synthetic |
View data
| Column | Column | Difference |
|---|---|---|
| age | age | 0 |
| annual income | age | 0.1622 |
| tenure_months | age | 0.7205 |
| signup | age | −0.0666 |
| visits | age | −0.0917 |
| age | annual income | 0.1622 |
| annual income | annual income | 0 |
| tenure_months | annual income | 0.1429 |
| signup | annual income | −0.0486 |
| visits | annual income | 0.2082 |
| age | tenure_months | 0.7205 |
| annual income | tenure_months | 0.1429 |
| tenure_months | tenure_months | 0 |
| signup | tenure_months | −0.1531 |
| visits | tenure_months | −0.0793 |
| age | signup | −0.0666 |
| annual income | signup | −0.0486 |
| tenure_months | signup | −0.1531 |
| signup | signup | 0 |
| visits | signup | −0.0522 |
| age | visits | −0.0917 |
| annual income | visits | 0.2082 |
| tenure_months | visits | −0.0793 |
| signup | visits | −0.0522 |
| visits | visits | 0 |
The loss can't reach 0: many noise–row pairs cross the same point with different velocities, so it levels off.
View data
| Part | Mean squared velocity error | Epoch |
|---|---|---|
| training rows | 1.919 | 1 |
| training rows | 1.815 | 2 |
| training rows | 1.818 | 3 |
| training rows | 1.855 | 4 |
| training rows | 1.818 | 5 |
| training rows | 1.672 | 6 |
| training rows | 1.600 | 7 |
| training rows | 1.615 | 8 |
| training rows | 1.616 | 9 |
| training rows | 1.577 | 10 |
| training rows | 1.529 | 11 |
| training rows | 1.605 | 12 |
| training rows | 1.550 | 13 |
| training rows | 1.651 | 14 |
| training rows | 1.618 | 15 |
| training rows | 1.535 | 16 |
| training rows | 1.555 | 17 |
| training rows | 1.525 | 18 |
| training rows | 1.568 | 19 |
| training rows | 1.546 | 20 |
Assumptions
- Enough rows for a neural generator — 293 complete training rows — neural generators have many weights to learn and can memorize small tables; compare with the copula or sequential trees.
- Training stayed finite — The velocity loss over the last 10% of epochs averaged 1.56.
- No synthetic row copies a training row — 0 synthetic rows are identical to a training row; the scorecard's distance to closest record checks near-copies.
- Synthetic columns match the data — Distance from the training rows: numeric columns 0.049 (mean Kolmogorov–Smirnov distance); categories 0.093 (mean total variation) — at most 0.10, which the Synthetic studio's scorecard rates as good column fidelity.
Real vs synthetic, column by column
| Column | Kind | Real | Synthetic | Distance | Measure |
|---|---|---|---|---|---|
| age | numeric | 43.14 ± 13.1 | 42.62 ± 14.7 | 0.0563 | Kolmogorov–Smirnov D |
| annual income | numeric | 2.929e+04 ± 1.43e+04 | 2.988e+04 ± 1.44e+04 | 0.0429 | Kolmogorov–Smirnov D |
| tenure_months | numeric | 15 ± 10.7 | 15.71 ± 11.3 | 0.0656 | Kolmogorov–Smirnov D |
| plan | categorical | plus 39.7% | plus 33.4% | 0.0625 | total variation |
| region | categorical | south 30.4% | south 24.3% | 0.1128 | total variation |
| churned | boolean | false 76.9% | false 66.6% | 0.1031 | total variation |
| signup | temporal | 2020-11-05 ± 621 days | 2020-10-17 ± 602 days | 0.0375 | Kolmogorov–Smirnov D |
| visits | numeric | 3.394 ± 2.09 | 3.503 ± 1.98 | 0.0437 | Kolmogorov–Smirnov D |
- 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.
The exact R script · R R version 4.5.1 (2025-06-13)
# Synthetic data — flow matching
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.flow_matching 1.0.1 · spec 63f9d71e9f455a9a
# Dataset: g1_customers (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
COLUMNS <- c("age", "annual income", "tenure_months", "plan", "region", "churned", "signup", "visits")
KINDS <- list(
age = "numeric",
`annual income` = "numeric",
tenure_months = "numeric",
plan = "categorical",
region = "categorical",
churned = "boolean",
signup = "temporal",
visits = "numeric"
)
LEVELS <- list(
plan = c("basic", "plus", "premium"),
region = c("east", "north", "south", "west")
)
SEED <- 42
loaded <- cs_synth_load("tests/parity/fixtures/g1_customers.parquet", COLUMNS, KINDS, LEVELS)
cols <- loaded$cols; n_input <- loaded$n
for (c in cols) if (c$kind == "numeric") cs_check_finite(c$values, c$name) # infinite values stop the run (registry/errors.yaml)
rng <- cs_rng(SEED) # shared stream: the same holdout and the same synthetic rows in Python and R
sp <- cs_synth_split(n_input, 0.2, rng)
train_rows <- sp$train; holdout_rows <- sp$holdout
train <- lapply(cols, cs_synth_take, rows = train_rows)
N_OUT <- length(train_rows)
warnings <- list()
fit_values <- list()
extra_tables <- list()
extra_charts <- list()
assumptions <- list()
model_note <- ""
if (length(holdout_rows)) {
warnings <- c(warnings, sprintf("%s of %s rows (%.0f%%) were held out of training so privacy and utility can be checked against rows the generator never saw.",
format(length(holdout_rows), big.mark = ","), format(n_input, big.mark = ","), 100 * length(holdout_rows) / n_input))
}
for (c in train) if (mean(cs_synth_missing(c)) == 1) cs_error("CS_E_ALL_MISSING", column = c$name) # no values in the training rows
n_complete <- length(cs_synth_complete(train))
assumptions[[1]] <- list(
key = "enough_rows", label = "Enough rows for a neural generator",
status = if (n_complete >= 1000) "pass" else "warn",
detail = paste0(sprintf("%s complete training rows", format(n_complete, big.mark = ",")),
if (n_complete >= 1000) "." else " — neural generators have many weights to learn and can memorize small tables; compare with the copula or sequential trees.")
)
# %% Generate
# Training options, live progress and checkpoints (twin: codesplash.deep.trainer.configure).
cs_deep_trainer_configure(list(
dp_epsilon = NULL,
dp_noise_multiplier = NULL,
dp_max_grad_norm = 1,
dp_delta = NULL,
dp_sampling = "poisson",
optimizer = "default",
lr_schedule = "none",
warmup_epochs = 0,
grad_clip = 0,
ema_decay = 0,
swa_start = 0,
history_every_step = FALSE,
profile = "parity",
checkpoint_every = NULL
), out_dir = "target/academy-parity/run-8142/synth.flow_matching/customers_rk4/out-r")
# A velocity network learns to carry N(0, I) noise along straight lines to the rows (normal scores of numbers,
# one-hot categories); new rows follow it from t = 0 to 1 in 8 rk4 steps.
# Twin of codesplash.synth.flows.fit_flow_matching (written from the papers).
HIDDEN <- as.integer(unlist(c(32, 32)))
fit <- cs_synth_flow_matching(
train, N_OUT, HIDDEN,
epochs = as.integer(20),
batch_size = 100,
lr = 0.001,
time_dim = as.integer(16),
steps = as.integer(8),
sampler = "rk4",
seed = SEED
)
synth <- fit$cols
hist <- fit$history
history <- data.frame(
epoch = vapply(hist, function(h) as.numeric(h$epoch), numeric(1)),
loss = vapply(hist, function(h) h$loss, numeric(1))
)
last <- max(1L, nrow(history) %/% 10L) # the last 10% of epochs
tail_rows <- (nrow(history) - last + 1L):nrow(history)
fit_values$batch_size <- fit$facts$batch_size
fit_values$final_loss <- mean(history$loss[tail_rows])
fit_values$steps <- fit$facts$steps
fit_values$evaluations <- fit$facts$evaluations
model_note <- " with flow matching"
ne <- nrow(history)
extra_charts[[length(extra_charts) + 1L]] <- cs_chart("training", "training-components", "Velocity loss by epoch", list(
x = cs_col("Epoch", history$epoch, "numeric"),
value = cs_col("Mean squared velocity error", history$loss, "numeric"),
component = cs_col("Part", rep("training rows", ne), "categorical", levels = c("training rows"))
), note = "The loss can't reach 0: many noise–row pairs cross the same point with different velocities, so it levels off.")
finite <- all(is.finite(history$loss))
assumptions[[length(assumptions) + 1L]] <- list(
key = "training_stable", label = "Training stayed finite",
status = if (finite) "pass" else "fail",
detail = if (finite) sprintf("The velocity loss over the last 10%% of epochs averaged %s.", format(signif(fit_values$final_loss, 3)))
else "The loss became infinite or undefined; lower the learning rate."
)
synth <- cs_synth_add_missing(synth, train, rng, "keep_rate") # each column's missing share, at random
# %% Write and compare
out <- cs_ml_out_dir("target/academy-parity/run-8142/synth.flow_matching/customers_rk4/out-r")
path <- cs_synth_write(file.path(out, "synthetic.parquet"), synth)
split <- cs_synth_write_split(file.path(out, "split.parquet"), n_input, train_rows, holdout_rows)
nanoparquet::write_parquet(history, file.path(out, "history.parquet"))
sm <- cs_synth_summarize(train, synth, length(train_rows), n_input, length(holdout_rows), fit_values)
values <- sm$values
assumptions[[length(assumptions) + 1L]] <- list(
key = "no_copies", label = "No synthetic row copies a training row",
status = if (values$exact_matches == 0) "pass" else "warn",
detail = sprintf("%s synthetic row%s identical to a training row; the scorecard's distance to closest record checks near-copies.",
format(values$exact_matches, big.mark = ","), if (values$exact_matches != 1) "s are" else " is")
)
# Fidelity (Stage 12.10): judged on the mean column distances, the scorecard's column fidelity (good at >= 0.9 = 1 - 0.1).
fid_d <- numeric(); fid_t <- character()
if (!is.nan(values$fidelity_ks_mean)) {
fid_d <- c(fid_d, values$fidelity_ks_mean)
fid_t <- c(fid_t, sprintf("numeric columns %.3f (mean Kolmogorov–Smirnov distance)", values$fidelity_ks_mean))
}
if (!is.nan(values$fidelity_tv_mean)) {
fid_d <- c(fid_d, values$fidelity_tv_mean)
fid_t <- c(fid_t, sprintf("categories %.3f (mean total variation)", values$fidelity_tv_mean))
}
assumptions[[length(assumptions) + 1L]] <- if (!length(fid_d)) {
list(key = "fidelity", label = "Synthetic columns match the data", status = "info",
detail = "No column could be compared with the data.")
} else {
list(key = "fidelity", label = "Synthetic columns match the data",
status = if (max(fid_d) <= 0.1) "pass" else "warn",
detail = paste0("Distance from the training rows: ", paste(fid_t, collapse = "; "),
if (max(fid_d) <= 0.1) " — at most 0.10, which the Synthetic studio's scorecard rates as good column fidelity."
else " — above 0.10, so some columns' distributions differ visibly from the data; the scorecard shows which columns and pairs."))
}
summary <- sprintf("%s synthetic rows over %d column%s from %s training rows%s.",
format(values$n_rows, big.mark = ","), length(COLUMNS), if (length(COLUMNS) != 1) "s" else "",
format(length(train_rows), big.mark = ","), model_note)
if (!is.nan(values$fidelity_ks_mean)) {
summary <- paste0(summary, sprintf(" Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of %.3f", values$fidelity_ks_mean),
if (!is.nan(values$fidelity_tv_mean)) sprintf(" and categories by a mean total variation of %.3f.", values$fidelity_tv_mean) else ".")
} else if (!is.nan(values$fidelity_tv_mean)) {
summary <- paste0(summary, sprintf(" Categories differ from the data by a mean total variation of %.3f.", values$fidelity_tv_mean))
}
if (values$exact_matches > 0) {
summary <- paste0(summary, sprintf(" %s synthetic row%s identical to a training row.", format(values$exact_matches, big.mark = ","),
if (values$exact_matches != 1) "s are" else " is"))
}
cs_publish(list(
title = "Synthetic data — flow matching",
engine = cs_engine_info("torch", "nanoparquet", "codesplashr", "nanoparquet"),
n = values$n_real, summary = summary,
statistics = list(
list(key = "n_rows", label = "Synthetic rows", value = values$n_rows, format = "integer"),
list(key = "fidelity_ks_mean", label = "Mean KS distance", value = values$fidelity_ks_mean),
list(key = "fidelity_tv_mean", label = "Mean TV distance", value = values$fidelity_tv_mean),
list(key = "exact_matches", label = "Rows copied from the data", value = values$exact_matches, format = "integer")),
tables = c(list(sm$table), extra_tables),
values = values, charts = c(sm$charts, extra_charts), assumptions = assumptions, warnings = warnings,
artifacts = list(list(key = "synthetic", path = path, format = "parquet", title = "Synthetic rows"),
list(key = "split", path = split, format = "parquet", title = "Training and holdout rows"),
list(key = "history", path = file.path(out, "history.parquet"), format = "parquet", title = "Training history")),
model = list(kind = "generator", columns = I(COLUMNS), params = list(
n_rows = NULL,
hidden_layers = c(32, 32),
epochs = 20,
batch_size = 100,
learning_rate = 0.001,
time_dim = 16,
sampler = "rk4",
steps = 8,
missing = "keep_rate",
holdout = 0.2,
dp_epsilon = NULL,
dp_noise_multiplier = NULL,
dp_max_grad_norm = 1,
dp_delta = NULL,
dp_sampling = "poisson",
optimizer = "default",
lr_schedule = "none",
warmup_epochs = 0,
grad_clip = 0,
ema_decay = 0,
swa_start = 0,
history_every_step = FALSE,
profile = "parity",
checkpoint_every = NULL
))
))
320 synthetic rows over 8 columns from 320 training rows with flow matching. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.049 and categories by a mean total variation of 0.093.
- Synthetic rows
- 320
- Mean KS distance
- 0.0492
- Mean TV distance
- 0.0928
- Rows copied from the data
- 0
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Enough rows for a neural generator — 293 complete training rows — neural generators have many weights to learn and can memorize small tables; compare with the copula or sequential trees.
- Training stayed finite — The velocity loss over the last 10% of epochs averaged 1.56.
- No synthetic row copies a training row — 0 synthetic rows are identical to a training row; the scorecard's distance to closest record checks near-copies.
- Synthetic columns match the data — Distance from the training rows: numeric columns 0.049 (mean Kolmogorov–Smirnov distance); categories 0.093 (mean total variation) — at most 0.10, which the Synthetic studio's scorecard rates as good column fidelity.
Real vs synthetic, column by column
| Column | Kind | Real | Synthetic | Distance | Measure |
|---|---|---|---|---|---|
| age | numeric | 43.14 ± 13.1 | 42.62 ± 14.7 | 0.0562 | Kolmogorov–Smirnov D |
| annual income | numeric | 2.929e+04 ± 1.43e+04 | 2.988e+04 ± 1.44e+04 | 0.0429 | Kolmogorov–Smirnov D |
| tenure_months | numeric | 15 ± 10.7 | 15.71 ± 11.3 | 0.0656 | Kolmogorov–Smirnov D |
| plan | categorical | plus 39.7% | plus 33.4% | 0.0625 | total variation |
| region | categorical | south 30.4% | south 24.3% | 0.1128 | total variation |
| churned | boolean | false 76.9% | false 66.6% | 0.1031 | total variation |
| signup | temporal | 2020-11-05 ± 621 days | 2020-10-17 ± 602 days | 0.0375 | Kolmogorov–Smirnov D |
| visits | numeric | 3.394 ± 2.09 | 3.503 ± 1.98 | 0.0438 | Kolmogorov–Smirnov D |
- 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Synthetic data — flow matching
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.flow_matching 1.0.1 · spec 63f9d71e9f455a9a
# Dataset: g1_customers (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.errors import check_finite
from codesplash.ml.run import out_dir
from codesplash.stats.rng import Rng
from codesplash.synth import common as sy
from codesplash.synth import flows # twin of codesplashr::cs_synth_flow_matching (written from the papers)
# %% Data
COLUMNS = ["age", "annual income", "tenure_months", "plan", "region", "churned", "signup", "visits"]
KINDS = {
"age": "numeric",
"annual income": "numeric",
"tenure_months": "numeric",
"plan": "categorical",
"region": "categorical",
"churned": "boolean",
"signup": "temporal",
"visits": "numeric",
}
LEVELS = {
"plan": ["basic", "plus", "premium"],
"region": ["east", "north", "south", "west"],
}
SEED = 42
cols, n_input = sy.load("tests/parity/fixtures/g1_customers.parquet", COLUMNS, KINDS, LEVELS)
for c in cols:
if c.kind == "numeric":
check_finite(c.values, c.name) # infinite values stop the run (registry/errors.yaml)
rng = Rng(SEED) # shared stream: the same holdout and the same synthetic rows in Python and R
train_rows, holdout_rows = sy.split_holdout(n_input, 0.2, rng)
train = [c.take(train_rows) for c in cols]
N_OUT = None or len(train_rows)
warnings = []
fit_values = {}
extra_tables = []
extra_charts = []
assumptions = []
model_note = ""
if len(holdout_rows):
warnings.append(f"{len(holdout_rows):,} of {n_input:,} rows ({len(holdout_rows) / n_input:.0%}) were held out of training so privacy and utility can be checked against rows the generator never saw.")
for c in train:
share = float(np.mean(c.missing()))
if share == 1.0:
cs.cs_error("CS_E_ALL_MISSING", column=c.name) # no values in the training rows
n_complete = len(sy.complete_rows(train))
assumptions.append({
"key": "enough_rows",
"label": "Enough rows for a neural generator",
"status": "pass" if n_complete >= 1000 else "warn",
"detail": f"{n_complete:,} complete training rows"
+ ("." if n_complete >= 1000 else " — neural generators have many weights to learn and can memorize small tables; compare with the copula or sequential trees."),
})
# %% Generate
from codesplash.deep import trainer as deep_trainer # training options, live progress, checkpoints (twin: cs_deep_trainer_*)
deep_trainer.configure(
{
"dp_epsilon": None,
"dp_noise_multiplier": None,
"dp_max_grad_norm": 1,
"dp_delta": None,
"dp_sampling": "poisson",
"optimizer": "default",
"lr_schedule": "none",
"warmup_epochs": 0,
"grad_clip": 0,
"ema_decay": 0,
"swa_start": 0,
"history_every_step": False,
"profile": "parity",
"checkpoint_every": None,
},
out_dir="target/academy-parity/run-8142/synth.flow_matching/customers_rk4/out-python",
)
# A velocity network learns to carry N(0, I) noise along straight lines to the rows (normal scores of numbers,
# one-hot categories); new rows follow it from t = 0 to 1 in 8 rk4 steps.
HIDDEN = [int(u) for u in [32, 32]]
synth, facts, hist = flows.fit_flow_matching(
train, N_OUT, HIDDEN,
epochs=20,
batch_size=100,
lr=0.001,
time_dim=16,
steps=8,
sampler="rk4",
seed=SEED,
)
history = pd.DataFrame(hist)
last = max(1, len(hist) // 10) # the last 10% of epochs
fit_values["batch_size"] = facts["batch_size"]
fit_values["final_loss"] = float(np.mean([h["loss"] for h in hist[-last:]]))
fit_values["steps"] = facts["steps"]
fit_values["evaluations"] = facts["evaluations"]
model_note = " with flow matching"
ep = history["epoch"].tolist()
extra_charts.append(cs.chart("training", "training-components", "Velocity loss by epoch", {
"x": cs.col("Epoch", ep, "numeric"),
"value": cs.col("Mean squared velocity error", history["loss"].tolist(), "numeric"),
"component": cs.col("Part", ["training rows"] * len(ep), "categorical", levels=["training rows"]),
}, note="The loss can't reach 0: many noise–row pairs cross the same point with different velocities, so it levels off."))
finite = bool(np.all(np.isfinite(history["loss"].to_numpy())))
assumptions.append({
"key": "training_stable",
"label": "Training stayed finite",
"status": "pass" if finite else "fail",
"detail": f"The velocity loss over the last 10% of epochs averaged {fit_values['final_loss']:.3g}." if finite else "The loss became infinite or undefined; lower the learning rate.",
})
sy.add_missing(synth, train, rng, "keep_rate") # each column's missing share, at random
# %% Write and compare
out = out_dir("target/academy-parity/run-8142/synth.flow_matching/customers_rk4/out-python")
path = sy.write(os.path.join(out, "synthetic.parquet"), synth)
split = sy.write_split(os.path.join(out, "split.parquet"), n_input, train_rows, holdout_rows)
history.to_parquet(os.path.join(out, "history.parquet"), index=False)
values, table, charts = sy.summarize(train, synth, len(train_rows), n_input, len(holdout_rows), fit_values)
assumptions.append({
"key": "no_copies",
"label": "No synthetic row copies a training row",
"status": "pass" if values["exact_matches"] == 0 else "warn",
"detail": f"{values['exact_matches']:,} synthetic row{'s are' if values['exact_matches'] != 1 else ' is'} identical to a training row; the scorecard's distance to closest record checks near-copies.",
})
# Fidelity (Stage 12.10): judged on the mean column distances, the scorecard's column fidelity (good at ≥ 0.9 = 1 − 0.1).
fid_parts = []
if not np.isnan(values["fidelity_ks_mean"]):
fid_parts.append((values["fidelity_ks_mean"], f"numeric columns {values['fidelity_ks_mean']:.3f} (mean Kolmogorov–Smirnov distance)"))
if not np.isnan(values["fidelity_tv_mean"]):
fid_parts.append((values["fidelity_tv_mean"], f"categories {values['fidelity_tv_mean']:.3f} (mean total variation)"))
fid_worst = max((d for d, _ in fid_parts), default=None)
assumptions.append({
"key": "fidelity",
"label": "Synthetic columns match the data",
"status": "info" if fid_worst is None else ("pass" if fid_worst <= 0.1 else "warn"),
"detail": "No column could be compared with the data." if fid_worst is None else
"Distance from the training rows: " + "; ".join(t for _, t in fid_parts)
+ (" — at most 0.10, which the Synthetic studio's scorecard rates as good column fidelity." if fid_worst <= 0.1 else
" — above 0.10, so some columns' distributions differ visibly from the data; the scorecard shows which columns and pairs."),
})
summary = (
f"{values['n_rows']:,} synthetic rows over {len(COLUMNS)} column{'s' if len(COLUMNS) != 1 else ''} from "
f"{len(train_rows):,} training rows{model_note}."
)
if not np.isnan(values["fidelity_ks_mean"]):
summary += f" Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of {values['fidelity_ks_mean']:.3f}"
summary += f" and categories by a mean total variation of {values['fidelity_tv_mean']:.3f}." if not np.isnan(values["fidelity_tv_mean"]) else "."
elif not np.isnan(values["fidelity_tv_mean"]):
summary += f" Categories differ from the data by a mean total variation of {values['fidelity_tv_mean']:.3f}."
if values["exact_matches"]:
summary += f" {values['exact_matches']:,} synthetic row{'s are' if values['exact_matches'] != 1 else ' is'} identical to a training row."
cs.publish({
"title": "Synthetic data — flow matching",
"engine": cs.engine_info("torch", "scipy", "pyarrow", "codesplash", "numpy", "pyarrow"),
"n": values["n_real"],
"summary": summary,
"statistics": [
{"key": "n_rows", "label": "Synthetic rows", "value": values["n_rows"], "format": "integer"},
{"key": "fidelity_ks_mean", "label": "Mean KS distance", "value": values.get("fidelity_ks_mean")},
{"key": "fidelity_tv_mean", "label": "Mean TV distance", "value": values.get("fidelity_tv_mean")},
{"key": "exact_matches", "label": "Rows copied from the data", "value": values["exact_matches"], "format": "integer"},
],
"tables": [table, *extra_tables],
"values": values,
"charts": charts + extra_charts,
"assumptions": assumptions,
"warnings": warnings,
"artifacts": [
{"key": "synthetic", "path": path, "format": "parquet", "title": "Synthetic rows"},
{"key": "split", "path": split, "format": "parquet", "title": "Training and holdout rows"},
{"key": "history", "path": os.path.join(out, "history.parquet"), "format": "parquet", "title": "Training history"},
],
"model": {"kind": "generator", "columns": COLUMNS, "params": {
"n_rows": None,
"hidden_layers": [32, 32],
"epochs": 20,
"batch_size": 100,
"learning_rate": 0.001,
"time_dim": 16,
"sampler": "rk4",
"steps": 8,
"missing": "keep_rate",
"holdout": 0.2,
"dp_epsilon": None,
"dp_noise_multiplier": None,
"dp_max_grad_norm": 1,
"dp_delta": None,
"dp_sampling": "poisson",
"optimizer": "default",
"lr_schedule": "none",
"warmup_epochs": 0,
"grad_clip": 0,
"ema_decay": 0,
"swa_start": 0,
"history_every_step": False,
"profile": "parity",
"checkpoint_every": None,
}},
})
Flow matching 0.049, TVAE 0.107, diffusion 0.136, GAN 0.179.
Now the mean absolute gap between real and synthetic correlations: diffusion 0.067, flow matching 0.173, TVAE 0.196, GAN 0.217. The ranking changes with the question.
Fidelity, diversity and privacy pull apart
ExploreA generator that copies training rows scores perfectly on fidelity and terribly on privacy. Raise the noise added to copies below and watch fidelity and the privacy ratio move against each other.
DExplorable · Synthetic data: fidelity against privacy
Can synthetic data look like the real thing without copying it?
A ratio near 1 means synthetic rows sit about as far from the training data as new real rows do. What will this generator's ratio be?
How it's generated
Used by “Copy rows and add noise”.
- Real (training)
- Synthetic
- Privacy ratio
- Largest column KS × 4
Commit your prediction above to see the result
Make your prediction to see the result.
What runs here
ReadCheck: scoring generators
CheckpointCheck yourself
Two papers report FID for their generators. When can you compare the numbers?
Show the answer
Answer: b
FID depends on the feature extractor, resizing and sample size (it is biased upward for small samples). Different protocols give incomparable numbers.
Check yourself
What does FID compare?
Show the answer
Answer: a
It is the Fréchet distance between two Gaussians in feature space. It doesn't separate fidelity from diversity.
Check yourself
A KID estimate comes out slightly below zero. What does that mean?
Show the answer
Answer: b
Unbiasedness means the estimate is right on average, which requires it to fall on both sides of a small true value. Report the spread over subsets.
Check yourself
Why might you prefer KID to FID when you only have a few hundred images?
Show the answer
Answer: a
FID shrinks as the sample grows, so small-sample comparisons can mislead. KID doesn't have that bias, though it is noisy.
Check yourself
What does the Inception Score compare generated images with?
Show the answer
Answer: b
IS rewards confident, varied labels. Because it never sees real data, it can't tell whether samples resemble your dataset.
Check yourself
For a classifier with 10 classes, what is the highest possible Inception Score?
Show the answer
Answer: b
The maximum is reached when every image gets one class with certainty and the classes are equally common: exp(log 10) = 10.
Check yourself
A generator has high precision and low coverage. What is the likeliest problem?
Show the answer
Answer: a
Precision asks whether samples look real; coverage asks whether every kind of real data is reached. High and low means realistic but narrow.
Check yourself
What decides how strict generative precision and coverage are?
Show the answer
Answer: b
Larger k gives larger balls and more lenient scores; a different feature space changes what counts as close. Report both choices.
Recap
Recap- Image scores compare features from a fixed network; they are comparable only under one protocol.
- FID compares Gaussian fits and is biased for small samples; KID is unbiased and can dip below zero; IS ignores real data.
- Precision measures realism, recall and coverage measure reach; mode collapse is high precision, low coverage.
- For tables, read the whole scorecard: different metrics rank generators differently.
Concepts in this lesson