mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 14:02:59 +00:00 
			
		
		
		
	rv:: kohonen
This commit is contained in:
		| @@ -264,10 +264,7 @@ bool triangulate(kohvec d, neuron& w, map<cell*, neuron*>& find, transmatrix& re | ||||
|         } | ||||
|       if(diff < bdiff) bdiff = diff, candidate = w2, cdir = i;       | ||||
|       } | ||||
|     if(cdir == -1) { | ||||
|       println(hlog, "not enough directions"); | ||||
|       return false; | ||||
|       } | ||||
|     if(cdir == -1) break; | ||||
|     dirs.push_back(cdir); | ||||
|     other.push_back(candidate); | ||||
|     kv.push_back(candidate->net); | ||||
| @@ -291,6 +288,7 @@ bool triangulate(kohvec d, neuron& w, map<cell*, neuron*>& find, transmatrix& re | ||||
|   for(int i=0; i<q; i++) { | ||||
|     R[i][i] = vdot(kv[i], kv[i]); | ||||
|     if(R[i][i] < 1e-12) { | ||||
|       /* | ||||
|       auto head = [] (const vector<ld>& v) { vector<ld> res; for(int i=0; i<10; i++) res.push_back(v[i]); return res; }; | ||||
|       println(hlog, "dot too small, i=", i,", dirs=", dirs); | ||||
|       println(hlog, "a = ", head(a)); | ||||
| @@ -299,6 +297,7 @@ bool triangulate(kohvec d, neuron& w, map<cell*, neuron*>& find, transmatrix& re | ||||
|         println(hlog, "orig kv: ", head(z->net), " @ ", z->where); | ||||
|       for(auto z: kv) | ||||
|         println(hlog, "curr kv: ", head(z)); | ||||
|       */ | ||||
|       return false; | ||||
|       } | ||||
|     for(int j=i+1; j<q; j++) { | ||||
| @@ -445,7 +444,7 @@ struct cellcrawler { | ||||
|         store(cw, i, j, cl); | ||||
|         } | ||||
|       } | ||||
|     if(gaussian) for(cellcrawlerdata& s: data) | ||||
|     if(gaussian || true) for(cellcrawlerdata& s: data) | ||||
|       s.dist = mydistance(s.orig.at, start.at); | ||||
|     } | ||||
|    | ||||
| @@ -462,11 +461,13 @@ struct cellcrawler { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|   vector<vector<ld>> dispersion; | ||||
|   vector<vector<float>> dispersion; | ||||
|   }; | ||||
|  | ||||
| double dispersion_end_at = 1.6; | ||||
|  | ||||
| bool dispersion_long; | ||||
|  | ||||
| double dispersion_precision = .0001; | ||||
| int dispersion_each = 1; | ||||
|  | ||||
| @@ -476,10 +477,10 @@ void buildcellcrawler(cell *c, cellcrawler& cr, int dir) { | ||||
|   cr.build(cellwalker(c,dir)); | ||||
|  | ||||
|   if(!gaussian) { | ||||
|     vector<ld> curtemp; | ||||
|     vector<ld> newtemp; | ||||
|     vector<float> curtemp; | ||||
|     vector<float> newtemp; | ||||
|     vector<int> qty; | ||||
|     vector<pair<ld*, ld*> > pairs; | ||||
|     vector<pair<float*, float*> > pairs; | ||||
|     int N = isize(net); | ||||
|      | ||||
|     curtemp.resize(N, 0); | ||||
| @@ -503,8 +504,8 @@ void buildcellcrawler(cell *c, cellcrawler& cr, int dir) { | ||||
|     auto &d = cr.dispersion; | ||||
|      | ||||
|     d.clear(); | ||||
|    | ||||
|     DEBBI(DF_LOG, ("Building dispersion, precision = ", dispersion_precision, " end_at = ", dispersion_end_at, "...\n")); | ||||
|      | ||||
|     // DEBBI(DF_LOG, ("Building dispersion, precision = ", dispersion_precision, " end_at = ", dispersion_end_at, "...\n")); | ||||
|      | ||||
|     for(iter=0; dispersion_count ? true : vmax > vmin * dispersion_end_at; iter++) { | ||||
|       if(iter % dispersion_each == 0) { | ||||
| @@ -527,10 +528,13 @@ void buildcellcrawler(cell *c, cellcrawler& cr, int dir) { | ||||
|       for(int i=0; i<N; i++)  | ||||
|         if(curtemp[i] < vmin) vmin = curtemp[i]; | ||||
|         else if(curtemp[i] > vmax) vmax = curtemp[i]; | ||||
|       // if(iter % 50 == 0) println(hlog, "iter=", iter, " vmin=", vmin, " vmax=", vmax, " pairs=", isize(pairs)); | ||||
|       } | ||||
|    | ||||
|     dispersion_count = isize(d); | ||||
|     DEBB(DF_LOG, ("Dispersion count = ", dispersion_count)); | ||||
|     if(!dispersion_count) { | ||||
|       if(!dispersion_long) dispersion_count = isize(d); | ||||
|       DEBB(DF_LOG, ("Dispersion count = ", isize(d), " celldist = ", celldist(c))); | ||||
|       } | ||||
|     /* | ||||
|     println(hlog, "dlast = ", d.back()); | ||||
|     println(hlog, "dlast2 = ", d[d.size()-2]); | ||||
| @@ -542,7 +546,9 @@ void buildcellcrawler(cell *c, cellcrawler& cr, int dir) { | ||||
| map<int, cellcrawler> scc; | ||||
|  | ||||
| pair<int, int> get_cellcrawler_id(cell *c) { | ||||
|   if(among(geometry, gZebraQuotient, gMinimal, gArnoldCat, gField435, gField534) || (euclid && quotient && !bounded) || IRREGULAR || (GDIM == 3 && sphere) || (hyperbolic && GDIM == 3 && quotient) | ||||
|   if(!bounded) | ||||
|     return make_pair(neuronId(*getNeuronSlow(c)), 0); | ||||
|   if(among(geometry, gZebraQuotient, gMinimal, gArnoldCat, gField435, gField534) || (euclid && quotient && !bounded) || IRREGULAR || (GDIM == 3 && sphere) || (hyperbolic && GDIM == 3) | ||||
|     || (euclid && nonorientable)) { | ||||
|     // Zebra Quotient does exhibit some symmetries, | ||||
|     // but these are so small anyway that it is safer to just build | ||||
| @@ -893,7 +899,7 @@ void initialize_dispersion() { | ||||
|  | ||||
|   DEBBI(DF_LOG, ("Initializing dispersion")); | ||||
|  | ||||
|   if(gaussian) { | ||||
|   if(gaussian || true) { | ||||
|     DEBB(DF_LOG, ("dist = ", fts(mydistance(net[0].where, net[1].where)))); | ||||
|     cell *c1 = net[cells/2].where; | ||||
|     vector<double> mapdist; | ||||
| @@ -902,19 +908,26 @@ void initialize_dispersion() { | ||||
|     maxdist = mapdist[isize(mapdist)*5/6] * distmul; | ||||
|     DEBB(DF_LOG, ("maxdist = ", fts(maxdist))); | ||||
|     } | ||||
|      | ||||
|  | ||||
|   dispersion_count = 0;   | ||||
|    | ||||
|  | ||||
|   if(!gaussian) | ||||
|     DEBB(DF_LOG, ("dispersion precision = ", dispersion_precision, " end_at = ", dispersion_end_at, "...\n")); | ||||
|  | ||||
|   DEBB(DF_LOG, ("building crawlers...\n")); | ||||
|  | ||||
|   scc.clear(); | ||||
|   for(int i=0; i<cells; i++) { | ||||
|     cell *c = net[i].where; | ||||
|     auto cid = get_cellcrawler_id(c); | ||||
|     if(!scc.count(cid.first)) { | ||||
|       DEBB(DF_LOG, ("Building cellcrawler id = ", itsh(cid.first))); | ||||
|       // DEBB(DF_LOG, ("Building cellcrawler id = ", itsh(cid.first))); | ||||
|       buildcellcrawler(c, scc[cid.first], cid.second); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|   DEBB(DF_LOG, ("crawlers constructed = ", isize(scc), "\n")); | ||||
|  | ||||
|   lpct = -46130; | ||||
|   state |= KS_DISPERSION; | ||||
|   } | ||||
| @@ -1552,7 +1565,7 @@ int readArgs() { | ||||
|     gaussian = 0;  | ||||
|     state &=~ KS_DISPERSION; | ||||
|     } | ||||
|   else if(argis("-somcgauss")) { | ||||
|   else if(argis("-somcgauss") || argis("-cgauss")) { | ||||
|     gaussian = 1; | ||||
|     state &=~ KS_DISPERSION; | ||||
|     } | ||||
| @@ -1582,11 +1595,18 @@ int readArgs() { | ||||
|     shift(); t = (t*1./tmax) * argi(); | ||||
|     tmax = argi(); | ||||
|     } | ||||
|   else if(argis("-somlong")) { | ||||
|     shift(); dispersion_long = argi(); | ||||
|     } | ||||
|   else if(argis("-somlearn")) { | ||||
|     // this one can be changed at any moment | ||||
|     shift_arg_formula(learning_factor); | ||||
|     } | ||||
|  | ||||
|   else if(argis("-som-analyze")) { | ||||
|     analyze(); | ||||
|     } | ||||
|  | ||||
|   else if(argis("-somrun")) { | ||||
|     initialize_rv();  | ||||
|     set_neuron_initial(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue