Ask Your Question

# How to generate an element from laplace distribution

Hi, I am wondering how to generate a random element according to laplace distribution. I tried the method RealDistribution(). But it failed.

According to the reference manual, laplace distribution is not supported. http://www.sagemath.org/doc/reference...

In the manual, there are some examples showing how to deal with uniform distribution, Gaussian distribution, etc.

My questions are:

(1) How do I know exactly which distributions are supported by the RealDistribution() method?

(2) Is there anyway I can simply generate an element according to laplace distribution in sage?

Thank you in advance.

edit retag close merge delete

## Comments

I found a way to do this by using numpy in sage. http://docs.scipy.org/doc/numpy/refer...

import numpy numpy.random.laplace(loc,scal,size)

will generate an element for laplace distribution. But it is not a very "sage" way to do it. And I am still concerned about my first question.

( 2015-04-22 12:38:18 -0500 )edit

## 1 answer

Sort by » oldest newest most voted

First of all...

\$ fgrep -i -C1 lapla /usr/lib/sagemath/src/sage/gsl/probability_distribution.pyx
#TODO: Add more distributions available in gsl
#available but not currently wrapped are exponential, laplace, cauchy, landau, gamma,
#gamma, beta logistic.


For my purposes i used then in statistics and probability scipy, for instance in order to get a random variable sample of size ten...

sage: from scipy import stats
sage: stats.laplace.rvs( 2017, size=10 )
array([ 2015.97251004,  2014.09872554,  2016.98175955,  2017.07587794,
2017.11026863,  2019.19102019,  2015.86935513,  2016.53066666,
2019.09275965,  2016.89277916])

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2015-04-21 14:57:56 -0500

Seen: 469 times

Last updated: Mar 02 '17