On Wed, Jun 13, 2012 at 7:43 PM, Aleksandar Makelov
<[email protected]> wrote:
> How does this work (and does it work) in sympy?
>
> A classical example is a Monte Carlo algorithm. Is there an accepted way to
> test these in sympy? For one-sided Monte Carlo algorithms, we can easily
> test one direction in a deterministic way, but this doesn't feel very
> satisfactory.

I see two aspects to a randomized algorithm: doing the right thing
with the random input and using good random number generation. Python
has addressed the latter, so we just need to make sure that the right
thing is being done with it. Let's say I had an MC integration
routine. If I sample the region randomly I should get a good result.
But however I sample it I need to be sure that I am doing the right
thing with the results. The latter (though it may give a bad answer
for bad input) is what I should test in sympy and I don't need more
than a minimum number of points to test it (depending on how many
branches in decisions there are for the algorithm) e.g.

```
def MC_integr(xrange, yrange, shape, rand_seq):
    area = xrange*yrange
    hit = miss = 0
    for x in rand_seq:
        for y in rand_seq:
            if Point(x,y) in shape: hit += 1
            else: miss += 1
            if tolerance(hit, miss) is True: break # some routine that
figures out if the precision is ok
    return hit/(hit+miss)*area
```

This routine could be tested with a rand_seq of 4 elements: one giving
a point inside and one outside; the return area should be
xrange*yrange/2. The tolerance function could be tested independently
to see that if hit+miss > 1000 (or whatever) that it quits.

>
> Another example is the algorithms outputting random group elements that are
> supposed to be nearly uniformly distributed in the group.

If they are selected by integers which themselves have been tested to
be uniformly distributed (i.e. python's generator) then I don't think
you have to test the sympy output. But perhaps I am misunderstanding.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
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/sympy?hl=en.

Reply via email to