ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 10 Apr 2017 22:24:11 -0500random element in user defined classhttp://ask.sagemath.org/question/36668/random-element-in-user-defined-class/ Can I get random element of a user defined class of objects?
For example if I define xyz(n) to generate all the $n \times n$ matrices with a particular property. How can I get a random matrix in my class xyz(5).
Mon, 20 Feb 2017 00:09:04 -0600http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/Answer by tmonteil for <p>Can I get random element of a user defined class of objects?
For example if I define xyz(n) to generate all the $n \times n$ matrices with a particular property. How can I get a random matrix in my class xyz(5).</p>
http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?answer=36670#post-id-36670You have to implement a `random_element` method by yourself, since sage will not discover which measure has to be sampled. If the property happens frequently among all matrices, you can use rejection the method: pick a random matrix (in the larger space) until you find one with the property and return that matrix.Mon, 20 Feb 2017 00:40:17 -0600http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?answer=36670#post-id-36670Comment by tmonteil for <p>You have to implement a <code>random_element</code> method by yourself, since sage will not discover which measure has to be sampled. If the property happens frequently among all matrices, you can use rejection the method: pick a random matrix (in the larger space) until you find one with the property and return that matrix.</p>
http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=37259#post-id-37259It really depends on the property. Could you provide some examples of some ` xyz(n)` that you would like to sample ?Mon, 10 Apr 2017 22:24:11 -0500http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=37259#post-id-37259Comment by Deepak Sarma for <p>You have to implement a <code>random_element</code> method by yourself, since sage will not discover which measure has to be sampled. If the property happens frequently among all matrices, you can use rejection the method: pick a random matrix (in the larger space) until you find one with the property and return that matrix.</p>
http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=36862#post-id-36862Sorry, I don't have any idea how to implement it by myself. Can you please explain with an example? Any web link will be helpful.
Thank youWed, 08 Mar 2017 01:36:03 -0600http://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=36862#post-id-36862