Skip to content

Robustness, label quality, and active data acquisition · Robustness, label quality, and active data acquisition · ROB003 · Algorithm

Randomized smoothing certification

Construct a smoothed classifier by voting over Gaussian-noised copies of an input and, under the stated conditions, certify an L2 radius within which its predicted class remains unchanged.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's run and the reference's record

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 run and the reference's record
CodeSplash's run
Verified in Python and R through explain.certify. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Construct a smoothed classifier by voting over Gaussian-noised copies of an input and, under the stated conditions, certify an L2 radius within which its predicted class remains unchanged.

Question / hypotheses

For this fixed input and base classifier, is the smoothed decision provably invariant within a radius with a specified Monte Carlo confidence level? Certification is distinct from empirical attack accuracy.

Architecture / computational structure

A base classifier is wrapped in a Gaussian perturbation sampler and vote aggregator. Separate pilot samples select a candidate class; independent certification samples estimate its probability. A lower confidence bound determines a radius or an abstention.

Assumptions

Noise is independent isotropic Gaussian with the declared σ. Certification draws are independent and the base classifier/selection protocol is fixed. Probability-bound coverage is essential; plugging an uncorrected empirical fraction into the theorem does not create a confidence guarantee.

Formula / computational definition

g(x)=arg⁡max⁡cPr⁡{f(x+ε)=c},ε∼N(0,σ2I),R=σ2[Φ−1(p‾A)−Φ−1(p‾B)].p‾B=1−p‾A⇒R=σΦ−1(p‾A).g(x)=\arg\max_c\Pr\{f(x+\varepsilon)=c\},\quad\varepsilon\sim N(0,\sigma^2I),\quad R=\tfrac{\sigma}{2}[\Phi^{-1}(\underline p_A)-\Phi^{-1}(\overline p_B)].\quad \overline p_B=1-\underline p_A\Rightarrow R=\sigma\Phi^{-1}(\underline p_A).

Parameters and notation

Learned: base classifier weights, usually trained for noise tolerance. Inference choices: σ, independent pilot/certification sample counts, confidence error α, and desired radius. Class counts and confidence bounds are estimates, not network parameters. Larger σ can improve radius while harming clean accuracy.

Fitting, fine-tuning, and adaptation

Noise-aware training can improve usefulness, but the certificate refers to the exact deployed base classifier and noise distribution. Recompute after fine-tuning, quantization, or preprocessing changes. Training-time augmentation does not remove the need for inference-time certification.

How to use and calibrate

Report certified accuracy versus radius and the abstention rate with sample budget and runtime. When certifying many cases, clarify whether confidence is per case or simultaneous; use appropriate multiplicity control for a simultaneous statement.

Example application

Given 900 votes out of 1000 for a class selected by an independent pilot, calculate a one-sided binomial lower bound and a conservative Gaussian smoothing radius.

Interpretation / pitfalls

Watch out

The guarantee concerns the smoothed classifier and the stated L2 threat set, not all semantic corruptions or every base-classifier prediction. Sampling can be expensive. Abstention is a valid output, not a zero-confidence guess.

Python and R code examples

Scope: Complete confidence-bound/radius calculation from supplied votes; no classifier training or image sampling. Python: SciPy. R: stats.

Validation: Python executed successfully on the supplied fixture; R reviewed but not executed.

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 — Complete confidence-bound/radius calculation from supplied votes; no classifier training or image sampling. · needs scipy

from scipy.stats import beta,norm
n,k,sigma,alpha=1000,900,.25,.001
lower=beta.ppf(alpha,k,n-k+1) if k else 0.
radius=sigma*norm.ppf(lower) if lower>.5 else 0.
print({"lower_p":float(lower),"radius":float(radius),"abstain":lower<=.5})
assert 0<lower<k/n and radius>0
R

Component demo, not a trained model — Complete confidence-bound/radius calculation from supplied votes; no classifier training or image sampling.

n <- 1000; k <- 900; sigma <- .25; alpha <- .001
lower <- if (k>0) qbeta(alpha,k,n-k+1) else 0
radius <- if (lower>.5) sigma*qnorm(lower) else 0
print(list(lower_p=lower,radius=radius,abstain=lower<=.5))
stopifnot(lower>0,lower<k/n,radius>0)

Sources

From the CodeSplash reference, entry ROB003.