{"id":1807,"date":"2026-11-22T09:00:48","date_gmt":"2026-11-22T09:00:48","guid":{"rendered":"https:\/\/genia.inaf.it\/?page_id=1807"},"modified":"2026-11-22T09:00:48","modified_gmt":"2026-11-22T09:00:48","slug":"diffusion-playground","status":"publish","type":"page","link":"https:\/\/genia.inaf.it\/?page_id=1807","title":{"rendered":"Diffusion playground"},"content":{"rendered":"\n<div class=\"gx-play\">\n<p class=\"gx-lead\">Image generators such as Stable Diffusion are built on <strong>diffusion models<\/strong>: they learn to turn random noise into structure, one small step at a time. Drag the slider or press <em>Denoise<\/em> to watch it happen.<\/p>\n<div class=\"gx-play-shapes\" role=\"group\" aria-label=\"Choose what to generate\"><button type=\"button\" data-shape=\"galaxy\" class=\"is-on\">Spiral galaxy<\/button><button type=\"button\" data-shape=\"cluster\">Globular cluster<\/button><button type=\"button\" data-shape=\"nebula\">Planetary nebula<\/button><button type=\"button\" data-shape=\"genia\">Gen.IA<\/button><\/div>\n<figure class=\"gx-play-canvas\"><canvas role=\"img\" aria-label=\"Points that move from random noise to the selected shape as the noise level decreases\"><\/canvas><span class=\"gx-play-label\" aria-hidden=\"true\"><\/span><span class=\"gx-play-step\" aria-hidden=\"true\"><\/span><\/figure>\n<div class=\"gx-play-controls\"><label for=\"gx-noise\">Clean<\/label><input id=\"gx-noise\" class=\"gx-play-noise\" type=\"range\" min=\"0\" max=\"1000\" value=\"1000\" aria-label=\"Noise level\"><label for=\"gx-noise\">Noise<\/label><button type=\"button\" class=\"gx-play-denoise\">Denoise<\/button><button type=\"button\" class=\"gx-play-addnoise\">Add noise<\/button><\/div>\n<p class=\"gx-play-eq\"><\/p>\n<div class=\"gx-contrib-grid\">\n<div class=\"genia-box\"><h3>How it works<\/h3><p>During training, real data x\u2080 is mixed with Gaussian noise \u03b5: x<sub>t<\/sub> = \u221a\u1fb1<sub>t<\/sub> \u00b7 x\u2080 + \u221a(1 \u2212 \u1fb1<sub>t<\/sub>) \u00b7 \u03b5, where \u1fb1<sub>t<\/sub> goes from 1 (clean) to 0 (pure noise) over the steps t = 0\u2026T. A neural network learns to predict the noise contained in x<sub>t<\/sub>. To generate something new, the model starts from pure noise and removes a little of the predicted noise at every step.<\/p><\/div>\n<div class=\"genia-box\"><h3>What is simplified here<\/h3><p>This demo already knows the target shape and simply moves along the same formula, with a cosine noise schedule and 50 steps. A real model has to estimate the noise at each step from what it learned during training: that is why it produces new samples instead of copies. In astrophysics, diffusion models are being explored for mock galaxy images, source deblending and the reconstruction of noisy data.<\/p><\/div>\n<\/div>\n<\/div>\n<script>(function () { \"use strict\"; var root = document.querySelector(\".gx-play\"); if (!root) return; var fig = root.querySelector(\".gx-play-canvas\"); var cv = fig.querySelector(\"canvas\"); var ctx = cv.getContext(\"2d\"); var slider = root.querySelector(\".gx-play-noise\"); var stepOut = root.querySelector(\".gx-play-step\"); var eqOut = root.querySelector(\".gx-play-eq\"); var label = root.querySelector(\".gx-play-label\"); var shapeBtns = root.querySelectorAll(\"[data-shape]\"); var btnDen = root.querySelector(\".gx-play-denoise\"); var btnNoise = root.querySelector(\".gx-play-addnoise\"); var STEPS = 50; var small = window.matchMedia ? matchMedia(\"(max-width: 600px)\").matches : false; var N = small ? 1300 : 2600; var seed = 7; function rnd() { seed = (seed * 16807) % 2147483647; return (seed - 1) \/ 2147483646; } function gauss() { var u = 1 - rnd(), v = rnd(); return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v); } var eps = new Float32Array(2 * N), ph = new Float32Array(N), size = new Float32Array(N); for (var i = 0; i < N; i++) { eps[2 * i] = gauss() * 0.75; eps[2 * i + 1] = gauss() * 0.75; ph[i] = rnd() * 6.283; size[i] = rnd() < 0.08 ? 2.1 : (rnd() < 0.5 ? 1.4 : 1.0); } function galaxy() { var a = new Float32Array(2 * N), c = new Uint8Array(N); for (var i = 0; i < N; i++) { var x, y, u = rnd(); if (u < 0.2) { x = gauss() * 0.11; y = gauss() * 0.11; c[i] = rnd() < 0.7 ? 1 : 0; } else { var r = 0.07 + 0.95 * Math.pow(rnd(), 0.75); var arm = (i % 2) ? Math.PI : 0; var th = Math.log(r \/ 0.07) \/ 0.32 + arm + gauss() * (u < 0.85 ? 0.22 : 0.9); x = r * Math.cos(th) + gauss() * 0.025; y = r * Math.sin(th) + gauss() * 0.025; c[i] = rnd() < 0.04 ? 2 : (r < 0.25 ? (rnd() < 0.4 ? 1 : 0) : 0); } a[2 * i] = x; a[2 * i + 1] = y; } return { p: a, c: c, incl: 0.52, name: \"spiral galaxy\" }; } function cluster() { var a = new Float32Array(2 * N), c = new Uint8Array(N); for (var i = 0; i < N; i++) { var m = Math.max(rnd(), 0.02); var r = Math.min(0.22 \/ Math.sqrt(Math.pow(m, -2 \/ 3) - 1 + 1e-6), 1.1); var ct = 2 * rnd() - 1, phi = 2 * Math.PI * rnd(), st = Math.sqrt(1 - ct * ct); a[2 * i] = r * st * Math.cos(phi); a[2 * i + 1] = r * st * Math.sin(phi); c[i] = rnd() < 0.25 ? 1 : (rnd() < 0.03 ? 2 : 0); } return { p: a, c: c, incl: 1, name: \"globular cluster\" }; } function nebula() { var a = new Float32Array(2 * N), c = new Uint8Array(N); for (var i = 0; i < N; i++) { var u = rnd(), th = 2 * Math.PI * rnd(), r; if (u < 0.04) { r = Math.abs(gauss()) * 0.03; c[i] = 1; } else if (u < 0.8) { r = 0.55 + gauss() * 0.06; c[i] = rnd() < 0.3 ? 2 : 0; } else { r = 0.62 + Math.abs(gauss()) * 0.28; c[i] = 0; } a[2 * i] = r * Math.cos(th) * 1.25; a[2 * i + 1] = r * Math.sin(th); } return { p: a, c: c, incl: 1, name: \"planetary nebula\" }; } function words() { var off = document.createElement(\"canvas\"), w = 620, h = 220; off.width = w; off.height = h; var o = off.getContext(\"2d\"); o.fillStyle = \"#fff\"; o.font = \"bold 150px Arial, Helvetica, sans-serif\"; o.textAlign = \"center\"; o.textBaseline = \"middle\"; o.fillText(\"Gen.IA\", w \/ 2, h \/ 2 + 6); var d = o.getImageData(0, 0, w, h).data, pts = []; for (var yy = 0; yy < h; yy += 2) for (var xx = 0; xx < w; xx += 2) if (d[(yy * w + xx) * 4 + 3] > 128) pts.push(xx, yy); var a = new Float32Array(2 * N), c = new Uint8Array(N), m = pts.length \/ 2; var dotX = o.measureText(\"Gen\").width - o.measureText(\"Gen.IA\").width \/ 2 + w \/ 2; for (var i = 0; i < N; i++) { var k = Math.floor(rnd() * m), px = pts[2 * k], py = pts[2 * k + 1]; a[2 * i] = (px - w \/ 2) \/ (h \/ 2) * 0.55 + gauss() * 0.006; a[2 * i + 1] = (py - h \/ 2) \/ (h \/ 2) * 0.55 + gauss() * 0.006; c[i] = px > dotX ? 2 : 0; } return { p: a, c: c, incl: 1, name: \"Gen.IA\" }; } var shapes = { galaxy: galaxy(), cluster: cluster(), nebula: nebula(), genia: words() }; var cur = \"galaxy\"; var u = 1, target = null, speed = 0; function alphaBar(x) { var s = Math.cos((x * 0.98 + 0.01) * Math.PI \/ 2); return s * s; } var W = 1, H = 1, DPR = 1; var COLORS = [\"#dfe8ff\", \"#ffd8b4\", \"#ff9b57\"]; var lastT = 0; function resize() { var r = fig.getBoundingClientRect(); DPR = Math.min(window.devicePixelRatio || 1, 2); W = Math.max(1, Math.round(r.width)); H = Math.max(1, Math.round(r.height)); cv.width = W * DPR; cv.height = H * DPR; draw(lastT); } function draw(t) { lastT = t; var s = shapes[cur], ab = u <= 0 ? 1 : (u >= 1 ? 0 : alphaBar(u)); var sa = Math.sqrt(ab), sn = Math.sqrt(1 - ab); var cx = W * DPR \/ 2, cy = H * DPR \/ 2, S = H * DPR * 0.44; ctx.clearRect(0, 0, cv.width, cv.height); ctx.globalCompositeOperation = \"lighter\"; for (var g = 0; g < 3; g++) { ctx.fillStyle = COLORS[g]; ctx.globalAlpha = (g === 2 ? 0.95 : 0.7) * (0.55 + 0.45 * ab); for (var i = 0; i < N; i++) { if (s.c[i] !== g) continue; var wob = 0.03 * sn; var nx = eps[2 * i] * 1.7 + wob * Math.sin(t * 0.9 + ph[i]); var ny = eps[2 * i + 1] + wob * Math.cos(t * 1.1 + ph[i]); var x = cx + (sa * s.p[2 * i] + sn * nx) * S; var y = cy + (sa * s.p[2 * i + 1] * s.incl + sn * ny) * S; var z = size[i] * DPR; ctx.fillRect(x - z \/ 2, y - z \/ 2, z, z); } } ctx.globalAlpha = 1; ctx.globalCompositeOperation = \"source-over\"; var step = Math.round(u * STEPS); if (stepOut) stepOut.textContent = \"t = \" + step + \" \/ \" + STEPS; if (eqOut) eqOut.textContent = \"x\u209c = \" + sa.toFixed(2) + \" \u00b7 x\u2080 + \" + sn.toFixed(2) + \" \u00b7 \u03b5\"; if (label) label.textContent = step === 0 ? s.name : (step === STEPS ? \"pure noise\" : \"denoising\u2026\"); if (slider) slider.value = String(Math.round(u * 1000)); } var prev = 0; function loop(now) { var dt = prev ? Math.min(0.05, (now - prev) \/ 1000) : 0; prev = now; if (target !== null) { var d = target - u, stepv = speed * dt; if (Math.abs(d) <= stepv) { u = target; target = null; } else { u += d > 0 ? stepv : -stepv; } } draw(now \/ 1000); requestAnimationFrame(loop); } function go(to, seconds) { target = to; speed = 1 \/ seconds; } if (slider) slider.addEventListener(\"input\", function () { target = null; u = parseInt(slider.value, 10) \/ 1000; }); if (btnDen) btnDen.addEventListener(\"click\", function () { go(0, 5); }); if (btnNoise) btnNoise.addEventListener(\"click\", function () { go(1, 3); }); for (var b = 0; b < shapeBtns.length; b++) { shapeBtns[b].addEventListener(\"click\", function () { for (var k = 0; k < shapeBtns.length; k++) shapeBtns[k].classList.remove(\"is-on\"); this.classList.add(\"is-on\"); cur = this.getAttribute(\"data-shape\"); u = 1; go(0, 5); }); } resize(); if (window.ResizeObserver) new ResizeObserver(resize).observe(fig); var reduce = window.matchMedia ? matchMedia(\"(prefers-reduced-motion: reduce)\").matches : false; if (reduce) { u = 0; draw(0); } else { go(0, 5); } requestAnimationFrame(loop); })();<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Image generators such as Stable Diffusion are built on diffusion models: they learn to turn random noise into structure, one small step at a time. Drag the slider or press Denoise to watch it happen. Spiral galaxyGlobular clusterPlanetary nebulaGen.IA CleanNoiseDenoiseAdd noise How it works During training, real data x\u2080 is mixed with Gaussian noise \u03b5:&hellip;&nbsp;<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":1487,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"class_list":["post-1807","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/pages\/1807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/genia.inaf.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1807"}],"version-history":[{"count":0,"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/pages\/1807\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/genia.inaf.it\/index.php?rest_route=\/wp\/v2\/pages\/1487"}],"wp:attachment":[{"href":"https:\/\/genia.inaf.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}