probability-density

MATLAB: Pricing a digital option, Monte Carlo vs. explicit integral formula?

笑着哭i 提交于 2019-12-11 21:14:53
问题 I am stuck with the following problem using MATLAB: Let Z be lognormally distributed such that ln Z has mean m and variance w. Let eta be a negative number and c a positive constant. I am trying to compute the expected value (let I(Z<=c) denote the indicator function of the set (Z<=c)) E[Z^(eta+1) I(Z<=c)] = (1/sqrt(w)) integral_0^c x^(eta) phi((ln x - m)/sqrt(w)) dx, where phi() denotes the probability distribution function of a standard normal random variable. First thing I did was to

Plot one data frame column against all other columns using ggplots and showing densities in R

风流意气都作罢 提交于 2019-12-11 18:14:19
问题 I have a data frame with 20 columns, and I want to plot one specific column (called BB) against each single column in the data frame. The plots I need are probability density plots, and I’m using the following code to generate one plot (plotting columns BB vs. AA as an example): mydata = as.data.frame(fread("filename.txt")) #read my data as data frame #function to calculate density get_density <- function(x, y, n = 100) { dens <- MASS::kde2d(x = x, y = y, n = n) ix <- findInterval(x, dens$x)

Optimize computation time for PDF approximation based on Kernel Density Estimation

佐手、 提交于 2019-12-11 17:38:33
问题 I have a code to find the pdf's approximation of a vector based on the formula for kernel estimation: I implemented this formula in the code below (see previous question). However, that code takes long time to run (two loops are used). Could you see the below code and help me to make it faster? This is the code: function pdf_est=KDE() close all; %%Random values of 20 pixels, range=[1 256] data=randi([1 256],1,20)-1; %// changed: "-1" %% Estimate histogram%%%%% pdf_est=zeros(1,256); z=256; for

normpdf behaves strangely

≡放荡痞女 提交于 2019-12-10 16:26:08
问题 In the following manner, function ret = f(pIx5, dS) sigma = 1; rho = dS(1); theta = dS(2); mu_x = rho*cos(theta); display(pIx5); display(mu_x); pdf = normpdf(pIx5, mu_x, sigma); ret = max(pdf); end I get the following error message, pIx5 = 54 65 11 0 0 mu_x = 11.9218 Error using normpdf (line 36) Non-scalar arguments must match in size. Error in f (line 11) pdf = normpdf(pIx5, mu_x, sigma); But, it works fine in the following manner, function ret = f(pIx5, dS) sigma = 1; rho = dS(1); theta =

Plotting probability density function with frequency counts

戏子无情 提交于 2019-12-10 10:23:57
问题 I want to convert fitted distribution to frequency. import numpy as np import matplotlib.pyplot as plt from scipy import stats %matplotlib notebook # sample data generation np.random.seed(42) data = sorted(stats.lognorm.rvs(s=0.5, loc=1, scale=1000, size=1000)) # fit lognormal distribution shape, loc, scale = stats.lognorm.fit(data, loc=0) pdf_lognorm = stats.lognorm.pdf(data, shape, loc, scale) fig, ax = plt.subplots(figsize=(8, 4)) ax.hist(data, bins='auto', density=True) ax.plot(data, pdf

R: Generate data from a probability density distribution

房东的猫 提交于 2019-12-09 04:55:05
问题 Say I have a simple array, with a corresponding probability distribution. library(stats) data <- c(0,0.08,0.15,0.28,0.90) pdf_of_data <- density(data, from= 0, to=1, bw=0.1) Is there a way I could generate another set of data using the same distribution. As the operation is probabilistic, it need not exactly match the initial distribution anymore, but will be just generated from it. I did have success finding a simple solution on my own. Thanks! 回答1: Your best bet is to generate the empirical

Plot Lognormal Probability Density in R

一个人想着一个人 提交于 2019-12-07 23:20:40
问题 I am trying to generate a plot for Lognormal Probability Density in R, with 3 different means log and standards deviation log. I have tried the following, but my graph is so ugly and does not look good at all. x<- seq(0,10,length = 100) a <- dlnorm(x, meanlog = 0, sdlog = 1, log = FALSE) b <- dlnorm(x, meanlog = 0, sdlog = 1.5, log = FALSE) g <- dlnorm(x, meanlog = 1.5, sdlog = 0.2, log = FALSE) plot(x,a, lty=5, col="blue", lwd=3) lines(x,b, lty=2, col = "red") lines(x,g, lty=4, col = "green"

Sampling from a multivariate probability density function in python

≯℡__Kan透↙ 提交于 2019-12-07 20:12:41
问题 I have a multivariate probability density function P(x,y,z), and I want to sample from it. Normally, I would use numpy.random.choice() for this sort of task, but this function only works for 1-dimensional probability densities. Is there an equivalent function for multivariate pdfs? 回答1: There a few different paths one can follow here. (1) If P(x,y,z) factors as P(x,y,z) = P(x) P(y) P(z) (i.e., x, y, and z are independent) then you can sample each one separately. (2) If P(x,y,z) has a more

How to random sample lognormal data in Python using the inverse CDF and specify target percentiles?

泄露秘密 提交于 2019-12-07 17:50:42
问题 I'm trying to generate random samples from a lognormal distribution in Python, the application is for simulating network traffic. I'd like to generate samples such that: The modal sample result is 320 (~10^2.5) 80% of the samples lie within the range 100 to 1000 (10^2 to 10^3) My strategy is to use the inverse CDF (or Smirnov transform I believe): Use the PDF for a normal distribution centred around 2.5 to calculate the PDF for 10^x where x ~ N(2.5,sigma). Calculate the CDF for the above

Random sampling from a dataset, while preserving original probability distribution

丶灬走出姿态 提交于 2019-12-07 03:30:53
问题 I have a set of >2000 numbers, gathered from measurement. I want to sample from this data set, ~10 times in each test, while preserving probability distribution overall, and in each test (to extent approximately possible). For example, in each test, I want some small value, some middle class value, some big value, with the mean and variance approximately close to the original distribution. Combining all the tests, I also want the total mean and variance of all the samples, approximately close