From 80eaaf93e76a30d3c14c7823d0009ccef009689d Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 5 Jul 2022 16:04:19 +0200 Subject: [PATCH] rv::kohonen:: heatmap drawing --- rogueviz/som/kohonen.cpp | 85 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/rogueviz/som/kohonen.cpp b/rogueviz/som/kohonen.cpp index 7b9dc6f0..19d45931 100644 --- a/rogueviz/som/kohonen.cpp +++ b/rogueviz/som/kohonen.cpp @@ -1376,8 +1376,87 @@ void neurondisttable(const string &name) { bool animate_loop; bool animate_once; +bool animate_dispersion; +int heatmap_width = 16; + +color_t heatmap(ld x) { + if(x < 1/10.) return gradient(0x101010, 0x800000, 0, x, 1/10.); + else if(x < 1/2.) return gradient(0x800000, 0xFF8000, 1/10., x, 1/2.); + else return gradient(0xFF8000, 0xFFFFFF, 1/2., x, 1); + } + +bool draw_heatmap() { + if(animate_dispersion && heatmap_width) { + dynamicval g(geometry, gEuclid); + dynamicval pm(pmodel, mdDisk); + dynamicval ga(vid.always3, false); + dynamicval ou(poly_outline); + dynamicval gi(ginf[gEuclid].g, giEuclid2); + initquickqueue(); + check_cgi(); cgi.require_shapes(); + println(hlog, "animate_dispersion called"); + + int pixstep = 4; + int width = heatmap_width; + for(int y=width; ywhere->landparam = heatmap(nu); + } + } if(kohonen::animate_once && !kohonen::finished()) { unsigned int t = SDL_GetTicks(); while(SDL_GetTicks() < t+20) kohonen::step(); @@ -1390,7 +1469,8 @@ void steps() { if(t1 > t) { initialize_rv(); set_neuron_initial(); - last_analyze_step = t = tmax; + t = tmax; + analyze(); } while(t > t1) kohonen::step(); setindex(false); @@ -1789,7 +1869,9 @@ auto hooks4 = addHook(hooks_clearmemory, 100, clear) param_b(show_rings, "som_show_rings"); param_b(animate_once, "som_animate_once"); param_b(animate_loop, "som_animate_loop"); + param_b(animate_dispersion, "som_animate_dispersion"); param_f(analyze_each, "som_analyze_each"); + param_i(heatmap_width, "som_heatmap_width"); param_f(dispersion_precision, "som_dispersion") -> set_reaction([] { state &=~ KS_DISPERSION; }); }); @@ -1817,6 +1899,7 @@ void initialize_rv() { rv_hook(hooks_readcolor, 100, kohonen_color); rv_hook(hooks_drawcell, 100, coloring_3d); rv_hook(anims::hooks_anim, 100, analyzer); + rv_hook(hooks_prestats, 25, draw_heatmap); } }