queso-0.53.0
Macros | Functions | Variables
rand.h File Reference
#include <cstdlib>
#include <cmath>
#include <ANN/ANN.h>
Include dependency graph for rand.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ANN_RAND   random
 
#define ANN_SRAND   srandom
 
#define ANN_RAND_MAX   2147483647UL
 

Functions

void annUniformPts (ANNpointArray pa, int n, int dim)
 
void annGaussPts (ANNpointArray pa, int n, int dim, double std_dev)
 
void annCoGaussPts (ANNpointArray pa, int n, int dim, double correlation)
 
void annLaplacePts (ANNpointArray pa, int n, int dim)
 
void annCoLaplacePts (ANNpointArray pa, int n, int dim, double correlation)
 
void annClusGaussPts (ANNpointArray pa, int n, int dim, int n_clus, ANNbool new_clust, double std_dev)
 
void annClusOrthFlats (ANNpointArray pa, int n, int dim, int n_clus, ANNbool new_clust, double std_dev, int max_dim)
 
void annClusEllipsoids (ANNpointArray pa, int n, int dim, int n_clus, ANNbool new_clust, double std_dev_small, double std_dev_lo, double std_dev_hi, int max_dim)
 
void annPlanted (ANNpointArray pa, int n, int dim, ANNpointArray src, int n_src, double std_dev)
 

Variables

int annIdum
 

Macro Definition Documentation

#define ANN_RAND   random

Definition at line 52 of file rand.h.

Referenced by annRan0().

#define ANN_RAND_MAX   2147483647UL

Definition at line 54 of file rand.h.

Referenced by annRan0().

#define ANN_SRAND   srandom

Definition at line 53 of file rand.h.

Referenced by annRan0().

Function Documentation

void annClusEllipsoids ( ANNpointArray  pa,
int  n,
int  dim,
int  n_clus,
ANNbool  new_clust,
double  std_dev_small,
double  std_dev_lo,
double  std_dev_hi,
int  max_dim 
)

Definition at line 503 of file rand.cpp.

References annAllocPts(), annDeallocPts(), annRan0(), annRanInt(), annRanUnif(), dim, genGauss(), and std_dev.

Referenced by generatePts().

513 {
514  static ANNpointArray centers = NULL; // cluster centers
515  static ANNpointArray std_dev = NULL; // standard deviations
516 
517  if (centers == NULL || new_clust) { // need new cluster centers
518  if (centers != NULL) // clusters already exist
519  annDeallocPts(centers); // get rid of them
520  if (std_dev != NULL) // std deviations already exist
521  annDeallocPts(std_dev); // get rid of them
522 
523  centers = annAllocPts(n_clus, dim); // alloc new clusters and devs
524  std_dev = annAllocPts(n_clus, dim);
525 
526  for (int i = 0; i < n_clus; i++) { // gen cluster center coords
527  for (int d = 0; d < dim; d++) {
528  centers[i][d] = (ANNcoord) annRanUnif(-1,1);
529  }
530  }
531  for (int c = 0; c < n_clus; c++) { // generate cluster std dev
532  int n_dim = 1 + annRanInt(max_dim); // number of dimensions in flat
533  for (int d = 0; d < dim; d++) { // generate std dev's
534  // prob. of picking next dim
535  double Prob = ((double) n_dim)/((double) (dim-d));
536  if (annRan0() < Prob) { // add this one to ellipse
537  // generate random std dev
538  std_dev[c][d] = annRanUnif(std_dev_lo, std_dev_hi);
539  n_dim--; // one fewer dim to fill
540  }
541  else { // don't take this one
542  std_dev[c][d] = std_dev_small;// use small std dev
543  }
544  }
545  }
546  }
547 
548  int offset = 0; // next slot to fill
549  for (int c = 0; c < n_clus; c++) { // generate clusters
550  int pick = (n+c)/n_clus; // number of points to pick
551  // generate the points
552  genGauss(pa+offset, pick, dim, centers[c], std_dev[c]);
553  offset += pick; // increment offset in array
554  }
555 }
double ANNcoord
Definition: ANN.h:158
double std_dev_lo
Definition: ann_test.cpp:481
DLL_API void annDeallocPts(ANNpointArray &pa)
Definition: ANN.cpp:133
ANNpoint * ANNpointArray
Definition: ANN.h:376
int max_dim
Definition: ann_test.cpp:477
static int annRanInt(int n)
Definition: rand.cpp:112
int dim
Definition: ann2fig.cpp:81
ANNbool new_clust
Definition: ann_test.cpp:476
double annRan0()
Definition: rand.cpp:59
double std_dev
Definition: ann_test.cpp:480
static double annRanUnif(double lo, double hi)
Definition: rand.cpp:124
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
double std_dev_hi
Definition: ann_test.cpp:482
static void genGauss(ANNpointArray pa, int n, int dim, double *center, double *std_dev)
Definition: rand.cpp:489
void annClusGaussPts ( ANNpointArray  pa,
int  n,
int  dim,
int  n_clus,
ANNbool  new_clust,
double  std_dev 
)

Definition at line 314 of file rand.cpp.

References annAllocPts(), annDeallocPts(), annRanGauss(), annRanInt(), annRanUnif(), and dim.

Referenced by generatePts().

321 {
322  static ANNpointArray clusters = NULL;// cluster storage
323 
324  if (clusters == NULL || new_clust) {// need new cluster centers
325  if (clusters != NULL) // clusters already exist
326  annDeallocPts(clusters); // get rid of them
327  clusters = annAllocPts(n_clus, dim);
328  // generate cluster center coords
329  for (int i = 0; i < n_clus; i++) {
330  for (int d = 0; d < dim; d++) {
331  clusters[i][d] = (ANNcoord) annRanUnif(-1,1);
332  }
333  }
334  }
335 
336  for (int i = 0; i < n; i++) {
337  int c = annRanInt(n_clus); // generate cluster index
338  for (int d = 0; d < dim; d++) {
339  pa[i][d] = (ANNcoord) (std_dev*annRanGauss() + clusters[c][d]);
340  }
341  }
342 }
static double annRanGauss()
Definition: rand.cpp:137
double ANNcoord
Definition: ANN.h:158
DLL_API void annDeallocPts(ANNpointArray &pa)
Definition: ANN.cpp:133
ANNpoint * ANNpointArray
Definition: ANN.h:376
static int annRanInt(int n)
Definition: rand.cpp:112
int dim
Definition: ann2fig.cpp:81
ANNbool new_clust
Definition: ann_test.cpp:476
double std_dev
Definition: ann_test.cpp:480
static double annRanUnif(double lo, double hi)
Definition: rand.cpp:124
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
void annClusOrthFlats ( ANNpointArray  pa,
int  n,
int  dim,
int  n_clus,
ANNbool  new_clust,
double  std_dev,
int  max_dim 
)

Definition at line 408 of file rand.cpp.

References annAllocPts(), annDeallocPts(), annRan0(), annRanInt(), annRanUnif(), CO_FLAG, dim, and genOrthFlat().

Referenced by generatePts().

416 {
417  static ANNpointArray control = NULL; // control vectors
418 
419  if (control == NULL || new_clust) { // need new cluster centers
420  if (control != NULL) { // clusters already exist
421  annDeallocPts(control); // get rid of them
422  }
423  control = annAllocPts(n_clus, dim);
424 
425  for (int c = 0; c < n_clus; c++) { // generate clusters
426  int n_dim = 1 + annRanInt(max_dim); // number of dimensions in flat
427  for (int d = 0; d < dim; d++) { // generate side locations
428  // prob. of picking next dim
429  double Prob = ((double) n_dim)/((double) (dim-d));
430  if (annRan0() < Prob) { // add this one to flat
431  control[c][d] = CO_FLAG; // flag this entry
432  n_dim--; // one fewer dim to fill
433  }
434  else { // don't take this one
435  control[c][d] = annRanUnif(-1,1);// random value in [-1,1]
436  }
437  }
438  }
439  }
440  int offset = 0; // offset in pa array
441  for (int c = 0; c < n_clus; c++) { // generate clusters
442  int pick = (n+c)/n_clus; // number of points to pick
443  // generate the points
444  genOrthFlat(pa+offset, pick, dim, control[c], std_dev);
445  offset += pick; // increment offset
446  }
447 }
DLL_API void annDeallocPts(ANNpointArray &pa)
Definition: ANN.cpp:133
static void genOrthFlat(ANNpointArray pa, int n, int dim, double *control, double std_dev)
Definition: rand.cpp:391
ANNpoint * ANNpointArray
Definition: ANN.h:376
const double CO_FLAG
Definition: rand.cpp:389
int max_dim
Definition: ann_test.cpp:477
static int annRanInt(int n)
Definition: rand.cpp:112
int dim
Definition: ann2fig.cpp:81
ANNbool new_clust
Definition: ann_test.cpp:476
double annRan0()
Definition: rand.cpp:59
double std_dev
Definition: ann_test.cpp:480
static double annRanUnif(double lo, double hi)
Definition: rand.cpp:124
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
void annCoGaussPts ( ANNpointArray  pa,
int  n,
int  dim,
double  correlation 
)

Definition at line 250 of file rand.cpp.

References annRanGauss(), and dim.

Referenced by generatePts().

255 {
256  double std_dev_w = sqrt(1.0 - correlation * correlation);
257  for (int i = 0; i < n; i++) {
258  double previous = annRanGauss();
259  pa[i][0] = (ANNcoord) previous;
260  for (int d = 1; d < dim; d++) {
261  previous = correlation*previous + std_dev_w*annRanGauss();
262  pa[i][d] = (ANNcoord) previous;
263  }
264  }
265 }
static double annRanGauss()
Definition: rand.cpp:137
double ANNcoord
Definition: ANN.h:158
int dim
Definition: ann2fig.cpp:81
void annCoLaplacePts ( ANNpointArray  pa,
int  n,
int  dim,
double  correlation 
)

Definition at line 273 of file rand.cpp.

References annRan0(), annRanLaplace(), and dim.

Referenced by generatePts().

278 {
279  double wn;
280  double corr_sq = correlation * correlation;
281 
282  for (int i = 0; i < n; i++) {
283  double previous = annRanLaplace();
284  pa[i][0] = (ANNcoord) previous;
285  for (int d = 1; d < dim; d++) {
286  double temp = annRan0();
287  if (temp < corr_sq)
288  wn = 0.0;
289  else
290  wn = annRanLaplace();
291  previous = correlation * previous + wn;
292  pa[i][d] = (ANNcoord) previous;
293  }
294  }
295 }
double ANNcoord
Definition: ANN.h:158
static double annRanLaplace()
Definition: rand.cpp:181
int dim
Definition: ann2fig.cpp:81
double annRan0()
Definition: rand.cpp:59
void annGaussPts ( ANNpointArray  pa,
int  n,
int  dim,
double  std_dev 
)

Definition at line 214 of file rand.cpp.

References annRanGauss(), dim, and std_dev.

Referenced by generatePts().

219 {
220  for (int i = 0; i < n; i++) {
221  for (int d = 0; d < dim; d++) {
222  pa[i][d] = (ANNcoord) (annRanGauss() * std_dev);
223  }
224  }
225 }
static double annRanGauss()
Definition: rand.cpp:137
double ANNcoord
Definition: ANN.h:158
int dim
Definition: ann2fig.cpp:81
double std_dev
Definition: ann_test.cpp:480
void annLaplacePts ( ANNpointArray  pa,
int  n,
int  dim 
)

Definition at line 232 of file rand.cpp.

References annRanLaplace(), and dim.

Referenced by generatePts().

236 {
237  for (int i = 0; i < n; i++) {
238  for (int d = 0; d < dim; d++) {
239  pa[i][d] = (ANNcoord) annRanLaplace();
240  }
241  }
242 }
double ANNcoord
Definition: ANN.h:158
static double annRanLaplace()
Definition: rand.cpp:181
int dim
Definition: ann2fig.cpp:81
void annPlanted ( ANNpointArray  pa,
int  n,
int  dim,
ANNpointArray  src,
int  n_src,
double  std_dev 
)

Definition at line 580 of file rand.cpp.

References annRanGauss(), annRanInt(), and dim.

Referenced by generatePts().

587 {
588  for (int i = 0; i < n; i++) {
589  int c = annRanInt(n_src); // generate source index
590  for (int d = 0; d < dim; d++) {
591  pa[i][d] = (ANNcoord) (std_dev*annRanGauss() + src[c][d]);
592  }
593  }
594 }
static double annRanGauss()
Definition: rand.cpp:137
double ANNcoord
Definition: ANN.h:158
static int annRanInt(int n)
Definition: rand.cpp:112
int dim
Definition: ann2fig.cpp:81
double std_dev
Definition: ann_test.cpp:480
void annUniformPts ( ANNpointArray  pa,
int  n,
int  dim 
)

Definition at line 196 of file rand.cpp.

References annRanUnif(), and dim.

Referenced by generatePts().

200 {
201  for (int i = 0; i < n; i++) {
202  for (int d = 0; d < dim; d++) {
203  pa[i][d] = (ANNcoord) (annRanUnif(-1,1));
204  }
205  }
206 }
double ANNcoord
Definition: ANN.h:158
int dim
Definition: ann2fig.cpp:81
static double annRanUnif(double lo, double hi)
Definition: rand.cpp:124

Variable Documentation

int annIdum

Definition at line 42 of file rand.cpp.

Referenced by annRan0(), generatePts(), initGlobals(), and main().


Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5