# Simulation Techniques for Soft Matter Sciences (SS 2007)/Introduction

# Introduction

## Overview

This tutorial covers

- Introduction to Linux
- How to shoot Pi
- Simple sampling / Importance sampling
- GNU Scientific Library (GSL)

## Contents

### Introduction to Linux

In this part of the tutorial you have to do something ...

### How to shoot Pi

Now, do something else ..

### Simple sampling / Importance sampling

### GNU Scientific Library (GSL)

http://www.gnu.org/software/gsl/ http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Generation.html

Generator: gsl_rng_rand

This is the BSD rand generator. Its sequence is

x_{n+1} = (a x_n + c) mod m

with a = 1103515245, c = 12345 and m = 2^31. The seed specifies the initial value, x_1. The period of this generator is 2^31, and it uses 1 word of storage per generator.

Generator: gsl_rng_mt19937

The MT19937 generator of Makoto Matsumoto and Takuji Nishimura is a variant of the twisted generalized feedback shift-register algorithm, and is known as the “Mersenne Twister” generator. It has a Mersenne prime period of 2^19937 - 1 (about 10^6000) and is equi-distributed in 623 dimensions. It has passed the diehard statistical tests. It uses 624 words of state per generator and is comparable in speed to the other generators. The original generator used a default seed of 4357 and choosing s equal to zero in gsl_rng_set reproduces this. Later versions switched to 5489 as the default seed, you can choose this explicitly via gsl_rng_set instead if you require it.

For more information see,

* Makoto Matsumoto and Takuji Nishimura, “Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator”. ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1 (Jan. 1998), Pages 3–30

The generator gsl_rng_mt19937 uses the second revision of the seeding procedure published by the two authors above in 2002. The original seeding procedures could cause spurious artifacts for some seed values. They are still available through the alternative generators gsl_rng_mt19937_1999 and gsl_rng_mt19937_1998.

Uniform vs. non-uniform distribution

— Function: double gsl_ran_gaussian (const gsl_rng * r, double sigma)

This function returns a Gaussian random variate, with mean zero and standard deviation sigma. The probability distribution for Gaussian random variates is,

p(x) dx = {1 \over \sqrt{2 \pi \sigma^2}} \exp (-x^2 / 2\sigma^2) dx

for x in the range -\infty to +\infty. Use the transformation z = \mu + x on the numbers returned by gsl_ran_gaussian to obtain a Gaussian distribution with mean \mu. This function uses the Box-Mueller algorithm which requires two calls to the random number generator r.

http://en.wikipedia.org/wiki/Importance_sampling

The fundamental issue in implementing IS simulation is the choice of the biased distribution which encourages the important regions of the input variables. Choosing or designing a good biased distribution is the "art" of IS. The rewards for a good distribution can be huge run-time savings; the penalty for a bad distribution can be longer run times than for a general Monte Carlo simulation without importance sampling.

http://www.cs.cmu.edu/~ggordon/MCMC/

## Resources

Here you can download everything and don't have to work anymore ....