Markopy
Utilizing Markov Models for brute forcing attacks
Python.CudaMarkopy.CudaMarkopyCLI Class Reference

CUDA extension to MarkopyCLI. More...

Inheritance diagram for Python.CudaMarkopy.CudaMarkopyCLI:
Collaboration diagram for Python.CudaMarkopy.CudaMarkopyCLI:

Public Member Functions

None __init__ (self)
 
def help (self)
 overload help function to print submodel helps More...
 
def parse (self)
 
def parse_fail (self)
 
def add_arguments (self)
 add -mt/–model_type constructor More...
 
def init_post_arguments (self)
 
def init_post_arguments (sel)
 
def process (self)
 Process parameters for operation. More...
 
def stub (self)
 
def evaluate (self, str filename)
 
def parse_arguments (self)
 
def parse_arguments (self)
 
def parse_arguments (self)
 
def parse_arguments (self)
 
def import_model (self, str filename)
 Import a model file. More...
 
def import_model (self, str filename)
 Import a model file. More...
 
def import_model (self, str filename)
 Import a model file. More...
 
def import_model (self, str filename)
 Import a model file. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def FastRandomWalk (int count, str wordlist, int minlen, int maxlen)
 
int FastRandomWalk (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
bool ConstructMatrix ()
 Construct the related Matrix data for the model. More...
 
void DumpJSON ()
 Debug function to dump the model to a JSON file. More...
 
void Import (const char *filename)
 Open a file to import with filename, and call bool Model::Import with std::ifstream. More...
 
bool Import (std::ifstream *)
 Import a file to construct the model. More...
 
def Import (str filename)
 
bool Import (std::ifstream *)
 Import a file to construct the model. More...
 
void Train (const char *datasetFileName, char delimiter, int threads)
 Train the model with the dataset file. More...
 
def Train (str dataset, str seperator, int threads)
 
std::ifstream * OpenDatasetFile (const char *filename)
 Open dataset file and return the ifstream pointer. More...
 
std::ifstream * OpenDatasetFile (const char *filename)
 Open dataset file and return the ifstream pointer. More...
 
std::ofstream * Save (const char *filename)
 Export model to file. More...
 
std::ofstream * Save (const char *filename)
 Export model to file. More...
 
void Generate (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
 Call Markov::Model::RandomWalk n times, and collect output. More...
 
def Generate (int count, str wordlist, int minlen, int maxlen, int threads)
 
void Generate (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
 Call Markov::Model::RandomWalk n times, and collect output. More...
 
void Buff (const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
 Buff expression of some characters in the model. More...
 
void Buff (const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
 Buff expression of some characters in the model. More...
 
char * RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
 Do a random walk on this model. More...
 
char * RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
 Do a random walk on this model. More...
 
void AdjustEdge (const char *payload, long int occurrence)
 Adjust the model with a single string. More...
 
void AdjustEdge (const char *payload, long int occurrence)
 Adjust the model with a single string. More...
 
bool Export (std::ofstream *)
 Export a file of the model. More...
 
bool Export (const char *filename)
 Open a file to export with filename, and call bool Model::Export with std::ofstream. More...
 
def Export (str filename)
 
bool Export (std::ofstream *)
 Export a file of the model. More...
 
bool Export (const char *filename)
 Open a file to export with filename, and call bool Model::Export with std::ofstream. More...
 
Node< char > * StarterNode ()
 Return starter Node. More...
 
Node< char > * StarterNode ()
 Return starter Node. More...
 
std::vector< Edge< char > * > * Edges ()
 Return a vector of all the edges in the model. More...
 
std::vector< Edge< char > * > * Edges ()
 Return a vector of all the edges in the model. More...
 
std::map< char, Node< char > * > * Nodes ()
 Return starter Node. More...
 
std::map< char, Node< char > * > * Nodes ()
 Return starter Node. More...
 
void OptimizeEdgeOrder ()
 Sort edges of all nodes in the model ordered by edge weights. More...
 
void OptimizeEdgeOrder ()
 Sort edges of all nodes in the model ordered by edge weights. More...
 
def add_arguments (self)
 
def init_post_arguments (self)
 
def parse_arguments (self)
 
def parse_arguments (self)
 
def import_model (self, str filename)
 Import a model file. More...
 
def import_model (self, str filename)
 Import a model file. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def train (self, str dataset, str seperator, str output, bool output_forced=False, bool bulk=False)
 Train a model via CLI parameters. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def export (self, str filename)
 Export model to a file. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def generate (self, str wordlist, bool bulk=False)
 Generate strings from the model. More...
 
def FastRandomWalk (int count, str wordlist, int minlen, int maxlen)
 
int FastRandomWalk (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
__host__ void FastRandomWalk (unsigned long int n, const char *wordlistFileName, int minLen, int maxLen, bool bFileIO, bool bInfinite)
 Random walk on the Matrix-reduced Markov::Model. More...
 
int FastRandomWalk (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
bool ConstructMatrix ()
 Construct the related Matrix data for the model. More...
 
bool ConstructMatrix ()
 Construct the related Matrix data for the model. More...
 
void DumpJSON ()
 Debug function to dump the model to a JSON file. More...
 
void DumpJSON ()
 Debug function to dump the model to a JSON file. More...
 
void Import (const char *filename)
 Open a file to import with filename, and call bool Model::Import with std::ifstream. More...
 
bool Import (std::ifstream *)
 Import a file to construct the model. More...
 
void Import (const char *filename)
 Open a file to import with filename, and call bool Model::Import with std::ifstream. More...
 
bool Import (std::ifstream *)
 Import a file to construct the model. More...
 
void Train (const char *datasetFileName, char delimiter, int threads)
 Train the model with the dataset file. More...
 
void Train (const char *datasetFileName, char delimiter, int threads)
 Train the model with the dataset file. More...
 
std::ifstream * OpenDatasetFile (const char *filename)
 Open dataset file and return the ifstream pointer. More...
 
std::ifstream * OpenDatasetFile (const char *filename)
 Open dataset file and return the ifstream pointer. More...
 
std::ofstream * Save (const char *filename)
 Export model to file. More...
 
std::ofstream * Save (const char *filename)
 Export model to file. More...
 
void Generate (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
 Call Markov::Model::RandomWalk n times, and collect output. More...
 
void Generate (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
 Call Markov::Model::RandomWalk n times, and collect output. More...
 
void Buff (const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
 Buff expression of some characters in the model. More...
 
void Buff (const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
 Buff expression of some characters in the model. More...
 
char * RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
 Do a random walk on this model. More...
 
char * RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
 Do a random walk on this model. More...
 
void AdjustEdge (const char *payload, long int occurrence)
 Adjust the model with a single string. More...
 
void AdjustEdge (const char *payload, long int occurrence)
 Adjust the model with a single string. More...
 
bool Export (std::ofstream *)
 Export a file of the model. More...
 
bool Export (const char *filename)
 Open a file to export with filename, and call bool Model::Export with std::ofstream. More...
 
bool Export (std::ofstream *)
 Export a file of the model. More...
 
bool Export (const char *filename)
 Open a file to export with filename, and call bool Model::Export with std::ofstream. More...
 
Node< char > * StarterNode ()
 Return starter Node. More...
 
Node< char > * StarterNode ()
 Return starter Node. More...
 
std::vector< Edge< char > * > * Edges ()
 Return a vector of all the edges in the model. More...
 
std::vector< Edge< char > * > * Edges ()
 Return a vector of all the edges in the model. More...
 
std::map< char, Node< char > * > * Nodes ()
 Return starter Node. More...
 
std::map< char, Node< char > * > * Nodes ()
 Return starter Node. More...
 
void OptimizeEdgeOrder ()
 Sort edges of all nodes in the model ordered by edge weights. More...
 
void OptimizeEdgeOrder ()
 Sort edges of all nodes in the model ordered by edge weights. More...
 
__host__ void MigrateMatrix ()
 Migrate the class members to the VRAM. More...
 
__host__ void FlattenMatrix ()
 Flatten migrated matrix from 2d to 1d. More...
 

Static Public Member Functions

def check_import_path (str filename)
 check import path for validity More...
 
def check_import_path (str filename)
 check import path for validity More...
 
def check_import_path (str filename)
 check import path for validity More...
 
def check_import_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
def check_import_path (str filename)
 check import path for validity More...
 
def check_import_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_corpus_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
def check_export_path (str filename)
 check import path for validity More...
 
static __host__ void ListCudaDevices ()
 List CUDA devices in the system. More...
 

Public Attributes

 args
 
 cli
 
 parser
 
 parser
 
 parser
 
 parser
 
 print_help
 
 print_help
 
 print_help
 
 print_help
 
 model
 
 model
 
 model
 
 fileIO
 
 model
 
 bInfinite
 
 fileIO
 
 parser
 
 parser
 
 print_help
 
 print_help
 

Protected Member Functions

int FastRandomWalk (unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
void FastRandomWalkPartition (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
 A single partition of FastRandomWalk event. More...
 
void FastRandomWalkThread (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
 A single thread of a single partition of FastRandomWalk. More...
 
bool DeallocateMatrix ()
 Deallocate matrix and make it ready for re-construction. More...
 
int FastRandomWalk (unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
int FastRandomWalk (unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
 Random walk on the Matrix-reduced Markov::Model. More...
 
void FastRandomWalkPartition (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
 A single partition of FastRandomWalk event. More...
 
void FastRandomWalkPartition (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
 A single partition of FastRandomWalk event. More...
 
void FastRandomWalkThread (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
 A single thread of a single partition of FastRandomWalk. More...
 
void FastRandomWalkThread (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
 A single thread of a single partition of FastRandomWalk. More...
 
bool DeallocateMatrix ()
 Deallocate matrix and make it ready for re-construction. More...
 
bool DeallocateMatrix ()
 Deallocate matrix and make it ready for re-construction. More...
 
__host__ char * AllocVRAMOutputBuffer (long int n, long int singleGenMaxLen, long int CUDAKernelGridSize, long int sizePerGrid)
 Allocate the output buffer for kernel operation. More...
 
__host__ void LaunchAsyncKernel (int kernelID, int minLen, int maxLen)
 
__host__ void prepKernelMemoryChannel (int numberOfStreams)
 
__host__ void GatherAsyncKernelOutput (int kernelID, bool bFileIO, std::ofstream &wordlist)
 

Static Protected Member Functions

static __host__ int CudaCheckNotifyErr (cudaError_t _status, const char *msg, bool bExit=true)
 Check results of the last operation on GPU. More...
 
template<typename T >
static __host__ cudaError_t CudaMalloc2DToFlat (T **dst, int row, int col)
 Malloc a 2D array in device space. More...
 
template<typename T >
static __host__ cudaError_t CudaMemcpy2DToFlat (T *dst, T **src, int row, int col)
 Memcpy a 2D array in device space after flattening. More...
 
template<typename T >
static __host__ cudaError_t CudaMigrate2DFlat (T **dst, T **src, int row, int col)
 Both malloc and memcpy a 2D array into device VRAM. More...
 

Protected Attributes

char ** edgeMatrix
 2-D Character array for the edge Matrix (The characters of Nodes) More...
 
long int ** valueMatrix
 2-d Integer array for the value Matrix (For the weights of Edges) More...
 
int matrixSize
 to hold Matrix size More...
 
char * matrixIndex
 to hold the Matrix index (To hold the orders of 2-D arrays') More...
 
long int * totalEdgeWeights
 Array of the Total Edge Weights. More...
 
bool ready
 True when matrix is constructed. False if not. More...
 
char ** edgeMatrix
 2-D Character array for the edge Matrix (The characters of Nodes) More...
 
char ** edgeMatrix
 2-D Character array for the edge Matrix (The characters of Nodes) More...
 
long int ** valueMatrix
 2-d Integer array for the value Matrix (For the weights of Edges) More...
 
long int ** valueMatrix
 2-d Integer array for the value Matrix (For the weights of Edges) More...
 
int matrixSize
 to hold Matrix size More...
 
int matrixSize
 to hold Matrix size More...
 
char * matrixIndex
 to hold the Matrix index (To hold the orders of 2-D arrays') More...
 
char * matrixIndex
 to hold the Matrix index (To hold the orders of 2-D arrays') More...
 
long int * totalEdgeWeights
 Array of the Total Edge Weights. More...
 
long int * totalEdgeWeights
 Array of the Total Edge Weights. More...
 
bool ready
 True when matrix is constructed. False if not. More...
 
bool ready
 True when matrix is constructed. False if not. More...
 

Private Member Functions

def _generate (self, str wordlist)
 wrapper for generate function. More...
 
void TrainThread (Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
 A single thread invoked by the Train function. More...
 
void GenerateThread (std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
 A single thread invoked by the Generate function. More...
 

Private Attributes

std::ifstream * datasetFile
 
std::ofstream * modelSavefile
 Dataset file input of our system
More...
 
std::ofstream * outputFile
 File to save model of our system
More...
 
std::map< char, Node< char > * > nodes
 Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer. More...
 
Node< char > * starterNode
 Starter Node of this model. More...
 
std::vector< Edge< char > * > edges
 A list of all edges in this model. More...
 
char * device_edgeMatrix
 VRAM Address pointer of edge matrix (from modelMatrix.h) More...
 
long int * device_valueMatrix
 VRAM Address pointer of value matrix (from modelMatrix.h) More...
 
char * device_matrixIndex
 VRAM Address pointer of matrixIndex (from modelMatrix.h) More...
 
long int * device_totalEdgeWeights
 VRAM Address pointer of total edge weights (from modelMatrix.h) More...
 
char ** device_outputBuffer
 RandomWalk results in device. More...
 
char ** outputBuffer
 RandomWalk results in host. More...
 
char * flatEdgeMatrix
 Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing. More...
 
long int * flatValueMatrix
 Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing. More...
 
int cudaBlocks
 
int cudaThreads
 
int iterationsPerKernelThread
 
long int totalOutputPerSync
 
long int totalOutputPerKernel
 
int numberOfPartitions
 
int cudaGridSize
 
int cudaMemPerGrid
 
long int cudaPerKernelAllocationSize
 
int alternatingKernels
 
unsigned long ** device_seeds
 
cudaStream_t * cudastreams
 

Detailed Description

CUDA extension to MarkopyCLI.

Adds CudaModelMatrixCLI to the interface.

Definition at line 46 of file cudamarkopy.py.

Constructor & Destructor Documentation

◆ __init__()

None Python.CudaMarkopy.CudaMarkopyCLI.__init__ (   self)

Reimplemented from Python.CudaMarkopy.CudaModelMatrixCLI.

Definition at line 53 of file cudamarkopy.py.

53  def __init__(self) -> None:
54  "! @brief initialize CLI selector"
55  markopy.MarkopyCLI.__init__(self,add_help=False)
56  self.parser.epilog+=f"""
57  {__file__.split("/")[-1]} -mt CUDA generate trained.mdl -n 500 -w output.txt
58  Import trained.mdl, and generate 500 lines to output.txt
59  """
60 

References Python.Markopy.BaseCLI.parser.

Member Function Documentation

◆ _generate()

def Python.Markopy.BaseCLI._generate (   self,
str  wordlist 
)
privateinherited

wrapper for generate function.

This can be overloaded by other models

Parameters
wordlistfilename to generate to

Reimplemented in Python.Markopy.ModelMatrixCLI, and Python.CudaMarkopy.CudaModelMatrixCLI.

Definition at line 161 of file base.py.

161  def _generate(self, wordlist : str):
162  """!
163  @brief wrapper for generate function. This can be overloaded by other models
164  @param wordlist filename to generate to
165  """
166  self.model.Generate(int(self.args.count), wordlist, int(self.args.min), int(self.args.max), int(self.args.threads))
167 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.generate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_arguments() [1/2]

def Python.CudaMarkopy.CudaModelMatrixCLI.add_arguments (   self)
inherited

Reimplemented from Python.Markopy.AbstractGenerationModelCLI.

Definition at line 67 of file cudammx.py.

67  def add_arguments(self):
68  super().add_arguments()
69  self.parser.add_argument("-if", "--infinite", action="store_true", help="Infinite generation mode")
70 

References Python.Markopy.BaseCLI.parser.

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ add_arguments() [2/2]

def Python.Markopy.MarkopyCLI.add_arguments (   self)
inherited

add -mt/–model_type constructor

Reimplemented from Python.Markopy.BaseCLI.

Definition at line 83 of file markopy.py.

83  def add_arguments(self):
84  """!
85  @brief add -mt/--model_type constructor
86  """
87  self.parser.add_argument("-mt", "--model_type", default="_MMX", help="Model type to use. Accepted values: MP, MMX")
88  self.parser.add_argument("-h", "--help", action="store_true", help="Model type to use. Accepted values: MP, MMX")
89  self.parser.add_argument("-ev", "--evaluate", help="Evaluate a models integrity")
90  self.parser.add_argument("-evt", "--evaluate_type", help="Evaluation type, model or corpus")
91  self.parser.print_help = self.help
92 

References Markov::API::CLI::Argparse.help(), Python.CudaMarkopy.CudaMarkopyCLI.help(), Python.Markopy.BaseCLI.help(), Python.Markopy.MarkopyCLI.help(), and Python.Markopy.BaseCLI.parser.

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AdjustEdge() [1/4]

void Markov::Model< char >::AdjustEdge ( const NodeStorageType payload,
long int  occurrence 
)
inherited

Adjust the model with a single string.

Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.

Then, update the edge EdgeWeight from current node, to the terminator node.

This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.

Example Use: Create an empty model and train it with string: "testdata"

char test[] = "testdata";
model.AdjustEdge(test, 15);
Parameters
string- String that is passed from the training, and will be used to AdjustEdge the model with
occurrence- Occurrence of this string.

Definition at line 109 of file model.h.

337  {
338  NodeStorageType p = payload[0];
341  int i = 0;
342 
343  if (p == 0) return;
344  while (p != 0) {
345  e = curnode->FindEdge(p);
346  if (e == NULL) return;
347  e->AdjustEdge(occurrence);
348  curnode = e->RightNode();
349  p = payload[++i];
350  }
351 
352  e = curnode->FindEdge('\xff');
353  e->AdjustEdge(occurrence);
354  return;
355 }
Edge class used to link nodes in the model together.
Definition: edge.h:23
Node< NodeStorageType > * RightNode()
return edge's RightNode
Definition: edge.h:170
void AdjustEdge(long int offset)
Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
Definition: edge.h:137
Node< char > * starterNode
Starter Node of this model.
Definition: model.h:198
Edge< storageType > * FindEdge(storageType repr)
Find an edge with its character representation.
Definition: node.h:260

◆ AdjustEdge() [2/4]

void Markov::Model< char >::AdjustEdge ( const NodeStorageType payload,
long int  occurrence 
)
inherited

Adjust the model with a single string.

Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.

Then, update the edge EdgeWeight from current node, to the terminator node.

This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.

Example Use: Create an empty model and train it with string: "testdata"

char test[] = "testdata";
model.AdjustEdge(test, 15);
Parameters
string- String that is passed from the training, and will be used to AdjustEdge the model with
occurrence- Occurrence of this string.

Definition at line 109 of file model.h.

337  {
338  NodeStorageType p = payload[0];
341  int i = 0;
342 
343  if (p == 0) return;
344  while (p != 0) {
345  e = curnode->FindEdge(p);
346  if (e == NULL) return;
347  e->AdjustEdge(occurrence);
348  curnode = e->RightNode();
349  p = payload[++i];
350  }
351 
352  e = curnode->FindEdge('\xff');
353  e->AdjustEdge(occurrence);
354  return;
355 }

◆ AdjustEdge() [3/4]

void Markov::Model< char >::AdjustEdge ( const NodeStorageType payload,
long int  occurrence 
)
inherited

Adjust the model with a single string.

Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.

Then, update the edge EdgeWeight from current node, to the terminator node.

This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.

Example Use: Create an empty model and train it with string: "testdata"

char test[] = "testdata";
model.AdjustEdge(test, 15);
Parameters
string- String that is passed from the training, and will be used to AdjustEdge the model with
occurrence- Occurrence of this string.

Definition at line 109 of file model.h.

337  {
338  NodeStorageType p = payload[0];
341  int i = 0;
342 
343  if (p == 0) return;
344  while (p != 0) {
345  e = curnode->FindEdge(p);
346  if (e == NULL) return;
347  e->AdjustEdge(occurrence);
348  curnode = e->RightNode();
349  p = payload[++i];
350  }
351 
352  e = curnode->FindEdge('\xff');
353  e->AdjustEdge(occurrence);
354  return;
355 }

◆ AdjustEdge() [4/4]

void Markov::Model< char >::AdjustEdge ( const NodeStorageType payload,
long int  occurrence 
)
inherited

Adjust the model with a single string.

Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.

Then, update the edge EdgeWeight from current node, to the terminator node.

This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.

Example Use: Create an empty model and train it with string: "testdata"

char test[] = "testdata";
model.AdjustEdge(test, 15);
Parameters
string- String that is passed from the training, and will be used to AdjustEdge the model with
occurrence- Occurrence of this string.

Definition at line 109 of file model.h.

337  {
338  NodeStorageType p = payload[0];
341  int i = 0;
342 
343  if (p == 0) return;
344  while (p != 0) {
345  e = curnode->FindEdge(p);
346  if (e == NULL) return;
347  e->AdjustEdge(occurrence);
348  curnode = e->RightNode();
349  p = payload[++i];
350  }
351 
352  e = curnode->FindEdge('\xff');
353  e->AdjustEdge(occurrence);
354  return;
355 }

◆ AllocVRAMOutputBuffer()

__host__ char* Markov::API::CUDA::CUDAModelMatrix::AllocVRAMOutputBuffer ( long int  n,
long int  singleGenMaxLen,
long int  CUDAKernelGridSize,
long int  sizePerGrid 
)
protectedinherited

Allocate the output buffer for kernel operation.

TODO

Parameters
n- Number of passwords to generate.
singleGenMaxLen- maximum string length for a single generation
CUDAKernelGridSize- Total number of grid members in CUDA kernel
sizePerGrid- Size to allocate per grid member
Returns
pointer to the allocation on VRAM

◆ Buff() [1/4]

void Markov::API::MarkovPasswords::Buff ( const char *  str,
double  multiplier,
bool  bDontAdjustSelfLoops = true,
bool  bDontAdjustExtendedLoops = false 
)
inherited

Buff expression of some characters in the model.

Parameters
strA string containing all the characters to be buffed
multiplierA constant value to buff the nodes with.
bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter

Definition at line 153 of file markovPasswords.cpp.

153  {
154  std::string buffstr(str);
155  std::map< char, Node< char > * > *nodes;
156  std::map< char, Edge< char > * > *edges;
157  nodes = this->Nodes();
158  int i=0;
159  for (auto const& [repr, node] : *nodes){
160  edges = node->Edges();
161  for (auto const& [targetrepr, edge] : *edges){
162  if(buffstr.find(targetrepr)!= std::string::npos){
163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
164  if(bDontAdjustExtendedLoops){
165  if(buffstr.find(repr)!= std::string::npos){
166  continue;
167  }
168  }
169  long int weight = edge->EdgeWeight();
170  weight = weight*multiplier;
171  edge->AdjustEdge(weight);
172  }
173 
174  }
175  i++;
176  }
177 
178  this->OptimizeEdgeOrder();
179 }
std::vector< Edge< char > * > edges
A list of all edges in this model.
Definition: model.h:204
std::map< char, Node< char > * > * Nodes()
Return starter Node.
Definition: model.h:181
std::map< char, Node< char > * > nodes
Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
Definition: model.h:193
void OptimizeEdgeOrder()
Sort edges of all nodes in the model ordered by edge weights.
Definition: model.h:265

References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Buff() [2/4]

void Markov::API::MarkovPasswords::Buff ( const char *  str,
double  multiplier,
bool  bDontAdjustSelfLoops = true,
bool  bDontAdjustExtendedLoops = false 
)
inherited

Buff expression of some characters in the model.

Parameters
strA string containing all the characters to be buffed
multiplierA constant value to buff the nodes with.
bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter

Definition at line 153 of file markovPasswords.cpp.

153  {
154  std::string buffstr(str);
155  std::map< char, Node< char > * > *nodes;
156  std::map< char, Edge< char > * > *edges;
157  nodes = this->Nodes();
158  int i=0;
159  for (auto const& [repr, node] : *nodes){
160  edges = node->Edges();
161  for (auto const& [targetrepr, edge] : *edges){
162  if(buffstr.find(targetrepr)!= std::string::npos){
163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
164  if(bDontAdjustExtendedLoops){
165  if(buffstr.find(repr)!= std::string::npos){
166  continue;
167  }
168  }
169  long int weight = edge->EdgeWeight();
170  weight = weight*multiplier;
171  edge->AdjustEdge(weight);
172  }
173 
174  }
175  i++;
176  }
177 
178  this->OptimizeEdgeOrder();
179 }

References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Buff() [3/4]

void Markov::API::MarkovPasswords::Buff ( const char *  str,
double  multiplier,
bool  bDontAdjustSelfLoops = true,
bool  bDontAdjustExtendedLoops = false 
)
inherited

Buff expression of some characters in the model.

Parameters
strA string containing all the characters to be buffed
multiplierA constant value to buff the nodes with.
bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter

Definition at line 153 of file markovPasswords.cpp.

153  {
154  std::string buffstr(str);
155  std::map< char, Node< char > * > *nodes;
156  std::map< char, Edge< char > * > *edges;
157  nodes = this->Nodes();
158  int i=0;
159  for (auto const& [repr, node] : *nodes){
160  edges = node->Edges();
161  for (auto const& [targetrepr, edge] : *edges){
162  if(buffstr.find(targetrepr)!= std::string::npos){
163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
164  if(bDontAdjustExtendedLoops){
165  if(buffstr.find(repr)!= std::string::npos){
166  continue;
167  }
168  }
169  long int weight = edge->EdgeWeight();
170  weight = weight*multiplier;
171  edge->AdjustEdge(weight);
172  }
173 
174  }
175  i++;
176  }
177 
178  this->OptimizeEdgeOrder();
179 }

References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Buff() [4/4]

void Markov::API::MarkovPasswords::Buff ( const char *  str,
double  multiplier,
bool  bDontAdjustSelfLoops = true,
bool  bDontAdjustExtendedLoops = false 
)
inherited

Buff expression of some characters in the model.

Parameters
strA string containing all the characters to be buffed
multiplierA constant value to buff the nodes with.
bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter

Definition at line 153 of file markovPasswords.cpp.

153  {
154  std::string buffstr(str);
155  std::map< char, Node< char > * > *nodes;
156  std::map< char, Edge< char > * > *edges;
157  nodes = this->Nodes();
158  int i=0;
159  for (auto const& [repr, node] : *nodes){
160  edges = node->Edges();
161  for (auto const& [targetrepr, edge] : *edges){
162  if(buffstr.find(targetrepr)!= std::string::npos){
163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
164  if(bDontAdjustExtendedLoops){
165  if(buffstr.find(repr)!= std::string::npos){
166  continue;
167  }
168  }
169  long int weight = edge->EdgeWeight();
170  weight = weight*multiplier;
171  edge->AdjustEdge(weight);
172  }
173 
174  }
175  i++;
176  }
177 
178  this->OptimizeEdgeOrder();
179 }

References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_corpus_path() [1/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_corpus_path() [2/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_corpus_path() [3/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_corpus_path() [4/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_corpus_path() [5/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_corpus_path() [6/6]

def Python.Markopy.BaseCLI.check_corpus_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 181 of file base.py.

181  def check_corpus_path(filename : str):
182  """!
183  @brief check import path for validity
184  @param filename filename to check
185  """
186 
187  if(not os.path.isfile(filename)):
188  return False
189  return True
190 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [1/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [2/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [3/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [4/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [5/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_export_path() [6/6]

def Python.Markopy.BaseCLI.check_export_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 192 of file base.py.

192  def check_export_path(filename : str):
193  """!
194  @brief check import path for validity
195  @param filename filename to check
196  """
197 
198  if(filename and os.path.isfile(filename)):
199  return True
200  return True
201 

Referenced by Python.Markopy.BaseCLI.train().

Here is the caller graph for this function:

◆ check_import_path() [1/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ check_import_path() [2/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ check_import_path() [3/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ check_import_path() [4/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ check_import_path() [5/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ check_import_path() [6/6]

def Python.Markopy.BaseCLI.check_import_path ( str  filename)
staticinherited

check import path for validity

Parameters
filenamefilename to check

Definition at line 169 of file base.py.

169  def check_import_path(filename : str):
170  """!
171  @brief check import path for validity
172  @param filename filename to check
173  """
174 
175  if(not os.path.isfile(filename)):
176  return False
177  else:
178  return True
179 

Referenced by Python.Markopy.BaseCLI.import_model().

Here is the caller graph for this function:

◆ ConstructMatrix() [1/3]

bool Markov::API::ModelMatrix::ConstructMatrix ( )
inherited

Construct the related Matrix data for the model.

This operation can be used after importing/training to allocate and populate the matrix content.

this will initialize: char** edgeMatrix -> a 2D array of mapping left and right connections of each edge. long int **valueMatrix -> a 2D array representing the edge weights. int matrixSize -> Size of the matrix, aka total number of nodes. char* matrixIndex -> order of nodes in the model long int *totalEdgeWeights -> total edge weights of each Node.

Returns
True if constructed. False if already construced.

Definition at line 31 of file modelMatrix.cpp.

31  {
32  if(this->ready) return false;
33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
34 
35  this->matrixIndex = new char[this->matrixSize];
36  this->totalEdgeWeights = new long int[this->matrixSize];
37 
38  this->edgeMatrix = new char*[this->matrixSize];
39  for(int i=0;i<this->matrixSize;i++){
40  this->edgeMatrix[i] = new char[this->matrixSize];
41  }
42  this->valueMatrix = new long int*[this->matrixSize];
43  for(int i=0;i<this->matrixSize;i++){
44  this->valueMatrix[i] = new long int[this->matrixSize];
45  }
46  std::map< char, Node< char > * > *nodes;
47  nodes = this->Nodes();
48  int i=0;
49  for (auto const& [repr, node] : *nodes){
50  if(repr!=0) this->matrixIndex[i] = repr;
51  else this->matrixIndex[i] = 199;
52  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
53  for(int j=0;j<this->matrixSize;j++){
54  char val = node->NodeValue();
55  if(val < 0){
56  for(int k=0;k<this->matrixSize;k++){
57  this->valueMatrix[i][k] = 0;
58  this->edgeMatrix[i][k] = 255;
59  }
60  break;
61  }
62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
63  this->valueMatrix[i][j] = 0;
64  this->edgeMatrix[i][j] = 255;
65  }else if(j==(this->matrixSize-1)) {
66  this->valueMatrix[i][j] = 0;
67  this->edgeMatrix[i][j] = 255;
68  }else{
69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
71  }
72 
73  }
74  i++;
75  }
76  this->ready = true;
77  return true;
78  //this->DumpJSON();
79 }
long int ** valueMatrix
2-d Integer array for the value Matrix (For the weights of Edges)
Definition: modelMatrix.h:180
int matrixSize
to hold Matrix size
Definition: modelMatrix.h:185
long int * totalEdgeWeights
Array of the Total Edge Weights.
Definition: modelMatrix.h:195
bool ready
True when matrix is constructed. False if not.
Definition: modelMatrix.h:200
char ** edgeMatrix
2-D Character array for the edge Matrix (The characters of Nodes)
Definition: modelMatrix.h:175
char * matrixIndex
to hold the Matrix index (To hold the orders of 2-D arrays')
Definition: modelMatrix.h:190
Node< char > * StarterNode()
Return starter Node.
Definition: model.h:171
std::vector< Edge< storageType > * > edgesV
Definition: node.h:173

References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::API::ModelMatrix::totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConstructMatrix() [2/3]

bool Markov::API::ModelMatrix::ConstructMatrix ( )
inherited

Construct the related Matrix data for the model.

This operation can be used after importing/training to allocate and populate the matrix content.

this will initialize: char** edgeMatrix -> a 2D array of mapping left and right connections of each edge. long int **valueMatrix -> a 2D array representing the edge weights. int matrixSize -> Size of the matrix, aka total number of nodes. char* matrixIndex -> order of nodes in the model long int *totalEdgeWeights -> total edge weights of each Node.

Returns
True if constructed. False if already construced.

Definition at line 31 of file modelMatrix.cpp.

31  {
32  if(this->ready) return false;
33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
34 
35  this->matrixIndex = new char[this->matrixSize];
36  this->totalEdgeWeights = new long int[this->matrixSize];
37 
38  this->edgeMatrix = new char*[this->matrixSize];
39  for(int i=0;i<this->matrixSize;i++){
40  this->edgeMatrix[i] = new char[this->matrixSize];
41  }
42  this->valueMatrix = new long int*[this->matrixSize];
43  for(int i=0;i<this->matrixSize;i++){
44  this->valueMatrix[i] = new long int[this->matrixSize];
45  }
46  std::map< char, Node< char > * > *nodes;
47  nodes = this->Nodes();
48  int i=0;
49  for (auto const& [repr, node] : *nodes){
50  if(repr!=0) this->matrixIndex[i] = repr;
51  else this->matrixIndex[i] = 199;
52  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
53  for(int j=0;j<this->matrixSize;j++){
54  char val = node->NodeValue();
55  if(val < 0){
56  for(int k=0;k<this->matrixSize;k++){
57  this->valueMatrix[i][k] = 0;
58  this->edgeMatrix[i][k] = 255;
59  }
60  break;
61  }
62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
63  this->valueMatrix[i][j] = 0;
64  this->edgeMatrix[i][j] = 255;
65  }else if(j==(this->matrixSize-1)) {
66  this->valueMatrix[i][j] = 0;
67  this->edgeMatrix[i][j] = 255;
68  }else{
69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
71  }
72 
73  }
74  i++;
75  }
76  this->ready = true;
77  return true;
78  //this->DumpJSON();
79 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::API::ModelMatrix::totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConstructMatrix() [3/3]

bool Markov::API::ModelMatrix::ConstructMatrix ( )
inherited

Construct the related Matrix data for the model.

This operation can be used after importing/training to allocate and populate the matrix content.

this will initialize: char** edgeMatrix -> a 2D array of mapping left and right connections of each edge. long int **valueMatrix -> a 2D array representing the edge weights. int matrixSize -> Size of the matrix, aka total number of nodes. char* matrixIndex -> order of nodes in the model long int *totalEdgeWeights -> total edge weights of each Node.

Returns
True if constructed. False if already construced.

Definition at line 31 of file modelMatrix.cpp.

31  {
32  if(this->ready) return false;
33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
34 
35  this->matrixIndex = new char[this->matrixSize];
36  this->totalEdgeWeights = new long int[this->matrixSize];
37 
38  this->edgeMatrix = new char*[this->matrixSize];
39  for(int i=0;i<this->matrixSize;i++){
40  this->edgeMatrix[i] = new char[this->matrixSize];
41  }
42  this->valueMatrix = new long int*[this->matrixSize];
43  for(int i=0;i<this->matrixSize;i++){
44  this->valueMatrix[i] = new long int[this->matrixSize];
45  }
46  std::map< char, Node< char > * > *nodes;
47  nodes = this->Nodes();
48  int i=0;
49  for (auto const& [repr, node] : *nodes){
50  if(repr!=0) this->matrixIndex[i] = repr;
51  else this->matrixIndex[i] = 199;
52  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
53  for(int j=0;j<this->matrixSize;j++){
54  char val = node->NodeValue();
55  if(val < 0){
56  for(int k=0;k<this->matrixSize;k++){
57  this->valueMatrix[i][k] = 0;
58  this->edgeMatrix[i][k] = 255;
59  }
60  break;
61  }
62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
63  this->valueMatrix[i][j] = 0;
64  this->edgeMatrix[i][j] = 255;
65  }else if(j==(this->matrixSize-1)) {
66  this->valueMatrix[i][j] = 0;
67  this->edgeMatrix[i][j] = 255;
68  }else{
69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
71  }
72 
73  }
74  i++;
75  }
76  this->ready = true;
77  return true;
78  //this->DumpJSON();
79 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::API::ModelMatrix::totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CudaCheckNotifyErr()

__host__ int Markov::API::CUDA::CUDADeviceController::CudaCheckNotifyErr ( cudaError_t  _status,
const char *  msg,
bool  bExit = true 
)
staticprotectedinherited

Check results of the last operation on GPU.

Check the status returned from cudaMalloc/cudaMemcpy to find failures.

If a failure occurs, its assumed beyond redemption, and exited.

Parameters
_statusCuda error status to check
msgMessage to print in case of a failure
Returns
0 if successful, 1 if failure. Example output:
char *da, a = "test";
cudastatus = cudaMalloc((char **)&da, 5*sizeof(char*));
CudaCheckNotifyErr(cudastatus, "Failed to allocate VRAM for *da.\n");
static __host__ int CudaCheckNotifyErr(cudaError_t _status, const char *msg, bool bExit=true)
Check results of the last operation on GPU.

Definition at line 32 of file cudaDeviceController.cu.

32  {
33  if (_status != cudaSuccess) {
34  std::cerr << "\033[1;31m" << msg << " -> " << cudaGetErrorString(_status) << " ("<< _status << ")" << "\033[0m" << "\n";
35 
36  if(bExit) {
37  cudaDeviceReset();
38  exit(1);
39  }
40  }
41  return 0;
42  }

◆ CudaMalloc2DToFlat()

template<typename T >
static __host__ cudaError_t Markov::API::CUDA::CUDADeviceController::CudaMalloc2DToFlat ( T **  dst,
int  row,
int  col 
)
inlinestaticprotectedinherited

Malloc a 2D array in device space.

This function will allocate enough space on VRAM for flattened 2D array.

Parameters
dstdestination pointer
rowrow size of the 2d array
colcolumn size of the 2d array
Returns
cudaError_t status of the cudaMalloc operation

Example output:

cudaError_t cudastatus;
char* dst;
cudastatus = CudaMalloc2DToFlat<char>(&dst, 5, 15);
if(cudastatus!=cudaSuccess){
CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
}

Definition at line 75 of file cudaDeviceController.h.

75  {
76  cudaError_t cudastatus = cudaMalloc((T **)dst, row*col*sizeof(T));
77  CudaCheckNotifyErr(cudastatus, "cudaMalloc Failed.", false);
78  return cudastatus;
79  }

References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

Here is the call graph for this function:

◆ CudaMemcpy2DToFlat()

template<typename T >
static __host__ cudaError_t Markov::API::CUDA::CUDADeviceController::CudaMemcpy2DToFlat ( T *  dst,
T **  src,
int  row,
int  col 
)
inlinestaticprotectedinherited

Memcpy a 2D array in device space after flattening.

Resulting buffer will not be true 2D array.

Parameters
dstdestination pointer
rcsource pointer
rowrow size of the 2d array
colcolumn size of the 2d array
Returns
cudaError_t status of the cudaMalloc operation

Example output:

cudaError_t cudastatus;
char* dst;
cudastatus = CudaMalloc2DToFlat<char>(&dst, 5, 15);
CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
cudastatus = CudaMemcpy2DToFlat<char>(*dst,src,15,15);
CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);

Definition at line 103 of file cudaDeviceController.h.

103  {
104  T* tempbuf = new T[row*col];
105  for(int i=0;i<row;i++){
106  memcpy(&(tempbuf[row*i]), src[i], col);
107  }
108  return cudaMemcpy(dst, tempbuf, row*col*sizeof(T), cudaMemcpyHostToDevice);
109 
110  }

References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

Here is the call graph for this function:

◆ CudaMigrate2DFlat()

template<typename T >
static __host__ cudaError_t Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat ( T **  dst,
T **  src,
int  row,
int  col 
)
inlinestaticprotectedinherited

Both malloc and memcpy a 2D array into device VRAM.

Resulting buffer will not be true 2D array.

Parameters
dstdestination pointer
rcsource pointer
rowrow size of the 2d array
colcolumn size of the 2d array
Returns
cudaError_t status of the cudaMalloc operation

Example output:

cudaError_t cudastatus;
char* dst;
cudastatus = CudaMigrate2DFlat<long int>(
&dst, this->valueMatrix, this->matrixSize, this->matrixSize);
CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize value matrix row.");

Definition at line 132 of file cudaDeviceController.h.

132  {
133  cudaError_t cudastatus;
134  cudastatus = CudaMalloc2DToFlat<T>(dst, row, col);
135  if(cudastatus!=cudaSuccess){
136  CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
137  return cudastatus;
138  }
139  cudastatus = CudaMemcpy2DToFlat<T>(*dst,src,row,col);
140  CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);
141  return cudastatus;
142  }

References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

Referenced by Markov::API::CUDA::CUDADeviceController::CudaMalloc2DToFlat(), Markov::API::CUDA::CUDADeviceController::CudaMemcpy2DToFlat(), and Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeallocateMatrix() [1/3]

bool Markov::API::ModelMatrix::DeallocateMatrix ( )
protectedinherited

Deallocate matrix and make it ready for re-construction.

Returns
True if deallocated. False if matrix was not initialized

Definition at line 81 of file modelMatrix.cpp.

81  {
82  if(!this->ready) return false;
83  delete[] this->matrixIndex;
84  delete[] this->totalEdgeWeights;
85 
86  for(int i=0;i<this->matrixSize;i++){
87  delete[] this->edgeMatrix[i];
88  }
89  delete[] this->edgeMatrix;
90 
91  for(int i=0;i<this->matrixSize;i++){
92  delete[] this->valueMatrix[i];
93  }
94  delete[] this->valueMatrix;
95 
96  this->matrixSize = -1;
97  this->ready = false;
98  return true;
99 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the caller graph for this function:

◆ DeallocateMatrix() [2/3]

bool Markov::API::ModelMatrix::DeallocateMatrix ( )
protectedinherited

Deallocate matrix and make it ready for re-construction.

Returns
True if deallocated. False if matrix was not initialized

Definition at line 81 of file modelMatrix.cpp.

81  {
82  if(!this->ready) return false;
83  delete[] this->matrixIndex;
84  delete[] this->totalEdgeWeights;
85 
86  for(int i=0;i<this->matrixSize;i++){
87  delete[] this->edgeMatrix[i];
88  }
89  delete[] this->edgeMatrix;
90 
91  for(int i=0;i<this->matrixSize;i++){
92  delete[] this->valueMatrix[i];
93  }
94  delete[] this->valueMatrix;
95 
96  this->matrixSize = -1;
97  this->ready = false;
98  return true;
99 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the caller graph for this function:

◆ DeallocateMatrix() [3/3]

bool Markov::API::ModelMatrix::DeallocateMatrix ( )
protectedinherited

Deallocate matrix and make it ready for re-construction.

Returns
True if deallocated. False if matrix was not initialized

Definition at line 81 of file modelMatrix.cpp.

81  {
82  if(!this->ready) return false;
83  delete[] this->matrixIndex;
84  delete[] this->totalEdgeWeights;
85 
86  for(int i=0;i<this->matrixSize;i++){
87  delete[] this->edgeMatrix[i];
88  }
89  delete[] this->edgeMatrix;
90 
91  for(int i=0;i<this->matrixSize;i++){
92  delete[] this->valueMatrix[i];
93  }
94  delete[] this->valueMatrix;
95 
96  this->matrixSize = -1;
97  this->ready = false;
98  return true;
99 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

Here is the caller graph for this function:

◆ DumpJSON() [1/3]

void Markov::API::ModelMatrix::DumpJSON ( )
inherited

Debug function to dump the model to a JSON file.

Might not work 100%. Not meant for production use.

Definition at line 101 of file modelMatrix.cpp.

101  {
102 
103  std::cout << "{\n \"index\": \"";
104  for(int i=0;i<this->matrixSize;i++){
105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
108  else if(i==0) std::cout << "\\\\xff";
109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
110  else std::cout << this->matrixIndex[i];
111  }
112  std::cout <<
113  "\",\n"
114  " \"edgemap\": {\n";
115 
116  for(int i=0;i<this->matrixSize;i++){
117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
122  for(int j=0;j<this->matrixSize;j++){
123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
129  if(j!=this->matrixSize-1) std::cout << ", ";
130  }
131  std::cout << "],\n";
132  }
133  std::cout << "},\n";
134 
135  std::cout << "\" weightmap\": {\n";
136  for(int i=0;i<this->matrixSize;i++){
137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
142 
143  for(int j=0;j<this->matrixSize;j++){
144  std::cout << this->valueMatrix[i][j];
145  if(j!=this->matrixSize-1) std::cout << ", ";
146  }
147  std::cout << "],\n";
148  }
149  std::cout << " }\n}\n";
150 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the caller graph for this function:

◆ DumpJSON() [2/3]

void Markov::API::ModelMatrix::DumpJSON ( )
inherited

Debug function to dump the model to a JSON file.

Might not work 100%. Not meant for production use.

Definition at line 101 of file modelMatrix.cpp.

101  {
102 
103  std::cout << "{\n \"index\": \"";
104  for(int i=0;i<this->matrixSize;i++){
105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
108  else if(i==0) std::cout << "\\\\xff";
109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
110  else std::cout << this->matrixIndex[i];
111  }
112  std::cout <<
113  "\",\n"
114  " \"edgemap\": {\n";
115 
116  for(int i=0;i<this->matrixSize;i++){
117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
122  for(int j=0;j<this->matrixSize;j++){
123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
129  if(j!=this->matrixSize-1) std::cout << ", ";
130  }
131  std::cout << "],\n";
132  }
133  std::cout << "},\n";
134 
135  std::cout << "\" weightmap\": {\n";
136  for(int i=0;i<this->matrixSize;i++){
137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
142 
143  for(int j=0;j<this->matrixSize;j++){
144  std::cout << this->valueMatrix[i][j];
145  if(j!=this->matrixSize-1) std::cout << ", ";
146  }
147  std::cout << "],\n";
148  }
149  std::cout << " }\n}\n";
150 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the caller graph for this function:

◆ DumpJSON() [3/3]

void Markov::API::ModelMatrix::DumpJSON ( )
inherited

Debug function to dump the model to a JSON file.

Might not work 100%. Not meant for production use.

Definition at line 101 of file modelMatrix.cpp.

101  {
102 
103  std::cout << "{\n \"index\": \"";
104  for(int i=0;i<this->matrixSize;i++){
105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
108  else if(i==0) std::cout << "\\\\xff";
109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
110  else std::cout << this->matrixIndex[i];
111  }
112  std::cout <<
113  "\",\n"
114  " \"edgemap\": {\n";
115 
116  for(int i=0;i<this->matrixSize;i++){
117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
122  for(int j=0;j<this->matrixSize;j++){
123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
129  if(j!=this->matrixSize-1) std::cout << ", ";
130  }
131  std::cout << "],\n";
132  }
133  std::cout << "},\n";
134 
135  std::cout << "\" weightmap\": {\n";
136  for(int i=0;i<this->matrixSize;i++){
137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
142 
143  for(int j=0;j<this->matrixSize;j++){
144  std::cout << this->valueMatrix[i][j];
145  if(j!=this->matrixSize-1) std::cout << ", ";
146  }
147  std::cout << "],\n";
148  }
149  std::cout << " }\n}\n";
150 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the caller graph for this function:

◆ Edges() [1/4]

std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
inlineinherited

Return a vector of all the edges in the model.

Returns
vector of edges

Definition at line 176 of file model.h.

176 { return &edges;}

◆ Edges() [2/4]

std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
inlineinherited

Return a vector of all the edges in the model.

Returns
vector of edges

Definition at line 176 of file model.h.

176 { return &edges;}

◆ Edges() [3/4]

std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
inlineinherited

Return a vector of all the edges in the model.

Returns
vector of edges

Definition at line 176 of file model.h.

176 { return &edges;}

◆ Edges() [4/4]

std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
inlineinherited

Return a vector of all the edges in the model.

Returns
vector of edges

Definition at line 176 of file model.h.

176 { return &edges;}

◆ evaluate()

def Python.Markopy.MarkopyCLI.evaluate (   self,
str  filename 
)
inherited

Definition at line 163 of file markopy.py.

163  def evaluate(self,filename : str):
164  if(not self.args.evaluate_type):
165  if(filename.endswith(".mdl")):
166  ModelEvaluator(filename).evaluate()
167  else:
168  CorpusEvaluator(filename).evaluate()
169  else:
170  if(self.args.evaluate_type == "model"):
171  ModelEvaluator(filename).evaluate()
172  else:
173  CorpusEvaluator(filename).evaluate()
174 

Referenced by Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ Export() [1/9]

bool Markov::Model< char >::Export ( const char *  filename)
inherited

Open a file to export with filename, and call bool Model::Export with std::ofstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Export file to filename

model.Export("test.mdl");

Definition at line 166 of file model.h.

300  {
301  std::ofstream exportfile;
302  exportfile.open(filename);
303  return this->Export(&exportfile);
304 }
bool Export(std::ofstream *)
Export a file of the model.
Definition: model.h:288

◆ Export() [2/9]

bool Markov::Model< char >::Export ( const char *  filename)
inherited

Open a file to export with filename, and call bool Model::Export with std::ofstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Export file to filename

model.Export("test.mdl");

Definition at line 166 of file model.h.

300  {
301  std::ofstream exportfile;
302  exportfile.open(filename);
303  return this->Export(&exportfile);
304 }

◆ Export() [3/9]

bool Markov::Model< char >::Export ( const char *  filename)
inherited

Open a file to export with filename, and call bool Model::Export with std::ofstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Export file to filename

model.Export("test.mdl");

Definition at line 166 of file model.h.

300  {
301  std::ofstream exportfile;
302  exportfile.open(filename);
303  return this->Export(&exportfile);
304 }

◆ Export() [4/9]

bool Markov::Model< char >::Export ( const char *  filename)
inherited

Open a file to export with filename, and call bool Model::Export with std::ofstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Export file to filename

model.Export("test.mdl");

Definition at line 166 of file model.h.

300  {
301  std::ofstream exportfile;
302  exportfile.open(filename);
303  return this->Export(&exportfile);
304 }

◆ export() [1/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export() [2/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export() [3/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export() [4/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export() [5/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export() [6/6]

def Python.Markopy.BaseCLI.export (   self,
str  filename 
)
inherited

Export model to a file.

Parameters
filenamefilename to export to

Definition at line 138 of file base.py.

138  def export(self, filename : str):
139  """!
140  @brief Export model to a file
141  @param filename filename to export to
142  """
143  self.model.Export(filename)
144 

References Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.train().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Export() [5/9]

bool Markov::Model< char >::Export ( std::ofstream *  f)
inherited

Export a file of the model.

File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.

Iterate over this vertices, and their edges, and write them to file.

Returns
True if successful, False for incomplete models.

Example Use: Export file to ofstream

std::ofstream file("test.mdl");
model.Export(&file);

Definition at line 155 of file model.h.

288  {
290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
291  e = this->edges[i];
292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
294  }
295 
296  return true;
297 }
uint64_t EdgeWeight()
return edge's EdgeWeight.
Definition: edge.h:160
Node< NodeStorageType > * LeftNode()
return edge's LeftNode
Definition: edge.h:165
unsigned char NodeValue()
Return character representation of this node.
Definition: node.h:215
f
output file handle
Definition: model_2gram.py:16

◆ Export() [6/9]

bool Markov::Model< char >::Export ( std::ofstream *  f)
inherited

Export a file of the model.

File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.

Iterate over this vertices, and their edges, and write them to file.

Returns
True if successful, False for incomplete models.

Example Use: Export file to ofstream

std::ofstream file("test.mdl");
model.Export(&file);

Definition at line 155 of file model.h.

288  {
290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
291  e = this->edges[i];
292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
294  }
295 
296  return true;
297 }

◆ Export() [7/9]

bool Markov::Model< char >::Export ( std::ofstream *  f)
inherited

Export a file of the model.

File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.

Iterate over this vertices, and their edges, and write them to file.

Returns
True if successful, False for incomplete models.

Example Use: Export file to ofstream

std::ofstream file("test.mdl");
model.Export(&file);

Definition at line 155 of file model.h.

288  {
290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
291  e = this->edges[i];
292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
294  }
295 
296  return true;
297 }

◆ Export() [8/9]

bool Markov::Model< char >::Export ( std::ofstream *  f)
inherited

Export a file of the model.

File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.

Iterate over this vertices, and their edges, and write them to file.

Returns
True if successful, False for incomplete models.

Example Use: Export file to ofstream

std::ofstream file("test.mdl");
model.Export(&file);

Definition at line 155 of file model.h.

288  {
290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
291  e = this->edges[i];
292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
294  }
295 
296  return true;
297 }

◆ Export() [9/9]

def Python.Markopy.MarkovModel.Export ( str  filename)
inherited

Definition at line 26 of file mm.py.

26  def Export(filename : str):
27  pass
28 

◆ FastRandomWalk() [1/9]

def Python.Markopy.ModelMatrix.FastRandomWalk ( int  count,
str  wordlist,
int  minlen,
int  maxlen 
)
inherited

Definition at line 48 of file mm.py.

48  def FastRandomWalk(count : int, wordlist : str, minlen : int, maxlen : int):
49  pass

Referenced by Python.Markopy.ModelMatrixCLI._generate().

Here is the caller graph for this function:

◆ FastRandomWalk() [2/9]

def Python.Markopy.ModelMatrix.FastRandomWalk ( int  count,
str  wordlist,
int  minlen,
int  maxlen 
)
inherited

Definition at line 48 of file mm.py.

48  def FastRandomWalk(count : int, wordlist : str, minlen : int, maxlen : int):
49  pass

Referenced by Python.Markopy.ModelMatrixCLI._generate().

Here is the caller graph for this function:

◆ FastRandomWalk() [3/9]

__host__ void Markov::API::CUDA::CUDAModelMatrix::FastRandomWalk ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen,
int  maxLen,
bool  bFileIO,
bool  bInfinite 
)
inherited

Random walk on the Matrix-reduced Markov::Model.

TODO

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
Class to flatten and reduce Markov::Model to a Matrix.
Definition: modelMatrix.h:23
Definition: mp.py:1

Definition at line 58 of file cudaModelMatrix.cu.

58  {
59  cudaDeviceProp prop;
60  int device=0;
61  cudaGetDeviceProperties(&prop, device);
62  cudaChooseDevice(&device, &prop);
63  //std::cout << "Flattening matrix." << std::endl;
64  this->FlattenMatrix();
65  //std::cout << "Migrating matrix." << std::endl;
66  this->MigrateMatrix();
67  //std::cout << "Migrated matrix." << std::endl;
68  std::ofstream wordlist;
69  if(bFileIO)
70  wordlist.open(wordlistFileName);
71 
72 
73  cudaBlocks = 1024;
74  cudaThreads = 256;
83  this->prepKernelMemoryChannel(alternatingKernels);
84 
85  unsigned long int leftover = n - (totalOutputPerSync*numberOfPartitions);
86 
87  if(bInfinite && !numberOfPartitions) numberOfPartitions=5;
88  std::cerr << cudaPerKernelAllocationSize << "\n";
89 
90  if(n%totalOutputPerSync) std::cerr << "For optimization, request outputs muliples of "<< totalOutputPerSync << ".\n";
91 
92  //start kernelID 1
93  this->LaunchAsyncKernel(1, minLen, maxLen);
94 
95  for(int i=1;i<numberOfPartitions;i++){
96  if(bInfinite) i=0;
97 
98  //wait kernelID1 to finish, and start kernelID 0
99  cudaStreamSynchronize(this->cudastreams[1]);
100  this->LaunchAsyncKernel(0, minLen, maxLen);
101 
102  //start memcpy from kernel 1 (block until done)
103  this->GatherAsyncKernelOutput(1, bFileIO, wordlist);
104 
105  //wait kernelID 0 to finish, then start kernelID1
106  cudaStreamSynchronize(this->cudastreams[0]);
107  this->LaunchAsyncKernel(1, minLen, maxLen);
108 
109  //start memcpy from kernel 0 (block until done)
110  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
111 
112  }
113 
114  //wait kernelID1 to finish, and start kernelID 0
115  cudaStreamSynchronize(this->cudastreams[1]);
116  this->LaunchAsyncKernel(0, minLen, maxLen);
117  this->GatherAsyncKernelOutput(1, bFileIO, wordlist);
118  cudaStreamSynchronize(this->cudastreams[0]);
119  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
120 
121 
122  if(!leftover) return;
124  std::cerr << "Remaining line count (" << leftover << ") is lower than partition. Adjusting CUDA workload..\n";
125  this->iterationsPerKernelThread = leftover/cudaGridSize;
126  this->LaunchAsyncKernel(0, minLen, maxLen);
127  cudaStreamSynchronize(this->cudastreams[0]);
128  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
129 
130  leftover -= this->iterationsPerKernelThread*cudaGridSize;
131  if(!leftover) return;
132 
133  std::cerr << "Remaining line count (" << leftover << ") is lower than minimum possible. Handing over to CPU generation.\n";
134  this->iterationsPerKernelThread = leftover/cudaGridSize;
135 
136  leftover -= this->iterationsPerKernelThread;
137 
138  if(!leftover) return;
139  std::cerr << "Remaining " << leftover << " lines are absolutely not worth printing.\n";
141  Markov::API::ModelMatrix::FastRandomWalk(leftover, &wordlist, minLen, maxLen, 1, bFileIO);
142 
143  }
__host__ void MigrateMatrix()
Migrate the class members to the VRAM.
__host__ void LaunchAsyncKernel(int kernelID, int minLen, int maxLen)
__host__ void GatherAsyncKernelOutput(int kernelID, bool bFileIO, std::ofstream &wordlist)
__host__ void prepKernelMemoryChannel(int numberOfStreams)
__host__ void FlattenMatrix()
Flatten migrated matrix from 2d to 1d.
int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
Random walk on the Matrix-reduced Markov::Model.
bool ConstructMatrix()
Construct the related Matrix data for the model.
Definition: modelMatrix.cpp:31

References Markov::API::CUDA::CUDAModelMatrix::alternatingKernels, Markov::API::CUDA::CUDAModelMatrix::cudaBlocks, Markov::API::CUDA::CUDAModelMatrix::cudaGridSize, Markov::API::CUDA::CUDAModelMatrix::cudaMemPerGrid, Markov::API::CUDA::CUDAModelMatrix::cudaPerKernelAllocationSize, Markov::API::CUDA::CUDAModelMatrix::cudaThreads, Markov::API::CUDA::CUDAModelMatrix::iterationsPerKernelThread, Markov::API::CUDA::CUDAModelMatrix::numberOfPartitions, Markov::API::CUDA::CUDAModelMatrix::totalOutputPerKernel, and Markov::API::CUDA::CUDAModelMatrix::totalOutputPerSync.

Referenced by Python.CudaMarkopy.CudaModelMatrixCLI::_generate().

Here is the caller graph for this function:

◆ FastRandomWalk() [4/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
inherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 217 of file modelMatrix.cpp.

217  {
218  std::ofstream wordlist;
219  if(bFileIO)
220  wordlist.open(wordlistFileName);
221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
222  return 0;
223 }

References Markov::API::ModelMatrix::FastRandomWalk().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalk() [5/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
inherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 217 of file modelMatrix.cpp.

217  {
218  std::ofstream wordlist;
219  if(bFileIO)
220  wordlist.open(wordlistFileName);
221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
222  return 0;
223 }

References Markov::API::ModelMatrix::FastRandomWalk().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalk() [6/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
inherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 217 of file modelMatrix.cpp.

217  {
218  std::ofstream wordlist;
219  if(bFileIO)
220  wordlist.open(wordlistFileName);
221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
222  return 0;
223 }

References Markov::API::ModelMatrix::FastRandomWalk().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalk() [7/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
std::ofstream *  wordlist,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
protectedinherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 204 of file modelMatrix.cpp.

204  {
205 
206 
207  std::mutex mlock;
208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
209  else{
210  int numberOfPartitions = n/50000000ull;
211  for(int i=0;i<numberOfPartitions;i++)
212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
213  }
214  return 0;
215 }
void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
A single partition of FastRandomWalk event.

References Markov::API::ModelMatrix::FastRandomWalkPartition().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalk() [8/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
std::ofstream *  wordlist,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
protectedinherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 204 of file modelMatrix.cpp.

204  {
205 
206 
207  std::mutex mlock;
208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
209  else{
210  int numberOfPartitions = n/50000000ull;
211  for(int i=0;i<numberOfPartitions;i++)
212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
213  }
214  return 0;
215 }

References Markov::API::ModelMatrix::FastRandomWalkPartition().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalk() [9/9]

int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n,
std::ofstream *  wordlist,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20,
bool  bFileIO = true 
)
protectedinherited

Random walk on the Matrix-reduced Markov::Model.

This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.
mp.Import("models/finished.mdl");
mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);

Definition at line 204 of file modelMatrix.cpp.

204  {
205 
206 
207  std::mutex mlock;
208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
209  else{
210  int numberOfPartitions = n/50000000ull;
211  for(int i=0;i<numberOfPartitions;i++)
212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
213  }
214  return 0;
215 }

References Markov::API::ModelMatrix::FastRandomWalkPartition().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkPartition() [1/3]

void Markov::API::ModelMatrix::FastRandomWalkPartition ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
bool  bFileIO,
int  threads 
)
protectedinherited

A single partition of FastRandomWalk event.

Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks, large n parameters would lead to huge memory allocations. Without Partitioning:

  • 50M results 12 characters max -> 550 Mb Memory allocation
  • 5B results 12 characters max -> 55 Gb Memory allocation
  • 50B results 12 characters max -> 550GB Memory allocation

Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 225 of file modelMatrix.cpp.

225  {
226 
227  int iterationsPerThread = n/threads;
228  int iterationsPerThreadCarryOver = n%threads;
229 
230  std::vector<std::thread*> threadsV;
231 
232  int id = 0;
233  for(int i=0;i<threads;i++){
234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
235  id++;
236  }
237 
238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
239 
240  for(int i=0;i<threads;i++){
241  threadsV[i]->join();
242  }
243 }
void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
A single thread of a single partition of FastRandomWalk.

References Markov::API::ModelMatrix::FastRandomWalkThread().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkPartition() [2/3]

void Markov::API::ModelMatrix::FastRandomWalkPartition ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
bool  bFileIO,
int  threads 
)
protectedinherited

A single partition of FastRandomWalk event.

Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks, large n parameters would lead to huge memory allocations. Without Partitioning:

  • 50M results 12 characters max -> 550 Mb Memory allocation
  • 5B results 12 characters max -> 55 Gb Memory allocation
  • 50B results 12 characters max -> 550GB Memory allocation

Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 225 of file modelMatrix.cpp.

225  {
226 
227  int iterationsPerThread = n/threads;
228  int iterationsPerThreadCarryOver = n%threads;
229 
230  std::vector<std::thread*> threadsV;
231 
232  int id = 0;
233  for(int i=0;i<threads;i++){
234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
235  id++;
236  }
237 
238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
239 
240  for(int i=0;i<threads;i++){
241  threadsV[i]->join();
242  }
243 }

References Markov::API::ModelMatrix::FastRandomWalkThread().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkPartition() [3/3]

void Markov::API::ModelMatrix::FastRandomWalkPartition ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
bool  bFileIO,
int  threads 
)
protectedinherited

A single partition of FastRandomWalk event.

Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks, large n parameters would lead to huge memory allocations. Without Partitioning:

  • 50M results 12 characters max -> 550 Mb Memory allocation
  • 5B results 12 characters max -> 55 Gb Memory allocation
  • 50B results 12 characters max -> 550GB Memory allocation

Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 225 of file modelMatrix.cpp.

225  {
226 
227  int iterationsPerThread = n/threads;
228  int iterationsPerThreadCarryOver = n%threads;
229 
230  std::vector<std::thread*> threadsV;
231 
232  int id = 0;
233  for(int i=0;i<threads;i++){
234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
235  id++;
236  }
237 
238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
239 
240  for(int i=0;i<threads;i++){
241  threadsV[i]->join();
242  }
243 }

References Markov::API::ModelMatrix::FastRandomWalkThread().

Referenced by Markov::API::ModelMatrix::FastRandomWalk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkThread() [1/3]

void Markov::API::ModelMatrix::FastRandomWalkThread ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
int  id,
bool  bFileIO 
)
protectedinherited

A single thread of a single partition of FastRandomWalk.

A FastRandomWalkPartition will initiate as many of this function as requested.

This function contains the bulk of the generation algorithm.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
id- DEPRECATED Thread id - No longer used
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 153 of file modelMatrix.cpp.

153  {
154  if(n==0) return;
155 
156  Markov::Random::Marsaglia MarsagliaRandomEngine;
157  char* e;
158  char *res = new char[(maxLen+2)*n];
159  int index = 0;
160  char next;
161  int len=0;
162  long int selection;
163  char cur;
164  long int bufferctr = 0;
165  for (int i = 0; i < n; i++) {
166  cur=199;
167  len=0;
168  while (true) {
169  e = strchr(this->matrixIndex, cur);
170  index = e - this->matrixIndex;
171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
172  for(int j=0;j<this->matrixSize;j++){
173  selection -= this->valueMatrix[index][j];
174  if (selection < 0){
175  next = this->edgeMatrix[index][j];
176  break;
177  }
178  }
179 
180  if (len >= maxLen) break;
181  else if ((next < 0) && (len < minLen)) continue;
182  else if (next < 0) break;
183  cur = next;
184  res[bufferctr + len++] = cur;
185  }
186  res[bufferctr + len++] = '\n';
187  bufferctr+=len;
188 
189  }
190  if(bFileIO){
191  mlock->lock();
192  *wordlist << res;
193  mlock->unlock();
194  }else{
195  mlock->lock();
196  std::cout << res;
197  mlock->unlock();
198  }
199  delete res;
200 
201 }
Implementation of Marsaglia Random Engine.
Definition: random.h:125
unsigned long random()
Generate Random Number.
Definition: random.h:140
__device__ char * strchr(char *p, char c, int s_len)
srtchr implementation on device space

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkThread() [2/3]

void Markov::API::ModelMatrix::FastRandomWalkThread ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
int  id,
bool  bFileIO 
)
protectedinherited

A single thread of a single partition of FastRandomWalk.

A FastRandomWalkPartition will initiate as many of this function as requested.

This function contains the bulk of the generation algorithm.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
id- DEPRECATED Thread id - No longer used
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 153 of file modelMatrix.cpp.

153  {
154  if(n==0) return;
155 
156  Markov::Random::Marsaglia MarsagliaRandomEngine;
157  char* e;
158  char *res = new char[(maxLen+2)*n];
159  int index = 0;
160  char next;
161  int len=0;
162  long int selection;
163  char cur;
164  long int bufferctr = 0;
165  for (int i = 0; i < n; i++) {
166  cur=199;
167  len=0;
168  while (true) {
169  e = strchr(this->matrixIndex, cur);
170  index = e - this->matrixIndex;
171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
172  for(int j=0;j<this->matrixSize;j++){
173  selection -= this->valueMatrix[index][j];
174  if (selection < 0){
175  next = this->edgeMatrix[index][j];
176  break;
177  }
178  }
179 
180  if (len >= maxLen) break;
181  else if ((next < 0) && (len < minLen)) continue;
182  else if (next < 0) break;
183  cur = next;
184  res[bufferctr + len++] = cur;
185  }
186  res[bufferctr + len++] = '\n';
187  bufferctr+=len;
188 
189  }
190  if(bFileIO){
191  mlock->lock();
192  *wordlist << res;
193  mlock->unlock();
194  }else{
195  mlock->lock();
196  std::cout << res;
197  mlock->unlock();
198  }
199  delete res;
200 
201 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastRandomWalkThread() [3/3]

void Markov::API::ModelMatrix::FastRandomWalkThread ( std::mutex *  mlock,
std::ofstream *  wordlist,
unsigned long int  n,
int  minLen,
int  maxLen,
int  id,
bool  bFileIO 
)
protectedinherited

A single thread of a single partition of FastRandomWalk.

A FastRandomWalkPartition will initiate as many of this function as requested.

This function contains the bulk of the generation algorithm.

Parameters
mlock- mutex lock to distribute to child threads
wordlist- Reference to the wordlist file to write to
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
id- DEPRECATED Thread id - No longer used
bFileIO- If false, filename will be ignored and will output to stdout.

Definition at line 153 of file modelMatrix.cpp.

153  {
154  if(n==0) return;
155 
156  Markov::Random::Marsaglia MarsagliaRandomEngine;
157  char* e;
158  char *res = new char[(maxLen+2)*n];
159  int index = 0;
160  char next;
161  int len=0;
162  long int selection;
163  char cur;
164  long int bufferctr = 0;
165  for (int i = 0; i < n; i++) {
166  cur=199;
167  len=0;
168  while (true) {
169  e = strchr(this->matrixIndex, cur);
170  index = e - this->matrixIndex;
171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
172  for(int j=0;j<this->matrixSize;j++){
173  selection -= this->valueMatrix[index][j];
174  if (selection < 0){
175  next = this->edgeMatrix[index][j];
176  break;
177  }
178  }
179 
180  if (len >= maxLen) break;
181  else if ((next < 0) && (len < minLen)) continue;
182  else if (next < 0) break;
183  cur = next;
184  res[bufferctr + len++] = cur;
185  }
186  res[bufferctr + len++] = '\n';
187  bufferctr+=len;
188 
189  }
190  if(bFileIO){
191  mlock->lock();
192  *wordlist << res;
193  mlock->unlock();
194  }else{
195  mlock->lock();
196  std::cout << res;
197  mlock->unlock();
198  }
199  delete res;
200 
201 }

References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlattenMatrix()

__host__ void Markov::API::CUDA::CUDAModelMatrix::FlattenMatrix ( )
inherited

Flatten migrated matrix from 2d to 1d.

Definition at line 261 of file cudaModelMatrix.cu.

261  {
262  this->flatEdgeMatrix = new char[this->matrixSize*this->matrixSize];
263 
264  this->flatValueMatrix = new long int[this->matrixSize*this->matrixSize];
265  for(int i=0;i<this->matrixSize;i++){
266  memcpy(&this->flatEdgeMatrix[i*this->matrixSize], this->edgeMatrix[i], this->matrixSize );
267  memcpy(&this->flatValueMatrix[i*this->matrixSize], this->valueMatrix[i], this->matrixSize*sizeof(long int) );
268  }
269  }
char * flatEdgeMatrix
Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.
long int * flatValueMatrix
Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.

References Markov::API::CUDA::CUDAModelMatrix::flatEdgeMatrix, Markov::API::CUDA::CUDAModelMatrix::flatValueMatrix, and Markov::API::ModelMatrix::matrixSize.

◆ GatherAsyncKernelOutput()

__host__ void Markov::API::CUDA::CUDAModelMatrix::GatherAsyncKernelOutput ( int  kernelID,
bool  bFileIO,
std::ofstream &  wordlist 
)
protectedinherited

Definition at line 180 of file cudaModelMatrix.cu.

180  {
181  cudaMemcpy(this->outputBuffer[kernelID],this->device_outputBuffer[kernelID],cudaPerKernelAllocationSize, cudaMemcpyDeviceToHost);
182  //std::cerr << "Kernel" << kernelID << " output copied\n";
183  if(bFileIO){
184  for(long int j=0;j<cudaPerKernelAllocationSize;j+=cudaMemPerGrid){
185  wordlist << &this->outputBuffer[kernelID][j];
186  }
187  }else{
188  for(long int j=0;j<cudaPerKernelAllocationSize;j+=cudaMemPerGrid){
189  std::cout << &this->outputBuffer[kernelID][j];
190  }
191  }
192  }
char ** device_outputBuffer
RandomWalk results in device.
char ** outputBuffer
RandomWalk results in host.

References Markov::API::CUDA::CUDAModelMatrix::cudaMemPerGrid, Markov::API::CUDA::CUDAModelMatrix::cudaPerKernelAllocationSize, and Markov::API::CUDA::CUDAModelMatrix::outputBuffer.

◆ Generate() [1/5]

def Python.Markopy.MarkovModel.Generate ( int  count,
str  wordlist,
int  minlen,
int  maxlen,
int  threads 
)
inherited

Definition at line 34 of file mm.py.

34  def Generate(count : int, wordlist : str, minlen : int, maxlen: int, threads : int):
35  pass
36 
37 

Referenced by Python.Markopy.MarkovPasswordsCLI._generate().

Here is the caller graph for this function:

◆ generate() [1/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate() [2/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate() [3/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate() [4/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate() [5/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate() [6/6]

def Python.Markopy.BaseCLI.generate (   self,
str  wordlist,
bool  bulk = False 
)
inherited

Generate strings from the model.

Parameters
modelmodel instance
wordlistwordlist filename
bulkmarks bulk operation with directories

Definition at line 145 of file base.py.

145  def generate(self, wordlist : str, bulk : bool=False):
146  """!
147  @brief Generate strings from the model
148  @param model: model instance
149  @param wordlist wordlist filename
150  @param bulk marks bulk operation with directories
151  """
152  if not (wordlist or self.args.count):
153  logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.")
154  return False
155 
156  if(bulk and os.path.isfile(wordlist)):
157  logging.pprint(f"{wordlist} exists and will be overwritten.", 1)
158  self._generate(wordlist)
159 

References Python.CudaMarkopy.CudaModelMatrixCLI._generate(), Python.Markopy.BaseCLI._generate(), Python.Markopy.ModelMatrixCLI._generate(), Python.Markopy.MarkovPasswordsCLI._generate(), Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Generate() [2/5]

void Markov::API::MarkovPasswords::Generate ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20 
)
inherited

Call Markov::Model::RandomWalk n times, and collect output.

Generate from model and write results to a file. a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.

Deprecated:
See Markov::API::MatrixModel::FastRandomWalk for more information.
Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn

Definition at line 118 of file markovPasswords.cpp.

118  {
119  char* res;
120  char print[100];
121  std::ofstream wordlist;
122  wordlist.open(wordlistFileName);
123  std::mutex mlock;
124  int iterationsPerThread = n/threads;
125  int iterationsCarryOver = n%threads;
126  std::vector<std::thread*> threadsV;
127  for(int i=0;i<threads;i++){
128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
129  }
130 
131  for(int i=0;i<threads;i++){
132  threadsV[i]->join();
133  delete threadsV[i];
134  }
135 
136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
137 
138 }
void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
A single thread invoked by the Generate function.

References Markov::API::MarkovPasswords::GenerateThread().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Generate() [3/5]

void Markov::API::MarkovPasswords::Generate ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20 
)
inherited

Call Markov::Model::RandomWalk n times, and collect output.

Generate from model and write results to a file. a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.

Deprecated:
See Markov::API::MatrixModel::FastRandomWalk for more information.
Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn

Definition at line 118 of file markovPasswords.cpp.

118  {
119  char* res;
120  char print[100];
121  std::ofstream wordlist;
122  wordlist.open(wordlistFileName);
123  std::mutex mlock;
124  int iterationsPerThread = n/threads;
125  int iterationsCarryOver = n%threads;
126  std::vector<std::thread*> threadsV;
127  for(int i=0;i<threads;i++){
128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
129  }
130 
131  for(int i=0;i<threads;i++){
132  threadsV[i]->join();
133  delete threadsV[i];
134  }
135 
136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
137 
138 }

References Markov::API::MarkovPasswords::GenerateThread().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Generate() [4/5]

void Markov::API::MarkovPasswords::Generate ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20 
)
inherited

Call Markov::Model::RandomWalk n times, and collect output.

Generate from model and write results to a file. a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.

Deprecated:
See Markov::API::MatrixModel::FastRandomWalk for more information.
Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn

Definition at line 118 of file markovPasswords.cpp.

118  {
119  char* res;
120  char print[100];
121  std::ofstream wordlist;
122  wordlist.open(wordlistFileName);
123  std::mutex mlock;
124  int iterationsPerThread = n/threads;
125  int iterationsCarryOver = n%threads;
126  std::vector<std::thread*> threadsV;
127  for(int i=0;i<threads;i++){
128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
129  }
130 
131  for(int i=0;i<threads;i++){
132  threadsV[i]->join();
133  delete threadsV[i];
134  }
135 
136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
137 
138 }

References Markov::API::MarkovPasswords::GenerateThread().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Generate() [5/5]

void Markov::API::MarkovPasswords::Generate ( unsigned long int  n,
const char *  wordlistFileName,
int  minLen = 6,
int  maxLen = 12,
int  threads = 20 
)
inherited

Call Markov::Model::RandomWalk n times, and collect output.

Generate from model and write results to a file. a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.

Deprecated:
See Markov::API::MatrixModel::FastRandomWalk for more information.
Parameters
n- Number of passwords to generate.
wordlistFileName- Filename to write to
minLen- Minimum password length to generate
maxLen- Maximum password length to generate
threads- number of OS threads to spawn

Definition at line 118 of file markovPasswords.cpp.

118  {
119  char* res;
120  char print[100];
121  std::ofstream wordlist;
122  wordlist.open(wordlistFileName);
123  std::mutex mlock;
124  int iterationsPerThread = n/threads;
125  int iterationsCarryOver = n%threads;
126  std::vector<std::thread*> threadsV;
127  for(int i=0;i<threads;i++){
128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
129  }
130 
131  for(int i=0;i<threads;i++){
132  threadsV[i]->join();
133  delete threadsV[i];
134  }
135 
136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
137 
138 }

References Markov::API::MarkovPasswords::GenerateThread().

Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateThread()

void Markov::API::MarkovPasswords::GenerateThread ( std::mutex *  outputLock,
unsigned long int  n,
std::ofstream *  wordlist,
int  minLen,
int  maxLen 
)
privateinherited

A single thread invoked by the Generate function.

DEPRECATED: See Markov::API::MatrixModel::FastRandomWalkThread for more information. This has been replaced with a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.

Parameters
outputLock- shared mutex lock to lock during output operation. Prevents race condition on write.
nnumber of lines to be generated by this thread
wordlistwordlistfile
minLen- Minimum password length to generate
maxLen- Maximum password length to generate

Definition at line 140 of file markovPasswords.cpp.

140  {
141  char* res = new char[maxLen+5];
142  if(n==0) return;
143 
144  Markov::Random::Marsaglia MarsagliaRandomEngine;
145  for (int i = 0; i < n; i++) {
146  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
147  outputLock->lock();
148  *wordlist << res << "\n";
149  outputLock->unlock();
150  }
151 }
char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
Do a random walk on this model.
Definition: model.h:307

References Markov::Model< NodeStorageType >::RandomWalk().

Referenced by Markov::API::MarkovPasswords::Generate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ help()

def Python.CudaMarkopy.CudaMarkopyCLI.help (   self)

overload help function to print submodel helps

Reimplemented from Python.Markopy.MarkopyCLI.

Definition at line 61 of file cudamarkopy.py.

61  def help(self):
62  "! @brief overload help string"
63  self.parser.print_help = self.stub
64  self.args = self.parser.parse_known_args()[0]
65  if(self.args.model_type!="_MMX"):
66  if(self.args.model_type=="MP"):
67  mp = MarkovPasswordsCLI()
68  mp.add_arguments()
69  mp.parser.print_help()
70  elif(self.args.model_type=="MMX"):
71  mp = ModelMatrixCLI()
72  mp.add_arguments()
73  mp.parser.print_help()
74  elif(self.args.model_type == "CUDA"):
75  mp = CudaModelMatrixCLI()
76  mp.add_arguments()
77  mp.parser.print_help()
78  else:
79  print(colored("Model Mode selection choices:", "green"))
80  self.print_help()
81  print(colored("Following are applicable for -mt MP mode:", "green"))
82  mp = MarkovPasswordsCLI()
83  mp.add_arguments()
84  mp.parser.print_help()
85  print(colored("Following are applicable for -mt MMX mode:", "green"))
86  mp = ModelMatrixCLI()
87  mp.add_arguments()
88  mp.parser.print_help()
89  print(colored("Following are applicable for -mt CUDA mode:", "green"))
90  mp = CudaModelMatrixCLI()
91  mp.add_arguments()
92  mp.parser.print_help()
93  exit()
94 

References Python.Markopy.BaseCLI.parser, and Python.Markopy.MarkopyCLI.stub().

Referenced by Python.Markopy.MarkopyCLI.add_arguments().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Import() [1/8]

void Markov::API::ModelMatrix::Import ( const char *  filename)
inherited

Open a file to import with filename, and call bool Model::Import with std::ifstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file with filename

model.Import("test.mdl");

Construct the matrix when done.

Definition at line 19 of file modelMatrix.cpp.

19  {
20  this->DeallocateMatrix();
22  this->ConstructMatrix();
23 }
bool DeallocateMatrix()
Deallocate matrix and make it ready for re-construction.
Definition: modelMatrix.cpp:81
bool Import(std::ifstream *)
Import a file to construct the model.
Definition: model.h:216

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Import() [2/8]

void Markov::API::ModelMatrix::Import ( const char *  filename)
inherited

Open a file to import with filename, and call bool Model::Import with std::ifstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file with filename

model.Import("test.mdl");

Construct the matrix when done.

Definition at line 19 of file modelMatrix.cpp.

19  {
20  this->DeallocateMatrix();
22  this->ConstructMatrix();
23 }

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Import() [3/8]

void Markov::API::ModelMatrix::Import ( const char *  filename)
inherited

Open a file to import with filename, and call bool Model::Import with std::ifstream.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file with filename

model.Import("test.mdl");

Construct the matrix when done.

Definition at line 19 of file modelMatrix.cpp.

19  {
20  this->DeallocateMatrix();
22  this->ConstructMatrix();
23 }

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Import() [4/8]

bool Markov::Model< char >::Import ( std::ifstream *  f)
inherited

Import a file to construct the model.

File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr

Iterate over this list, and construct nodes and edges accordingly.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file from ifstream

std::ifstream file("test.mdl");
model.Import(&file);

Definition at line 126 of file model.h.

216  {
217  std::string cell;
218 
219  char src;
220  char target;
221  long int oc;
222 
223  while (std::getline(*f, cell)) {
224  //std::cout << "cell: " << cell << std::endl;
225  src = cell[0];
226  target = cell[cell.length() - 1];
227  char* j;
228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
229  //std::cout << oc << "\n";
233  if (this->nodes.find(src) == this->nodes.end()) {
234  srcN = new Markov::Node<NodeStorageType>(src);
235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
236  //std::cout << "Creating new node at start.\n";
237  }
238  else {
239  srcN = this->nodes.find(src)->second;
240  }
241 
242  if (this->nodes.find(target) == this->nodes.end()) {
243  targetN = new Markov::Node<NodeStorageType>(target);
244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
245  //std::cout << "Creating new node at end.\n";
246  }
247  else {
248  targetN = this->nodes.find(target)->second;
249  }
250  e = srcN->Link(targetN);
251  e->AdjustEdge(oc);
252  this->edges.push_back(e);
253 
254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
255 
256 
257  }
258 
259  this->OptimizeEdgeOrder();
260 
261  return true;
262 }
Edge< storageType > * Link(Node< storageType > *)
Link this node with another, with this node as its source.
Definition: node.h:220

◆ Import() [5/8]

bool Markov::Model< char >::Import ( std::ifstream *  f)
inherited

Import a file to construct the model.

File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr

Iterate over this list, and construct nodes and edges accordingly.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file from ifstream

std::ifstream file("test.mdl");
model.Import(&file);

Definition at line 126 of file model.h.

216  {
217  std::string cell;
218 
219  char src;
220  char target;
221  long int oc;
222 
223  while (std::getline(*f, cell)) {
224  //std::cout << "cell: " << cell << std::endl;
225  src = cell[0];
226  target = cell[cell.length() - 1];
227  char* j;
228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
229  //std::cout << oc << "\n";
233  if (this->nodes.find(src) == this->nodes.end()) {
234  srcN = new Markov::Node<NodeStorageType>(src);
235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
236  //std::cout << "Creating new node at start.\n";
237  }
238  else {
239  srcN = this->nodes.find(src)->second;
240  }
241 
242  if (this->nodes.find(target) == this->nodes.end()) {
243  targetN = new Markov::Node<NodeStorageType>(target);
244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
245  //std::cout << "Creating new node at end.\n";
246  }
247  else {
248  targetN = this->nodes.find(target)->second;
249  }
250  e = srcN->Link(targetN);
251  e->AdjustEdge(oc);
252  this->edges.push_back(e);
253 
254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
255 
256 
257  }
258 
259  this->OptimizeEdgeOrder();
260 
261  return true;
262 }

◆ Import() [6/8]

bool Markov::Model< char >::Import ( std::ifstream *  f)
inherited

Import a file to construct the model.

File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr

Iterate over this list, and construct nodes and edges accordingly.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file from ifstream

std::ifstream file("test.mdl");
model.Import(&file);

Definition at line 126 of file model.h.

216  {
217  std::string cell;
218 
219  char src;
220  char target;
221  long int oc;
222 
223  while (std::getline(*f, cell)) {
224  //std::cout << "cell: " << cell << std::endl;
225  src = cell[0];
226  target = cell[cell.length() - 1];
227  char* j;
228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
229  //std::cout << oc << "\n";
233  if (this->nodes.find(src) == this->nodes.end()) {
234  srcN = new Markov::Node<NodeStorageType>(src);
235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
236  //std::cout << "Creating new node at start.\n";
237  }
238  else {
239  srcN = this->nodes.find(src)->second;
240  }
241 
242  if (this->nodes.find(target) == this->nodes.end()) {
243  targetN = new Markov::Node<NodeStorageType>(target);
244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
245  //std::cout << "Creating new node at end.\n";
246  }
247  else {
248  targetN = this->nodes.find(target)->second;
249  }
250  e = srcN->Link(targetN);
251  e->AdjustEdge(oc);
252  this->edges.push_back(e);
253 
254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
255 
256 
257  }
258 
259  this->OptimizeEdgeOrder();
260 
261  return true;
262 }

◆ Import() [7/8]

bool Markov::Model< char >::Import ( std::ifstream *  f)
inherited

Import a file to construct the model.

File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr

Iterate over this list, and construct nodes and edges accordingly.

Returns
True if successful, False for incomplete models or corrupt file formats

Example Use: Import a file from ifstream

std::ifstream file("test.mdl");
model.Import(&file);

Definition at line 126 of file model.h.

216  {
217  std::string cell;
218 
219  char src;
220  char target;
221  long int oc;
222 
223  while (std::getline(*f, cell)) {
224  //std::cout << "cell: " << cell << std::endl;
225  src = cell[0];
226  target = cell[cell.length() - 1];
227  char* j;
228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
229  //std::cout << oc << "\n";
233  if (this->nodes.find(src) == this->nodes.end()) {
234  srcN = new Markov::Node<NodeStorageType>(src);
235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
236  //std::cout << "Creating new node at start.\n";
237  }
238  else {
239  srcN = this->nodes.find(src)->second;
240  }
241 
242  if (this->nodes.find(target) == this->nodes.end()) {
243  targetN = new Markov::Node<NodeStorageType>(target);
244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
245  //std::cout << "Creating new node at end.\n";
246  }
247  else {
248  targetN = this->nodes.find(target)->second;
249  }
250  e = srcN->Link(targetN);
251  e->AdjustEdge(oc);
252  this->edges.push_back(e);
253 
254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
255 
256 
257  }
258 
259  this->OptimizeEdgeOrder();
260 
261  return true;
262 }

◆ Import() [8/8]

def Python.Markopy.MarkovModel.Import ( str  filename)
inherited

Definition at line 22 of file mm.py.

22  def Import(filename : str):
23  pass
24 

◆ import_model() [1/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_model() [2/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_model() [3/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_model() [4/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_model() [5/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_model() [6/6]

def Python.Markopy.BaseCLI.import_model (   self,
str  filename 
)
inherited

Import a model file.

Parameters
filenamefilename to import

Definition at line 77 of file base.py.

77  def import_model(self, filename : str):
78  """!
79  @brief Import a model file
80  @param filename filename to import
81  """
82  logging.pprint("Importing model file.", 1)
83 
84  if not self.check_import_path(filename):
85  logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory")
86  return False
87 
88  self.model.Import(filename)
89  logging.pprint("Model imported successfully.", 2)
90  return True
91 
92 
93 

References Python.Markopy.BaseCLI.check_import_path(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_post_arguments() [1/3]

def Python.Markopy.MarkopyCLI.init_post_arguments (   sel)
inherited

Reimplemented from Python.Markopy.BaseCLI.

Definition at line 175 of file markopy.py.

175  def init_post_arguments(sel):
176  pass
177 

References Python.Markopy.MarkopyCLI.init_post_arguments().

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_post_arguments() [2/3]

def Python.CudaMarkopy.CudaModelMatrixCLI.init_post_arguments (   self)
inherited

Reimplemented from Python.Markopy.ModelMatrixCLI.

Definition at line 71 of file cudammx.py.

71  def init_post_arguments(self):
72  super().init_post_arguments()
73  self.bInfinite = self.args.infinite
74 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ init_post_arguments() [3/3]

def Python.Markopy.MarkopyCLI.init_post_arguments (   self)
inherited

Reimplemented from Python.Markopy.BaseCLI.

Definition at line 145 of file markopy.py.

145  def init_post_arguments(self):
146  pass
147 

Referenced by Python.Markopy.MarkopyCLI.init_post_arguments(), Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ LaunchAsyncKernel()

__host__ void Markov::API::CUDA::CUDAModelMatrix::LaunchAsyncKernel ( int  kernelID,
int  minLen,
int  maxLen 
)
protectedinherited

Definition at line 171 of file cudaModelMatrix.cu.

171  {
172 
173  //if(kernelID == 0);// cudaStreamSynchronize(this->cudastreams[2]);
174  //else cudaStreamSynchronize(this->cudastreams[kernelID-1]);
177  //std::cerr << "Started kernel" << kernelID << "\n";
178  }
char * device_edgeMatrix
VRAM Address pointer of edge matrix (from modelMatrix.h)
char * device_matrixIndex
VRAM Address pointer of matrixIndex (from modelMatrix.h)
long int * device_valueMatrix
VRAM Address pointer of value matrix (from modelMatrix.h)
long int * device_totalEdgeWeights
VRAM Address pointer of total edge weights (from modelMatrix.h)
__global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
CUDA kernel for the FastRandomWalk operation.

◆ ListCudaDevices()

__host__ void Markov::API::CUDA::CUDADeviceController::ListCudaDevices ( )
staticinherited

List CUDA devices in the system.

This function will print details of every CUDA capable device in the system.

Example output:

Device Number: 0
Device name: GeForce RTX 2070
Memory Clock Rate (KHz): 7001000
Memory Bus Width (bits): 256
Peak Memory Bandwidth (GB/s): 448.064
Max Linear Threads: 1024

Definition at line 16 of file cudaDeviceController.cu.

16  { //list cuda Capable devices on host.
17  int nDevices;
18  cudaGetDeviceCount(&nDevices);
19  for (int i = 0; i < nDevices; i++) {
20  cudaDeviceProp prop;
21  cudaGetDeviceProperties(&prop, i);
22  std::cerr << "Device Number: " << i << "\n";
23  std::cerr << "Device name: " << prop.name << "\n";
24  std::cerr << "Memory Clock Rate (KHz): " << prop.memoryClockRate << "\n";
25  std::cerr << "Memory Bus Width (bits): " << prop.memoryBusWidth << "\n";
26  std::cerr << "Peak Memory Bandwidth (GB/s): " << 2.0 * prop.memoryClockRate * (prop.memoryBusWidth / 8) / 1.0e6 << "\n";
27  std::cerr << "Max Linear Threads: " << prop.maxThreadsDim[0] << "\n";
28 
29  }
30  }

◆ MigrateMatrix()

__host__ void Markov::API::CUDA::CUDAModelMatrix::MigrateMatrix ( )
inherited

Migrate the class members to the VRAM.

Cannot be used without calling Markov::API::ModelMatrix::ConstructMatrix at least once. This function will manage the memory allocation and data transfer from CPU RAM to GPU VRAM.

Newly allocated VRAM pointers are set in the class member variables.

Definition at line 20 of file cudaModelMatrix.cu.

20  {
21  cudaError_t cudastatus;
22 
23  cudastatus = cudaMalloc((char**)&(this->device_matrixIndex),
24  this->matrixSize*sizeof(char));
25  CudaCheckNotifyErr(cudastatus, "Cuda failed to initialize device_matrixIndex.");
26 
27  cudastatus = cudaMalloc((long int **)&(this->device_totalEdgeWeights), this->matrixSize*sizeof(long int));
28  CudaCheckNotifyErr(cudastatus, "Cuda failed to initialize device_totalEdgeWeights.");
29 
30  cudastatus = cudaMemcpy(this->device_matrixIndex, this->matrixIndex,
31  this->matrixSize*sizeof(char), cudaMemcpyHostToDevice);
32  CudaCheckNotifyErr(cudastatus, "Cuda failed to copy to device memory. (Index)");
33 
34  cudastatus = cudaMemcpy(this->device_totalEdgeWeights, this->totalEdgeWeights,
35  this->matrixSize*sizeof(long int), cudaMemcpyHostToDevice);
36  CudaCheckNotifyErr(cudastatus, "Cuda failed to copy to device memory. (Total Edge Values)");
37 
38  cudastatus = CudaMigrate2DFlat<char>(
39  &(this->device_edgeMatrix), this->edgeMatrix, this->matrixSize, this->matrixSize);
40  CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize edge matrix.");
41 
42  cudastatus = CudaMigrate2DFlat<long int>(
43  &(this->device_valueMatrix), this->valueMatrix, this->matrixSize, this->matrixSize);
44  CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize value matrix row.");
45 
46  }

◆ Nodes() [1/4]

std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 181 of file model.h.

181 { return &nodes;}

◆ Nodes() [2/4]

std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 181 of file model.h.

181 { return &nodes;}

◆ Nodes() [3/4]

std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 181 of file model.h.

181 { return &nodes;}

◆ Nodes() [4/4]

std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 181 of file model.h.

181 { return &nodes;}

◆ OpenDatasetFile() [1/4]

std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile ( const char *  filename)
inherited

Open dataset file and return the ifstream pointer.

Parameters
filename- Filename to open
Returns
ifstream* to the the dataset file

Definition at line 51 of file markovPasswords.cpp.

51  {
52 
53  std::ifstream* datasetFile;
54 
55  std::ifstream newFile(filename);
56 
57  datasetFile = &newFile;
58 
59  this->Import(datasetFile);
60  return datasetFile;
61 }

References Markov::Model< NodeStorageType >::Import().

Here is the call graph for this function:

◆ OpenDatasetFile() [2/4]

std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile ( const char *  filename)
inherited

Open dataset file and return the ifstream pointer.

Parameters
filename- Filename to open
Returns
ifstream* to the the dataset file

Definition at line 51 of file markovPasswords.cpp.

51  {
52 
53  std::ifstream* datasetFile;
54 
55  std::ifstream newFile(filename);
56 
57  datasetFile = &newFile;
58 
59  this->Import(datasetFile);
60  return datasetFile;
61 }

References Markov::Model< NodeStorageType >::Import().

Here is the call graph for this function:

◆ OpenDatasetFile() [3/4]

std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile ( const char *  filename)
inherited

Open dataset file and return the ifstream pointer.

Parameters
filename- Filename to open
Returns
ifstream* to the the dataset file

Definition at line 51 of file markovPasswords.cpp.

51  {
52 
53  std::ifstream* datasetFile;
54 
55  std::ifstream newFile(filename);
56 
57  datasetFile = &newFile;
58 
59  this->Import(datasetFile);
60  return datasetFile;
61 }

References Markov::Model< NodeStorageType >::Import().

Here is the call graph for this function:

◆ OpenDatasetFile() [4/4]

std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile ( const char *  filename)
inherited

Open dataset file and return the ifstream pointer.

Parameters
filename- Filename to open
Returns
ifstream* to the the dataset file

Definition at line 51 of file markovPasswords.cpp.

51  {
52 
53  std::ifstream* datasetFile;
54 
55  std::ifstream newFile(filename);
56 
57  datasetFile = &newFile;
58 
59  this->Import(datasetFile);
60  return datasetFile;
61 }

References Markov::Model< NodeStorageType >::Import().

Here is the call graph for this function:

◆ OptimizeEdgeOrder() [1/4]

void Markov::Model< char >::OptimizeEdgeOrder
inherited

Sort edges of all nodes in the model ordered by edge weights.

Definition at line 186 of file model.h.

265  {
266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
269  return lhs->EdgeWeight() > rhs->EdgeWeight();
270  });
271  //for(int i=0;i<x.second->edgesV.size();i++)
272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
273  //std::cout << "\n";
274  }
275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
277 }

◆ OptimizeEdgeOrder() [2/4]

void Markov::Model< char >::OptimizeEdgeOrder
inherited

Sort edges of all nodes in the model ordered by edge weights.

Definition at line 186 of file model.h.

265  {
266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
269  return lhs->EdgeWeight() > rhs->EdgeWeight();
270  });
271  //for(int i=0;i<x.second->edgesV.size();i++)
272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
273  //std::cout << "\n";
274  }
275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
277 }

◆ OptimizeEdgeOrder() [3/4]

void Markov::Model< char >::OptimizeEdgeOrder
inherited

Sort edges of all nodes in the model ordered by edge weights.

Definition at line 186 of file model.h.

265  {
266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
269  return lhs->EdgeWeight() > rhs->EdgeWeight();
270  });
271  //for(int i=0;i<x.second->edgesV.size();i++)
272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
273  //std::cout << "\n";
274  }
275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
277 }

◆ OptimizeEdgeOrder() [4/4]

void Markov::Model< char >::OptimizeEdgeOrder
inherited

Sort edges of all nodes in the model ordered by edge weights.

Definition at line 186 of file model.h.

265  {
266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
269  return lhs->EdgeWeight() > rhs->EdgeWeight();
270  });
271  //for(int i=0;i<x.second->edgesV.size();i++)
272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
273  //std::cout << "\n";
274  }
275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
277 }

◆ parse()

def Python.CudaMarkopy.CudaMarkopyCLI.parse (   self)

Reimplemented from Python.Markopy.MarkopyCLI.

Definition at line 95 of file cudamarkopy.py.

95  def parse(self):
96  markopy.MarkopyCLI.parse(self)
97 

◆ parse_arguments() [1/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_arguments() [2/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_arguments() [3/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_arguments() [4/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_arguments() [5/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_arguments() [6/6]

def Python.Markopy.BaseCLI.parse_arguments (   self)
inherited

Definition at line 73 of file base.py.

73  def parse_arguments(self):
74  "! @brief trigger parser"
75  self.args = self.parser.parse_known_args()[0]
76 

Referenced by Python.Markopy.BaseCLI.parse(), and Python.Markopy.MarkopyCLI.parse().

Here is the caller graph for this function:

◆ parse_fail()

def Python.CudaMarkopy.CudaMarkopyCLI.parse_fail (   self)

Reimplemented from Python.Markopy.MarkopyCLI.

Definition at line 98 of file cudamarkopy.py.

98  def parse_fail(self):
99  "! @brief Not a valid model type"
100  if(self.args.model_type == "CUDA"):
101  self.cli = CudaModelMatrixCLI()
102  else:
103  markopy.MarkopyCLI.parse_fail(self)
104 
105 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, and Python.Markopy.MarkopyCLI.args.

◆ prepKernelMemoryChannel()

__host__ void Markov::API::CUDA::CUDAModelMatrix::prepKernelMemoryChannel ( int  numberOfStreams)
protectedinherited

Definition at line 145 of file cudaModelMatrix.cu.

145  {
146 
147  this->cudastreams = new cudaStream_t[numberOfStreams];
148  for(int i=0;i<numberOfStreams;i++)
149  cudaStreamCreate(&this->cudastreams[i]);
150 
151  this-> outputBuffer = new char*[numberOfStreams];
152  for(int i=0;i<numberOfStreams;i++)
153  this->outputBuffer[i]= new char[cudaPerKernelAllocationSize];
154 
155  cudaError_t cudastatus;
156  this-> device_outputBuffer = new char*[numberOfStreams];
157  for(int i=0;i<numberOfStreams;i++){
158  cudastatus = cudaMalloc((char**)&(device_outputBuffer[i]), cudaPerKernelAllocationSize);
159  CudaCheckNotifyErr(cudastatus, "Failed to establish memory channel. Possibly out of VRAM?");
160  }
161 
162  this-> device_seeds = new unsigned long*[numberOfStreams];
163  for(int i=0;i<numberOfStreams;i++){
166  delete[] MEarr;
167  }
168 
169  }
Extension of Markov::Random::Marsaglia which is capable o working on device space.
Definition: cudarandom.h:20
static unsigned long * MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize)
Migrate a Marsaglia[] to VRAM as seedChunk.
Definition: cudarandom.h:28

References Markov::API::CUDA::CUDAModelMatrix::cudaGridSize, Markov::API::CUDA::CUDAModelMatrix::cudaPerKernelAllocationSize, Markov::API::CUDA::CUDAModelMatrix::device_outputBuffer, Markov::API::CUDA::CUDAModelMatrix::device_seeds, Markov::API::CUDA::Random::Marsaglia::MigrateToVRAM(), and Markov::API::CUDA::CUDAModelMatrix::outputBuffer.

Here is the call graph for this function:

◆ process()

def Python.Markopy.MarkopyCLI.process (   self)
inherited

Process parameters for operation.

Reimplemented from Python.Markopy.BaseCLI.

Definition at line 154 of file markopy.py.

154  def process(self):
155  "! @brief pass the process request to selected submodel"
156  return self.cli.process()
157 

References Python.CudaMarkopy.CudaMarkopyCLI.cli, and Python.Markopy.MarkopyCLI.cli.

◆ RandomWalk() [1/4]

char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine,
int  minSetting,
int  maxSetting,
NodeStorageType buffer 
)
inherited

Do a random walk on this model.

Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext

If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

Model.import("model.mdl");
char* res = new char[11];
Markov::Random::Marsaglia MarsagliaRandomEngine;
for (int i = 0; i < 10; i++) {
this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
std::cout << res << "\n";
}
Model()
Initialize a model with only start and end nodes.
Definition: model.h:210
Parameters
randomEngineRandom Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
minSettingMinimum number of characters to generate
maxSettingMaximum number of character to generate
bufferbuffer to write the result to
Returns
Null terminated string that was generated.

Definition at line 86 of file model.h.

307  {
309  int len = 0;
311  while (true) {
312  temp_node = n->RandomNext(randomEngine);
313  if (len >= maxSetting) {
314  break;
315  }
316  else if ((temp_node == NULL) && (len < minSetting)) {
317  continue;
318  }
319 
320  else if (temp_node == NULL){
321  break;
322  }
323 
324  n = temp_node;
325 
326  buffer[len++] = n->NodeValue();
327  }
328 
329  //null terminate the string
330  buffer[len] = 0x00;
331 
332  //do something with the generated string
333  return buffer; //for now
334 }
Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
Definition: node.h:234

◆ RandomWalk() [2/4]

char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine,
int  minSetting,
int  maxSetting,
NodeStorageType buffer 
)
inherited

Do a random walk on this model.

Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext

If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

Model.import("model.mdl");
char* res = new char[11];
Markov::Random::Marsaglia MarsagliaRandomEngine;
for (int i = 0; i < 10; i++) {
this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
std::cout << res << "\n";
}
Parameters
randomEngineRandom Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
minSettingMinimum number of characters to generate
maxSettingMaximum number of character to generate
bufferbuffer to write the result to
Returns
Null terminated string that was generated.

Definition at line 86 of file model.h.

307  {
309  int len = 0;
311  while (true) {
312  temp_node = n->RandomNext(randomEngine);
313  if (len >= maxSetting) {
314  break;
315  }
316  else if ((temp_node == NULL) && (len < minSetting)) {
317  continue;
318  }
319 
320  else if (temp_node == NULL){
321  break;
322  }
323 
324  n = temp_node;
325 
326  buffer[len++] = n->NodeValue();
327  }
328 
329  //null terminate the string
330  buffer[len] = 0x00;
331 
332  //do something with the generated string
333  return buffer; //for now
334 }

◆ RandomWalk() [3/4]

char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine,
int  minSetting,
int  maxSetting,
NodeStorageType buffer 
)
inherited

Do a random walk on this model.

Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext

If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

Model.import("model.mdl");
char* res = new char[11];
Markov::Random::Marsaglia MarsagliaRandomEngine;
for (int i = 0; i < 10; i++) {
this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
std::cout << res << "\n";
}
Parameters
randomEngineRandom Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
minSettingMinimum number of characters to generate
maxSettingMaximum number of character to generate
bufferbuffer to write the result to
Returns
Null terminated string that was generated.

Definition at line 86 of file model.h.

307  {
309  int len = 0;
311  while (true) {
312  temp_node = n->RandomNext(randomEngine);
313  if (len >= maxSetting) {
314  break;
315  }
316  else if ((temp_node == NULL) && (len < minSetting)) {
317  continue;
318  }
319 
320  else if (temp_node == NULL){
321  break;
322  }
323 
324  n = temp_node;
325 
326  buffer[len++] = n->NodeValue();
327  }
328 
329  //null terminate the string
330  buffer[len] = 0x00;
331 
332  //do something with the generated string
333  return buffer; //for now
334 }

◆ RandomWalk() [4/4]

char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine,
int  minSetting,
int  maxSetting,
NodeStorageType buffer 
)
inherited

Do a random walk on this model.

Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext

If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

Model.import("model.mdl");
char* res = new char[11];
Markov::Random::Marsaglia MarsagliaRandomEngine;
for (int i = 0; i < 10; i++) {
this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
std::cout << res << "\n";
}
Parameters
randomEngineRandom Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
minSettingMinimum number of characters to generate
maxSettingMaximum number of character to generate
bufferbuffer to write the result to
Returns
Null terminated string that was generated.

Definition at line 86 of file model.h.

307  {
309  int len = 0;
311  while (true) {
312  temp_node = n->RandomNext(randomEngine);
313  if (len >= maxSetting) {
314  break;
315  }
316  else if ((temp_node == NULL) && (len < minSetting)) {
317  continue;
318  }
319 
320  else if (temp_node == NULL){
321  break;
322  }
323 
324  n = temp_node;
325 
326  buffer[len++] = n->NodeValue();
327  }
328 
329  //null terminate the string
330  buffer[len] = 0x00;
331 
332  //do something with the generated string
333  return buffer; //for now
334 }

◆ Save() [1/4]

std::ofstream * Markov::API::MarkovPasswords::Save ( const char *  filename)
inherited

Export model to file.

Parameters
filename- Export filename.
Returns
std::ofstream* of the exported file.

Definition at line 106 of file markovPasswords.cpp.

106  {
107  std::ofstream* exportFile;
108 
109  std::ofstream newFile(filename);
110 
111  exportFile = &newFile;
112 
113  this->Export(exportFile);
114  return exportFile;
115 }

References Markov::Model< NodeStorageType >::Export().

Here is the call graph for this function:

◆ Save() [2/4]

std::ofstream * Markov::API::MarkovPasswords::Save ( const char *  filename)
inherited

Export model to file.

Parameters
filename- Export filename.
Returns
std::ofstream* of the exported file.

Definition at line 106 of file markovPasswords.cpp.

106  {
107  std::ofstream* exportFile;
108 
109  std::ofstream newFile(filename);
110 
111  exportFile = &newFile;
112 
113  this->Export(exportFile);
114  return exportFile;
115 }

References Markov::Model< NodeStorageType >::Export().

Here is the call graph for this function:

◆ Save() [3/4]

std::ofstream * Markov::API::MarkovPasswords::Save ( const char *  filename)
inherited

Export model to file.

Parameters
filename- Export filename.
Returns
std::ofstream* of the exported file.

Definition at line 106 of file markovPasswords.cpp.

106  {
107  std::ofstream* exportFile;
108 
109  std::ofstream newFile(filename);
110 
111  exportFile = &newFile;
112 
113  this->Export(exportFile);
114  return exportFile;
115 }

References Markov::Model< NodeStorageType >::Export().

Here is the call graph for this function:

◆ Save() [4/4]

std::ofstream * Markov::API::MarkovPasswords::Save ( const char *  filename)
inherited

Export model to file.

Parameters
filename- Export filename.
Returns
std::ofstream* of the exported file.

Definition at line 106 of file markovPasswords.cpp.

106  {
107  std::ofstream* exportFile;
108 
109  std::ofstream newFile(filename);
110 
111  exportFile = &newFile;
112 
113  this->Export(exportFile);
114  return exportFile;
115 }

References Markov::Model< NodeStorageType >::Export().

Here is the call graph for this function:

◆ StarterNode() [1/4]

Node<char >* Markov::Model< char >::StarterNode ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 171 of file model.h.

171 { return starterNode;}

◆ StarterNode() [2/4]

Node<char >* Markov::Model< char >::StarterNode ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 171 of file model.h.

171 { return starterNode;}

◆ StarterNode() [3/4]

Node<char >* Markov::Model< char >::StarterNode ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 171 of file model.h.

171 { return starterNode;}

◆ StarterNode() [4/4]

Node<char >* Markov::Model< char >::StarterNode ( )
inlineinherited

Return starter Node.

Returns
starter node with 00 NodeValue

Definition at line 171 of file model.h.

171 { return starterNode;}

◆ stub()

def Python.Markopy.MarkopyCLI.stub (   self)
inherited

Definition at line 158 of file markopy.py.

158  def stub(self):
159  "! @brief stub function to hack help requests"
160  return
161 
162 

Referenced by Python.CudaMarkopy.CudaMarkopyCLI.help(), and Python.Markopy.MarkopyCLI.help().

Here is the caller graph for this function:

◆ Train() [1/4]

void Markov::API::ModelMatrix::Train ( const char *  datasetFileName,
char  delimiter,
int  threads 
)
inherited

Train the model with the dataset file.

Parameters
datasetFileName- Ifstream* to the dataset. If null, use class member
delimiter- a character, same as the delimiter in dataset content
threads- number of OS threads to spawn
mp.Import("models/2gram.mdl");
mp.Train("password.corpus");
Markov::Model with char represented nodes.

Construct the matrix when done.

Definition at line 25 of file modelMatrix.cpp.

25  {
26  this->DeallocateMatrix();
27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
28  this->ConstructMatrix();
29 }
void Train(const char *datasetFileName, char delimiter, int threads)
Train the model with the dataset file.

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Train() [2/4]

void Markov::API::ModelMatrix::Train ( const char *  datasetFileName,
char  delimiter,
int  threads 
)
inherited

Train the model with the dataset file.

Parameters
datasetFileName- Ifstream* to the dataset. If null, use class member
delimiter- a character, same as the delimiter in dataset content
threads- number of OS threads to spawn
mp.Import("models/2gram.mdl");
mp.Train("password.corpus");

Construct the matrix when done.

Definition at line 25 of file modelMatrix.cpp.

25  {
26  this->DeallocateMatrix();
27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
28  this->ConstructMatrix();
29 }

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Train() [3/4]

void Markov::API::ModelMatrix::Train ( const char *  datasetFileName,
char  delimiter,
int  threads 
)
inherited

Train the model with the dataset file.

Parameters
datasetFileName- Ifstream* to the dataset. If null, use class member
delimiter- a character, same as the delimiter in dataset content
threads- number of OS threads to spawn
mp.Import("models/2gram.mdl");
mp.Train("password.corpus");

Construct the matrix when done.

Definition at line 25 of file modelMatrix.cpp.

25  {
26  this->DeallocateMatrix();
27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
28  this->ConstructMatrix();
29 }

References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [1/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [2/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [3/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [4/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [5/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ train() [6/6]

def Python.Markopy.BaseCLI.train (   self,
str  dataset,
str  seperator,
str  output,
bool  output_forced = False,
bool  bulk = False 
)
inherited

Train a model via CLI parameters.

Parameters
modelModel instance
datasetfilename for the dataset
seperatorseperator used with the dataset
outputoutput filename
output_forcedforce overwrite
bulkmarks bulk operation with directories

Definition at line 94 of file base.py.

94  def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False):
95  """!
96  @brief Train a model via CLI parameters
97  @param model Model instance
98  @param dataset filename for the dataset
99  @param seperator seperator used with the dataset
100  @param output output filename
101  @param output_forced force overwrite
102  @param bulk marks bulk operation with directories
103  """
104  logging.pprint("Training.")
105 
106  if not (dataset and seperator and (output or not output_forced)):
107  logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.")
108  return False
109 
110  if not bulk and not self.check_corpus_path(dataset):
111  logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory")
112  return False
113 
114  if not self.check_export_path(output):
115  logging.pprint(f"Cannot create output at {output}")
116  return False
117 
118  if(seperator == '\\t'):
119  logging.pprint("Escaping seperator.", 3)
120  seperator = '\t'
121 
122  if(len(seperator)!=1):
123  logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.')
124  exit(4)
125 
126  logging.pprint(f'Starting training.', 3)
127  self.model.Train(dataset,seperator, int(self.args.threads))
128  logging.pprint(f'Training completed.', 2)
129 
130  if(output):
131  logging.pprint(f'Exporting model to {output}', 2)
132  self.export(output)
133  else:
134  logging.pprint(f'Model will not be exported.', 1)
135 
136  return True
137 

References Python.CudaMarkopy.CudaMarkopyCLI.args, Python.Markopy.BaseCLI.args, Python.Markopy.MarkopyCLI.args, Python.Markopy.BaseCLI.check_corpus_path(), Python.Markopy.BaseCLI.check_export_path(), Python.Markopy.BaseCLI.export(), Python.CudaMarkopy.CudaModelMatrixCLI.model, Python.Markopy.BaseCLI.model, Python.Markopy.ModelMatrixCLI.model, Python.Markopy.MarkovPasswordsCLI.model, and Markov::GUI::MarkovPasswordsGUI.model().

Referenced by Python.Markopy.BaseCLI.process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Train() [4/4]

def Python.Markopy.MarkovModel.Train ( str  dataset,
str  seperator,
int  threads 
)
inherited

Definition at line 30 of file mm.py.

30  def Train(dataset: str, seperator : str, threads : int):
31  pass
32 

◆ TrainThread()

void Markov::API::MarkovPasswords::TrainThread ( Markov::API::Concurrency::ThreadSharedListHandler listhandler,
char  delimiter 
)
privateinherited

A single thread invoked by the Train function.

Parameters
listhandler- Listhandler class to read corpus from
delimiter- a character, same as the delimiter in dataset content

Definition at line 85 of file markovPasswords.cpp.

85  {
86  char format_str[] ="%ld,%s";
87  format_str[3]=delimiter;
88  std::string line;
89  while (listhandler->next(&line) && keepRunning) {
90  long int oc;
91  if (line.size() > 100) {
92  line = line.substr(0, 100);
93  }
94  char* linebuf = new char[line.length()+5];
95 #ifdef _WIN32
96  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
97 #else
98  sscanf(line.c_str(), format_str, &oc, linebuf);
99 #endif
100  this->AdjustEdge((const char*)linebuf, oc);
101  delete linebuf;
102  }
103 }
bool next(std::string *line)
Read the next line from the file.
void AdjustEdge(const char *payload, long int occurrence)
Adjust the model with a single string.
Definition: model.h:337
static volatile int keepRunning

References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

Referenced by Markov::API::MarkovPasswords::Train().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ alternatingKernels

int Markov::API::CUDA::CUDAModelMatrix::alternatingKernels
privateinherited

◆ args

◆ bInfinite

Python.CudaMarkopy.CudaModelMatrixCLI.bInfinite
inherited

Definition at line 73 of file cudammx.py.

Referenced by Python.CudaMarkopy.CudaModelMatrixCLI._generate().

◆ cli

Python.CudaMarkopy.CudaMarkopyCLI.cli

Definition at line 101 of file cudamarkopy.py.

Referenced by Python.Markopy.MarkopyCLI.process().

◆ cudaBlocks

int Markov::API::CUDA::CUDAModelMatrix::cudaBlocks
privateinherited

◆ cudaGridSize

int Markov::API::CUDA::CUDAModelMatrix::cudaGridSize
privateinherited

◆ cudaMemPerGrid

int Markov::API::CUDA::CUDAModelMatrix::cudaMemPerGrid
privateinherited

◆ cudaPerKernelAllocationSize

long int Markov::API::CUDA::CUDAModelMatrix::cudaPerKernelAllocationSize
privateinherited

◆ cudastreams

cudaStream_t* Markov::API::CUDA::CUDAModelMatrix::cudastreams
privateinherited

Definition at line 139 of file cudaModelMatrix.h.

◆ cudaThreads

int Markov::API::CUDA::CUDAModelMatrix::cudaThreads
privateinherited

◆ datasetFile

std::ifstream* Markov::API::MarkovPasswords::datasetFile
privateinherited

Definition at line 123 of file markovPasswords.h.

◆ device_edgeMatrix

char* Markov::API::CUDA::CUDAModelMatrix::device_edgeMatrix
privateinherited

VRAM Address pointer of edge matrix (from modelMatrix.h)

Definition at line 88 of file cudaModelMatrix.h.

◆ device_matrixIndex

char* Markov::API::CUDA::CUDAModelMatrix::device_matrixIndex
privateinherited

VRAM Address pointer of matrixIndex (from modelMatrix.h)

Definition at line 98 of file cudaModelMatrix.h.

◆ device_outputBuffer

char** Markov::API::CUDA::CUDAModelMatrix::device_outputBuffer
privateinherited

RandomWalk results in device.

Definition at line 108 of file cudaModelMatrix.h.

Referenced by Markov::API::CUDA::CUDAModelMatrix::prepKernelMemoryChannel().

◆ device_seeds

unsigned long** Markov::API::CUDA::CUDAModelMatrix::device_seeds
privateinherited

◆ device_totalEdgeWeights

long int* Markov::API::CUDA::CUDAModelMatrix::device_totalEdgeWeights
privateinherited

VRAM Address pointer of total edge weights (from modelMatrix.h)

Definition at line 103 of file cudaModelMatrix.h.

◆ device_valueMatrix

long int* Markov::API::CUDA::CUDAModelMatrix::device_valueMatrix
privateinherited

VRAM Address pointer of value matrix (from modelMatrix.h)

Definition at line 93 of file cudaModelMatrix.h.

◆ edgeMatrix [1/3]

char** Markov::API::ModelMatrix::edgeMatrix
protectedinherited

◆ edgeMatrix [2/3]

char** Markov::API::ModelMatrix::edgeMatrix
protectedinherited

◆ edgeMatrix [3/3]

char** Markov::API::ModelMatrix::edgeMatrix
protectedinherited

◆ edges

std::vector<Edge<char >*> Markov::Model< char >::edges
privateinherited

A list of all edges in this model.

Definition at line 204 of file model.h.

◆ fileIO [1/2]

Python.Markopy.ModelMatrixCLI.fileIO
inherited

◆ fileIO [2/2]

Python.Markopy.ModelMatrixCLI.fileIO
inherited

◆ flatEdgeMatrix

char* Markov::API::CUDA::CUDAModelMatrix::flatEdgeMatrix
privateinherited

Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.

Definition at line 118 of file cudaModelMatrix.h.

Referenced by Markov::API::CUDA::CUDAModelMatrix::FlattenMatrix().

◆ flatValueMatrix

long int* Markov::API::CUDA::CUDAModelMatrix::flatValueMatrix
privateinherited

Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.

Definition at line 123 of file cudaModelMatrix.h.

Referenced by Markov::API::CUDA::CUDAModelMatrix::FlattenMatrix().

◆ iterationsPerKernelThread

int Markov::API::CUDA::CUDAModelMatrix::iterationsPerKernelThread
privateinherited

◆ matrixIndex [1/3]

char* Markov::API::ModelMatrix::matrixIndex
protectedinherited

◆ matrixIndex [2/3]

char* Markov::API::ModelMatrix::matrixIndex
protectedinherited

◆ matrixIndex [3/3]

char* Markov::API::ModelMatrix::matrixIndex
protectedinherited

◆ matrixSize [1/3]

◆ matrixSize [2/3]

◆ matrixSize [3/3]

◆ model [1/4]

◆ model [2/4]

◆ model [3/4]

◆ model [4/4]

◆ modelSavefile

std::ofstream* Markov::API::MarkovPasswords::modelSavefile
privateinherited

Dataset file input of our system

Definition at line 124 of file markovPasswords.h.

◆ nodes

std::map<char , Node<char >*> Markov::Model< char >::nodes
privateinherited

Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.

Definition at line 193 of file model.h.

◆ numberOfPartitions

int Markov::API::CUDA::CUDAModelMatrix::numberOfPartitions
privateinherited

◆ outputBuffer

char** Markov::API::CUDA::CUDAModelMatrix::outputBuffer
privateinherited

◆ outputFile

std::ofstream* Markov::API::MarkovPasswords::outputFile
privateinherited

File to save model of our system

Definition at line 125 of file markovPasswords.h.

◆ parser [1/6]

◆ parser [2/6]

◆ parser [3/6]

◆ parser [4/6]

◆ parser [5/6]

◆ parser [6/6]

◆ print_help [1/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ print_help [2/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ print_help [3/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ print_help [4/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ print_help [5/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ print_help [6/6]

Python.Markopy.BaseCLI.print_help
inherited

Definition at line 39 of file base.py.

Referenced by Python.Markopy.BaseCLI.help(), and Python.Markopy.MarkopyCLI.help().

◆ ready [1/3]

bool Markov::API::ModelMatrix::ready
protectedinherited

True when matrix is constructed. False if not.

Definition at line 200 of file modelMatrix.h.

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

◆ ready [2/3]

bool Markov::API::ModelMatrix::ready
protectedinherited

True when matrix is constructed. False if not.

Definition at line 200 of file modelMatrix.h.

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

◆ ready [3/3]

bool Markov::API::ModelMatrix::ready
protectedinherited

True when matrix is constructed. False if not.

Definition at line 200 of file modelMatrix.h.

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

◆ starterNode

Node<char >* Markov::Model< char >::starterNode
privateinherited

Starter Node of this model.

Definition at line 198 of file model.h.

◆ totalEdgeWeights [1/3]

long int* Markov::API::ModelMatrix::totalEdgeWeights
protectedinherited

◆ totalEdgeWeights [2/3]

long int* Markov::API::ModelMatrix::totalEdgeWeights
protectedinherited

◆ totalEdgeWeights [3/3]

long int* Markov::API::ModelMatrix::totalEdgeWeights
protectedinherited

◆ totalOutputPerKernel

long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerKernel
privateinherited

◆ totalOutputPerSync

long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerSync
privateinherited

◆ valueMatrix [1/3]

long int** Markov::API::ModelMatrix::valueMatrix
protectedinherited

◆ valueMatrix [2/3]

long int** Markov::API::ModelMatrix::valueMatrix
protectedinherited

◆ valueMatrix [3/3]

long int** Markov::API::ModelMatrix::valueMatrix
protectedinherited

The documentation for this class was generated from the following file: