-
Notifications
You must be signed in to change notification settings - Fork 2k
Inject other Random.Generator (like mersenne twister) #628
Comments
Hi there, Well, the reason for having it read-only is that changing this generator might affect the behavior of the entire framework, and not only the code that you need. However, I agree that the framework shouldn't prevent much what users can do with it, so probably this could be changed. May I ask which components/classes are you mostly interested in using with a different generator? |
Yes, I understand that this is a central piece but I think the implementation is a bit problematic as it (as you say) prevent one from changing the random generator. The class for now that I want to use a Mersenne twister generator in is the MultivariateNormalDistribution. Thanks for a great lib and a quick reply (as always :)) Cheers |
It looks like the random class in the framework needs a factory pattern
where the type of generator can be selected. I would be willing to add
several generators to the library if that is a desired feature.
Steve
…On Mon, Jun 5, 2017 at 4:56 AM, nwiman ***@***.***> wrote:
Yes, I understand that this is a central piece but I think the
implementation is a bit problematic as it (as you say) prevent one from
changing the random generator.
The class for now that I want to use a Mersenne twister generator in is
the MultivariateNormalDistribution.
It would be nice to have a container that you could bootstrap with a
generator or an override where you pass a System.Random, I haven't looked
too much in the source code but you maybe have an idea of how to do this in
a clean way...
Thanks for a great lib and a quick reply (as always :))
Cheers
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#628 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB1x2zLZRxH7tX_vDglKrbzwUJIVdGPKks5sA8KygaJpZM4NuXdn>
.
|
Yes I see what you mean, but in my case I need to get hold of the actual reference to the Random as well. |
@fsteveb Thanks a lot for the comment and offer to help! The framework currently offers an However, I still think that replacing the central generator is not a very good idea as it can be quite hard to control it since it can be called from anywhere in and outside the framework, including multiple threads. @nwiman I had the suspicion you would like to use it from inside the probability distributions :-) In this case, what maybe could easily be done without breaking too much code is to add a new property or virtual method to the base class of all distributions where a |
I like the Idea of the interface option, it seems simple for a starter... :) |
Where exactly would you like to replace the random generation? Is it in the Generate function, when generating/sampling new observations from the distribution, or is it during learning/fitting the GMM model to the data? Actually I've realized that adding this extra property would require every single .Clone() method of every distribution to be modified to cascade their internal generator to the cloned instances. This would also have some problems with distributions that are actually containers to other distributions such as Mixture or Independent. So I have therefore changed the interface for the .Generate() methods to accept a Random generator as the last parameter instead, as this was simpler to accomplish. In order to use your own generator, please inherit from .NET's Random class and override its appropriate methods, then pass it at the last parameter of the .Generate() method to generate new samples with your own generator. If you would also need this functionality in other methods than .Generate(), please let me know! Regards, |
For now I'm only using the Generate function but I suspected that you would have to pass the "random" in the ctor or the generate function as it in the MultivariateNormal case uses a static Random function on the NormalDistribution. Thanks again for all support! |
Added in release 3.6.0. |
For now you can only control the seed of the Accord.Math.Random.Generator, but i want to change the Generator to a MersenneTwister... is there a reason for having the Generator readonly, if you could inject a generator and know the limitations wouldn't this be a good thing?
The text was updated successfully, but these errors were encountered: