probability

Java- Math.random(): Selecting an element of a 13 by 13 triangular array

匆匆过客 提交于 2019-12-22 09:14:08
问题 Edit: This problem is solved. If you would like to help on another problem, please visit Java Biasing Random Numbers in a Triangular Array. I'm doing a multiplication game, so I pick 2 numbers between 0 and 12 inclusive. If I do that like this: int num1 = (int)(Math.random() * 13); int num2 = (int)(Math.random() * 13); the squares (0x0,1x1,2x2,etc) are picked half the time (because 1x2 is the same as 2x1). How can I make all combinations picked at the same frequency? There are 91 possible

Distribution plot of an array

江枫思渺然 提交于 2019-12-22 07:18:08
问题 I have a numpy array containing float values in [-10..10]. I would like to plot a distribution-graph of the values, like this (here it is done for a binomial random variable) : For example I would like bars counting the number of elements in each interval [-10, -9.5], [-9.5, -9], ..., [9.5, 10]. How to prepare such a distribution plot with Python? 回答1: Indeed matplotlib, more precisely you'll find samples of code corresponding to what you are after at: http://matplotlib.org/examples/pylab

How can I compute the probability at a point given a normal distribution in Perl?

人走茶凉 提交于 2019-12-21 20:33:43
问题 Is there a package in Perl that allows you to compute the height of probability distribution at each given point. For example this can be done in R this way: > dnorm(0, mean=4,sd=10) > 0.03682701 Namely the probability of point x=0 falls into a normal distribution, with mean=4 and sd=10, is 0.0368. I looked at Statistics::Distribution but it doesn't give that very function to do it. 回答1: Why not something along these lines (I am writing in R, but it could be done in perl with Statistics:

How to properly clamp beckmann distribution

夙愿已清 提交于 2019-12-21 02:35:34
问题 I am trying to implement a Microfacet BRDF shading model (similar to the Cook-Torrance model) and I am having some trouble with the Beckmann Distribution defined in this paper: https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf Where M is a microfacet normal, N is the macrofacet normal and ab is a "hardness" parameter between [0, 1]. My issue is that this distribution often returns obscenely large values, especially when ab is very small. For instance, the Beckmann distribution is

Python - modelling probability

青春壹個敷衍的年華 提交于 2019-12-20 23:48:17
问题 I have a simple problem. I need a way to make a function which generates 0s in p percent cases and 1s in all other cases. I tried doing it with random.random() like this: p = 0.40 def generate(): x = random.random() if x < p: return 0 else: return 1 However, this doesn't seem like a good way. Or it is? 回答1: Your current method is perfectly fine, you can verify this by performing a few trials with a lot of attempts. For example we would expect approximately 600000 True results with 1000000

Python equivalent for MATLAB's normplot?

孤人 提交于 2019-12-20 14:09:18
问题 Is there a python equivalent function similar to normplot from MATLAB? Perhaps in matplotlib? MATLAB syntax: x = normrnd(10,1,25,1); normplot(x) Gives: I have tried using matplotlib & numpy module to determine the probability/percentile of the values in array but the output plot y-axis scales are linear as compared to the plot from MATLAB. import numpy as np import matplotlib.pyplot as plt data =[-11.83,-8.53,-2.86,-6.49,-7.53,-9.74,-9.44,-3.58,-6.68,-13.26,-4.52] plot_percentiles = range(0,

Calculate the number of ways to roll a certain number

十年热恋 提交于 2019-12-20 09:36:43
问题 I'm a high school Computer Science student, and today I was given a problem to: Program Description: There is a belief among dice players that in throwing three dice a ten is easier to get than a nine. Can you write a program that proves or disproves this belief? Have the computer compute all the possible ways three dice can be thrown: 1 + 1 + 1, 1 + 1 + 2, 1 + 1 + 3, etc. Add up each of these possibilities and see how many give nine as the result and how many give ten. If more give ten, then

Choose list variable given probability of each variable

寵の児 提交于 2019-12-20 08:35:23
问题 I've been trying to code a program that uses the softmax activation function in the middle. Right now, I have a list of probabilities like this: P[0.10,0.25,0.60,0.05] The sum of all the variables in P is always 1. I wanted a way to pick the index of the list given the probability attached to it. Or, in other words, a function that returned 0 - 10% of the time 1 - 25% of the time 2 - 60% of the time 3 - 5% of the time I've absolutely no idea where to start on this. Any help would be

choose unique random numbers with specific range

徘徊边缘 提交于 2019-12-20 07:26:14
问题 my problem is I want my program to make four unique random choices in range of numbers between 0 to 3 I tried to do it in random class but I could not, , if you could help by code it will be great,my program will be something like this to make it clear my range 0 1 2 3 randomly chosen number 3 0 1 2 randomly chosen number 1 0 2 randomly chosen number 2 0 it will choose 0 and then the program closes 回答1: You're effectively looking for a random permutation of the integers from 0 to n-1 . You

Understanding Markov Chain source code in R

断了今生、忘了曾经 提交于 2019-12-20 06:24:54
问题 The following source code is from a book. Comments are written by me to understand the code better. #================================================================== # markov(init,mat,n,states) = Simulates n steps of a Markov chain #------------------------------------------------------------------ # init = initial distribution # mat = transition matrix # labels = a character vector of states used as label of data-frame; # default is 1, .... k #----------------------------------------------