# CAD/process conditional-diffusion diagnostic

This experiment generates CAD-correspondent deformed point clouds from prepared
CAD representations and XLS process conditions. It is a weak-label diagnostic,
not a validated production model: both supplied runs are NG with one observed
type (`찍힘`), paired registration and defect extent are unvalidated, and the
heater-to-CAD projection validity mask is false.

## Directory map

- `processed_inputs/` — per-variant conditioned arrays (`.npz`), provenance
  (`.json`), and real prepared-representation/condition previews (`.png`).
- `models/` — topology-aware diffusion source and diagnostic checkpoints.
- `outputs/` — the gallery, architecture, loss curves, generated point clouds,
  comparisons, and full metric report.
- `feature_attributions/` — local risk-gradient diagnostic plots and JSON files
  retaining the original Korean XLS feature names. These are not causal process
  attributions.

Open [the output gallery](outputs/index.html) and the four prepared-input
previews: [2-D image](processed_inputs/image_2d.png),
[3-D voxel](processed_inputs/voxel_3d.png),
[point](processed_inputs/point_6000.png), and
[graph](processed_inputs/graph_6000.png).

## Rerun

From the workspace root, run:

```sh
.venv/bin/python -m gen_models.models.four_conditional_diffusion \
  --allow-diagnostic-weak-labels --epochs 120 \
  --diffusion-steps 30 --sample-steps 12 --samples 4
```

The four variants use explicit 2-D image-grid messages, sparse 3-D
voxel-neighbor messages, PointNet-style local/global pooling, and CAD-graph
edge messages at each denoising step. Generated points use
`CAD position + CAD normal × signed deformation`; the HTML gallery and JSON
report show deformation, risk, weak-label loss, MAE/RMSE, two Chamfer measures,
and sampling uncertainty.

## Paper-inspired TAG Graph U-Net

The additional `graph_unet_6000` candidate adapts Ferguson et al.'s
Topology-Agnostic Graph U-Net as the conditional DDPM denoiser. It uses three
balanced kd-tree pooling levels, groups of at most eight 3-D nodes, mean pool,
copied unpool, 12-nearest-neighbour coarse graphs, EdgeConv-style max messages,
coordinates at each convolution, and concatenated encoder skips. Relative edge
delta and Euclidean length are recomputed at every resolution.

```sh
.venv/bin/python -m gen_models.models.graph_unet_conditional_diffusion \
  --allow-diagnostic-weak-labels --epochs 24 \
  --diffusion-steps 30 --sample-steps 12 --samples 4
```

This is a paper-inspired adaptation rather than an exact reproduction: the
paper performs direct scalar-field regression, while this experiment uses its
backbone to predict DDPM noise plus the existing weak risk head.
