Guide 05 · Counterfactual
Ask what bounded change reaches another class.
Select the destination class and constrain the search so the result answers a precise question.
Run the search
vraven counterfactual model.pt \
--model-format state_dict \
--factory my_project.models:Classifier \
--input input.npy \
--sample-index 0 \
--target-class 2 \
--steps 200 \
--max-linf 0.05 \
--clamp-min 0 \
--clamp-max 1 \
--output counterfactual.json
Read the result
Check whether the target class was reached, the final perturbation size, the score change and the largest changed input coordinates. A failed bounded search means no candidate was found by this procedure—not that none exists.
Use the correct validity claim
Model validity is not domain validity.A candidate can change the model prediction while being impossible or inappropriate in the real domain. Apply a domain validator before calling it realistic.
For the simpler bundle workflow:
vraven analyse ./my-model \
--task counterfactual \
--target-class 2 \
--preset thorough \
--output counterfactual.json