Ask Your Question
1

How to generate an element from laplace distribution

asked 2015-04-21 21:57:56 +0200

qbyte gravatar image

updated 2017-11-22 13:05:08 +0200

FrédéricC gravatar image

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 flag offensive 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.

qbyte gravatar imageqbyte ( 2015-04-22 19:38:18 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-03-02 22:11:28 +0200

dan_fulea gravatar image

updated 2017-03-02 22:11:55 +0200

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])
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-21 21:57:56 +0200

Seen: 747 times

Last updated: Mar 02 '17