tf_G.utils

tf_G.utils Module

It contains a set of utilities that is used for another classes of tf_G module.

DataSets

class tf_G.utils.datasets.DataSets[source]

DataSets class represents some data sets included in the package.

The class provides compose_from_path method to import personal sets.

static compose_from_path(path: str, index_decrement: bool) → numpy.ndarray[source]

This method generates a data set from a given path.

The method obtains the data from the given path, then decrements its values if is necessary and permutes the resulting data set.

The decrement option is offered because of in some cases the data set treats the initial node as 1 but many data structures in python are 0-indexed, so decrementing the values improves space performance.

Parameters:
  • path (str) – The path of the file of data set csv.
  • index_decrement (bool) – Decrements all valus by one if True, do nothing otherwise.
Returns:

The data set that represents the Graph.

Return type:

(np.ndarray)

static naive_4() → numpy.ndarray[source]

This method returns the naive_4 data set.

The data set is obtained from Cornell University guide lecture of PageRank algorithm.

This graph contains 4 vertices and 8 edges.

Url:
http://www.math.cornell.edu/~mec/Winter2009/RalucaRemus/Lecture3/lecture3.html
Returns:The data set that represents the Graph.
Return type:(np.ndarray)
static naive_6() → numpy.ndarray[source]

This method returns the naive_6 data set.

The data set is obtained from mathworks study of PageRank algorithm.

This graph contains 6 vertices and 9 edges.

Url:
https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/moler/exm/chapters/pagerank.pdf
Returns:The data set that represents the Graph.
Return type:(np.ndarray)
static permute_edges(edges_np: numpy.ndarray) → numpy.ndarray[source]

Method that permutes the rows order of given the input set.

Parameters:edges_np (np.ndarray) – The input data set.
Returns:The input data set permuted in rows
Return type:(np.ndarray)

TensorFlowObject

class tf_G.utils.tensorflow_object.TensorFlowObject(sess: tensorflow.python.client.session.Session, name: str, writer: tensorflow.python.summary.writer.writer.FileWriter = None, is_sparse: bool = False) → None[source]

This class gives represents a TensorFlow object in the package.

It acts as Parent class of many classes that uses the TensorFlow library and needs to execute code, so it’s necessary to have a session and other attributes.

__init__(sess: tensorflow.python.client.session.Session, name: str, writer: tensorflow.python.summary.writer.writer.FileWriter = None, is_sparse: bool = False) → None[source]

The constructor of class.

It assign the input parameters to the class objects and no more.

Parameters:
  • sess (tf.Session) – This attribute represents the session that runs the TensorFlow operations.
  • name (str) – This attribute represents the name of the object in TensorFlow’s op Graph.
  • writer (tf.summary.FileWriter) – This attribute represents a TensorFlow’s Writer, that is used to obtain stats.
  • is_sparse (bool) – Use sparse Tensors if it’s set to True. Not implemented yet. Show the Todo.

Todo

  • Implement variables as sparse when it’s possible. Waiting to TensorFlow for it.
run_tf(input_to_run)[source]

Run method to execute TensorFlow operations

Parameters:input_to_run – This parameter represents a TensorFlow operation.
Returns:The result of the operation as numpy array

Utils

class tf_G.utils.utils.Utils[source]

Utils class of the tf_G package.

This class contains static methods that will be used by another classes around the package.

static ranked(x: numpy.ndarray) → numpy.ndarray[source]

This method sorts the array indices given by its values.

It can be used to generate a ranking based on the values of an array in which the value represents the score and the index the object identifier.

Parameters:x (np.ndarray) – A 2-D np.ndarray to rank the results by rows.
Returns:
An array containing the indices of the input array
sorted in decremental order.
Return type:(np.ndarray)
static save_ranks(filename: str, array: numpy.ndarray, index_increment: bool = True) → None[source]

This method will save the input array in the filesystem.

The method creates a file in the filesystem with name filename and puts the array content inside it.

This method provides the index_increment that increments the first column by one if True. The reason of this option is that the method is created to store results of graph operations, and in some cases the graph vertices is represented as 0-indexed and anothers as 1-indexed.

Parameters:
  • filename (str) – The name of the file that will be created.
  • array (np.ndarray) – The array that contains the data that will be saved.
  • index_increment (bool, optional) – Increments the first column of the array input if True, do nothing otherwise.
Returns:

This method returns nothing.