MarkovChain
class braidgenerator.MarkovChain(**kwargs)
MarkovChain is an encapsulation of the Markov Chain. It takes a BraidWord and constructs a model that creates a specified number of braid representatives of a fixed knot type, called ``braidreps," along with the logs pertaining to that braidrep (i.e. which Markov step was made at some iteration).
-
braidword
BraidWord
- A BraidWord to have braidreps generated from it. Note that a simple Python list of integers can be given as a parameter as well, which will be converted to a BraidWord behind the scenes.
-
maxgen
int
- The maximum absolute value a generator can be in the BraidWord and its subsequent braidreps.
-
maxlen
int
- The maxmimum length of that any subsequent braidreps can reach.
Parameters
-
braidagg
dictionary
- Dictionary that holds braidreps and logs.
-
braid
BraidWord
- Contains braidword parameter.
-
maxgen
int
- Contains maxgen parameter.
-
maxlen
int
- Contains maxlen parameter.
Attributes
<MarkovChain>.methods
-
Getter method that returns a dictionary of MarkovChain instance’s braidreps and logs, both contained in their respective lists.
self.braidagg
Returns
-
Method to clear braid instance. That is, it clears braidagg.
None
Returns
-
Method to return MarkovChain instance braidreps as a list.
-
as_word
bool
-
Defaults to return list populated by BraidWords. Setting
as_word
returns the list populated by BraidWord.word (i.e. lists).=True
Parameters
-
self.braidagg['braidreps']
Returns
-
Function to dynamically create log of Markov step @[mstep]
-
movetype
int
- Markov step[i] for i in [0, 6], inclusive. There are 7 Markov steps that determine the braid-to-braidrep modification.
-
name
str
- The name of the Markov step.
-
result
bool
- Boolean representing whether the move was successfully executed or not.
Parameters
- String of log for BraidWord.word at Markov step [i] for i in [0, 6], inclusive.
Returns
-
Method to return MarkovChain instance logs in a list. Note that the length of the list is equal to the number of braidreps requested in the num_braidreps argument of model. Each log represents the logs undergone to create a specific braidrep and is held in a dictionary. The size of the dictionary is equal to the argument passed for msteps in model.
-
self.braidagg['logs']
Returns
-
Method to model the BraidWord and generate braidreps and logs. A random number is picked between (0, 6), inclusive, determining the Markov step to perform. Another random number is picked from range(len(BraidWord.word)) that represents the index of BraidWord.word to perform the Markov step on. The braidrep is generated by picking a random index from the set of possible indices for BraidWord.word and a random Markov step that acts on BraidWord.word at the given index.
-
num_braidreps
int
- Number of braidreps to be modeled from the BraidWord given to the Markov Chain.
-
msteps
int
- The number of steps to be taken until an braidrep is considered to be complete. That is, msteps many iterations of the model process take place on a given BraidWord.
Parameters
-
Appends braidrep and log to
self.braidagg['logs']
.
Returns
Method to set a new BraidWord.
-
braidword
BraidWord
- The new BraidWord to replace the old BraidWord.
Parameters
None
Returns
-
Method to export logs, braidreps to csv. If path_or_filename not given, will export the csv to current directory with the name braidreps.csv or braidreps_and_Logs.csv. The name is implicitly determined by the parameter passed to only_braidreps.
-
path_or_filename
str
- Path or filename to store csv. If none is given, will store file in current directory under the name 'braidreps.csv' or 'braidreps_and_Logs.csv', based on the value assigned to only_braidreps.
-
only_braidreps
bool
- Determines if only braidreps should be returned or both braidreps and logs.
Parameters
- A csv file containing a dataframe with either only braidreps or both braidreps and logs, depending on parameter passed to only_braidreps.
Returns
-
Method to export logs and/or braidreps to a pandas dataframe.
-
only_braidreps
bool
- Determines if only braidreps should be returned or both braidreps and logs.
Parameters
- If only_braidreps=True returns a pandas dataframe of only braidreps. Otherwise will return a pandas dataframe with both braidreps and logs.
Returns
-
Method to export logs, braidreps to a txt file. If path_or_filename not given, will export the csv to current directory with the name braidreps.txt or braidreps_and_Logs.txt. The name is implicitly determined by the parameter passed to only_braidreps.
Note
Output Format
The format in the resulting .txt file is as follows:
braidrep[1]
...
braidrep[n]
(newline)
log[1]
...
log[n]
-
path_or_filename
str
- Path or filename to store csv. If none is given, will store file in current directory under the name 'braidreps.csv' or 'braidreps_and_Logs.csv', based on the value assigned to only_braidreps.
-
only_braidreps
bool
- Determines if only braidreps should be returned or both braidreps and logs.
Parameters
- A txt file containing a either only braidreps or both braidreps and logs, depending on parameter passed to only_braidreps.
Returns