# Differentiable Euler-density morphology loss

- ID: 2728
- Canonical URL: https://synthcore.org/idea/2728/differentiable-euler-density-morphology-loss
- API JSON: https://synthcore.org/api/idea/2728.json
- API Markdown: https://synthcore.org/api/idea/2728.md
- Verification status: mech_ok_no_baseline
- Source: [arXiv:2608.24897](https://arxiv.org/abs/2608.24897)
- Category: regularization
- Solves: accuracy, generalization
- ML areas: diffusion, gan, loss
- Math tags: topology, combinatorics, probability
- Ratings: usefulness 7/10; difficulty 3/10; novelty 5/10

## Idea description

Add a threshold-dependent Euler-density loss to an image generator or diffusion denoiser. The loss matches the predicted field's local excursion topology to that of real images using differentiable soft occupancy probabilities over pixels, horizontal and vertical edges, and 2x2 faces.

## Mathematical statement

For a binary excursion set formed by cells with density \(\rho>\nu\), Eq. (4) states that the bulk Euler density per unit area is \(\chi_j(\nu)/A=p_1-p_{Eh}-p_{Ev}+p_F\). Here \(p_1=\Pr(\rho>\nu)\) is the one-cell exceedance probability, \(p_{Eh}\) and \(p_{Ev}\) are the probabilities that horizontally or vertically adjacent cell pairs both exceed \(\nu\), and \(p_F\) is the probability that all four cells in a 2x2 block exceed \(\nu\). The alternating signs are the cubical Euler-characteristic inclusion-exclusion rule: occupied cells contribute \(+1\), shared edges contribute \(-1\), and filled faces contribute \(+1\). For a neural image \(x\), replace the hard indicator \(1[x_u>\nu]\) by \(s_u=\sigma((x_u-\nu)/T)\), where \(T>0\) is a temperature. Estimate each probability by spatial averages of the corresponding products. Match this statistic at several thresholds because one threshold constrains only one morphology regime.

## Key formulas

- $$\frac{\chi_j(\nu)}{A}=p_1-p_{Eh}-p_{Ev}+p_F,$$
- $$s_u(\nu)=\sigma\!\left(\frac{x_u-\nu}{T}\right),\quad \widehat p_1=\frac{1}{|V|}\sum_{u\in V}s_u,$$
- $$\widehat\chi(\nu)=\widehat p_1-\frac{1}{|E_h|}\sum_{(u,v)\in E_h}s_us_v-\frac{1}{|E_v|}\sum_{(u,v)\in E_v}s_us_v+\frac{1}{|F|}\sum_{(u_1,u_2,u_3,u_4)\in F}\prod_{k=1}^{4}s_{u_k},$$
- $$\mathcal L_{\mathrm{Euler}}=\sum_{\nu\in\mathcal T}\lambda_\nu\left(\widehat\chi_{\mathrm{gen}}(\nu)-\widehat\chi_{\mathrm{real}}(\nu)\right)^2$$

## Implementation notes

Integrate this as an auxiliary loss on generated images, either on the final sample of a GAN or on reconstructed clean images \(\hat x_0\) predicted by a diffusion model. Normalize each image channel to a fixed range and choose thresholds \(\mathcal T\) as empirical real-data quantiles, for example \(\{0.1,0.2,\ldots,0.9\}\). For each threshold, compute \(s=\operatorname{sigmoid}((x-\nu)/T)\), with \(T\) initially 0.1 and optionally annealed to 0.03. Compute the mean occupancy, mean products for horizontal neighbors, mean products for vertical neighbors, and mean four-way products in 2x2 windows. Combine them exactly as \(\widehat\chi=\widehat p_1-\widehat p_{Eh}-\widehat p_{Ev}+\widehat p_F\), then add \(\lambda\mathcal L_{Euler}\) to the normal generator or denoising objective. Maintain exponential moving averages of the four real-image statistics, or compute minibatch targets directly. Ramp \(\lambda\) from zero during the first 10% of training. The paper supplies the cubical formula; the sigmoid temperature, thresholds, and weighting are empirical. First test on CIFAR-10, CelebA-64, or binary microscopy images with a small UNet or GAN, comparing the baseline against baseline plus Euler loss at equal compute. Evaluate FID or reconstruction quality and exact hard-threshold Euler curves using binary 2x2 counts. Success means lower integrated Euler-curve error without worse FID, plus improved connected-component and hole statistics.

## Verification

- Status: mech_ok_no_baseline
- Mechanism evidence: yes
- Mechanism confirmed: yes
- Practical verdict: no_effect
- Verdict: Implemented differentiable multi-threshold Euler-density morphology loss with exact hard-threshold reference and a small denoising integration. The mechanism checks passed: temperature reduction monotonically approached the hard statistic, constant-field cancellation matched the predicted zero bulk density, and iid Bernoulli measurements matched q−2q²+q⁴ within 0.00018. The denoising experiment showed only a negligible morphology improvement, so the mathematical mechanism is validated but a meaningful ML quality win was not demonstrated.

### Mechanism check

- Verdict: Implemented differentiable multi-threshold Euler-density morphology loss with exact hard-threshold reference and a small denoising integration. The mechanism checks passed: temperature reduction monotonically approached the hard statistic, constant-field cancellation matched the predicted zero bulk density, and iid Bernoulli measurements matched q−2q²+q⁴ within 0.00018. The denoising experiment showed only a negligible morphology improvement, so the mathematical mechanism is validated but a meaningful ML quality win was not demonstrated.
- Confidence: 8/10
- Limitations: Only a tiny synthetic 16x16 denoising task and 80 optimization steps were tested; no CIFAR-10, diffusion, GAN, FID, connected-component, hole-count, equal-FLOP, or GPU comparison was performed. The observed practical improvement is too small to claim generalization.

### Practical benchmark

- Paired seeds: 8
- Baseline mean: 0
- Idea mean: 0
- p-value: 0.0917
- Paired wins: 3/8
- Benchmark verdict: no measurable effect

## Artifacts

- [REPORT.md](https://synthcore.org/code/1080/REPORT.md)
- [bench_euler.py](https://synthcore.org/code/1080/bench_euler.py)
- [bench_report.json](https://synthcore.org/code/1080/bench_report.json)
- [euler_custom_track.py](https://synthcore.org/code/1080/euler_custom_track.py)
- [report.md](https://synthcore.org/code/1080/report.md)
- [report_bench_2026-09-02T001928.md](https://synthcore.org/code/1080/report_bench_2026-09-02T001928.md)
- [results.json](https://synthcore.org/code/1080/results.json)
- [run_experiment.py](https://synthcore.org/code/1080/run_experiment.py)
- [Download all files as ZIP](https://synthcore.org/download/1080)

## Disclaimer

AI-generated research hypothesis, automatically tested. Not peer-reviewed.
