Skip to content

Sequences, streaming data, robotics, and scientific extensions · Entry index · SEQ002 · Model

CSDI: conditional score-based diffusion imputation

A conditional diffusion approach producing distributions for missing values in multivariate time series. It trains using observed/context masks and target masks, allowing several plausible imputations instead of one…

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's own run

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
Verified in Python and R through missing.csdi. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, but on a different version of the code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

A conditional diffusion approach producing distributions for missing values in multivariate time series. It trains using observed/context masks and target masks, allowing several plausible imputations instead of one deterministic fill. Imputation and forecasting are distinct uses of the conditioning design.

Question / hypotheses

What values are plausible at missing positions given the observations legitimately available for this task? There is no inherent null test; evaluation concerns conditional accuracy, uncertainty, and sensitivity to missing-data mechanisms.

Architecture / computational structure

A conditional denoising network integrates time and feature information while distinguishing observed context from targets. Multiple reverse-process samples approximate the missing-value distribution. Replacing unknown values with zeros without an explicit mask confuses true zeros with missingness.

Assumptions

The conditioning mask must reflect the intended information boundary. Retrospective imputation can use later observations, while online forecasts cannot. Artificial masking during training may not match informative real missingness, and conditioning on observed values does not make a missing-not-at-random mechanism ignorable.

Formula / computational definition

A core masked objective is L=E[∑i∈Mtarget(ϵi−ϵθ(xt,t,xobs,Mobs)i)2/∣Mtarget∣]\mathcal L=\mathbb E[\sum_{i\in M_{target}}(\epsilon_i-\epsilon_\theta(x_t,t,x_{obs},M_{obs})_i)^2/|M_{target}|]. The conditioning set MobsM_{obs} and prediction set MtargetM_{target} are disjoint; observed values and masks guide reverse diffusion.

Parameters and notation

Learned parameters: conditional score network, temporal/feature embeddings, and conditioning projections. Hyperparameters: training mask distribution, noise schedule, diffusion steps, context window, sampling count, and target-loss normalization. Mask construction changes the statistical task more fundamentally than a small optimizer adjustment.

Fitting, fine-tuning, and adaptation

Train and validate with realistic block/channel/point missingness patterns, not only random individual entries. Fine-tune conditional layers or the full score network while retaining feature scaling and masking conventions. Keep any validation targets out of the conditioning tensor, including through normalization or interpolation preprocessing.

How to use and calibrate

Compare imputation error, distributional scores, empirical interval coverage, and cross-channel dependence over missingness patterns. Evaluate forecasting separately with strictly past-only conditions. Report masking rules, retained observations, and reconstruction uncertainty rather than presenting completed data as known truth.

Example application

Hide contiguous sections of correlated sensor traces and compare conditional samples with isolated-point masking to reveal the harder extrapolation problem.

Interpretation / pitfalls

Watch out

Python: the authors’ CSDI implementation or a faithful custom score model. R: reticulate for training/inference and native evaluation. The example illustrates masking of denoising error; it is not a learned imputer and does not justify a missing-data assumption.

Python and R code examples (dependencies/validation)

Python uses NumPy and the shared mse helper when called; base R uses the shared helper when called. Validation: Python component executed; R companion reviewed, not executed. Scope: the specific component described above, not the full model or its training.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
import numpy as np

def mse(a,b):
    a,b=np.asarray(a),np.asarray(b)
    if a.shape!=b.shape or a.size==0:
        raise ValueError("MSE needs nonempty equal shapes")
    return float(np.mean((a-b)**2))
noise=np.array([[.2,-.4],[.1,.3]]); predicted=.8*noise
target_mask=np.array([[False,True],[True,False]])
result=mse(predicted[target_mask],noise[target_mask])
print(result)
R

Component demo, not a trained model — synthetic mathematical component, not a full-model implementation

Shared setup for this chapter
mse <- function(a,b) {
  stopifnot(length(a)>0L, identical(dim(a),dim(b)), length(a)==length(b))
  mean((a-b)^2)
}
noise <- rbind(c(.2,-.4),c(.1,.3)); predicted <- .8*noise
target_mask <- rbind(c(FALSE,TRUE),c(TRUE,FALSE))
result <- mse(predicted[target_mask],noise[target_mask])
print(result)

Sources

From the CodeSplash reference, entry SEQ002.