4,048 questions
4
votes
3
answers
169
views
Generator that yields True a fixed number of times at random intervals before exhausting
I want to iterate through a list of size n, with A 1s in it (the rest are 0s), and I want the 1s randomly distributed.
n and A are large, so I'm trying to make a generator instead of a list.
If they ...
0
votes
2
answers
110
views
What is an effective method to do a "reverse" Weighted RNG?
I'm working on designing an RNG loot table for something a friend is running, and the obvious solution given the nature of the loot table (its for a foraging system) is to use a weighted RNG method. ...
-4
votes
1
answer
98
views
Tensorflow GPU acceleration but not for Deep Learning tasks
I am a mathematician. I am doing some work on simulating probability distribution draws, but there are lots of calculations involved in terms of numerical integration, function inversion. All of this ...
0
votes
0
answers
69
views
1D Linear Value Noise Not Uniform Distribution; Is there a better noise function?
I have a simple 1D value noise function here:
public float ValueNoise1D(float x)
{
int l = Mathf.FloorToInt(x);
int r = l + 1;
float vl = hashToFloat(hash(l));
float vr = hashToFloat(...
1
vote
0
answers
71
views
log_prob for custom uniform distribution in PyTorch
When computing the dist.log_prob function for a uniform distribution on a box dist, the results seems to be -inf for the coordinates that are out-of-bound and -log(upper - lower) for the coordinates ...
4
votes
3
answers
170
views
how to generate random probability arrays with pre specified mean
I have a pre specified mean [0.5, 0.5, 0]. This is a probability array which sum up to 1.
I want to generate several, say 10 random probability arrays (each sums up to 1) whose mean is [0.5, 0.5, 0], ...
0
votes
3
answers
171
views
Fastest way to randomly shuffle an array based on probabilities in PHP? [closed]
I have an array with values and probabilities (or in PHP, keys and values):
Value Probability
John 3
Peter 2
Paul 1
I want to shuffle this array but have the order be influenced by the ...
6
votes
0
answers
148
views
Mean and Standard Devation of Kth Highest Number Given Infinite Samples of Size x
Given:
A list of numbers, "values".
A sample size, x
A kth highest number (ex: [3, 2, 1, 0], 2 is the 2nd highest
number)
Write a function kmax(x, k) that returns the Mean and Standard ...
0
votes
0
answers
37
views
Instrumental Amplifier with Monte Carlo in NGSPICE
I want to try to do the Monte Carlo in this circuit with an instrumental amplifier, but the loop does not work for me, I try to export in a txt file, but the 100 iterations are accumulated in the ...
2
votes
2
answers
78
views
How to make a probability figure using a logistic regression?
I am trying to remake this figure with my data.
I have 2 binary factors (P treatment & Embryo_Presence_vs._Absence) and 1 continuous value (Final_Size). Here is my data:
print.data.frame(x[c(&...
2
votes
3
answers
118
views
Perform a random binomial draw for each row in R without rowwise()
I have an R data frame that I need to perform a random binomial draw for each row. The n = argument in the random binomial draw will be based on a value in a column of that row. Further, this ...
4
votes
2
answers
182
views
How to Analyze the Best, Average, and Worst-Case Performance of a Randomized Algorithm for Finding a Value in an Array?
Consider the following algorithm:
while True:
i = random(1, n)
if a[i] == 1:
return i
The objective is to find a position in an array 𝑎[1..n] that contains the value 1, where half ...
0
votes
0
answers
67
views
Does it make sense to generate a unique key from the combination of two different hashing algorithms?
I want to expand on the following question and answers found here:
What are the chances that two messages have the same MD5 digest and the same SHA1 digest?
My interest in this question is not about ...
0
votes
0
answers
116
views
How can I correctly distribute cars across slots based on probabilistic assignment in Lua?
I'm working on a simulation in Lua where I need to randomly assign cars to a set of slots based on probabilities. Specifically, I want the probability for each slot to be adjusted dynamically as the ...
1
vote
1
answer
51
views
Sampling from joint probability mass function in python
I have a non-negative normalized vector p. I would like to sample an index from the index set of the vector. The probability getting sample k is p[k]. Using np.random.choice function, I can write the ...
0
votes
1
answer
96
views
CDF of the sum of two random variables not giving the expected result [closed]
I'm trying to numerically calculate the CDF of the sum of two random variables and I'm having trouble replicating answers on StackOverflow.
This question CDF of a sum of independent random variables ...
3
votes
1
answer
82
views
Generating all sequences and probabilities for a random process in R
I have a Markov Chain in R:
set.seed(123)
n_states <- 5
matrix <- matrix(runif(n_states^2), nrow=n_states)
# set some transitions to 0
matrix[1, 4:5] <- 0
matrix[5, 1:3] <- 0
matrix[...
0
votes
1
answer
72
views
How do i compute P(theta < 0.01 | y) in openbugs?
I need to use OpenBUGS to compute the posterior probability of the mean lifetime of a piece of equipment being greater than 100 hours.
Given that the data comes from an exponential distribution with ...
0
votes
1
answer
84
views
Simulation time of the ruin probability from package ruin in R
I'm working with an R package called "ruin package", and it is taking too long to compute the ruin probability for the parameter values that I chose. The function works, I already checked ...
7
votes
5
answers
873
views
Calculate transition probabilities
I have this data:
simulated_states = c("A", "E", "B", "B", "A", "C", "D", "A", "B", "D", "A&...
2
votes
1
answer
54
views
Generate weighted sample from weighted list
I have a list of historical frequencies of elements that have occurred together over time. These elements may have occurred (without repetition) in sequences of various order and length.
For example, ...
-2
votes
2
answers
49
views
Evaluating the Impact of Subject Combinations on Student Failure: Probabilistic Approach
i have students academic data and would like to investigate whether some subject combinations will increase the probability of failure.
let's make an example data set (data sourced from real uni data ...
0
votes
2
answers
95
views
Python scipy quad and nqaud giving different answers
I am not sure if this is more suitable for math stackexchange or stack overflow, but since the mathematical proofs look alright to me, I suspect its the code that's the issue and hence I will post it ...
0
votes
1
answer
118
views
Calculate probability from an excel file
I have an excel file with x rows with random numbers (from 1 till 25). The total number of columns (numbers) can vary (15, 16, 17, 18, 19 or 20):
I need python to tell me my probability of winning a ...
0
votes
1
answer
73
views
Excel number of combinations inside a specific array
Think of this problem similar to a lottery:
I have been trying to determine all possible combinations of 15 numbers (from 1 to 25). By mathematical calculation, I know it is 3.268.760 possibilities.
...
0
votes
2
answers
64
views
How to duplicate records in pandas dataframe based on column values
I have created a pandas dataframe as follows:
ds = {'col1' : ["A","B"], 'probability' : [0.3, 0.6]}
df = pd.DataFrame(data=ds)
The dataframe looks like this:
print(df)
col1 ...
0
votes
1
answer
66
views
How can I fix the next code in Julia so I try to program a function that generates samples without replace?
I have the next code in Julia but the problem is when I use the vector
p = [0.2,0.1,0.1,0.15,0.17] with n = 3
appears the next:
BoundsError: attempt to access 4-element Vector{Float64} at index [5]
...
0
votes
1
answer
193
views
Dynamic weights - efficient way to increase relative probability of specific items
I know that for static weights the recommended way to go is Walker Alias method because it has sampling complexity of O(1).
However I have a case where I need to be able to temporary adjust ...
0
votes
0
answers
95
views
How to make probability based using Flutter's Random function?
I was trying to implement a gacha system using probability and show the result with a SnackBar, I have found question #61822429, and tried using it but i could'nt found the right way.
I was expecting ...
3
votes
1
answer
80
views
When can we safely use the Randomized algorithm considering probability?
Recently when reading SICP, one footnote says:
Numbers that fool the Fermat test are called Carmichael numbers, and little is known about them other than that they are extremely rare. There are 255 ...
0
votes
0
answers
39
views
How to Predict Event Occurrence Using Logistic Regression with (factor?) Variables
An event can occur[1] or not[0]. It depends on the age of the object! It can happen in summer, autumn, winter, or spring, and then it has a different probability depending on the season. It can take ...
1
vote
1
answer
193
views
What's the best way to select an enum variant according to a non uniform probability?
I have an enum and I want to create instances of its variants by performing a random non uniform extraction. A possible solution involves using Rng::gen_range() from rand by trying to match the ...
1
vote
0
answers
411
views
How to identify the ideal probability threshold for XGBoost Classifier predictions?
Is there any basis in determining the probability threshold in xgb.predict_proba while using XGBClassifier, especially if the data are imbalanced. I know when xgb.predict is used, a probability ...
1
vote
1
answer
257
views
How to correctly do a Multivariate t-Distribution in R
I am working on a statistical analysis in R where I need to do a multivariate t-distribution. Each component of my parameter vector 𝛽
β should follow a univariate t-distribution derived from a ...
0
votes
0
answers
22
views
dmultinom yields a probability of zero
I am working with dmultinom function from the Stats package in R. I am trying to calculate the probability of observing these values:
observed_values <- c(23, 14, 81, 0, 0, 0, 154, 0, 0, 54, 0, 0, ...
-3
votes
1
answer
188
views
Calculate Win/Lose/Draw probability If I stand with given hand in BlackJack [closed]
I am trying to solve a code challenge. It is about the game blackjack. 2 cards are given to me, 1 to the dealer. I know every card including the deck. I need to calculate the probability to win, to ...
0
votes
1
answer
167
views
How does the joint probability distribution help to generate things? [closed]
I am trying to understand the difference between discriminative models and generative models. One of the helpful answers at Stack Overflow is here: What is the difference between a generative and a ...
1
vote
1
answer
66
views
Picking a random object inside an array based on probability stored in keys
I'm just learning javascript and one of my personal projects for learning is a rpg game. I've been trying to get this working for several days, using functions I've seen on stackoverflow and trying to ...
0
votes
1
answer
370
views
How do I calculate weighted average of dates?
The context for this question is that say I have 200 dollars locked up that will be paid back to me each month for a varying amount of money with the final payment taking pace on the 4th year. I'm NOT ...
1
vote
0
answers
121
views
Excel - Summing the product of multiple ranges if their sum of different permutations of their row# adds up to a target value
I have a messy Excel formula that I'm trying to figure out. I have data with 2 or more columns, each associated with the probability (labeled p1, p2, p3, etc.) of a particular whole number outcome (...
0
votes
0
answers
103
views
Showing that the sum of exponentials is gamma distributed using the fourier transform
I am trying to use the result that $p(\omega)^n$ = Gamma(n, beta) where $p(\omega)$ is the fourier transform of an $Exp(\beta)$ distribution. My code does well for small n but as n increases the gamma ...
1
vote
1
answer
66
views
why different method lead to different outcome when calculate a probability problem
The question is
"The winning probability for each ticket is 0.005. You can get 25 lottery tickets for free. After the free ticket, you need to pay $9.6 to buy a ticket.
You are guaranteed to win ...
0
votes
2
answers
373
views
What is the probability that a value from one uniform distribution will be greater than a value from another? [closed]
Let our distributions both be uniform, the first (A) with bounds (ψ,Ψ) and the second (B) with bounds (φ,Φ). What is the probability of A.random() > B.random()?
# A>...
2
votes
1
answer
127
views
Calculate CDF of Weibull distribution in R
I want to calculate the probability that a Weibull random variable X is greater than 1000, where X ~ Weibull(lambda, g).
Using the CDF I calculate it as:
g = log(log(.7)/log(.5))/log(40/81)
lambda = -...
3
votes
3
answers
73
views
How to evaluate the probability of a range in R?
Supposed I toss 10 dice many times (let's say, 10000 times), and I want to know the probability of the sum on 10 dice falling into a range (10 to 20, 20 to 30, ..., 50 to 60). How can I divide the ...
0
votes
0
answers
91
views
shortest path algorithm with expected cost
My objective is to calculate the expected cost for each path from the starting point to the end point and identify the minimum expected cost for each path when the respective node serves as the ...
0
votes
1
answer
723
views
Coin throw probability on a chessboard square
I need some insights on the following problem. You are given a coin whose diameter is equivalent to half the length of a chessboard unit square. If you throw the coin on the board, what is the ...
1
vote
2
answers
209
views
Group dataframe and sample n rows with equal probability between groups
I have a pandas dataframe like this:
ID Value
0 a 2
1 a 4
2 b 6
3 c 8
4 c 10
5 c 12
I would like to sample equally from the ID groups. I know I can ...
0
votes
1
answer
409
views
hmmlearn MultinomialHMM emissionprob_ size
I'm using the code below to fit an HMM model with two hidden states, a vocabulary of size 5 (so 5 possible symbols), and a list of sequences, each with 10 observations.
I don't understand why model....
1
vote
1
answer
301
views
Calculating Conditional Distributions using Copula in R
I have three random variables X, Z, and Y, and I know their distribution functions F(X), F(Z), and F(Y). However, the dependence structure among them is not known. I want to calculate the conditional ...