-
Notifications
You must be signed in to change notification settings - Fork 3
/
ppunfix5.h
1526 lines (1156 loc) · 34.3 KB
/
ppunfix5.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// C++ Library: ppunfix5.h
//
// LSN April 2000
// May 2001 cleaned
// Oct 2001 new function estimate_means added
//
// Modification of ppunfix4.h
//
// NEW FEATURES: faster as space extended when needed
// can initialise with extra integer which means n(X) constant
//
// ---------------------------------------------------------------------------
//
// En punktprocess er defineret i k=1,2,3 dimensioner paa [0,ai]^k (*ikke s^2)
// med tilhoerende edge-correction window [lowi,uppi]^k (*nyt)
// Relationen er altid lebesgue afstand (*indskraenkning) og relationen
// findes selvom type process ikke er defineret (*NYT)
// Processen kan vaere Strauss eller Geyer
//
// k: dimension af process {1,2,3} DEFAULT=3
// initialiseres med initDim(k) eller readData(fil,k) (1)
// n: antal punkter DEFAULT=0 (DEFAULT is random number of points)
// initialiseres med initNum(n), readData(fil,k) eller makeProcess() (1)
// R: relations afstand DEFAULT=0
// initialiseres med initRelafst(R) (1)
// S: definitionsrum DEFAULT=[0,1]^k
// initialiseres med initAkse(i,lgd) saa (i+1)'te akse er [0,lgd]
// W: edge-correction vindue DEFAULT=S
// initialiseres med initWindow(i,low,upp) saa (i+1)'te akse er [low,upp]
// OBS: initWindow skal koeres EFTER initAkse (ellers overskrives W=S)
//
// (1) k, n og R initialiseres ogsaa ved def af special-process Strauss/Geyer
// Desuden initialiseres gamma (og c for Geyer)
//
//
// Tilknyttede funktioner:
//
// void random_number ( void );
// void fixed_number ( void ); Optional: can be called with or without
// void fixed_number ( int num ); specifying number of ponts
//
// void initNum ( int num );
// void initDim ( int dim );
// void initRelafst ( ind afst );
// void initAkse ( int i, double lgd );
// void initWindow ( int i, double low, double upp );
//
// void readData ( string filename, int dim );
// void saveData ( string filename );
//
// void transform ( int akseno, double & theta );
// void invTransform ( int akseno, double & theta );
//
// void copy ( pointprocess *x );
// void resetcoords ( int coord, pointprocess *x );
// Can only be used to reset coordinates coords to value of x,
// when other coords equals
// void croptowindow ( void );
//
// bool inside ( point eta );
// double whatis ( int i, int coord ); i er nummer punkt coord i {0,1,2}
// int whatis_n ( void ); #punkter i S
// int whatis_n_window ( void ); #punkter i W
// int whatis_s ( void ); #naboer i S
// int whatis_s_window (void); #naboer i W plus par hvor x1 i W x2 i S\W
// int whatis_k ( void );
// double whatis_R ( void );
// double whatis_akse ( int akseno );
// double whatis_L ( int akseno );
// double whatis_U ( int akseno );
// double whatis_sum ( int coord ); #sum af coord-coordinater
// double whatis_sum_window ( int coord ); #sum af coord-coordinater i W
//
// void triplets_canon ( int & nn, int & ss, int & ww );
// # Beregner kanoniske statistic for triplets process: n(x), s(x), w(x)
//
// int quadcount2D ( double x1, double x2, double y1, double y2 ); OBS kun 2D
// problemet med observerede data er, at de ofte ligger paa skillelinjen
// loesning: Gundersens metode. OBS: korrekt selv for yderste hoejre kant
//
// void countNeighboursTo( point eta, int & nn, int & nn_w );
// Taeller antal naboer til eta i nn: S og nn_w: W
// OBS: inklusiv eta selv hvis eta er i punktprocesses hhv pp snit W
// int countNeighbours( void );
// int countNeighbours_window ( void );
//
// void binoprocess ( void );
// void poissonprocess ( double intensity );
// void emptyprocess ( void );
// void makeMHBDstep ( void );
// Random number case: Metropolis-Hastings birth/death
// void makeMHRstep ( void );
// Fixed number case: Metropolis-Hastings replace
// void makeprocess ( int );
// Calls upper two according to case int=#iterations
// void begin_chain_here ( int );
// Chain start in current point pattern and int MH-steps are performed
//
// virtual double acceptProb( int j, int & nn, int & nn_w ) {}
// Generates the Strauss or the Geyer point processes in a window of the
// plane or the space with a random number of points.
//
// Parameters: beta, gamma, R and c (Geyer)
// xakse, yakse and zakse (length of the axis)
// WARNING: if c is an integer program does not work!!!
//
// Algorithm: Metropolis-Hastings birth and death.
// Cf. e.g. J. Moeller (1999) sect 4.3.2 (special case p 150)
//
// OBS: Det er denne process som opdaterer s og sw!!!
// nn og nn_w er 'snyde'-variable som recorder
// nn = s(eta;x snit W) og nn_w = s(eta;x snit S\W)
// Bemaerk at der skal traekkes 1 fra hvis eta selv er talt med som nabo
//
//
// Kommentar til mig selv:
//
// *En af de store forskelle paa dette og tidligere programmer
// *er maaden hvorpaa s er inkorporeret: Den er angivet som global variabel
// *GRUND: countNeighbours koerer langsomt, og den er koert en gang allerede
// *i hvert Metropolis-step, saa den information lagres til senere brug
// *Trick for ikke at beregne s ved readData og poissonprocess:
// * s og sw initialiseres til -1 fra start
// hvis makeMHstep bliver udfoert beregnes de automatisk
// ellers beregnes de foerst naar der spoerges: whatis_s(_window)
// Bemaek, ved transformation saettes s og sw til -1 igen
//
// *MODIFICATIONS: enable to make MCMC importance sampling and edge-correction
#ifndef __ppunfix5_h
#define __ppunfix5_h
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>
#include <cassert>
#include "common.h"
using namespace std;
class point
{
private:
public:
double pt[3];
double lebdist ( point& q, int k );
bool relatedTo ( int k, double R, point& q);
void replaceWith ( point& p );
void unifpoint ( int k, double xakse, double yakse, double zakse );
void transform ( int & akseno, double & a, double & theta );
void invTransform ( int & akseno, double & a, double & theta );
void invtransOtrans ( int & akseno, double & a, double & theta1, double & theta2 );
};
class pointprocess
{
protected:
int maxlgd, n, k, s, sw;
double R;
bool randomnumber;
double akse[3], windowL[3], windowU[3];
void extend_dataset( void );
void makeMHBDstep ( void );
void makeMHRstep ( void );
bool inside ( point eta );
void countNeighboursTo( point eta, int & nn, int & nn_w );
int countNeighbours ( void );
int countNeighbours ( double afst );
int countNeighbours_window ( void );
public:
point *data;
pointprocess ( void );
void random_number ( void );
void fixed_number ( void );
void fixed_number ( int num );
void initNum ( int num );
void initDim ( int dim );
void initRelafst ( double afst );
void initAkse ( int i, double lgd );
void initWindow ( int i, double low, double upp );
void readData ( string filename, int dim );
void saveData ( string filename );
void transform ( int akseno, double & theta );
void invTransform ( int akseno, double & theta );
void invtransOtrans ( int akseno, double & theta1, double & theta2 );
void copy ( pointprocess *x );
void resetcoords ( int coord, pointprocess *x );
void croptowindow ( void );
double whatis ( int i, int coord );
int whatis_n ( void );
int whatis_n_window ( void );
int whatis_s ( void );
int whatis_s ( double afst );
int whatis_s_window (void);
int whatis_k ( void );
double whatis_R ( void );
double whatis_akse ( int akseno );
double whatis_L ( int akseno );
double whatis_U ( int akseno );
double whatis_sum ( int coord );
double whatis_sum_window ( int coord );
double dist ( int coord1, int coord2 );
void triplets_canon ( int & nn, int & ss, int & ww );
int quadcount2D ( double x1, double x2, double y1, double y2 );
void binoprocess ( void );
void poissonprocess ( double intensity );
void emptyprocess ( void );
void begin_chain_here ( int );
void makeprocess ( int );
void estimate_means ( int nburn, int nsamp, int nspac,
double & En, double & Es );
//double Lnul ( double theta[k] );
virtual double acceptProb( int j, int & nn, int & nn_w ) {} // random num
virtual double acceptProb( point xi, int etaIndex ) {} // fixed num
};
class straussprocess : public pointprocess
{
protected:
double beta, gamma;
public:
straussprocess( int dim, double b, double gam, double afs );
straussprocess( int dim, double b, double gam, double afs, int num );
double acceptProb ( int j, int & nn, int & nn_w );
double acceptProb( point xi, int etaIndex );
// STRAUSSPROCESSENS EGNE FUNKTIONER
void resetGamma ( double gam );
void resetBeta ( double b );
double estiNON ( void );
double estiPOW ( double obsNON, double Gpow );
};
class geyerprocess : public pointprocess
{
double beta, gamma, c;
public:
geyerprocess
( int dim, double b, double gam, double afs, double upperlim );
geyerprocess
( int dim, double b, double gam, double afs, double upperlim, int num );
double acceptProb ( int j, int & nn, int & nn_w );
double acceptProb( point xi, int etaIndex );
// GEYERPROCESSENS EGNE FUNKTIONER
double u( void );
void reset_c ( double cval );
};
//---------------------------------------------------------------------------
// ******************************* POINT ************************************
//---------------------------------------------------------------------------
void point :: unifpoint ( int k, double xakse, double yakse, double zakse )
{
if ( k==2 )
{
pt[0] = drand48()*xakse;
pt[1] = drand48()*yakse;
pt[2] = 0;
}
if ( k==3 )
{
pt[0] = drand48()*xakse;
pt[1] = drand48()*yakse;
pt[2] = drand48()*zakse;
}
}
double point :: lebdist ( point& q, int k )
{
int i;
double res = 0;
for ( i=0; i<k; i++ ) //k is real dimension
{
res += pow((pt[i] - q.pt[i]),2);
}
return sqrt(res);
}
bool point :: relatedTo( int k, double R, point& q )
{
if ( lebdist( q, k ) <= R ) { return true; }
else { return false; }
}
/*
bool point :: relatedTo( int k, double R, point& q )
{
// Periodic relation (torus)
// we need to make all translations of one of the two points
// there are 3^k different translations
// associate: 0 = subtract, 1 = void, 2 = add
// Notice that (0,0,0) is usual relation
// Example in two dimensions, where mid square is the window.
// Need to consider all 9 points * whether one is related to @
//
// ----------------
// | | | |
// | | | |
// |* |* |* |
// ----------------
// | | @| |
// | | | |
// |* |* |* |
// ----------------
// | | | |
// | | | |
// |* |* |* |
// ----------------
// (only need to add if point closer than R to left border)
// OBS OBS OBS : Only made for unit square and two dimensions
point copy_q;
int i, j;
copy_q.replaceWith(q);
for ( i = 0; i < k; i++ )
copy_q.pt[i] -= 2;
for ( i = 0; i < 3; i++ ) // i is the coordinate
{
for ( j = 0; j < 3; j++ )
{
copy_q.pt[0] = q.pt[0] + i - 1;
copy_q.pt[1] = q.pt[1] + j - 1;
// only unit square, else = q.pt[i] + j*ai - 1
// where ai is the length of ith side of the window
if ( lebdist( copy_q, k ) <= R )
return true;
}
}
return false;
}
*/
void point :: replaceWith( point& p )
{
int j;
for ( j=0; j<3; j++ )
pt[j] = p.pt[j];
}
void point :: transform ( int & akseno, double & a, double & theta )
{
if ( ! (-0.001 < theta && theta < 0.001) )
pt[akseno] = log((exp(theta*a)-1)*pt[akseno]/a + 1)/theta;
}
void point :: invTransform ( int & akseno, double & a, double & theta )
{
if ( ! (-0.001 < theta && theta < 0.001) )
pt[akseno] = a*(exp(theta*pt[akseno])-1)/(exp(theta*a)-1);
}
void point :: invtransOtrans ( int & akseno, double & a, double & theta1, double & theta2 )
{
if ( ! ( -0.0001 < theta1-theta2 && theta1-theta2 < 0.0001 ) )
pt[akseno] =
a*( pow( (exp(theta1*a)-1)*pt[akseno]/a + 1 , theta2/theta1) )/
(exp(theta2*a)-1);
}
//---------------------------------------------------------------------------
// **************************** POINTPROCESS ********************************
//---------------------------------------------------------------------------
pointprocess :: pointprocess ( void )
{
// Default settings
maxlgd = 200;
data = new point[maxlgd];
n=0; k=3;
s=-1; sw=-1;
R=0;
randomnumber = true;
akse[0]=1; akse[1]=1; akse[2]=1;
windowL[0]=0; windowL[1]=0; windowL[2]=0;
windowU[0]=1; windowU[1]=1; windowU[2]=1;
}
void pointprocess :: extend_dataset( void )
{
point *olddata;
olddata = data;
data = new point[2*maxlgd];
int i;
for ( i = 0; i < maxlgd; i++ )
data[i].replaceWith(olddata[i]);
delete [] olddata;
maxlgd *= 2;
}
void pointprocess :: random_number ( void )
{
randomnumber = true;
}
void pointprocess :: fixed_number ( void )
{
randomnumber = false;
}
void pointprocess :: fixed_number ( int num )
{
randomnumber = false;
n = num;
}
void pointprocess :: initNum ( int num )
{
n = num;
s = -1;
sw = -1;
}
void pointprocess :: initDim ( int dim )
{
if ( ( dim == 1 ) || ( dim==2 ) || ( dim==3 ) )
k=dim;
else { cout << "Dimensionen skal vaere 1, 2 eller 3" << endl; abort(); }
s = -1;
sw = -1;
}
void pointprocess :: initRelafst ( double afst )
{
if ( afst > 0 )
R = afst;
else { cout << "Relations-afstanden R skal vaere positiv" << endl; abort(); }
s = -1;
sw = -1;
}
void pointprocess :: initAkse ( int i, double lgd )
{
if ( i < k && (( i==0 ) || ( i==1 ) || (i==2 )) )
akse[i] = lgd;
else { cout << "Akse-nummer er ugyldigt" << endl; abort(); }
s = -1;
sw = -1;
}
void pointprocess :: initWindow ( int i, double low, double upp )
{
if ( i < k && (( i==0 ) || ( i==1 ) || (i==2 )) )
{
windowL[i] = low;
windowU[i] = upp;
}
else { cout << "Akse-nummer er ugyldigt" << endl; abort(); }
s = -1;
sw = -1;
}
void pointprocess :: readData ( string filename, int dim )
{
ifstream infile ( filename.c_str() );
if (infile)
{
int i=0; int j;
while ( ! infile.eof() )
{
if ( i >= maxlgd )
extend_dataset();
for ( j = 0; j < dim; j++ )
infile >> data[i].pt[j];
i++;
}
k=dim;
n=--i;
s=-1;
sw=-1;
}
else
{
cout << "Error: infile does not exist" << endl;
abort();
}
}
void pointprocess :: saveData ( string filename )
{
ofstream OutputFile ( filename.c_str() );
if ( OutputFile )
{
int i,j;
for ( i=0; i<n; i++ )
{
for ( j=0; j<k; j++ )
OutputFile << data[i].pt[j] << " ";
OutputFile << endl;
}
OutputFile.close();
cout << "The data has been stored on the file: " << filename << endl;
}
else { cout << "COULD NOT CREATE FILE" << endl; abort(); }
}
void pointprocess :: transform ( int akseno, double & theta )
{
if ( akseno < k && ( akseno == 0 || akseno == 1 || akseno == 2 ) )
{
int i;
for ( i=0; i<n; i++ )
data[i].transform(akseno,akse[akseno],theta);
s=-1; // Da antal naboer er forkert efter transformationen
sw=-1;
}
else
{
cout << "Axis number is not valid in call transform" << endl;
abort();
}
}
void pointprocess :: invTransform ( int akseno, double & theta )
{
if ( akseno < k && ( akseno == 0 || akseno == 1 || akseno == 2 ) )
{
int i;
for ( i=0; i<n; i++ )
data[i].invTransform(akseno,akse[akseno],theta);
s=-1; // Da antal naboer er forkert efter transformationen
sw=-1;
}
else
{
cout << "Axis number is not valid in call invTransform" << endl;
abort();
}
}
void pointprocess :: invtransOtrans ( int akseno, double & theta1, double & theta2 )
{
if ( akseno < k && ( akseno == 0 || akseno == 1 || akseno == 2 ) )
{
int i;
for ( i=0; i<n; i++ )
data[i].invtransOtrans(akseno,akse[akseno],theta1,theta2);
s=-1; // Da antal naboer er forkert efter transformationen
sw=-1;
}
else
{
cout << "Axis number is not valid in call transform" << endl;
abort();
}
}
void pointprocess :: copy ( pointprocess *x )
{
int i,j;
n = x -> whatis_n();
while ( n > maxlgd )
extend_dataset();
k = x -> whatis_k();
for (i = 0; i < n; i++ )
for (j = 0; j < k; j++ )
data[i].pt[j] = x -> data[i].pt[j];
s = x -> whatis_s();
sw = x -> whatis_s_window();
R = x -> whatis_R();
for (j = 0; j < k; j++ )
{
akse[j] = x -> whatis_akse(j);
windowL[j] = x -> whatis_L(j);
windowU[j] = x -> whatis_U(j);
}
}
void pointprocess :: resetcoords ( int coord, pointprocess *x )
{
assert ( coord < k && (( coord==0 ) || ( coord==1 ) || ( coord==2 )) );
// Index out of range: point number or coordinate
assert ( k == x -> whatis_k() && n == x -> whatis_n() );
// Error in resetcoords - dimension of k or n differ
int i;
for (i = 0; i < n; i++ ) data[i].pt[coord] = x -> data[i].pt[coord];
s = x -> whatis_s();
sw = x -> whatis_s_window();
R = x -> whatis_R();
}
void pointprocess :: croptowindow ( void )
{
int i, j, up = 0;
int norig = n;
n = whatis_n_window();
for (i = 0; i < norig; i++ )
if ( inside(data[i]) )
{
for (j = 0; j < k; j++ )
data[up].pt[j] = data[i].pt[j] - windowL[j];
up++;
}
s = -1;
sw = -1;
for (j = 0; j < k; j++ )
{
akse[j] = windowU[j]-windowL[j];
windowL[j] = 0;
windowU[j] = akse[j];
}
}
bool pointprocess :: inside ( point eta )
{
int j;
for ( j = 0; j < k; j++ )
{
if ( eta.pt[j] < windowL[j] ) { return false; }
if ( windowU[j] < eta.pt[j] ) { return false; }
}
return true;
}
double pointprocess :: whatis ( int i, int coord )
{
if ( i < n && coord < k && (( coord==0 ) || ( coord==1 ) || ( coord==2 )) )
return data[i].pt[coord];
else
{
cout << "Index out of range: point number or coordinate" << endl;
abort();
}
}
int pointprocess :: whatis_n ( void )
{
return n;
}
int pointprocess :: whatis_n_window ( void )
{
int res = 0, i;
for ( i = 0; i < n; i++ )
if ( inside(data[i]) )
res++;
return res;
}
int pointprocess :: whatis_s ( void )
{
if ( s == -1 ) { s = countNeighbours(); }
return s;
}
int pointprocess :: whatis_s ( double afst )
{
return countNeighbours(afst);
}
int pointprocess :: whatis_s_window ( void )
{
if ( sw < 0 ) { sw = countNeighbours_window(); }
return sw;
}
int pointprocess :: whatis_k ( void )
{
return k;
}
double pointprocess :: whatis_R ( void )
{
return R;
}
double pointprocess :: whatis_akse ( int akseno )
{
return akse[akseno];
}
double pointprocess :: whatis_L ( int akseno )
{
return windowL[akseno];
}
double pointprocess :: whatis_U ( int akseno )
{
return windowU[akseno];
}
double pointprocess :: whatis_sum ( int coord )
{
double sum = 0;
if ( coord < k && (( coord==0 ) || ( coord==1 ) || ( coord==2 )) )
{
int i;
for ( i = 0; i < n; i++ ) { sum += data[i].pt[coord]; }
}
else
{
cout << "Index out of range: coordinate (whatis_sum)" << endl;
abort();
}
return sum;
}
double pointprocess :: whatis_sum_window ( int coord )
{
double sum = 0;
if ( coord < k && (( coord==0 ) || ( coord==1 ) || ( coord==2 )) )
{
int i;
double tmp, a = windowL[coord], b = windowU[coord];
// Kunne bruge inside() i stedet, men dette er hurtigere
for ( i = 0; i < n; i++ )
{
tmp = data[i].pt[coord];
if ( a < tmp && tmp < b ) { sum += tmp; }
}
}
else
{
cout << "Index out of range: coordinate (whatis_sum_window)" << endl;
abort();
}
return sum;
}
double pointprocess :: dist ( int coord1, int coord2 )
{
return data[coord1].lebdist(data[coord2],k);
}
void pointprocess :: triplets_canon ( int & nn, int & ss, int & ww )
{
nn = n;
ss = 0;
ww = 0;
int i, j, l;
for ( i = 0; i < n; i++ )
for ( j = 0; j < i; j++ )
if ( data[i].relatedTo(k,R,data[j]) )
{
ss++;
for ( l = 0; l < j; l++ )
if ( data[l].relatedTo(k,R,data[i]) &&
data[l].relatedTo(k,R,data[j]) )
ww++;
}
}
int pointprocess :: quadcount2D ( double x1, double x2, double y1, double y2 )
{
int antal=0;
int i;
for ( i=0; i<n; i++ )
if ( (x1-0.0000001 < data[i].pt[0]) && (data[i].pt[0] < x2) )
if ( (y1-0.0000001 < data[i].pt[1]) && (data[i].pt[1] < y2) )
antal++;
return antal;
}
void pointprocess :: countNeighboursTo( point eta, int & nn, int & nn_w )
{
// NUMBER OF NEIGHBOURS TO THE PT eta IN nn: S, nn_w: W
// (INCLUSIVE eta ITSELF IF eta IN {pp snit S} and {pp snit W}, RESPECTIVELY)
nn = 0;
nn_w = 0;
int i;
for ( i = 0; i < n; i++ )
if ( eta.relatedTo(k, R, data[i]) )
{
nn++;
if ( inside(data[i]) )
nn_w++;
}
}
int pointprocess :: countNeighbours(void )
{
int ant=0;
int i; int j;
for ( j=0; j<n; j++ )
for ( i=0; i<j; i++ )
if ( data[i].relatedTo(k,R,data[j]) )
ant++;
return ant;
}
int pointprocess :: countNeighbours( double afst )
{
int ant=0;
int i; int j;
for ( j=0; j<n; j++ )
for ( i=0; i<j; i++ )
if ( data[i].relatedTo(k,afst,data[j]) )
ant++;
return ant;
}
int pointprocess :: countNeighbours_window ( void )
{
// TAELLER ANTAL NABOER I ET WINDUE. DVS PUNKT i SKAL LIGGE I W
// MENS PUNKT j KAN LIGGE HVORSOMHELST I S
// HINT: sw(x) = sum_{eta i x snit W} s(eta; x\eta)
// = # naboer hvor mindst det ene punkt ligger i W
bool pktiW[n];
int i; int j, ant = 0;
for ( i=0; i<n; i++ )
{
if ( inside(data[i]) )
pktiW[i] = true;
else
pktiW[i] = false;
}
for ( i=0; i<n; i++ )
for ( j=0; j<i; j++ ) // KUN TAELLE ET PUNKTPAR MED EN GANG
if ( pktiW[i] || pktiW[j] ) // MINDST ET AF DE TO PUNKTER SKAL LIGGE I W
if ( data[i].relatedTo(k,R,data[j]) )
ant++;
return ant;
}
void pointprocess :: binoprocess ( void )
{
while ( n > maxlgd )
extend_dataset();
int i;
for ( i=0; i<n; i++ )
data[i].unifpoint(k,akse[0],akse[1],akse[2]);
}