calibrate_closeness: Calibrate the closeness of synthetic to real data

View source: R/closeness.R

calibrate_closenessR Documentation

Calibrate the closeness of synthetic to real data

Description

Finds the value of closeness (see generate()) for which synthetic data reach a target value of a distance metric. The metric is evaluated on a grid of closeness values with common random numbers, the grid interval containing the target is located, and the solution is refined by bisection, followed by a final linear interpolation step. Metric values are themselves estimates, so the achieved value varies somewhat with the random seed.

Available metrics (all computed against data, which should be the data the synthesizer was fitted on):

  • "auc" – cross-validated discriminator AUC (discriminator_auc()); 0.5 means indistinguishable, larger values mean more distant;

  • "dcr" – median distance to the closest real record relative to the real-to-real nearest-neighbour distance (dcr()); larger means further from real records;

  • "pmse" – pMSE ratio (pmse()) with the quadratic propensity model;

  • "marginal" – mean marginal distance (KS / TVD, marginal_metrics());

  • a function ⁠function(real, synthetic)⁠ returning a single number, for any other criterion, e.g. a disclosure-risk measure from disclosure_risk().

Usage

calibrate_closeness(
  object,
  data,
  target,
  metric = c("auc", "dcr", "pmse", "marginal"),
  n = NULL,
  grid = seq(0, 1, by = 0.1),
  refine = 4L,
  max_rows = 2000L,
  seed = 1,
  ...
)

Arguments

object

A fitted sp_synthesizer.

data

The real data the synthesizer was fitted on.

target

Target value of the metric.

metric

One of "auc", "dcr", "pmse", "marginal", or a function ⁠function(real, synthetic)⁠ returning a number.

n

Number of synthetic records generated per evaluation (default: size of data).

grid

Closeness values evaluated first.

refine

Number of bisection steps after the grid search.

max_rows

Maximum rows used by the metric computations.

seed

Random seed (the same seed is used at every closeness value).

...

Passed to generate() (e.g. perturb for directional perturbations kept fixed during calibration).

Value

An object of class sp_calibration with elements closeness (the calibrated value), achieved (metric value at that closeness), target, metric and path (all evaluations). It has print() and plot() methods.

Examples

fit <- fit_synthesizer(iris)
cal <- calibrate_closeness(fit, iris, target = 0.75, metric = "auc",
                           grid = seq(0, 1, 0.25), refine = 2)
cal
syn <- generate(fit, closeness = cal$closeness, seed = 1)

SynthesizerPlus documentation built on Oct. 16, 2026, 5:10 p.m.