ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 11 Apr 2017 05:24:11 +0200random element in user defined classhttps://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 07:09:04 +0100https://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>
https://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 07:40:17 +0100https://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?answer=36670#post-id-36670Comment 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>
https://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 08:36:03 +0100https://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=36862#post-id-36862Comment 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>
https://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 ?Tue, 11 Apr 2017 05:24:11 +0200https://ask.sagemath.org/question/36668/random-element-in-user-defined-class/?comment=37259#post-id-37259