Dear Nigel,
There are two questions here.
1) How to get distributions in Sage.
2) How to get Maxima to not crash.
The second one is harder than the first. But if your Sage is not
quite new, we have a different interface to Maxima that might (only
might) help. What version do you have? (Type version().)
As to the first, the RealDistribution command might help you.
Assuming that normal=Gaussian, then from the doc:
The gaussian distribution takes 1 parameter ``sigma``. The
standard
gaussian distribution has ``sigma = 1``:
sage: sigma = 1
sage: T = RealDistribution('gaussian', sigma)
sage: T.get_random_element() # random
0.818610064197
sage: T.distribution_function(0)
0.398942280401
sage: T.cum_distribution_function(1)
0.841344746069
sage: T.cum_distribution_function_inv(.5)
0.0
Unfortunately, the many many ways of getting distributions and
statistics in Sage are not always very easy to find.
- kcrisman
On Jun 9, 1:34 pm, NigelSmart <[email protected]> wrote:
> Hi
>
> First let me say I am a python and sage novice, but I seem to have a
> problem in using
> maxima within sage. My sage installation is on a CentOS linux
> distribution and I just
> unpacked the Redhat distribution and run it. So no clever installation
> things done.
>
> Now I have a medium'ish program (1500 lines) which at one point needs
> access to
> normal variates. I see maxima has this so I define a function....
>
> maxima("load(distrib)");
>
> def MultiVarNormal(n,r):
> s=maxima("random_normal(0,%s,%s)"%(r,n));
> return s;
>
> and run my program. Firstly the above function creates a significant
> slow down (compared to the dummy code I give later) and eventually I
> get a crash with the following error message....
>
> /home/crypto/linux.x86_64/sage/local/lib/python2.6/site-packages/sage/
> structure/parent.so in sage.structure.parent.Parent.__call__ (sage/
> structure/parent.c:6820)()
>
> /home/crypto/linux.x86_64/sage/local/lib/python2.6/site-packages/sage/
> structure/coerce_maps.so in
> sage.structure.coerce_maps.NamedConvertMap._call_ (sage/structure/
> coerce_maps.c:4221)()
>
> /home/crypto/linux.x86_64/sage/local/lib/python2.6/site-packages/sage/
> interfaces/maxima.pyc in _real_double_(self, R)
> 1896 2.41421356237
> 1897 """
> -> 1898 return R(self._sage_())
> 1899
> 1900 def real(self):
>
> /home/crypto/linux.x86_64/sage/local/lib/python2.6/site-packages/sage/
> interfaces/maxima.pyc in _sage_(self)
> 1822 import sage.calculus.calculus as calculus
> 1823 return
> calculus.symbolic_expression_from_maxima_string(self.name(),
> -> 1824 maxima=self.parent())
> 1825
> 1826 def _symbolic_(self, R):
>
> /home/crypto/linux.x86_64/sage/local/lib/python2.6/site-packages/sage/
> calculus/calculus.pyc in symbolic_expression_from_maxima_string(x,
> equals_sub, maxima)
> 1652 return symbolic_expression_from_string(s, syms,
> accept_sequence=True)
> 1653 except SyntaxError:
> -> 1654 raise TypeError, "unable to make sense of Maxima
> expression '%s' in Sage"%s
> 1655 finally:
> 1656 is_simplified = False
>
> TypeError: unable to make sense of Maxima expression
> '"__SAGE_SYNCHRO_MARKER_135903684"' in Sage
>
> Now as a test that it is the above maxima function causing the
> problems I replace the
> above code with....
>
> def MultiVarNormal_V2(n,r):
> s=[1..n];
> for i in range(0,n):
> s[i]=randint(-r,r);
> return s;
>
> OK Its no longer a normal distribution, but this is just a testing
> idea. The code now runs very fast and does not produce the crash. So
> this leads me to think it is the above function causing the problems.
>
> One initially suspects it could be some form of memory leak/corruption
> as when I move to a bigger machine the original version takes longer
> to crash (it still crashes). However, running top whilst the program
> runs does not seem to reveal a huge increase in memory. So
>
> I have been unable to produce a small code snippett which produces the
> crash since running MultiVarNormal a gazillion times does not seem to
> crash.
>
> I am therefore stuck as to how to proceed. Any ideas would be most
> welcome. And please remember I really am a python/sage idiot at this
> stage.
>
> Yours
>
> Nigel
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org