Re: [sage-support] random problem
> > Does this help? > > sage: R = RealField(100) > sage: R.random_element(1, 1+1/10^16) > 1.745276341034 > sage: R.random_element(1, 1+1/10^16) > 1.899962307929 > > and so on. Note that if you try to use RR (which is the same as > RealField(53)) you run into the same precision/roundoff problem as you > had before. Hence the need to increase the working precision. > > Also note that R.random_element() can only do uniform distribution, so > if you were hoping for something fancier this won't help. > thanks everyone, got it. As it happens I know the quantile function so this solution is fine for me. -- Robin Hankin Uncertainty Analyst hankin.ro...@gmail.com -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] random problem
> > > and so on. Note that if you try to use RR (which is the same as > RealField(53)) you run into the same precision/roundoff problem as you > had before. Hence the need to increase the working precision. > > Also note that R.random_element() can only do uniform distribution, so > if you were hoping for something fancier this won't help. > > Yeah, since the RealDistribution code uses GSL with code like elif self.distribution_type == gaussian: result = gsl_ran_gaussian(self.r, self.parameters[0]) elif self.distribution_type == rayleigh: result = gsl_ran_rayleigh(self.r, self.parameters[0]) elif self.distribution_type == lognormal: result = gsl_ran_lognormal(self.r, self.parameters[0], self.parameters[1]) elif self.distribution_type == pareto: result = gsl_ran_pareto(self.r, self.parameters[0], self.parameters[1]) elif self.distribution_type == t: result = gsl_ran_tdist(self.r, self.parameters[0]) elif self.distribution_type == F: where it's not clear that self.r passes on any precision information. That would be good to change, but I'm not sure how easy that would be, assuming it's possible for GSL to even take that into account in these functions. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] random problem
Hi, On Thu, Jul 26, 2012 at 7:40 PM, robin hankin wrote: > I am trying to generate random numbers and am running into roundoff > problems: > > RealDistribution('uniform', [1,1+1/10^16]).get_random_element()-1 > > This returns zero every time for me, something that is almost surely wrong. > I would expect a number chosen from the interval (0,1e-16). > > How do I make sage do what I want? Does this help? sage: R = RealField(100) sage: R.random_element(1, 1+1/10^16) 1.745276341034 sage: R.random_element(1, 1+1/10^16) 1.899962307929 and so on. Note that if you try to use RR (which is the same as RealField(53)) you run into the same precision/roundoff problem as you had before. Hence the need to increase the working precision. Also note that R.random_element() can only do uniform distribution, so if you were hoping for something fancier this won't help. -- Best, Alex -- Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne http://aghitza.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] random problem
On 2012-07-26 11:40, robin hankin wrote: > How do I make sage do what I want? Well, what do you want? -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] random problem
Dear Robin Actually you are working with machine precision, i.e., eps(10^-16) in double precison. it means that 1+eps == 1 in double precision. try from mpmath import * 10^-16*mp.rand() or, as you have coded from mpmath import * mp.dps = 30 (mpf(1.0)+10^-16*mp.rand())-mpf(1.0) On Thu, Jul 26, 2012 at 3:10 PM, robin hankin wrote: > I am trying to generate random numbers and am running into roundoff > problems: > > RealDistribution('uniform', [1,1+1/10^16]).get_random_element()-1 > > This returns zero every time for me, something that is almost surely > wrong. I would expect a number chosen from the interval (0,1e-16). > > How do I make sage do what I want? > > thanks > > > -- > Robin Hankin > Uncertainty Analyst > hankin.ro...@gmail.com > > -- > To post to this group, send email to sage-support@googlegroups.com > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org > -- Ajay Rawat Kalpakkam, IGCAR - Save Himalayas - -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org