| 241 | // ---------------------------- |
| 242 | |
| 243 | ILint contest(ILint b, ILint g, ILint r) |
| 244 | { |
| 245 | // finds closest neuron (min dist) and updates freq |
| 246 | // finds best neuron (min dist-bias) and returns position |
| 247 | // for frequently chosen neurons, freq[i] is high and bias[i] is negative |
| 248 | // bias[i] = gamma*((1/netsize)-freq[i]) |
| 249 | |
| 250 | ILint i,dist,a,biasdist,betafreq; |
| 251 | ILint bestpos,bestbiaspos,bestd,bestbiasd; |
| 252 | ILint *p,*f, *n; |
| 253 | |
| 254 | bestd = ~(((ILint) 1)<<31); |
| 255 | bestbiasd = bestd; |
| 256 | bestpos = -1; |
| 257 | bestbiaspos = bestpos; |
| 258 | p = bias; |
| 259 | f = freq; |
| 260 | |
| 261 | for (i=0; i<netsizethink; i++) { |
| 262 | n = network[i]; |
| 263 | dist = n[0] - b; if (dist<0) dist = -dist; |
| 264 | a = n[1] - g; if (a<0) a = -a; |
| 265 | dist += a; |
| 266 | a = n[2] - r; if (a<0) a = -a; |
| 267 | dist += a; |
| 268 | if (dist<bestd) {bestd=dist; bestpos=i;} |
| 269 | biasdist = dist - ((*p)>>(intbiasshift-netbiasshift)); |
| 270 | if (biasdist<bestbiasd) {bestbiasd=biasdist; bestbiaspos=i;} |
| 271 | betafreq = (*f >> betashift); |
| 272 | *f++ -= betafreq; |
| 273 | *p++ += (betafreq<<gammashift); |
| 274 | } |
| 275 | freq[bestpos] += beta; |
| 276 | bias[bestpos] -= betagamma; |
| 277 | return(bestbiaspos); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | // Move neuron i towards biased (b,g,r) by factor alpha |