Files
FYS-STK4155/doc/pub/Statistics/html/._Statistics-bs056.html
T
Morten Hjorth-Jensen 91de985709 Update on html files
2017-11-02 23:30:51 +01:00

515 lines
34 KiB
HTML

<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Data Analysis and Machine Learning: Elements of Probability Theory">
<title>Data Analysis and Machine Learning: Elements of Probability Theory</title>
<!-- Bootstrap style: bootstrap -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
<script src="http://sagecell.sagemath.org/static/jquery.min.js"></script>
<script src="http://sagecell.sagemath.org/embedded_sagecell.js"></script>
<link rel="stylesheet" type="text/css" href="https://sagecell.sagemath.org/static/sagecell_embed.css">
<script>
$(function () {
// Make the div with id 'mycell' a Sage cell
sagecell.makeSagecell({inputLocation: '#mycell',
template: sagecell.templates.minimal,
evalButtonText: 'Activate'});
// Make *any* div with class 'compute' a Sage cell
sagecell.makeSagecell({inputLocation: 'div.compute',
evalButtonText: 'Evaluate'});
});
</script>
</head>
<!-- tocinfo
{'highest level': 1,
'sections': [('Domains and probabilities', 2, None, '___sec0'),
('Tossing a dice', 2, None, '___sec1'),
('Stochastic variables', 2, None, '___sec2'),
('Stochastic variables and the main concepts, the discrete case',
2,
None,
'___sec3'),
('Stochastic variables and the main concepts, the continuous case',
2,
None,
'___sec4'),
('The cumulative probability', 2, None, '___sec5'),
('Properties of PDFs', 2, None, '___sec6'),
('Important distributions, the uniform distribution',
2,
None,
'___sec7'),
('Gaussian distribution', 2, None, '___sec8'),
('Exponential distribution', 2, None, '___sec9'),
('Expectation values', 2, None, '___sec10'),
('Stochastic variables and the main concepts, mean values',
2,
None,
'___sec11'),
('Stochastic variables and the main concepts, central moments, the variance',
2,
None,
'___sec12'),
('Probability Distribution Functions', 2, None, '___sec13'),
('Probability Distribution Functions', 2, None, '___sec14'),
('The three famous Probability Distribution Functions',
2,
None,
'___sec15'),
('Probability Distribution Functions, the normal distribution',
2,
None,
'___sec16'),
('Probability Distribution Functions, the normal distribution',
2,
None,
'___sec17'),
('Probability Distribution Functions, the cumulative distribution',
2,
None,
'___sec18'),
('Probability Distribution Functions, other important distribution',
2,
None,
'___sec19'),
('Probability Distribution Functions, the binomial distribution',
2,
None,
'___sec20'),
("Probability Distribution Functions, Poisson's distribution",
2,
None,
'___sec21'),
("Probability Distribution Functions, Poisson's distribution",
2,
None,
'___sec22'),
('Meet the covariance!', 2, None, '___sec23'),
('Meet the covariance in matrix disguise',
2,
None,
'___sec24'),
('Meet the covariance, uncorrelated events',
2,
None,
'___sec25'),
('Numerical experiments and the covariance',
2,
None,
'___sec26'),
('Numerical experiments and the covariance',
2,
None,
'___sec27'),
('Numerical experiments and the covariance, actual situations',
2,
None,
'___sec28'),
('Numerical experiments and the covariance, our observables',
2,
None,
'___sec29'),
('Numerical experiments and the covariance, the sample variance',
2,
None,
'___sec30'),
('Numerical experiments and the covariance, central limit theorem',
2,
None,
'___sec31'),
('Definition of Correlation Functions and Standard Deviation',
2,
None,
'___sec32'),
('Definition of Correlation Functions and Standard Deviation',
2,
None,
'___sec33'),
('Definition of Correlation Functions and Standard Deviation',
2,
None,
'___sec34'),
('Definition of Correlation Functions and Standard Deviation',
2,
None,
'___sec35'),
('Definition of Correlation Functions and Standard Deviation, sample variance',
2,
None,
'___sec36'),
('Definition of Correlation Functions and Standard Deviation',
2,
None,
'___sec37'),
('Random Numbers', 1, None, '___sec38'),
('Random Numbers, better name: pseudo random numbers',
1,
None,
'___sec39'),
('Random number generator RNG', 1, None, '___sec40'),
('Random number generator RNG and periodic outputs',
1,
None,
'___sec41'),
('Random number generator RNG and its period',
1,
None,
'___sec42'),
('Random number generator RNG, other examples',
1,
None,
'___sec43'),
('Random number generator RNG, other examples',
1,
None,
'___sec44'),
('Random number generator RNG, RAN0', 1, None, '___sec45'),
('Random number generator RNG, RAN0', 1, None, '___sec46'),
('Random number generator RNG, RAN0', 1, None, '___sec47'),
('Random number generator RNG, RAN0', 1, None, '___sec48'),
('Random number generator RNG, RAN0 code', 1, None, '___sec49'),
('Properties of Selected Random Number Generators',
2,
None,
'___sec50'),
('Properties of Selected Random Number Generators',
2,
None,
'___sec51'),
('Properties of Selected Random Number Generators',
2,
None,
'___sec52'),
('Simple demonstration of RNGs using python',
2,
None,
'___sec53'),
('Properties of Selected Random Number Generators',
2,
None,
'___sec54'),
('Correlation function and which random number generators should I use',
2,
None,
'___sec55'),
('Correlation function and which random number generators should I use',
2,
None,
'___sec56'),
('Which RNG should I use?', 1, None, '___sec57'),
('How to use the Mersenne generator', 2, None, '___sec58'),
('Why blocking?', 2, None, '___sec59'),
('Why blocking?', 2, None, '___sec60'),
('Code to demonstrate the calculation of the autocorrelation function',
2,
None,
'___sec61'),
('What is blocking?', 2, None, '___sec62'),
('What is blocking?', 2, None, '___sec63'),
('What is blocking?', 2, None, '___sec64'),
('Implementation', 2, None, '___sec65'),
('Actual implementation with code, main function',
2,
None,
'___sec66'),
('The Bootstrap method', 2, None, '___sec67'),
('Bootstrapping', 2, None, '___sec68'),
('Bootstrapping, recipe', 2, None, '___sec69'),
('Bootstrapping, "code":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Programs/Sampling/analysis.py"',
2,
None,
'___sec70'),
('Jackknife, "code":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Programs/Sampling/analysis.py"',
2,
None,
'___sec71')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Statistics-bs.html">Data Analysis and Machine Learning: Elements of Probability Theory</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="._Statistics-bs001.html#___sec0" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Domains and probabilities</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs002.html#___sec1" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Tossing a dice</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs003.html#___sec2" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic variables</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs004.html#___sec3" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic variables and the main concepts, the discrete case</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs005.html#___sec4" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic variables and the main concepts, the continuous case</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs006.html#___sec5" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The cumulative probability</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs007.html#___sec6" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Properties of PDFs</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs008.html#___sec7" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Important distributions, the uniform distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs009.html#___sec8" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Gaussian distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs010.html#___sec9" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Exponential distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs011.html#___sec10" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Expectation values</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs012.html#___sec11" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic variables and the main concepts, mean values</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs013.html#___sec12" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic variables and the main concepts, central moments, the variance</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs014.html#___sec13" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs015.html#___sec14" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs016.html#___sec15" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The three famous Probability Distribution Functions</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs017.html#___sec16" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, the normal distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs018.html#___sec17" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, the normal distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs019.html#___sec18" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, the cumulative distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs020.html#___sec19" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, other important distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs021.html#___sec20" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, the binomial distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs022.html#___sec21" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, Poisson's distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs023.html#___sec22" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Probability Distribution Functions, Poisson's distribution</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs024.html#___sec23" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Meet the covariance!</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs025.html#___sec24" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Meet the covariance in matrix disguise</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs026.html#___sec25" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Meet the covariance, uncorrelated events</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs027.html#___sec26" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs028.html#___sec27" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs029.html#___sec28" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance, actual situations</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs030.html#___sec29" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance, our observables</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs031.html#___sec30" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance, the sample variance</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs032.html#___sec31" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Numerical experiments and the covariance, central limit theorem</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs033.html#___sec32" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs034.html#___sec33" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs035.html#___sec34" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs036.html#___sec35" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs037.html#___sec36" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation, sample variance</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs038.html#___sec37" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Definition of Correlation Functions and Standard Deviation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs039.html#___sec38" style="font-size: 80%;"><b>Random Numbers</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs040.html#___sec39" style="font-size: 80%;"><b>Random Numbers, better name: pseudo random numbers</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs041.html#___sec40" style="font-size: 80%;"><b>Random number generator RNG</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs042.html#___sec41" style="font-size: 80%;"><b>Random number generator RNG and periodic outputs</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs043.html#___sec42" style="font-size: 80%;"><b>Random number generator RNG and its period</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs044.html#___sec43" style="font-size: 80%;"><b>Random number generator RNG, other examples</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs045.html#___sec44" style="font-size: 80%;"><b>Random number generator RNG, other examples</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs046.html#___sec45" style="font-size: 80%;"><b>Random number generator RNG, RAN0</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs047.html#___sec46" style="font-size: 80%;"><b>Random number generator RNG, RAN0</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs048.html#___sec47" style="font-size: 80%;"><b>Random number generator RNG, RAN0</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs049.html#___sec48" style="font-size: 80%;"><b>Random number generator RNG, RAN0</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs050.html#___sec49" style="font-size: 80%;"><b>Random number generator RNG, RAN0 code</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs051.html#___sec50" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Properties of Selected Random Number Generators</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs052.html#___sec51" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Properties of Selected Random Number Generators</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs053.html#___sec52" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Properties of Selected Random Number Generators</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs054.html#___sec53" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Simple demonstration of RNGs using python</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs055.html#___sec54" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Properties of Selected Random Number Generators</a></li>
<!-- navigation toc: --> <li><a href="#___sec55" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Correlation function and which random number generators should I use</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs057.html#___sec56" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Correlation function and which random number generators should I use</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs058.html#___sec57" style="font-size: 80%;"><b>Which RNG should I use?</b></a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs059.html#___sec58" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;How to use the Mersenne generator</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs060.html#___sec59" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Why blocking?</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs061.html#___sec60" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Why blocking?</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs062.html#___sec61" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Code to demonstrate the calculation of the autocorrelation function</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs063.html#___sec62" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;What is blocking?</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs064.html#___sec63" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;What is blocking?</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs065.html#___sec64" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;What is blocking?</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs066.html#___sec65" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Implementation</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs067.html#___sec66" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Actual implementation with code, main function</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs068.html#___sec67" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The Bootstrap method</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs069.html#___sec68" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Bootstrapping</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs070.html#___sec69" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Bootstrapping, recipe</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs071.html#___sec70" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Bootstrapping, "code":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Programs/Sampling/analysis.py"</a></li>
<!-- navigation toc: --> <li><a href="._Statistics-bs072.html#___sec71" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Jackknife, "code":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Programs/Sampling/analysis.py"</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0056"></a>
<!-- !split -->
<h2 id="___sec55" class="anchor">Correlation function and which random number generators should I use </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
The program here computes the correlation function for one of the standard functions included with the c++ compiler.
<p>
<!-- code=c++ (!bc cppcod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">// This function computes the autocorrelation function for </span>
<span style="color: #408080; font-style: italic">// the standard c++ random number generator</span>
<span style="color: #BC7A00">#include</span> <span style="color: #408080; font-style: italic">&lt;fstream&gt;</span><span style="color: #BC7A00"></span>
<span style="color: #BC7A00">#include</span> <span style="color: #408080; font-style: italic">&lt;iomanip&gt;</span><span style="color: #BC7A00"></span>
<span style="color: #BC7A00">#include</span> <span style="color: #408080; font-style: italic">&lt;iostream&gt;</span><span style="color: #BC7A00"></span>
<span style="color: #BC7A00">#include</span> <span style="color: #408080; font-style: italic">&lt;cmath&gt;</span><span style="color: #BC7A00"></span>
<span style="color: #008000; font-weight: bold">using</span> <span style="color: #008000; font-weight: bold">namespace</span> std;
<span style="color: #408080; font-style: italic">// output file as global variable</span>
ofstream ofile;
<span style="color: #408080; font-style: italic">// Main function begins here </span>
<span style="color: #B00040">int</span> <span style="color: #0000FF">main</span>(<span style="color: #B00040">int</span> argc, <span style="color: #B00040">char</span><span style="color: #666666">*</span> argv[])
{
<span style="color: #B00040">int</span> n;
<span style="color: #B00040">char</span> <span style="color: #666666">*</span>outfilename;
cin <span style="color: #666666">&gt;&gt;</span> n;
<span style="color: #B00040">double</span> MCint <span style="color: #666666">=</span> <span style="color: #666666">0.</span>; <span style="color: #B00040">double</span> MCintsqr2<span style="color: #666666">=0.</span>;
<span style="color: #B00040">double</span> invers_period <span style="color: #666666">=</span> <span style="color: #666666">1./</span>RAND_MAX; <span style="color: #408080; font-style: italic">// initialise the random number generator</span>
srand(time(<span style="color: #008000">NULL</span>)); <span style="color: #408080; font-style: italic">// This produces the so-called seed in MC jargon</span>
<span style="color: #408080; font-style: italic">// Compute the variance and the mean value of the uniform distribution</span>
<span style="color: #408080; font-style: italic">// Compute also the specific values x for each cycle in order to be able to</span>
<span style="color: #408080; font-style: italic">// the covariance and the correlation function </span>
<span style="color: #408080; font-style: italic">// Read in output file, abort if there are too few command-line arguments</span>
<span style="color: #008000; font-weight: bold">if</span>( argc <span style="color: #666666">&lt;=</span> <span style="color: #666666">2</span> ){
cout <span style="color: #666666">&lt;&lt;</span> <span style="color: #BA2121">&quot;Bad Usage: &quot;</span> <span style="color: #666666">&lt;&lt;</span> argv[<span style="color: #666666">0</span>] <span style="color: #666666">&lt;&lt;</span>
<span style="color: #BA2121">&quot; read also output file and number of cycles on same line&quot;</span> <span style="color: #666666">&lt;&lt;</span> endl;
exit(<span style="color: #666666">1</span>);
}
<span style="color: #008000; font-weight: bold">else</span>{
outfilename<span style="color: #666666">=</span>argv[<span style="color: #666666">1</span>];
}
ofile.open(outfilename);
<span style="color: #408080; font-style: italic">// Get the number of Monte-Carlo samples</span>
n <span style="color: #666666">=</span> atoi(argv[<span style="color: #666666">2</span>]);
<span style="color: #B00040">double</span> <span style="color: #666666">*</span>X;
X <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">double</span>[n];
<span style="color: #008000; font-weight: bold">for</span> (<span style="color: #B00040">int</span> i <span style="color: #666666">=</span> <span style="color: #666666">0</span>; i <span style="color: #666666">&lt;</span> n; i<span style="color: #666666">++</span>){
<span style="color: #B00040">double</span> x <span style="color: #666666">=</span> <span style="color: #B00040">double</span>(rand())<span style="color: #666666">*</span>invers_period;
X[i] <span style="color: #666666">=</span> x;
MCint <span style="color: #666666">+=</span> x;
MCintsqr2 <span style="color: #666666">+=</span> x<span style="color: #666666">*</span>x;
}
<span style="color: #B00040">double</span> Mean <span style="color: #666666">=</span> MCint<span style="color: #666666">/</span>((<span style="color: #B00040">double</span>) n );
MCintsqr2 <span style="color: #666666">=</span> MCintsqr2<span style="color: #666666">/</span>((<span style="color: #B00040">double</span>) n );
<span style="color: #B00040">double</span> STDev <span style="color: #666666">=</span> sqrt(MCintsqr2<span style="color: #666666">-</span>Mean<span style="color: #666666">*</span>Mean);
<span style="color: #B00040">double</span> Variance <span style="color: #666666">=</span> MCintsqr2<span style="color: #666666">-</span>Mean<span style="color: #666666">*</span>Mean;
<span style="color: #408080; font-style: italic">// Write mean value and standard deviation </span>
cout <span style="color: #666666">&lt;&lt;</span> <span style="color: #BA2121">&quot; Standard deviation= &quot;</span> <span style="color: #666666">&lt;&lt;</span> STDev <span style="color: #666666">&lt;&lt;</span> <span style="color: #BA2121">&quot; Integral = &quot;</span> <span style="color: #666666">&lt;&lt;</span> Mean <span style="color: #666666">&lt;&lt;</span> endl;
<span style="color: #408080; font-style: italic">// Now we compute the autocorrelation function</span>
<span style="color: #B00040">double</span> <span style="color: #666666">*</span>autocor; autocor <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">double</span>[n];
<span style="color: #008000; font-weight: bold">for</span> (<span style="color: #B00040">int</span> j <span style="color: #666666">=</span> <span style="color: #666666">0</span>; j <span style="color: #666666">&lt;</span> n; j<span style="color: #666666">++</span>){
<span style="color: #B00040">double</span> sum <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>;
<span style="color: #008000; font-weight: bold">for</span> (<span style="color: #B00040">int</span> k <span style="color: #666666">=</span> <span style="color: #666666">0</span>; k <span style="color: #666666">&lt;</span> (n<span style="color: #666666">-</span>j); k<span style="color: #666666">++</span>){
sum <span style="color: #666666">+=</span> (X[k]<span style="color: #666666">-</span>Mean)<span style="color: #666666">*</span>(X[k<span style="color: #666666">+</span>j]<span style="color: #666666">-</span>Mean);
}
autocor[j] <span style="color: #666666">=</span> sum<span style="color: #666666">/</span>Variance<span style="color: #666666">/</span>((<span style="color: #B00040">double</span>) n );
ofile <span style="color: #666666">&lt;&lt;</span> setiosflags(ios<span style="color: #666666">::</span>showpoint <span style="color: #666666">|</span> ios<span style="color: #666666">::</span>uppercase);
ofile <span style="color: #666666">&lt;&lt;</span> setw(<span style="color: #666666">15</span>) <span style="color: #666666">&lt;&lt;</span> setprecision(<span style="color: #666666">8</span>) <span style="color: #666666">&lt;&lt;</span> j;
ofile <span style="color: #666666">&lt;&lt;</span> setw(<span style="color: #666666">15</span>) <span style="color: #666666">&lt;&lt;</span> setprecision(<span style="color: #666666">8</span>) <span style="color: #666666">&lt;&lt;</span> autocor[j] <span style="color: #666666">&lt;&lt;</span> endl;
}
ofile.close(); <span style="color: #408080; font-style: italic">// close output file</span>
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">0</span>;
} <span style="color: #408080; font-style: italic">// end of main program </span>
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._Statistics-bs055.html">&laquo;</a></li>
<li><a href="._Statistics-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._Statistics-bs048.html">49</a></li>
<li><a href="._Statistics-bs049.html">50</a></li>
<li><a href="._Statistics-bs050.html">51</a></li>
<li><a href="._Statistics-bs051.html">52</a></li>
<li><a href="._Statistics-bs052.html">53</a></li>
<li><a href="._Statistics-bs053.html">54</a></li>
<li><a href="._Statistics-bs054.html">55</a></li>
<li><a href="._Statistics-bs055.html">56</a></li>
<li class="active"><a href="._Statistics-bs056.html">57</a></li>
<li><a href="._Statistics-bs057.html">58</a></li>
<li><a href="._Statistics-bs058.html">59</a></li>
<li><a href="._Statistics-bs059.html">60</a></li>
<li><a href="._Statistics-bs060.html">61</a></li>
<li><a href="._Statistics-bs061.html">62</a></li>
<li><a href="._Statistics-bs062.html">63</a></li>
<li><a href="._Statistics-bs063.html">64</a></li>
<li><a href="._Statistics-bs064.html">65</a></li>
<li><a href="._Statistics-bs065.html">66</a></li>
<li><a href="">...</a></li>
<li><a href="._Statistics-bs072.html">73</a></li>
<li><a href="._Statistics-bs057.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>