-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b30599
commit 5cc9097
Showing
14 changed files
with
304 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
docs/source/pages/API_reference/generators/deterministic.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Deterministic Generation | ||
======================== | ||
|
||
`Symmetria` provides a way to generate all the permutations of a given degree. The generation follows different | ||
algorithms which can be specified. | ||
|
||
You can use the generator of permutations in the following way | ||
|
||
.. code-block:: python | ||
import symmetria | ||
permutations = symmetria.generate(algorithm="lexicographic", degree=3) | ||
A list of implemented algorithms to generate permutations: | ||
|
||
.. list-table:: overview | ||
:widths: 35 50 15 | ||
:header-rows: 1 | ||
|
||
* - Algorithm | ||
- Description | ||
- Reference | ||
* - ``lexicographic`` | ||
- The permutations are generate following the **lexicographic order**. | ||
- `[1]`_ | ||
* - ``heap`` | ||
- The permutations are generate following the **Heap's algorithm**. | ||
- `[2]`_ | ||
* - ``steinhaus-johnson-trotter`` | ||
- The permutations are generate following the **Steinhaus-Johnson-Trotter algorithm**. | ||
- `[3]`_ | ||
|
||
.. _[1]: https://en.wikipedia.org/wiki/Lexicographic_order | ||
.. _[2]: https://academic.oup.com/comjnl/article/6/3/293/360213 | ||
.. _[3]: https://en.wikipedia.org/wiki/Steinhaus–Johnson–Trotter_algorithm | ||
|
||
==== | ||
|
||
The API of the method is given as following: | ||
|
||
.. automodule:: symmetria.generators.algorithm.api | ||
:members: generate | ||
:exclude-members: random, random_generator |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,15 @@ | ||
Generators | ||
========== | ||
|
||
`Symmetria` provides a way to generate all the permutations of a given degree. The generation follows different | ||
algorithms which can be specified. | ||
`Symmetria` provides a way to generate permutations of a given degree in two way: | ||
|
||
.. note:: The permutation are generated following a well-defined pattern, i.e., they are not random. | ||
- algorithmically, i.e., the permutations are generated following a given algorithm; | ||
- randomly, i.e., the permutations are generate randomly. | ||
|
||
A list of implemented algorithms to generate permutations: | ||
|
||
.. list-table:: overview | ||
:widths: 35 50 15 | ||
:header-rows: 1 | ||
|
||
* - Algorithm | ||
- Description | ||
- Reference | ||
* - ``lexicographic`` | ||
- The permutations are generate following the **lexicographic order**. | ||
- `[1]`_ | ||
* - ``heap`` | ||
- The permutations are generate following the **Heap's algorithm**. | ||
- `[2]`_ | ||
* - ``steinhaus-johnson-trotter`` | ||
- The permutations are generate following the **Steinhaus-Johnson-Trotter algorithm**. | ||
- `[3]`_ | ||
|
||
.. _[1]: https://en.wikipedia.org/wiki/Lexicographic_order | ||
.. _[2]: https://academic.oup.com/comjnl/article/6/3/293/360213 | ||
.. _[3]: https://en.wikipedia.org/wiki/Steinhaus–Johnson–Trotter_algorithm | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:hidden: | ||
|
||
generate | ||
deterministic | ||
random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Random Generation | ||
================= | ||
|
||
`Symmetria` provides a way to generate random permutation. | ||
|
||
You can use the random generation of permutations in the following way | ||
|
||
.. code-block:: python | ||
import symmetria | ||
permutations = symmetria.random_generator(algorithm="lexicographic", degree=3) | ||
If you don't want to have a generator and you want to just have a singular random permutation | ||
you can use write | ||
|
||
.. code-block:: python | ||
import symmetria | ||
permutation = symmetria.random(algorithm="lexicographic", degree=3) | ||
A list of implemented algorithms to generate permutations: | ||
|
||
.. list-table:: overview | ||
:widths: 35 50 15 | ||
:header-rows: 1 | ||
|
||
* - Algorithm | ||
- Description | ||
- Reference | ||
* - ``random`` | ||
- A permutation is generated by choosing the integer uniformly. | ||
- | ||
* - ``fisher-yates`` | ||
- The permutations are generate following the **Steinhaus-Johnson-Trotter algorithm**. | ||
- `[1]`_ | ||
|
||
.. _[1]: https://en.wikipedia.org/wiki/Lexicographic_order | ||
|
||
==== | ||
|
||
The API of the method is given as following: | ||
|
||
.. automodule:: symmetria.generators.random.api | ||
:members: random_generator | ||
:exclude-members: random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from symmetria.elements.cycle import Cycle | ||
from symmetria.generators.api import generate | ||
from symmetria.elements.permutation import Permutation | ||
from symmetria.generators.random.api import random, random_generator | ||
from symmetria.generators.algorithm.api import generate | ||
from symmetria.elements.cycle_decomposition import CycleDecomposition | ||
|
||
__version__ = "0.2.0" | ||
__all__ = ["__version__", "generate", "Permutation", "Cycle", "CycleDecomposition"] | ||
__all__ = [ | ||
"__version__", | ||
"generate", | ||
"random", | ||
"random_generator", | ||
"Permutation", | ||
"Cycle", | ||
"CycleDecomposition", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import List | ||
|
||
|
||
def _check_algorithm_parameter(value: str, supported: List[str]) -> None: | ||
"""Private method to check the value provided for the parameter `algorithm`. | ||
Recall that the parameter `algorithm` must be a string present in the list `supported`. | ||
""" | ||
if isinstance(value, str) is False: | ||
raise TypeError(f"The parameter `algorithm` must be of type string, but {type(value)} was provided.") | ||
if value not in supported: | ||
raise ValueError( | ||
f"The given algorithm ({value}) is not supported. \n " | ||
f"Here, a list of supported algorithm for generations of permutations {supported}." | ||
) | ||
|
||
|
||
def _check_degree_parameter(value: int) -> None: | ||
"""Private method to check the value provided for the parameter `degree`. | ||
Recall that the parameter `degree` must be a non-negative integer different from zero. | ||
""" | ||
if isinstance(value, int) is False: | ||
raise TypeError(f"The parameter `degree` must be of type int, but {type(value)} was provided.") | ||
if value < 1: | ||
raise ValueError(f"The parameter `degree` must be a non-zero positive integer, but {value} was provided.") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from random import randint, shuffle | ||
from typing import List, Generator | ||
|
||
from symmetria import Permutation | ||
|
||
|
||
def _random_shuffle(permutation: List[int]) -> Permutation: | ||
"""Private method to generate a random permutation using the random module of Python.""" | ||
shuffle(permutation) | ||
return Permutation(*permutation) | ||
|
||
|
||
def _random_shuffle_generator(degree: int) -> Generator[Permutation, None, None]: | ||
"""Private method to generate random permutations using the random module of Python.""" | ||
permutation = list(range(1, degree + 1)) | ||
while True: | ||
yield _random_shuffle(permutation=permutation) | ||
|
||
|
||
def _fisher_yates_shuffle(permutation: List[int]) -> Permutation: | ||
"""Private method to generate a random permutation using the Fisher-Yates shuffle.""" | ||
n = len(permutation) | ||
for i in range(n - 1, 0, -1): | ||
j = randint(0, i) | ||
permutation[i], permutation[j] = permutation[j], permutation[i] | ||
return Permutation(*permutation) | ||
|
||
|
||
def _fisher_yates_shuffle_generator(degree: int) -> Generator[Permutation, None, None]: | ||
"""Private method to generate random permutations using the Fisher-Yates shuffle.""" | ||
permutation = list(range(1, degree + 1)) | ||
while True: | ||
yield _fisher_yates_shuffle(permutation=permutation) |
Oops, something went wrong.