source: tol/tol_pkg/MatQuery/test/test_0001/test.tol @ aa1e2cc

1941-docker-image-to-testdevel
Last change on this file since aa1e2cc was aa1e2cc, checked in by Víctor de Buen <vdebuen@…>, 17 years ago

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1737 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/* -*- mode: C++ -*- */
2//////////////////////////////////////////////////////////////////////////////
3// FILE   : test.tol
4// PURPOSE: Package MatQuery test
5//////////////////////////////////////////////////////////////////////////////
6
7Text email_ = "vdebuen@tol-project.org";
8Text link_ = "";
9Text summary_ = "checking matrix row selection";
10
11  #Require MatQuery;
12//#Embed "../../../_embed_all.tol";
13
14//Write here the initial test TOL code if needed
15Real numErr0 = Copy(NError);
16Real numWar0 = Copy(NWarning);
17
18//Random seed setting
19Real PutRandomSeed(0);
20Real rndSeed = GetRandomSeed(0);
21WriteLn("Current Random Seed = "<<rndSeed);
22
23
24//The order of magnitude required for number of geographic points
25Real point.num.approx = 20000;
26//Number of cities
27Real city.num = 500;
28//Distance around targets
29Real distance = 2000;
30//Factor of Country size respect dtarget distance
31Real coordFactor = 400;
32//Distance of points inside a city
33Real cityInsideDistance = distance / 4;
34
35//Country dimensions
36Real coord.min = -distance*coordFactor;
37Real coord.max = +distance*coordFactor;
38
39//Log-Normal random generation of number of point by city
40Matrix city.points.num =
41{
42  Real sigma = 0.9995;
43  Real ratio = point.num.approx/city.num;
44  Real nu = Log(ratio)-0.5*sigma^2;
45  Round(Exp(Gaussian(city.num,1,nu,0.99995)))
46};
47Matrix city.points.freq = Frequency(city.points.num,100);
48
49//Exact number of geographic points
50Real point.num = MatSum(city.points.num);
51
52//Locations of cities
53Matrix city.center = BinGroup("<<",For(1,city.num, Matrix(Real city)
54{
55  Rand(1, 2, coord.min, coord.max)
56}));
57
58//Locations of points inside each city as gaussian around the center
59Set city.points = For(1,city.num, Matrix(Real city)
60{
61  Real n = MatDat(city.points.num,city,1);
62  Real x = MatDat(city.center,city,1);
63  Real y = MatDat(city.center,city,2);
64  Matrix X = Rand(n,1,x,x);
65  Matrix Y = Rand(n,1,y,y);
66  (X|Y)+Gaussian(n, 2, 0, cityInsideDistance)
67});
68
69//All points
70VMatrix points = Mat2VMat(BinGroup("<<",city.points));
71
72
73//Target point
74VMatrix p0 = SubRow(points,[[IntRand(1,point.num)]])+
75           Gaussian(1, 2, 0, cityInsideDistance);
76
77Real t0 = Copy(Time);
78//Selecting neighbors of target in an hipercube
79WriteLn("SelectRowsInHyperCube full ...");
80Set p0.select.idx.HC = MatQuery::SelectRowsInHyperCube(
81  points, p0, distance);
82VMatrix p0.select.HC = SubRow(points,p0.select.idx.HC);
83
84Real t1 = Copy(Time);
85WriteLn("SelectRowsInHyperCube full "<<VRows(p0.select.HC)+" items "
86  "Time:"<<(t1-t0));
87
88//Selecting neighbors of target in an hipersphere
89WriteLn("SelectRowsInHyperSphere full ...");
90Set p0.select.idx.HE.1 = MatQuery::SelectRowsInHyperSphere(
91  points, p0, distance);
92VMatrix p0.select.HE.1 = SubRow(points,p0.select.idx.HE.1);
93
94Real t2 = Copy(Time);
95WriteLn("SelectRowsInHyperSphere full "<<VRows(p0.select.HE.1)+" items "
96  "Time:"<<(t2-t1));
97
98//Selecting neighbors of target in an hipersphere from the hipercube
99WriteLn("SelectRowsInHyperSphere over SelectRowsInHyperCube ...");
100Set p0.select.idx.HE.2 = MatQuery::SelectRowsInHyperSphere(
101  p0.select.HC, p0, distance);
102VMatrix p0.select.HE.2 = SubRow(p0.select.HC,p0.select.idx.HE.2);
103Real t3 = Copy(Time);
104WriteLn("SelectRowsInHyperSphere over SelectRowsInHyperCube "<<
105  VRows(p0.select.HE.2)+" items Time:"<<(t3-t2));
106WriteLn("SelectRowsInHyperSphere+SelectRowsInHyperCube Time:"<<(t3-t2+t1-t0));
107
108Real ok.1 = And(
109  Card(p0.select.idx.HE.1) <= Card(p0.select.idx.HC),
110  Card(p0.select.idx.HE.1   *      p0.select.idx.HC) ==
111  Card(p0.select.idx.HE.1));
112
113Real ok.2 = VMatMax(Abs(p0.select.HE.2-p0.select.HE.1))==0;
114
115Real numErr1 = Copy(NError);
116Real numWar1 = Copy(NWarning);
117
118Set partialResults_ = [[numErr0, numErr1,
119                        ok.1, ok.2]];
120
121//This is a messure of the success of the test
122Real quality_ = And(numErr1 == numErr0,
123                    numWar1 == numWar0,
124                    ok.1, ok.2);
125
126//Return the results
127Set resultStr_ = @strTestStatus(summary_, link_, quality_,
128                  "Partial results = "<<partialResults_,
129                  "NO DBServerType", "NO DBServerHost", "NO DBAlias",
130                  email_);
131WriteLn(""<<resultStr_);
132resultStr_;
133
134/* */
135
Note: See TracBrowser for help on using the repository browser.