Lecture 4 Flashcards

1
Q

RNG, properties

A

Random Number Generators (truly-random method and pseudorandom method)

  • Random pattern
  • Long period
  • Efficiency
  • Repeatability
  • Portability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

period of a pseudorandom number generator

A

maximum length of the repetition-free prefix of the sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

LCG

A

Linear Congruential Generator
x_k = (ax_{k−1}+c) mod M

a, c integers, x_0 seed. Period can not exceed M.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Monte Carlo

A

Algorithms that rely on repeated random sampling to approximate a desired quantity.

  • Nondeterministic processes
  • Complicated deterministic problems with high dimensionality
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Monte Carlo error, dependance

A

err → Z/√(n), with Z ~ N(0,σ^2)
asymptotic behavior O(1/√(n)), n number of samples
MC depends on sample variance and number of samples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Monte Carlo:

n1 samples give an error e1. How many samples to get an error e2?

A

n1 * (e1/e2)^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where to use MC?

A
  • Integration of high-dimensional functions
  • Problems where high accuracy is not required
  • To determine the matrix conditioning by sampling vectors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Generate a random vector of n integers in [0,10]

A

v = np.random.choice(range(11), n, False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Get index of first item satisfying a condition in an array

A

index = np.argmax(array condition)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Classic plot

A

import matplotlib
import matplotlib.pyplot as plt

plt. plot(x, y)
plt. title(‘title’)
plt. ylabel(‘y label’)
plt. xlabel(‘x label’)
plt. show()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Plot loglog semilog…

A

Log scaling on the x axis: plt.semilogx(x,y)

plt. semilogy(x,y)
plt. loglog(x,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Examples loglog semilog…
y=a.x^b
y=a.b^x
y=a.log(b.x)

A

To get a line:

loglog: log(y) = log(a) + b.log(x)
semilogy: log(y) = log(a) + x.log(b) = ^a.x + b
semilogx: y = a.log(b) + log(x) = ^a + log(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Monte Carlo integration problem, estimation:

mu = int(x1,x2) int(y1,y2) f(x,y)dxdy

A

1/N Sum^N_{i=1} f(xi,yi) * (x2-x1) * (y2-y1) → mu when N → ∞ (Law large numbers)
With points generated within x1, x2, y1, y2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Monte Carlo pros/cons

A

Cons: Slow convergence rate
Pros: Efficiency does not degrade with increase in the dimension of the problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly