Note that there are some explanatory texts on larger screens.

plurals
  1. POReading C code written for R packages. Where to find definitions for RANDIN, UNIF, EPS, etc?
    primarykey
    data
    text
    <p>I am interested in precisely understanding C code for R packages. But I have come across code such as <code>RANDIN</code>, <code>RANDOUT</code>, <code>UNIF</code>, <code>EPS</code> etc (are they macros?) for which I don't know where to find the implementations/definitions.</p> <p>Where can I find the code (and explanations if any) for these capitalised 'expressions'?</p> <p>An example is the <code>VR_onlineSOM</code> function inside the 'class' R package. This function has the following code written in C:</p> <pre><code>void VR_onlineSOM(double *data, double *codes, double *nhbrdist, double *alpha, double *radii, Sint *pn, Sint *pp, Sint *pncodes, Sint *rlen) { int n = *pn, p = *pp, ncodes = *pncodes; int i, j, k, nearest = 0 /* -Wall */, nind; double dm, dist, tmp; unsigned int cd; /* avoid spurious warning from gcc pre-4.3.0 */ RANDIN; for (k = 0; k &lt; *rlen; k++) { /* pick a random data point */ i = (int)(n * UNIF); /* find the nearest code 'near' */ nind = 0; dm = DOUBLE_XMAX; for (cd = 0; cd &lt; ncodes; cd++) { dist = 0.0; for (j = 0; j &lt; p; j++) { tmp = data[i + j*n] - codes[cd + j*ncodes]; dist += tmp * tmp; } if (dist &lt;= dm * (1 + EPS)) { if (dist &lt; dm * (1 - EPS)) { nind = 0; nearest = cd; } else { if(++nind * UNIF &lt; 1.0) nearest = cd; } dm = dist; } /* update all codes within radii[k] of 'nearest' */ for (cd = 0; cd &lt; ncodes; cd++) { if(nhbrdist[cd + ncodes*nearest] &gt; radii[k]) continue; for(j = 0; j &lt; p; j++) codes[cd + j*ncodes] += alpha[k] * (data[i + j*n] - codes[cd + j*ncodes]); } } } RANDOUT; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload