Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permute list in place #23

Merged
merged 8 commits into from
Feb 5, 2024
Merged

Conversation

SrGonao
Copy link
Contributor

@SrGonao SrGonao commented Feb 3, 2024

I think this is good

@SrGonao SrGonao linked an issue Feb 3, 2024 that may be closed by this pull request
Copy link
Contributor

@jettjaniak jettjaniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good overall!

I think we want RNG as a class, but the permutation should just be a standalone function that makes an instance of RNG, does the permutation and discards of the RNG.

Another thing to figure out is how to make this function take 2 arguments: seed and epoch number.

Also, CI is failing on formatting, see https://github.com/delphi-suite/delphi?tab=readme-ov-file#formatting

src/delphi/train/permute.py Outdated Show resolved Hide resolved
src/delphi/train/permute.py Outdated Show resolved Hide resolved
Generate a random number between 0 and 1 using minstd_rand from C++11
"""
self.state = (self.state * 48271) % 4294967296
return self.state / 4294967296
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just return the state as an int
can you add type hint for return btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why it should return the state, I refactored it in a different way

Permute a list in place using Fisher-Yates shuffle
"""
for i in range(len(list)):
j = int(self.random_number_generator() * (i + 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if random_number_generator() would return int then you just need to % i (or i+1?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to random uniform and created a generate_number, which generates a number from 0 to max (which was required for the correct shuffling algorithm)

tests/test_permutations.py Outdated Show resolved Hide resolved
tests/test_permutations.py Outdated Show resolved Hide resolved
@SrGonao
Copy link
Contributor Author

SrGonao commented Feb 4, 2024

I resolved most of your changes but there's some where I'm not sure what you meant,
I assumed that the by the epoch number you wanted to be able to say a epoch number and go to the state of the RNG as if you had made epoch number -1 epochs. (I have a commit that I didn't push about starting the epoch at 1 and not 0, not sure what you think)

@SrGonao SrGonao merged commit 5448b4b into main Feb 5, 2024
1 check passed
@jettjaniak jettjaniak deleted the 11-deterministic-permutation-function branch February 5, 2024 22:28
siwei-li pushed a commit that referenced this pull request Feb 9, 2024
* Permute list in place

* Actual tests

* Move test to correct position and updated tests

* Fixed bug, separated function

* Adds epoch control

* misc fixes

* type hint

* % m in shuffle_epoch

---------

Co-authored-by: Jett <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deterministic permutation function
2 participants