homog2d library
Macros | Functions | Variables
dtest1.cpp File Reference

generates data for precision test More...

#include "../homog2d.hpp"
#include <limits>
#include <iostream>
Include dependency graph for dtest1.cpp:

Macros

#define NUMTYPE   long double
 

Functions

NUMTYPE getRandom ()
 
int main (int argc, const char **argv)
 

Variables

double gk = 1000.
 
double grmax = std::numeric_limits<double>::min()
 
double grmin = std::numeric_limits<double>::max()
 

Detailed Description

generates data for precision test

This program will run 1 million of the following experiment:

Eventually, it will print several computed value:

  1. range
  2. min coordinate value
  3. max coordinate value
  4. mean distance value
  5. max distance value
  6. mean distance value (computed with the "running std" method)
  7. standard deviation of distance value

Standard deviation is computed using a "single pass" algorithm, see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance

To run that experiment on several ranges use the provided target:

$ make dtest1

Macro Definition Documentation

◆ NUMTYPE

#define NUMTYPE   long double

Function Documentation

◆ getRandom()

NUMTYPE getRandom ( )
50 {
51  double r = (2.0*rand()/RAND_MAX -1.) * gk;
52  grmin = std::min( std::abs(r), grmin );
53  grmax = std::max( std::abs(r), grmax );
54  return r;
55 }
double grmax
Definition: dtest1.cpp:47
double gk
Definition: dtest1.cpp:44
double grmin
Definition: dtest1.cpp:46
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
const char **  argv 
)
58 {
59  auto nb = 1E6; // nb of runs
60  char sep = ';';
61  if( argc>1)
62  gk = std::atof( argv[1] );
63 // std::cout << "Running with k=" << gk << "\n";
64 
65  std::srand( time(0) );
66  long double sum = 0.;
67  long double vmax = 0.;
68  long double M2 = 0.;
69  long double mean = 0.;
70  for( auto i=0; i<nb; i++ )
71  {
74  auto li = pt1 * pt2;
75 
76  long double d = li.distTo(pt1);
77  vmax = std::max( vmax, d );
78  sum += d;
79 
80  auto delta = d - mean;
81  mean += delta / (i+1);
82  auto delta2 = d - mean;
83  M2 += delta * delta2;
84 
85  }
86  auto sigma = M2 / (nb-1);
87  std::cout << std::scientific
88  << gk << sep
89  << grmin << sep
90  << grmax << sep
91  << sep << sum / nb
92  << sep << vmax
93  << sep << mean
94  << sep << sigma
95  << "\n";
96 }
double grmax
Definition: dtest1.cpp:47
NUMTYPE getRandom()
Definition: dtest1.cpp:49
Line2d li
Definition: homog2d_test.cpp:4035
double gk
Definition: dtest1.cpp:44
double grmin
Definition: dtest1.cpp:46
HOMOG2D_INUMTYPE distTo(const Point2d_< FPT2 > &pt) const
overload for line to point distance
Definition: homog2d.hpp:4223
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:

Variable Documentation

◆ gk

double gk = 1000.

◆ grmax

double grmax = std::numeric_limits<double>::min()

◆ grmin

double grmin = std::numeric_limits<double>::max()