ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 02 Mar 2017 15:11:28 -0600How to generate an element from laplace distributionhttps://ask.sagemath.org/question/26617/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/probability/sage/gsl/probability_distribution.html
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. Tue, 21 Apr 2015 14:57:56 -0500https://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/Comment by qbyte for <p>Hi, I am wondering how to generate a random element according to laplace distribution.
I tried the method RealDistribution(). But it failed.</p>
<p>According to the reference manual, laplace distribution is not supported.
<a href="http://www.sagemath.org/doc/reference/probability/sage/gsl/probability_distribution.html">http://www.sagemath.org/doc/reference...</a></p>
<p>In the manual, there are some examples showing how to deal with uniform distribution, Gaussian distribution, etc.</p>
<p>My questions are:</p>
<p>(1) How do I know exactly which distributions are supported by the RealDistribution() method?</p>
<p>(2) Is there anyway I can simply generate an element according to laplace distribution in sage?</p>
<p>Thank you in advance. </p>
https://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/?comment=26624#post-id-26624I found a way to do this by using numpy in sage.
http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.laplace.html
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.Wed, 22 Apr 2015 12:38:18 -0500https://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/?comment=26624#post-id-26624Answer by dan_fulea for <p>Hi, I am wondering how to generate a random element according to laplace distribution.
I tried the method RealDistribution(). But it failed.</p>
<p>According to the reference manual, laplace distribution is not supported.
<a href="http://www.sagemath.org/doc/reference/probability/sage/gsl/probability_distribution.html">http://www.sagemath.org/doc/reference...</a></p>
<p>In the manual, there are some examples showing how to deal with uniform distribution, Gaussian distribution, etc.</p>
<p>My questions are:</p>
<p>(1) How do I know exactly which distributions are supported by the RealDistribution() method?</p>
<p>(2) Is there anyway I can simply generate an element according to laplace distribution in sage?</p>
<p>Thank you in advance. </p>
https://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/?answer=36793#post-id-36793First 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])
Thu, 02 Mar 2017 15:11:28 -0600https://ask.sagemath.org/question/26617/how-to-generate-an-element-from-laplace-distribution/?answer=36793#post-id-36793