tfConstrainedGauss.solve_me package
Submodules
tfConstrainedGauss.solve_me.model_me module
- class tfConstrainedGauss.solve_me.model_me.LayerPrecToCovMat(*args, **kwargs)
Bases:
tensorflow.python.keras.engine.base_layer.Layer
Layer that converts precision to covariance matrix
- __init__(n: int, non_zero_idx_pairs: List[Tuple[int, int]], non_zero_vals: numpy.array, **kwargs)
Constructor
- Args:
n (int): Size of matirx non_zero_idx_pairs (List[Tuple[int,int]]): List of lower triangular index pairs for non-zero elements in precision matrix non_zero_vals (np.array): Non-zero values corresponding to non_zero_idx_pairs
- call(inputs)
Construct the full precision matrix from the non-zero values and invert it to return the covariance matrix
- Args:
inputs ([type]): Anything; used only to determine batch size: size should be batch_size x whatever
- Returns:
[type]: Covariance matrix: batch_size x n x n
- classmethod constructDiag(n: int, non_zero_idx_pairs: List[Tuple[int, int]], init_diag_val: float = 1.0, **kwargs)
Constructor with initial precision matrix that is diagonsl
- Args:
n (int): Size of matirx non_zero_idx_pairs (List[Tuple[int,int]]): List of lower triangular index pairs for non-zero elements in precision matrix init_diag_val (float, optional): Initial diagonal value of precision matrix. Defaults to 1.0.
- Returns:
LayerPrecToCovMat: layer
- classmethod from_config(config)
- get_config()
Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.
- Returns:
Python dictionary.
- property n_non_zero
Number of non-zero unique elements in precision matrix (excluding symmetry)
- Returns:
int: Count
- class tfConstrainedGauss.solve_me.model_me.ModelME(*args, **kwargs)
Bases:
tensorflow.python.keras.engine.training.Model
Model for the MaxEnt method
- __init__(inv_lyr: tfConstrainedGauss.solve_me.model_me.LayerPrecToCovMat, **kwargs)
Constructor
- Args:
inv_lyr (LayerPrecToCovMat): Precision to covariance matrix layer
- call(input_tensor, training=False)
- Given some input_tensor that is only used to set the batch size (must be batch_size >= 2, else there are problems!)
Calls the precision matrix to covariance matrix layer and returns the vector of the elements in the covariance matrix corresponding to the non-zero entries in the precision matrix.
- Args:
input_tensor ([type]): Anything; used only to determine batch size: size should be batch_size x whatever
- Returns:
[type]: Elements in the covariance matrix corresponding to the non-zero entries in the precision matrix.: batch_size x no_non_zero
- classmethod from_config(config)
- get_config()
Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.
- Returns:
Python dictionary.
tfConstrainedGauss.solve_me.solve_me module
- class tfConstrainedGauss.solve_me.solve_me.InputsME(n: int, non_zero_idx_pairs: List[Tuple[int, int]], target_cov_mat_non_zero: numpy.array, epochs: int = 100, learning_rate: float = 0.01, use_weighted_loss: bool = False, verbose: bool = False)
Bases:
object
Inputs to the MaxEnt problem
- __init__(n: int, non_zero_idx_pairs: List[Tuple[int, int]], target_cov_mat_non_zero: numpy.array, epochs: int = 100, learning_rate: float = 0.01, use_weighted_loss: bool = False, verbose: bool = False) None
- convert_mat_non_zero_to_inv_mat_non_zero(mat_non_zero: numpy.array)
Wrapper around convert_mat_non_zero_to_inv_mat_non_zero
- epochs: int = 100
- learning_rate: float = 0.01
- n: int
- property n_non_zero
The number of unique non-zero elements in the precision matrix (excluding symmetry)
- Returns:
int: Count
- non_zero_idx_pairs: List[Tuple[int, int]]
- report()
Print some information
- target_cov_mat_non_zero: numpy.array
- use_weighted_loss: bool = False
- verbose: bool = False
- class tfConstrainedGauss.solve_me.solve_me.ResultsME(inputs: tfConstrainedGauss.solve_me.solve_me.InputsME, trained_model: tfConstrainedGauss.solve_me.model_me.ModelME, init_prec_mat_non_zero: numpy.array, init_cov_mat_reconstructed_non_zero: numpy.array, learned_prec_mat_non_zero: numpy.array, learned_cov_mat: numpy.array)
Bases:
object
Results of the MaxEnt problem
- __init__(inputs: tfConstrainedGauss.solve_me.solve_me.InputsME, trained_model: tfConstrainedGauss.solve_me.model_me.ModelME, init_prec_mat_non_zero: numpy.array, init_cov_mat_reconstructed_non_zero: numpy.array, learned_prec_mat_non_zero: numpy.array, learned_cov_mat: numpy.array) None
- init_cov_mat_reconstructed_non_zero: numpy.array
- init_prec_mat_non_zero: numpy.array
- learned_cov_mat: numpy.array
- property learned_cov_mat_non_zero: numpy.array
- property learned_prec_mat: numpy.array
- learned_prec_mat_non_zero: numpy.array
- report()
Print some information
- trained_model: tfConstrainedGauss.solve_me.model_me.ModelME
- tfConstrainedGauss.solve_me.solve_me.custom_weighted_mse(class_weights)
- tfConstrainedGauss.solve_me.solve_me.solve_me(inputs: tfConstrainedGauss.solve_me.solve_me.InputsME) tfConstrainedGauss.solve_me.solve_me.ResultsME
Solve the MaxEnt problem
- Args:
inputs (InputsME): Inputs
- Returns:
ResultsME: Results