Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Allowing seeds for randomness #138

@AtheMathmo

Description

@AtheMathmo

We frequently use randomness throughout rusty-machine and in all cases default to the rand::thread_rng (except in the new Shuffler added by #135). It is very valuable for users to be able to set a seed to ensure that their models behave the same way on different runs.

It would be nice if we could capture this with minimal effect on the current API. It is probably a requirement that the models (and other components) own their own random number generators. We would likely need to add a new generic type parameter on the models:

pub struct MLModel<T1, T2, ..., Tn, R> where R: Rng {
    // All the previous fields
   rng: Rng,
}

The alternative is to use a Box for this field and provide a trait which allows the user to modify the generator for the model:

pub trait Randomizable {
    fn set_rng(&miut self, rng: Rng);

    fn rng(&self) -> Box<Rng>;
}

This approach will keep the API a little cleaner. We can also control access to shared code requiring randomness by using the Randomizable trait. For example we could wrap some of the rand_utils functions to work on an object which implements Randomizable. I'd still like the rand_utils functions to be accessed in their current state though.

Thoughts on this are very welcome. I suspect we will need to implement something to get a good idea of the benefits/drawbacks of any approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions