source: tol/tol_pkg/MatQuery/test/test_0001/test.tol @ 4ddca89

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

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