added datafiles

This commit is contained in:
Morten Hjorth-Jensen
2020-09-17 15:37:23 +02:00
parent a7ea446efa
commit fc6d25f744
29 changed files with 22900 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
3.3773726001100143E-005, 3.1715032621225665E-002
2.7018980800880114E-004, 0.25379346864959029
9.1189060202970370E-004, 0.85691856357595775
2.1615184640704091E-003, 2.0322700794292126
4.2217157501375172E-003, 3.9716946611295496
7.2951248162376296E-003, 6.8678138410008760
1.1584388018377344E-002, 10.913973030767592
1.7292147712563273E-002, 16.304871533080519
2.4621046254802003E-002, 23.235226466525493
3.3773726001100138E-002, 31.902701432416372
4.4952829307464297E-002, 42.504284679798289
5.8360998529901037E-002, 55.243642496340065
7.4200876024417023E-002, 70.325036648868448
9.2675104147018753E-002, 87.967299710326188
0.11398632525371297, 108.39264632432710
0.13833718170050618 , 131.84282952216495
0.16593031584340495 , 158.57124952965228
0.19696837003841602 , 188.82820513039681
0.203199995458126059, 195.042764094891368
0.211199995279312130, 202.937172130123315
0.219199995100498229, 210.852580165355278
0.227199994921684245, 218.789988200587175
0.235199994742870316, 226.748396235819115
0.243199994564056388, 234.740804271051104
0.251199994385242487, 242.757212306283037
0.259199994206428530, 250.797620341515000
0.267199994027614574, 258.874028376746878
0.275199993848800673, 266.977436411978829
0.283199993669986716, 275.092844447210780
0.291199993491172815, 283.248252482442751
0.299199993312358858, 291.445660517674696
0.307199993133544902, 299.655068552906641
0.315199992954731001, 307.909476588138546
0.323199992775917044, 316.192884623370503
0.339199992418289187, 332.846700693834407
0.355199992060661329, 349.620516764298316
0.371199991703033416, 366.537332834762140
0.387199991345405559, 383.604148905225998
0.403199990987777701, 400.801964975689941
0.419199990630149844, 418.158781046153820
0.435199990272521986, 435.624597116617792
0.451199989914894073, 453.288413187081574
0.467199989557266215, 471.062229257545425
0.483199989199638358, 489.048045328009380
0.499199988842010500, 507.146861398473277
0.515199988484382643, 525.392677468937222
0.531199988126754730, 543.829493539401028
0.531999988108873390, 544.796634342924222
0.550079987704753859, 565.860416502548446
0.567999987304210641, 586.865970501467928
0.585599986910820047, 607.703068178978242
0.603199986517429343, 628.645165856488575
0.620639986127614951, 649.578035373294142
0.637919985741376872, 670.496676729395176
0.655199985355138792, 691.549318085496111
0.672479984968900713, 712.766959441597237
0.689599984586238834, 733.981372636993456
0.706879984200000755, 755.521013993094471
0.724159983813762675, 777.228655349195492
0.741439983427524596, 799.117296705296553
0.758719983041286516, 821.191938061397536
0.775999982655048326, 843.460579417498366
0.793439982265233934, 866.080448934304059
0.810879981875419542, 888.907318451109631
0.828479981482028949, 912.100416128620054
0.846239981085061932, 935.664741966834868
0.864159980684518825, 959.607295965754474
0.882079980283975607, 983.787849964674024
0.900159979879856187, 1008.36063212429838
0.918399979472160344, 1033.33564244462718
0.936639979064464612, 1058.56865276495591
0.955199978649616255, 1084.36811940669395
0.973919978231191585, 1110.59381420913678
0.992799977809190715, 1137.25073717228429
1.01183997738361353, 1164.35288829613614
1.06047997629642499, 1234.41724915034661
1.11039997518062594, 1307.72443529019392
1.16191997402906422, 1384.74890303708753
1.21535997283458719, 1466.00110871243692
1.27071997159719463, 1551.73305231624181
1.32847997030615828, 1642.68741833061654
1.38895996895432461, 1739.56266307697001
1.45263996753096580, 1843.32947103741640
1.52031996601820008, 1955.19398301547858
1.59295996439456933, 2077.14256797538474
1.67167996263504026, 2211.44382304206692
1.75855996069312082, 2361.74471430468566
1.85647995850443825, 2533.64534865592441
1.96959995597600934, 2734.93465827410455
2.10543995293974895, 2980.03336671234320
1 3.3773726001100143E-005 3.1715032621225665E-002
2 2.7018980800880114E-004 0.25379346864959029
3 9.1189060202970370E-004 0.85691856357595775
4 2.1615184640704091E-003 2.0322700794292126
5 4.2217157501375172E-003 3.9716946611295496
6 7.2951248162376296E-003 6.8678138410008760
7 1.1584388018377344E-002 10.913973030767592
8 1.7292147712563273E-002 16.304871533080519
9 2.4621046254802003E-002 23.235226466525493
10 3.3773726001100138E-002 31.902701432416372
11 4.4952829307464297E-002 42.504284679798289
12 5.8360998529901037E-002 55.243642496340065
13 7.4200876024417023E-002 70.325036648868448
14 9.2675104147018753E-002 87.967299710326188
15 0.11398632525371297 108.39264632432710
16 0.13833718170050618 131.84282952216495
17 0.16593031584340495 158.57124952965228
18 0.19696837003841602 188.82820513039681
19 0.203199995458126059 195.042764094891368
20 0.211199995279312130 202.937172130123315
21 0.219199995100498229 210.852580165355278
22 0.227199994921684245 218.789988200587175
23 0.235199994742870316 226.748396235819115
24 0.243199994564056388 234.740804271051104
25 0.251199994385242487 242.757212306283037
26 0.259199994206428530 250.797620341515000
27 0.267199994027614574 258.874028376746878
28 0.275199993848800673 266.977436411978829
29 0.283199993669986716 275.092844447210780
30 0.291199993491172815 283.248252482442751
31 0.299199993312358858 291.445660517674696
32 0.307199993133544902 299.655068552906641
33 0.315199992954731001 307.909476588138546
34 0.323199992775917044 316.192884623370503
35 0.339199992418289187 332.846700693834407
36 0.355199992060661329 349.620516764298316
37 0.371199991703033416 366.537332834762140
38 0.387199991345405559 383.604148905225998
39 0.403199990987777701 400.801964975689941
40 0.419199990630149844 418.158781046153820
41 0.435199990272521986 435.624597116617792
42 0.451199989914894073 453.288413187081574
43 0.467199989557266215 471.062229257545425
44 0.483199989199638358 489.048045328009380
45 0.499199988842010500 507.146861398473277
46 0.515199988484382643 525.392677468937222
47 0.531199988126754730 543.829493539401028
48 0.531999988108873390 544.796634342924222
49 0.550079987704753859 565.860416502548446
50 0.567999987304210641 586.865970501467928
51 0.585599986910820047 607.703068178978242
52 0.603199986517429343 628.645165856488575
53 0.620639986127614951 649.578035373294142
54 0.637919985741376872 670.496676729395176
55 0.655199985355138792 691.549318085496111
56 0.672479984968900713 712.766959441597237
57 0.689599984586238834 733.981372636993456
58 0.706879984200000755 755.521013993094471
59 0.724159983813762675 777.228655349195492
60 0.741439983427524596 799.117296705296553
61 0.758719983041286516 821.191938061397536
62 0.775999982655048326 843.460579417498366
63 0.793439982265233934 866.080448934304059
64 0.810879981875419542 888.907318451109631
65 0.828479981482028949 912.100416128620054
66 0.846239981085061932 935.664741966834868
67 0.864159980684518825 959.607295965754474
68 0.882079980283975607 983.787849964674024
69 0.900159979879856187 1008.36063212429838
70 0.918399979472160344 1033.33564244462718
71 0.936639979064464612 1058.56865276495591
72 0.955199978649616255 1084.36811940669395
73 0.973919978231191585 1110.59381420913678
74 0.992799977809190715 1137.25073717228429
75 1.01183997738361353 1164.35288829613614
76 1.06047997629642499 1234.41724915034661
77 1.11039997518062594 1307.72443529019392
78 1.16191997402906422 1384.74890303708753
79 1.21535997283458719 1466.00110871243692
80 1.27071997159719463 1551.73305231624181
81 1.32847997030615828 1642.68741833061654
82 1.38895996895432461 1739.56266307697001
83 1.45263996753096580 1843.32947103741640
84 1.52031996601820008 1955.19398301547858
85 1.59295996439456933 2077.14256797538474
86 1.67167996263504026 2211.44382304206692
87 1.75855996069312082 2361.74471430468566
88 1.85647995850443825 2533.64534865592441
89 1.96959995597600934 2734.93465827410455
90 2.10543995293974895 2980.03336671234320
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,67 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
double invers_period = 1./RAND_MAX; // initialise the random number generator
srand(time(NULL)); // This produces the so-called seed in MC jargon
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = double(rand())*invers_period;
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d between two
// to a most 1/4 of the total number of cycles
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
@@ -0,0 +1,76 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
// Initialize the seed and call the Mersienne algo
std::random_device rd;
std::mt19937_64 gen(rd());
// Set up the uniform distribution for x \in [[0, 1]
std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = RandomNumberGenerator(gen);
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt("autocor.dat")
data1 = np.loadtxt("automersenne.dat")
# Make arrays containing x-axis and binding energies as function of A
x = data[:,0]
corr = data[:,1]
corr2 = data1[:,1]
plt.plot(x, corr ,'ro', x, corr2, 'b')
plt.axis([0,1000,-0.2, 1.1])
plt.xlabel(r'$d$')
plt.ylabel(r'$C_d$')
plt.title(r'autocorrelation function for RNG')
plt.savefig('autocorr.pdf')
plt.show()
+90
View File
@@ -0,0 +1,90 @@
3.3773726001100143E-005, 3.1715032621225665E-002
2.7018980800880114E-004, 0.25379346864959029
9.1189060202970370E-004, 0.85691856357595775
2.1615184640704091E-003, 2.0322700794292126
4.2217157501375172E-003, 3.9716946611295496
7.2951248162376296E-003, 6.8678138410008760
1.1584388018377344E-002, 10.913973030767592
1.7292147712563273E-002, 16.304871533080519
2.4621046254802003E-002, 23.235226466525493
3.3773726001100138E-002, 31.902701432416372
4.4952829307464297E-002, 42.504284679798289
5.8360998529901037E-002, 55.243642496340065
7.4200876024417023E-002, 70.325036648868448
9.2675104147018753E-002, 87.967299710326188
0.11398632525371297, 108.39264632432710
0.13833718170050618 , 131.84282952216495
0.16593031584340495 , 158.57124952965228
0.19696837003841602 , 188.82820513039681
0.203199995458126059, 195.042764094891368
0.211199995279312130, 202.937172130123315
0.219199995100498229, 210.852580165355278
0.227199994921684245, 218.789988200587175
0.235199994742870316, 226.748396235819115
0.243199994564056388, 234.740804271051104
0.251199994385242487, 242.757212306283037
0.259199994206428530, 250.797620341515000
0.267199994027614574, 258.874028376746878
0.275199993848800673, 266.977436411978829
0.283199993669986716, 275.092844447210780
0.291199993491172815, 283.248252482442751
0.299199993312358858, 291.445660517674696
0.307199993133544902, 299.655068552906641
0.315199992954731001, 307.909476588138546
0.323199992775917044, 316.192884623370503
0.339199992418289187, 332.846700693834407
0.355199992060661329, 349.620516764298316
0.371199991703033416, 366.537332834762140
0.387199991345405559, 383.604148905225998
0.403199990987777701, 400.801964975689941
0.419199990630149844, 418.158781046153820
0.435199990272521986, 435.624597116617792
0.451199989914894073, 453.288413187081574
0.467199989557266215, 471.062229257545425
0.483199989199638358, 489.048045328009380
0.499199988842010500, 507.146861398473277
0.515199988484382643, 525.392677468937222
0.531199988126754730, 543.829493539401028
0.531999988108873390, 544.796634342924222
0.550079987704753859, 565.860416502548446
0.567999987304210641, 586.865970501467928
0.585599986910820047, 607.703068178978242
0.603199986517429343, 628.645165856488575
0.620639986127614951, 649.578035373294142
0.637919985741376872, 670.496676729395176
0.655199985355138792, 691.549318085496111
0.672479984968900713, 712.766959441597237
0.689599984586238834, 733.981372636993456
0.706879984200000755, 755.521013993094471
0.724159983813762675, 777.228655349195492
0.741439983427524596, 799.117296705296553
0.758719983041286516, 821.191938061397536
0.775999982655048326, 843.460579417498366
0.793439982265233934, 866.080448934304059
0.810879981875419542, 888.907318451109631
0.828479981482028949, 912.100416128620054
0.846239981085061932, 935.664741966834868
0.864159980684518825, 959.607295965754474
0.882079980283975607, 983.787849964674024
0.900159979879856187, 1008.36063212429838
0.918399979472160344, 1033.33564244462718
0.936639979064464612, 1058.56865276495591
0.955199978649616255, 1084.36811940669395
0.973919978231191585, 1110.59381420913678
0.992799977809190715, 1137.25073717228429
1.01183997738361353, 1164.35288829613614
1.06047997629642499, 1234.41724915034661
1.11039997518062594, 1307.72443529019392
1.16191997402906422, 1384.74890303708753
1.21535997283458719, 1466.00110871243692
1.27071997159719463, 1551.73305231624181
1.32847997030615828, 1642.68741833061654
1.38895996895432461, 1739.56266307697001
1.45263996753096580, 1843.32947103741640
1.52031996601820008, 1955.19398301547858
1.59295996439456933, 2077.14256797538474
1.67167996263504026, 2211.44382304206692
1.75855996069312082, 2361.74471430468566
1.85647995850443825, 2533.64534865592441
1.96959995597600934, 2734.93465827410455
2.10543995293974895, 2980.03336671234320
1 3.3773726001100143E-005 3.1715032621225665E-002
2 2.7018980800880114E-004 0.25379346864959029
3 9.1189060202970370E-004 0.85691856357595775
4 2.1615184640704091E-003 2.0322700794292126
5 4.2217157501375172E-003 3.9716946611295496
6 7.2951248162376296E-003 6.8678138410008760
7 1.1584388018377344E-002 10.913973030767592
8 1.7292147712563273E-002 16.304871533080519
9 2.4621046254802003E-002 23.235226466525493
10 3.3773726001100138E-002 31.902701432416372
11 4.4952829307464297E-002 42.504284679798289
12 5.8360998529901037E-002 55.243642496340065
13 7.4200876024417023E-002 70.325036648868448
14 9.2675104147018753E-002 87.967299710326188
15 0.11398632525371297 108.39264632432710
16 0.13833718170050618 131.84282952216495
17 0.16593031584340495 158.57124952965228
18 0.19696837003841602 188.82820513039681
19 0.203199995458126059 195.042764094891368
20 0.211199995279312130 202.937172130123315
21 0.219199995100498229 210.852580165355278
22 0.227199994921684245 218.789988200587175
23 0.235199994742870316 226.748396235819115
24 0.243199994564056388 234.740804271051104
25 0.251199994385242487 242.757212306283037
26 0.259199994206428530 250.797620341515000
27 0.267199994027614574 258.874028376746878
28 0.275199993848800673 266.977436411978829
29 0.283199993669986716 275.092844447210780
30 0.291199993491172815 283.248252482442751
31 0.299199993312358858 291.445660517674696
32 0.307199993133544902 299.655068552906641
33 0.315199992954731001 307.909476588138546
34 0.323199992775917044 316.192884623370503
35 0.339199992418289187 332.846700693834407
36 0.355199992060661329 349.620516764298316
37 0.371199991703033416 366.537332834762140
38 0.387199991345405559 383.604148905225998
39 0.403199990987777701 400.801964975689941
40 0.419199990630149844 418.158781046153820
41 0.435199990272521986 435.624597116617792
42 0.451199989914894073 453.288413187081574
43 0.467199989557266215 471.062229257545425
44 0.483199989199638358 489.048045328009380
45 0.499199988842010500 507.146861398473277
46 0.515199988484382643 525.392677468937222
47 0.531199988126754730 543.829493539401028
48 0.531999988108873390 544.796634342924222
49 0.550079987704753859 565.860416502548446
50 0.567999987304210641 586.865970501467928
51 0.585599986910820047 607.703068178978242
52 0.603199986517429343 628.645165856488575
53 0.620639986127614951 649.578035373294142
54 0.637919985741376872 670.496676729395176
55 0.655199985355138792 691.549318085496111
56 0.672479984968900713 712.766959441597237
57 0.689599984586238834 733.981372636993456
58 0.706879984200000755 755.521013993094471
59 0.724159983813762675 777.228655349195492
60 0.741439983427524596 799.117296705296553
61 0.758719983041286516 821.191938061397536
62 0.775999982655048326 843.460579417498366
63 0.793439982265233934 866.080448934304059
64 0.810879981875419542 888.907318451109631
65 0.828479981482028949 912.100416128620054
66 0.846239981085061932 935.664741966834868
67 0.864159980684518825 959.607295965754474
68 0.882079980283975607 983.787849964674024
69 0.900159979879856187 1008.36063212429838
70 0.918399979472160344 1033.33564244462718
71 0.936639979064464612 1058.56865276495591
72 0.955199978649616255 1084.36811940669395
73 0.973919978231191585 1110.59381420913678
74 0.992799977809190715 1137.25073717228429
75 1.01183997738361353 1164.35288829613614
76 1.06047997629642499 1234.41724915034661
77 1.11039997518062594 1307.72443529019392
78 1.16191997402906422 1384.74890303708753
79 1.21535997283458719 1466.00110871243692
80 1.27071997159719463 1551.73305231624181
81 1.32847997030615828 1642.68741833061654
82 1.38895996895432461 1739.56266307697001
83 1.45263996753096580 1843.32947103741640
84 1.52031996601820008 1955.19398301547858
85 1.59295996439456933 2077.14256797538474
86 1.67167996263504026 2211.44382304206692
87 1.75855996069312082 2361.74471430468566
88 1.85647995850443825 2533.64534865592441
89 1.96959995597600934 2734.93465827410455
90 2.10543995293974895 2980.03336671234320
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,67 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
double invers_period = 1./RAND_MAX; // initialise the random number generator
srand(time(NULL)); // This produces the so-called seed in MC jargon
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = double(rand())*invers_period;
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d between two
// to a most 1/4 of the total number of cycles
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
@@ -0,0 +1,76 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
// Initialize the seed and call the Mersienne algo
std::random_device rd;
std::mt19937_64 gen(rd());
// Set up the uniform distribution for x \in [[0, 1]
std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = RandomNumberGenerator(gen);
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt("autocor.dat")
data1 = np.loadtxt("automersenne.dat")
# Make arrays containing x-axis and binding energies as function of A
x = data[:,0]
corr = data[:,1]
corr2 = data1[:,1]
plt.plot(x, corr ,'ro', x, corr2, 'b')
plt.axis([0,1000,-0.2, 1.1])
plt.xlabel(r'$d$')
plt.ylabel(r'$C_d$')
plt.title(r'autocorrelation function for RNG')
plt.savefig('autocorr.pdf')
plt.show()
+90
View File
@@ -0,0 +1,90 @@
3.3773726001100143E-005, 3.1715032621225665E-002
2.7018980800880114E-004, 0.25379346864959029
9.1189060202970370E-004, 0.85691856357595775
2.1615184640704091E-003, 2.0322700794292126
4.2217157501375172E-003, 3.9716946611295496
7.2951248162376296E-003, 6.8678138410008760
1.1584388018377344E-002, 10.913973030767592
1.7292147712563273E-002, 16.304871533080519
2.4621046254802003E-002, 23.235226466525493
3.3773726001100138E-002, 31.902701432416372
4.4952829307464297E-002, 42.504284679798289
5.8360998529901037E-002, 55.243642496340065
7.4200876024417023E-002, 70.325036648868448
9.2675104147018753E-002, 87.967299710326188
0.11398632525371297, 108.39264632432710
0.13833718170050618 , 131.84282952216495
0.16593031584340495 , 158.57124952965228
0.19696837003841602 , 188.82820513039681
0.203199995458126059, 195.042764094891368
0.211199995279312130, 202.937172130123315
0.219199995100498229, 210.852580165355278
0.227199994921684245, 218.789988200587175
0.235199994742870316, 226.748396235819115
0.243199994564056388, 234.740804271051104
0.251199994385242487, 242.757212306283037
0.259199994206428530, 250.797620341515000
0.267199994027614574, 258.874028376746878
0.275199993848800673, 266.977436411978829
0.283199993669986716, 275.092844447210780
0.291199993491172815, 283.248252482442751
0.299199993312358858, 291.445660517674696
0.307199993133544902, 299.655068552906641
0.315199992954731001, 307.909476588138546
0.323199992775917044, 316.192884623370503
0.339199992418289187, 332.846700693834407
0.355199992060661329, 349.620516764298316
0.371199991703033416, 366.537332834762140
0.387199991345405559, 383.604148905225998
0.403199990987777701, 400.801964975689941
0.419199990630149844, 418.158781046153820
0.435199990272521986, 435.624597116617792
0.451199989914894073, 453.288413187081574
0.467199989557266215, 471.062229257545425
0.483199989199638358, 489.048045328009380
0.499199988842010500, 507.146861398473277
0.515199988484382643, 525.392677468937222
0.531199988126754730, 543.829493539401028
0.531999988108873390, 544.796634342924222
0.550079987704753859, 565.860416502548446
0.567999987304210641, 586.865970501467928
0.585599986910820047, 607.703068178978242
0.603199986517429343, 628.645165856488575
0.620639986127614951, 649.578035373294142
0.637919985741376872, 670.496676729395176
0.655199985355138792, 691.549318085496111
0.672479984968900713, 712.766959441597237
0.689599984586238834, 733.981372636993456
0.706879984200000755, 755.521013993094471
0.724159983813762675, 777.228655349195492
0.741439983427524596, 799.117296705296553
0.758719983041286516, 821.191938061397536
0.775999982655048326, 843.460579417498366
0.793439982265233934, 866.080448934304059
0.810879981875419542, 888.907318451109631
0.828479981482028949, 912.100416128620054
0.846239981085061932, 935.664741966834868
0.864159980684518825, 959.607295965754474
0.882079980283975607, 983.787849964674024
0.900159979879856187, 1008.36063212429838
0.918399979472160344, 1033.33564244462718
0.936639979064464612, 1058.56865276495591
0.955199978649616255, 1084.36811940669395
0.973919978231191585, 1110.59381420913678
0.992799977809190715, 1137.25073717228429
1.01183997738361353, 1164.35288829613614
1.06047997629642499, 1234.41724915034661
1.11039997518062594, 1307.72443529019392
1.16191997402906422, 1384.74890303708753
1.21535997283458719, 1466.00110871243692
1.27071997159719463, 1551.73305231624181
1.32847997030615828, 1642.68741833061654
1.38895996895432461, 1739.56266307697001
1.45263996753096580, 1843.32947103741640
1.52031996601820008, 1955.19398301547858
1.59295996439456933, 2077.14256797538474
1.67167996263504026, 2211.44382304206692
1.75855996069312082, 2361.74471430468566
1.85647995850443825, 2533.64534865592441
1.96959995597600934, 2734.93465827410455
2.10543995293974895, 2980.03336671234320
1 3.3773726001100143E-005 3.1715032621225665E-002
2 2.7018980800880114E-004 0.25379346864959029
3 9.1189060202970370E-004 0.85691856357595775
4 2.1615184640704091E-003 2.0322700794292126
5 4.2217157501375172E-003 3.9716946611295496
6 7.2951248162376296E-003 6.8678138410008760
7 1.1584388018377344E-002 10.913973030767592
8 1.7292147712563273E-002 16.304871533080519
9 2.4621046254802003E-002 23.235226466525493
10 3.3773726001100138E-002 31.902701432416372
11 4.4952829307464297E-002 42.504284679798289
12 5.8360998529901037E-002 55.243642496340065
13 7.4200876024417023E-002 70.325036648868448
14 9.2675104147018753E-002 87.967299710326188
15 0.11398632525371297 108.39264632432710
16 0.13833718170050618 131.84282952216495
17 0.16593031584340495 158.57124952965228
18 0.19696837003841602 188.82820513039681
19 0.203199995458126059 195.042764094891368
20 0.211199995279312130 202.937172130123315
21 0.219199995100498229 210.852580165355278
22 0.227199994921684245 218.789988200587175
23 0.235199994742870316 226.748396235819115
24 0.243199994564056388 234.740804271051104
25 0.251199994385242487 242.757212306283037
26 0.259199994206428530 250.797620341515000
27 0.267199994027614574 258.874028376746878
28 0.275199993848800673 266.977436411978829
29 0.283199993669986716 275.092844447210780
30 0.291199993491172815 283.248252482442751
31 0.299199993312358858 291.445660517674696
32 0.307199993133544902 299.655068552906641
33 0.315199992954731001 307.909476588138546
34 0.323199992775917044 316.192884623370503
35 0.339199992418289187 332.846700693834407
36 0.355199992060661329 349.620516764298316
37 0.371199991703033416 366.537332834762140
38 0.387199991345405559 383.604148905225998
39 0.403199990987777701 400.801964975689941
40 0.419199990630149844 418.158781046153820
41 0.435199990272521986 435.624597116617792
42 0.451199989914894073 453.288413187081574
43 0.467199989557266215 471.062229257545425
44 0.483199989199638358 489.048045328009380
45 0.499199988842010500 507.146861398473277
46 0.515199988484382643 525.392677468937222
47 0.531199988126754730 543.829493539401028
48 0.531999988108873390 544.796634342924222
49 0.550079987704753859 565.860416502548446
50 0.567999987304210641 586.865970501467928
51 0.585599986910820047 607.703068178978242
52 0.603199986517429343 628.645165856488575
53 0.620639986127614951 649.578035373294142
54 0.637919985741376872 670.496676729395176
55 0.655199985355138792 691.549318085496111
56 0.672479984968900713 712.766959441597237
57 0.689599984586238834 733.981372636993456
58 0.706879984200000755 755.521013993094471
59 0.724159983813762675 777.228655349195492
60 0.741439983427524596 799.117296705296553
61 0.758719983041286516 821.191938061397536
62 0.775999982655048326 843.460579417498366
63 0.793439982265233934 866.080448934304059
64 0.810879981875419542 888.907318451109631
65 0.828479981482028949 912.100416128620054
66 0.846239981085061932 935.664741966834868
67 0.864159980684518825 959.607295965754474
68 0.882079980283975607 983.787849964674024
69 0.900159979879856187 1008.36063212429838
70 0.918399979472160344 1033.33564244462718
71 0.936639979064464612 1058.56865276495591
72 0.955199978649616255 1084.36811940669395
73 0.973919978231191585 1110.59381420913678
74 0.992799977809190715 1137.25073717228429
75 1.01183997738361353 1164.35288829613614
76 1.06047997629642499 1234.41724915034661
77 1.11039997518062594 1307.72443529019392
78 1.16191997402906422 1384.74890303708753
79 1.21535997283458719 1466.00110871243692
80 1.27071997159719463 1551.73305231624181
81 1.32847997030615828 1642.68741833061654
82 1.38895996895432461 1739.56266307697001
83 1.45263996753096580 1843.32947103741640
84 1.52031996601820008 1955.19398301547858
85 1.59295996439456933 2077.14256797538474
86 1.67167996263504026 2211.44382304206692
87 1.75855996069312082 2361.74471430468566
88 1.85647995850443825 2533.64534865592441
89 1.96959995597600934 2734.93465827410455
90 2.10543995293974895 2980.03336671234320
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,67 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
double invers_period = 1./RAND_MAX; // initialise the random number generator
srand(time(NULL)); // This produces the so-called seed in MC jargon
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = double(rand())*invers_period;
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d between two
// to a most 1/4 of the total number of cycles
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
@@ -0,0 +1,76 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
// Initialize the seed and call the Mersienne algo
std::random_device rd;
std::mt19937_64 gen(rd());
// Set up the uniform distribution for x \in [[0, 1]
std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = RandomNumberGenerator(gen);
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt("autocor.dat")
data1 = np.loadtxt("automersenne.dat")
# Make arrays containing x-axis and binding energies as function of A
x = data[:,0]
corr = data[:,1]
corr2 = data1[:,1]
plt.plot(x, corr ,'ro', x, corr2, 'b')
plt.axis([0,1000,-0.2, 1.1])
plt.xlabel(r'$d$')
plt.ylabel(r'$C_d$')
plt.title(r'autocorrelation function for RNG')
plt.savefig('autocorr.pdf')
plt.show()
+90
View File
@@ -0,0 +1,90 @@
3.3773726001100143E-005, 3.1715032621225665E-002
2.7018980800880114E-004, 0.25379346864959029
9.1189060202970370E-004, 0.85691856357595775
2.1615184640704091E-003, 2.0322700794292126
4.2217157501375172E-003, 3.9716946611295496
7.2951248162376296E-003, 6.8678138410008760
1.1584388018377344E-002, 10.913973030767592
1.7292147712563273E-002, 16.304871533080519
2.4621046254802003E-002, 23.235226466525493
3.3773726001100138E-002, 31.902701432416372
4.4952829307464297E-002, 42.504284679798289
5.8360998529901037E-002, 55.243642496340065
7.4200876024417023E-002, 70.325036648868448
9.2675104147018753E-002, 87.967299710326188
0.11398632525371297, 108.39264632432710
0.13833718170050618 , 131.84282952216495
0.16593031584340495 , 158.57124952965228
0.19696837003841602 , 188.82820513039681
0.203199995458126059, 195.042764094891368
0.211199995279312130, 202.937172130123315
0.219199995100498229, 210.852580165355278
0.227199994921684245, 218.789988200587175
0.235199994742870316, 226.748396235819115
0.243199994564056388, 234.740804271051104
0.251199994385242487, 242.757212306283037
0.259199994206428530, 250.797620341515000
0.267199994027614574, 258.874028376746878
0.275199993848800673, 266.977436411978829
0.283199993669986716, 275.092844447210780
0.291199993491172815, 283.248252482442751
0.299199993312358858, 291.445660517674696
0.307199993133544902, 299.655068552906641
0.315199992954731001, 307.909476588138546
0.323199992775917044, 316.192884623370503
0.339199992418289187, 332.846700693834407
0.355199992060661329, 349.620516764298316
0.371199991703033416, 366.537332834762140
0.387199991345405559, 383.604148905225998
0.403199990987777701, 400.801964975689941
0.419199990630149844, 418.158781046153820
0.435199990272521986, 435.624597116617792
0.451199989914894073, 453.288413187081574
0.467199989557266215, 471.062229257545425
0.483199989199638358, 489.048045328009380
0.499199988842010500, 507.146861398473277
0.515199988484382643, 525.392677468937222
0.531199988126754730, 543.829493539401028
0.531999988108873390, 544.796634342924222
0.550079987704753859, 565.860416502548446
0.567999987304210641, 586.865970501467928
0.585599986910820047, 607.703068178978242
0.603199986517429343, 628.645165856488575
0.620639986127614951, 649.578035373294142
0.637919985741376872, 670.496676729395176
0.655199985355138792, 691.549318085496111
0.672479984968900713, 712.766959441597237
0.689599984586238834, 733.981372636993456
0.706879984200000755, 755.521013993094471
0.724159983813762675, 777.228655349195492
0.741439983427524596, 799.117296705296553
0.758719983041286516, 821.191938061397536
0.775999982655048326, 843.460579417498366
0.793439982265233934, 866.080448934304059
0.810879981875419542, 888.907318451109631
0.828479981482028949, 912.100416128620054
0.846239981085061932, 935.664741966834868
0.864159980684518825, 959.607295965754474
0.882079980283975607, 983.787849964674024
0.900159979879856187, 1008.36063212429838
0.918399979472160344, 1033.33564244462718
0.936639979064464612, 1058.56865276495591
0.955199978649616255, 1084.36811940669395
0.973919978231191585, 1110.59381420913678
0.992799977809190715, 1137.25073717228429
1.01183997738361353, 1164.35288829613614
1.06047997629642499, 1234.41724915034661
1.11039997518062594, 1307.72443529019392
1.16191997402906422, 1384.74890303708753
1.21535997283458719, 1466.00110871243692
1.27071997159719463, 1551.73305231624181
1.32847997030615828, 1642.68741833061654
1.38895996895432461, 1739.56266307697001
1.45263996753096580, 1843.32947103741640
1.52031996601820008, 1955.19398301547858
1.59295996439456933, 2077.14256797538474
1.67167996263504026, 2211.44382304206692
1.75855996069312082, 2361.74471430468566
1.85647995850443825, 2533.64534865592441
1.96959995597600934, 2734.93465827410455
2.10543995293974895, 2980.03336671234320
1 3.3773726001100143E-005 3.1715032621225665E-002
2 2.7018980800880114E-004 0.25379346864959029
3 9.1189060202970370E-004 0.85691856357595775
4 2.1615184640704091E-003 2.0322700794292126
5 4.2217157501375172E-003 3.9716946611295496
6 7.2951248162376296E-003 6.8678138410008760
7 1.1584388018377344E-002 10.913973030767592
8 1.7292147712563273E-002 16.304871533080519
9 2.4621046254802003E-002 23.235226466525493
10 3.3773726001100138E-002 31.902701432416372
11 4.4952829307464297E-002 42.504284679798289
12 5.8360998529901037E-002 55.243642496340065
13 7.4200876024417023E-002 70.325036648868448
14 9.2675104147018753E-002 87.967299710326188
15 0.11398632525371297 108.39264632432710
16 0.13833718170050618 131.84282952216495
17 0.16593031584340495 158.57124952965228
18 0.19696837003841602 188.82820513039681
19 0.203199995458126059 195.042764094891368
20 0.211199995279312130 202.937172130123315
21 0.219199995100498229 210.852580165355278
22 0.227199994921684245 218.789988200587175
23 0.235199994742870316 226.748396235819115
24 0.243199994564056388 234.740804271051104
25 0.251199994385242487 242.757212306283037
26 0.259199994206428530 250.797620341515000
27 0.267199994027614574 258.874028376746878
28 0.275199993848800673 266.977436411978829
29 0.283199993669986716 275.092844447210780
30 0.291199993491172815 283.248252482442751
31 0.299199993312358858 291.445660517674696
32 0.307199993133544902 299.655068552906641
33 0.315199992954731001 307.909476588138546
34 0.323199992775917044 316.192884623370503
35 0.339199992418289187 332.846700693834407
36 0.355199992060661329 349.620516764298316
37 0.371199991703033416 366.537332834762140
38 0.387199991345405559 383.604148905225998
39 0.403199990987777701 400.801964975689941
40 0.419199990630149844 418.158781046153820
41 0.435199990272521986 435.624597116617792
42 0.451199989914894073 453.288413187081574
43 0.467199989557266215 471.062229257545425
44 0.483199989199638358 489.048045328009380
45 0.499199988842010500 507.146861398473277
46 0.515199988484382643 525.392677468937222
47 0.531199988126754730 543.829493539401028
48 0.531999988108873390 544.796634342924222
49 0.550079987704753859 565.860416502548446
50 0.567999987304210641 586.865970501467928
51 0.585599986910820047 607.703068178978242
52 0.603199986517429343 628.645165856488575
53 0.620639986127614951 649.578035373294142
54 0.637919985741376872 670.496676729395176
55 0.655199985355138792 691.549318085496111
56 0.672479984968900713 712.766959441597237
57 0.689599984586238834 733.981372636993456
58 0.706879984200000755 755.521013993094471
59 0.724159983813762675 777.228655349195492
60 0.741439983427524596 799.117296705296553
61 0.758719983041286516 821.191938061397536
62 0.775999982655048326 843.460579417498366
63 0.793439982265233934 866.080448934304059
64 0.810879981875419542 888.907318451109631
65 0.828479981482028949 912.100416128620054
66 0.846239981085061932 935.664741966834868
67 0.864159980684518825 959.607295965754474
68 0.882079980283975607 983.787849964674024
69 0.900159979879856187 1008.36063212429838
70 0.918399979472160344 1033.33564244462718
71 0.936639979064464612 1058.56865276495591
72 0.955199978649616255 1084.36811940669395
73 0.973919978231191585 1110.59381420913678
74 0.992799977809190715 1137.25073717228429
75 1.01183997738361353 1164.35288829613614
76 1.06047997629642499 1234.41724915034661
77 1.11039997518062594 1307.72443529019392
78 1.16191997402906422 1384.74890303708753
79 1.21535997283458719 1466.00110871243692
80 1.27071997159719463 1551.73305231624181
81 1.32847997030615828 1642.68741833061654
82 1.38895996895432461 1739.56266307697001
83 1.45263996753096580 1843.32947103741640
84 1.52031996601820008 1955.19398301547858
85 1.59295996439456933 2077.14256797538474
86 1.67167996263504026 2211.44382304206692
87 1.75855996069312082 2361.74471430468566
88 1.85647995850443825 2533.64534865592441
89 1.96959995597600934 2734.93465827410455
90 2.10543995293974895 2980.03336671234320
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,67 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
double invers_period = 1./RAND_MAX; // initialise the random number generator
srand(time(NULL)); // This produces the so-called seed in MC jargon
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = double(rand())*invers_period;
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d between two
// to a most 1/4 of the total number of cycles
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
@@ -0,0 +1,76 @@
// This function computes the autocorrelation function for
// the standard c++ random number generator
#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
// output file as global variable
ofstream ofile;
// Main function begins here
int main(int argc, char* argv[])
{
int n;
char *outfilename;
cin >> n;
double MCint = 0.; double MCintsqr2=0.;
// Initialize the seed and call the Mersienne algo
std::random_device rd;
std::mt19937_64 gen(rd());
// Set up the uniform distribution for x \in [[0, 1]
std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
// Compute the variance and the mean value of the uniform distribution
// Compute also the specific values x for each cycle in order to be able to
// the covariance and the correlation function
// Read in output file, abort if there are too few command-line arguments
if( argc <= 2 ){
cout << "Bad Usage: " << argv[0] <<
" read also output file and number of cycles on same line" << endl;
exit(1);
}
else{
outfilename=argv[1];
}
ofile.open(outfilename);
// Get the number of Monte-Carlo samples
n = atoi(argv[2]);
double *X;
X = new double[n];
for (int i = 0; i < n; i++){
double x = RandomNumberGenerator(gen);
X[i] = x;
MCint += x;
MCintsqr2 += x*x;
}
double Mean = MCint/((double) n );
MCintsqr2 = MCintsqr2/((double) n );
double STDev = sqrt(MCintsqr2-Mean*Mean);
double Variance = MCintsqr2-Mean*Mean;
// Write mean value and standard deviation
cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
// Now we compute the autocorrelation function, setting the distance d
double *autocor; autocor = new double[n];
for (int j = 0; j < n; j++){
double sum = 0.0;
for (int k = 0; k < (n-j); k++){
sum += (X[k]-Mean)*(X[k+j]-Mean);
}
autocor[j] = sum/Variance/((double) n );
ofile << setiosflags(ios::showpoint | ios::uppercase);
ofile << setw(15) << setprecision(8) << j;
ofile << setw(15) << setprecision(8) << autocor[j] << endl;
}
ofile.close(); // close output file
return 0;
} // end of main program
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt("autocor.dat")
data1 = np.loadtxt("automersenne.dat")
# Make arrays containing x-axis and binding energies as function of A
x = data[:,0]
corr = data[:,1]
corr2 = data1[:,1]
plt.plot(x, corr ,'ro', x, corr2, 'b')
plt.axis([0,1000,-0.2, 1.1])
plt.xlabel(r'$d$')
plt.ylabel(r'$C_d$')
plt.title(r'autocorrelation function for RNG')
plt.savefig('autocorr.pdf')
plt.show()
+4
View File
@@ -13,6 +13,7 @@ DATE: today
!split
===== Thursday September 17 =====
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember17.mp4?vrtx=view-as-webpage" and "link to handwritten notes":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember17.pdf".
!split
===== Ridge and LASSO Regression, reminder =====
@@ -919,6 +920,9 @@ other models for all values of $\lambda$.
!split
===== Friday September 18: Intro to Logistic Regression =====
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember18.mp4?vrtx=view-as-webpage" and "link to handwritten notes":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember18.pdf".
!split
===== Logistic Regression =====