montecarlo

C++ class design for Monte Carlol simulation

拥有回忆 提交于 2019-12-11 18:01:25
问题 I'm trying to build a Monte Carlo object class and am wondering about the best way to design the relevant classes. The structure of the object (called Entity) contains name, description AND a Distribution type which can be of a few different types eg. Normal, Fixed Integer, Triangle etc. The Distribution class is (or might be) a superclass of the specific distributions eg. Normal. So, I have class Entity { public: string name; Distribution* dsn; // superclass. Can this be done? } class

Needed advice for an enjoyable AI in Buraco card game

自古美人都是妖i 提交于 2019-12-11 07:25:45
问题 i’m trying to build an effective AI for the Buraco card game (2 and 4 players). I want to avoid the heuristic approach : i’m not an expert of the game and for the last games i’ve developed this way i obtained mediocre results with that path. I know the montecarlo tree search algorithm, i’ve used it for a checkers game with discrete result but I’m really confused by the recent success of other Machine Learning options. For example i found this answer in stack overflow that really puzzles me,

Looking for a way to optimize this algorithm for parsing a very large string

岁酱吖の 提交于 2019-12-11 05:26:24
问题 The following class parses through a very large string (an entire novel of text) and breaks it into consecutive 4-character strings that are stored as a Tuple. Then each tuple can be assigned a probability based on a calculation. I am using this as part of a monte carlo/ genetic algorithm to train the program to recognize a language based on syntax only (just the character transitions). I am wondering if there is a faster way of doing this. It takes about 400ms to look up the probability of

Wrong result when doing simple Monte Carlo integration in R

萝らか妹 提交于 2019-12-11 03:54:07
问题 I'm giving part of a presentation on numerical integration. While the talk itself will go into better forms of numerical integration (mainly importance sampling and stratified sampling), I'm mentioning during part of my section Monte Carlo integration sampling from the uniform distribution. I've found that: mean(sin(runif(1e8, 0, pi))) is giving an answer of 0.636597 , rather than 1 that is expected. This answer seems pretty consistent with increasing sample size, and I'm unsure why there's

Shuffle a long list an even longer number of times in Python

故事扮演 提交于 2019-12-10 15:08:25
问题 I want to shuffle a long sequence (say it is has more than 10000 elements)a lot of times (say 10000). When reading Python Random documentation, I found the following: Note that even for small len(x), the total number of permutations of x can quickly grow larger than the period of most random number generators. This implies that most permutations of a long sequence can never be generated. For example, a sequence of length 2080 is the largest that can fit within the period of the Mersenne

Python large iterations number fail

风流意气都作罢 提交于 2019-12-10 01:56:49
问题 I wrote simple monte-carlo π calculation program in Python, using multiprocessing module. It works just fine, but when I pass 1E+10 iterations for each worker, some problem occur, and the result is wrong. I cant understand what is the problem, because everything is fine on 1E+9 iterations! import sys from multiprocessing import Pool from random import random def calculate_pi(iters): """ Worker function """ points = 0 # points inside circle for i in iters: x = random() y = random() if x ** 2 +

Algorithm for computing the plausibility of a function / Monte Carlo Method

不打扰是莪最后的温柔 提交于 2019-12-09 11:27:20
问题 I am writing a program that attempts to duplicate the algorithm discussed at the beginning of this article, http://www-stat.stanford.edu/~cgates/PERSI/papers/MCMCRev.pdf F is a function from char to char. Assume that Pl(f) is a 'plausibility' measure of that function. The algorithm is: Starting with a preliminary guess at the function, say f, and a then new function f* -- Compute Pl(f). Change to f* by making a random transposition of the values f assigns to two symbols. Compute Pl(f*); if

Python Uniform distribution of points on 4 dimensional sphere

一个人想着一个人 提交于 2019-12-09 05:51:05
问题 I need a uniform distribution of points on a 4 dimensional sphere. I know this is not as trivial as picking 3 angles and using polar coordinates. In 3 dimensions I use from random import random u=random() costheta = 2*u -1 #for distribution between -1 and 1 theta = acos(costheta) phi = 2*pi*random x=costheta y=sin(theta)*cos(phi) x=sin(theta)*sin(phi) This gives a uniform distribution of x, y and z. How can I obtain a similar distribution for 4 dimensions? 回答1: A standard way, though, perhaps

Fast generation of random set, Monte Carlo Simulation

坚强是说给别人听的谎言 提交于 2019-12-09 05:44:11
问题 I have a set of numbers ~100, I wish to perform MC simulation on this set, the basic idea is I fully randomize the set, do some comparison/checks on the first ~20 values, store the result and repeat. Now the actual comparison/check algorithm is extremely fast it actually completes in about 50 CPU cycles. With this in mind, and in order to optimize these simulations I need to generate the random sets as fast as possible. Currently I'm using a Multiply With Carry algorithm by George Marsaglia

Sampling a hemisphere using an arbitary distribtuion

情到浓时终转凉″ 提交于 2019-12-08 11:45:09
问题 I am writing a ray tracer and I wish to fire rays from a point p into a hemisphere above that point according to some distribution. 1) I have derived a method to uniformly sample within a solid angle (defined by theta) above p Image phi = 2*pi*X_1 alpha = arccos (1-(1-cos(theta))*X_2) x = sin(alpha)*cos(phi) y = sin(alpha)*sin*phi z = -cos(alpha) Where X is a uniform random number That works and Im pretty happy with that. But my question is what happens if I do not want a uniform distribution