void ParticleSystem::RenderLightning() { glUseProgram(m_lshader); glEnableVertexAttribArray(vtxpos); //Initiate random gen std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<int32_t> dist(1, m_vertices.size()); std::uniform_real_distribution<float> distf(1.0f, 5.0f); glLineWidth(distf(mt)); glDrawArrays(GL_LINE_STRIP, 0, dist(mt)); glDisableVertexAttribArray(vtxpos); }
void C_mapDataToCodes(double *data, double *codes, int *pncodes, int *pnd, int *pp, int *nnCodes, double *nnDists, int *dist){ int ncodes = *pncodes, nd = *pnd, p = *pp; int i, cd, counter, minid; double tmp, mindist; double (*distf)(double*,double*,int,int,int); if(*dist == 1){ distf = &manh; } else if (*dist == 2){ distf = &eucl; } else if (*dist == 3){ distf = &chebyshev; } else if (*dist == 4){ distf = &cosine; } else { distf = &eucl; } /* i is a counter over objects in data, cd is a counter over SOM units, p is the number of columns, nd is the number of datapoints and ncodes is the number of SOM units*/ counter = -1; for (i = 0; i < nd; i++) { minid = -1; mindist = DBL_MAX; for (cd = 0; cd < ncodes; cd++) { tmp = distf(&data[i], &codes[cd], p, nd, ncodes); //Rprintf("\ndist: %f",tmp2); if(tmp < mindist){ mindist = tmp; minid = cd; } } nnCodes[++counter] = minid+1; nnDists[counter] = mindist; } }
void C_SOM(double *data, double *codes, double *nhbrdist, double *alphas, double *radii, double *xdists, /* working arrays */ Sint *pn, Sint *ppx, Sint *pncodes, Sint *prlen, Sint *dist) { int n = *pn, px = *ppx, ncodes = *pncodes, rlen = *prlen; int cd, i, j, k, nearest, niter; double tmp, threshold, alpha, thresholdStep; double change; double (*distf)(double*,double*,int,int,int); if(*dist == 1){ distf = &manh; } else if (*dist == 2){ distf = &eucl; } else if (*dist == 3){ distf = &chebyshev; } else if (*dist == 4){ distf = &cosine; } else { distf = &eucl; } RANDIN; niter = rlen * n; threshold = radii[0]; thresholdStep = (radii[0] - radii[1]) / (double) niter; change = 1.0; for (k = 0; k < niter; k++) { if(k%n == 0){ if(change < 1){ k = niter; } change = 0.0; } /* i is a counter over objects in data, cd is a counter over units in the map, and j is a counter over variables */ i = (int)(n * UNIF); /* Select a random sample */ /*Rprintf("\ni: %d\n",i+1); for (j = 0; j < px; j++) { Rprintf(" j%d: %f",j,data[i*px + j]); }*/ nearest = 0; /* calculate distances in x and y spaces, and keep track of the nearest code */ for (cd = 0; cd < ncodes; cd++) { xdists[cd] = distf(&data[i], &codes[cd], px, n, ncodes); if (xdists[cd] < xdists[nearest]) nearest = cd; } if (threshold < 1.0) threshold = 0.5; alpha = alphas[0] - (alphas[0] - alphas[1]) * (double)k/(double)niter; for (cd = 0; cd < ncodes; cd++) { if(nhbrdist[cd + ncodes*nearest] > threshold) continue; for(j = 0; j < px; j++) { tmp = data[i + j*n] - codes[cd + j*ncodes]; change += abs(tmp); codes[cd + j*ncodes] += tmp * alpha; } } threshold -= thresholdStep; } RANDOUT; }