lundi 24 février 2020

Differences between Sampler, MonteCarlo, Metropolis-Hasting method, MCMC method and Fisher formalism

1) I make confusions between what wa call a "sampler". From what I understand, a sampler allows to generate a distribution of points that follows a known PDF (probability distribution function), doesn't it ?

2) On the other side, it exits Monte-Carlo method which allows for example to compute the number Pi by generating random values (x_i,y_i) and see if x_i^2+y^2 < R^2. The ratio between accepted points and total points generated will an estimation of Pi**.

3) Moreover, I have used previously the Metropolis-Hasting in this simple form, i.e to generate a distribution of points with a known PDF. But I have also seen that we can use it to do estimation of parameters of a model : at which level can we distinguish the "Sampler" Metroplis-Hasting from "Estimation of paramters" method.

4) For example, there is also the acceptance method (called also Von Neumann mathod), very used in Nuclear physics, which generates also a distribution from a known PDF : can it be qualified also of "sampler" ?

5) Finally, the Markov chain coupled wiht Monte Carlo (MCMC) is a pure method to estimate the parameters of amodel given the data : what is the respective role of Monte_Carlo and the Markov chain in this method.

To summarize, I show you below the problematic in which I am : it is about Forecast in astrophysics. In this post, I am talking about "Inverse problem" in Physics, i.e, we don't predict the data from a very accurate theorical model but I want to estimate the parameters of my theorical model given the data I have from experiment or from simulated data (what's we call fake data). The using of Bayes theorem is very practical in this kind of approach since we have a relation of proportionality between the posterior (probability of parameters given the data) and the likelihood (product of PDF taken at data values given the parameters model).

Principe of "Inverse Physics problem"

6) Fisher formalism is very usefull for estimation of the standard deviation compared to the fiducial values but we need to know these fiducial values before and second point, we have to assume that posterior distribution is always gaussian, haven't we ? (or that likelihood is gaussian, I don't remenber ... if someone could indicate this assumption).

So as you have seen, there are a lot of concept to integrate for me and I would like to convert this mess into ordered things.

First, I would like to make the difference between a "sampler" and an estimator method. After, any remark is welcome to clarify my confusions. If some of you have difficulties to explain all these differences, I would be glad to start a bounty.

Remark: I have asked different questions but all of them is linked in the sense they use random processes to generate distribution or evaluate parameters (by the Bayes theorem).

Thanks in advance, I hope that I have been clear enough. Regards




Random seed for order of elements in Python's Set to List conversion

I was executing some code in a Jupyter notebook and noticed that each time I ran it, the output was different despite not explicitly putting randomness in my program.

I narrowed it down to a line that removes all repeated elements from a list.

l = list(set(l))

I noticed two things:

  • If I re-run the same code in the same Jupyter kernel, I always get the same output for l, but

  • If I open up another notebook, I get a different output.

Is there some kind of hidden random seed that is used for the set -> list conversion for a given kernel? How does it work under the hood, and what would I do if I wanted deterministic output from the above code?




Jest: How to I test a function that calls another function in the body

I am trying to test the makeRandomComputerMove function, however, I am unable to properly mock the getRandomNumber function exported from the same module using Jest.

If I call the getRandomNumber function directly in the test file it works as expected, but I was under the impression that mocking the function in the test file should force the internal makeRandomComputerMove function to use the mocked value.

Any help would be appreciated.

test.ticTacToe.js

describe('TicTacToe Utils', () => {
    const randomMock = jest.spyOn(Utils, 'getRandomNumber')
        .mockReturnValueOnce(0)
        .mockReturnValueOnce(1)

    const board = [
        [['X'], [], []],
        [[], [], []],
        [[], [], []]
        ]

    it('makeRandomComputerMove', () => {
        const location = Utils.makeRandomComputerMove(board)
        // expect(location.x).toBe(0)
        // expect(location.y).toBe(1)
    })
})

ticTacToe.js

export const getRandomNumber = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

export const makeRandomComputerMove = (board) => {
    const location = {};
    location.x = getRandomNumber(0, board.length - 1);
    location.y = getRandomNumber(0, board.length - 1);
    if (location.x < 3 && location.y < 3) {
        return location

    }
    return makeRandomComputerMove(board);   
};



How do you change the generator with the Rand crate?

"The Rust Rand Book" documents various generators. thread_rng claims to be cryptographically secure while others do not. But, I don't see any reference to how to change the generator. I also don't see any way to find out what generator is being used when using thread_rng. I would like to do testing on the various options available, how can I do this?




Need help creating 10% random Array for sorting

Working on a CS Lab, and says we need to create a 10% out of order array, and a 1% out of order array to sort using various algorithms. How would you go about generating such an array?




How can I write test cases for operations performed on the randomly generated numpy array?

I have a numpy array generated using the random function.

n = [43, 20, 15, 29, 11]

Function do_something(n) takes numpy array as parameter and returns the result after performing the operation.

result = do_something(n)

How can I write the test cases for the function do_something(n) and verify the expected and actual result?




Why are signed/unsigned 8-bit integer types not supported by C++ random number generation?

From C++11 §26.5.1.1 on the requirements for random number generation:

Throughout this subclause 26.5, the effect of instantiating a template: [...] that has a template type parameter named IntType is undefined unless the corresponding template argument is cv-unqualified and is one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long.

What is the reason that 8-bit signed/unsigned types are excluded from random number generation like this in the requirements?