General framework for discrete exponential models. This class allows generating discrete exponential models in the form of a linear exponential model:
More...
|
void | update_normalizing_constants (const std::vector< double > ¶ms, BARRY_NCORES_ARG(=1), int i=-1) |
| Computes the normalizing constant for a given set of parameters. More...
|
|
void | update_likelihoods (const std::vector< double > ¶ms,) |
|
void | update_pset_probs (const std::vector< double > ¶ms, BARRY_NCORES_ARG(=1), int i=-1) |
|
void | set_rengine (std::mt19937 *rengine_, bool delete_=false) |
|
void | set_seed (size_t s) |
|
| Model () |
|
| Model (size_t size_) |
|
| Model (const Model< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type > &Model_) |
|
Model< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type > & | operator= (const Model< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type > &Model_) |
|
virtual | ~Model () |
|
void | store_psets () noexcept |
|
std::vector< double > | gen_key (const Array_Type &Array_) |
|
size_t | add_array (const Array_Type &Array_, bool force_new=false) |
| Adds an array to the support of not already included. More...
|
|
void | print_stats (size_t i) const |
|
virtual void | print () const |
| Prints information about the model. More...
|
|
Array_Type | sample (const Array_Type &Array_, const std::vector< double > ¶ms={}) |
|
Array_Type | sample (const size_t &i, const std::vector< double > ¶ms) |
|
double | conditional_prob (const Array_Type &Array_, const std::vector< double > ¶ms, size_t i, size_t j) |
| Conditional probability ("Gibbs sampler") More...
|
|
const std::mt19937 * | get_rengine () const |
|
Counters< Array_Type, Data_Counter_Type > * | get_counters () |
|
Rules< Array_Type, Data_Rule_Type > * | get_rules () |
|
Rules< Array_Type, Data_Rule_Dyn_Type > * | get_rules_dyn () |
|
Support< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type > * | get_support_fun () |
|
|
These will add counters to the model, which are shared by the support and the actual counter function.
|
void | add_counter (Counter< Array_Type, Data_Counter_Type > &counter) |
|
void | add_counter (Counter_fun_type< Array_Type, Data_Counter_Type > count_fun_, Counter_fun_type< Array_Type, Data_Counter_Type > init_fun_=nullptr, Data_Counter_Type data_=nullptr) |
|
void | set_counters (Counters< Array_Type, Data_Counter_Type > *counters_) |
|
void | add_hasher (Hasher_fun_type< Array_Type, Data_Counter_Type > fun_) |
|
|
These will add rules to the model, which are shared by the support and the actual counter function.
|
void | add_rule (Rule< Array_Type, Data_Rule_Type > &rule) |
|
void | add_rule (Rule_fun_type< Array_Type, Data_Rule_Type > count_fun_, Data_Rule_Type data_) |
|
void | set_rules (Rules< Array_Type, Data_Rule_Type > *rules_) |
|
void | add_rule_dyn (Rule< Array_Type, Data_Rule_Dyn_Type > &rule) |
|
void | add_rule_dyn (Rule_fun_type< Array_Type, Data_Rule_Dyn_Type > count_fun_, Data_Rule_Dyn_Type data_) |
|
void | set_rules_dyn (Rules< Array_Type, Data_Rule_Dyn_Type > *rules_) |
|
|
Calculation of likelihood functions is done reusing normalizing constants. Before recalculating the normalizing constant, the function checks whether params matches the last set vector of parameters used to compute it.
- Parameters
-
params | Vector of parameters |
as_log | When true , the function returns the log-likelihood. |
|
double | likelihood (const std::vector< double > ¶ms, const size_t &i, bool as_log=false, bool no_update_normconst=false) |
|
double | likelihood (const std::vector< double > ¶ms, const Array_Type &Array_, int i=-1, bool as_log=false, bool no_update_normconst=false) |
|
double | likelihood (const std::vector< double > ¶ms, const std::vector< double > &target_, const size_t &i, bool as_log=false, bool no_update_normconst=false) |
|
double | likelihood (const std::vector< double > ¶ms, const double *target_, const size_t &i, bool as_log=false, bool no_update_normconst=false) |
|
double | likelihood_total (const std::vector< double > ¶ms, bool as_log=false, BARRY_NCORES_ARG(=2), bool no_update_normconst=false) |
|
|
- Parameters
-
i | Index relative to the array in the model. |
params | A new vector of model parameters to compute the normalizing constant. |
as_log | When true returns the logged version of the normalizing constant. |
|
const std::vector< double > & | get_normalizing_constants () const |
|
const std::vector< double > & | get_likelihoods () const |
|
const std::vector< Array_Type > * | get_pset (const size_t &i) |
|
const double * | get_pset_stats (const size_t &i) |
|
|
Number of different supports included in the model
This will return the size of stats_target .
- Returns
size() returns the number of arrays in the model.
-
size_unique() returns the number of unique arrays (according to the hasher) in the model.
-
nterms() returns the number of terms in the model.
|
size_t | size () const noexcept |
|
size_t | size_unique () const noexcept |
|
size_t | nterms () const noexcept |
|
size_t | nrules () const noexcept |
|
size_t | nrules_dyn () const noexcept |
|
size_t | support_size () const noexcept |
|
std::vector< std::string > | colnames () const |
|
|
std::vector< std::vector< double > > * | get_stats_target () |
| Raw pointers to the support and target statistics. More...
|
|
std::vector< double > * | get_stats_support () |
| Sufficient statistics of the support(s) More...
|
|
std::vector< size_t > * | get_stats_support_sizes () |
| Number of vectors included in the support. More...
|
|
std::vector< size_t > * | get_stats_support_sizes_acc () |
| Accumulated number of vectors included in the support. More...
|
|
std::vector< size_t > * | get_arrays2support () |
|
std::vector< std::vector< Array_Type > > * | get_pset_arrays () |
|
std::vector< double > * | get_pset_stats () |
| Statistics of the support(s) More...
|
|
std::vector< double > * | get_pset_probs () |
|
std::vector< size_t > * | get_pset_sizes () |
|
std::vector< size_t > * | get_pset_locations () |
|
|
void | set_transform_model (std::function< std::vector< double >(double *, size_t)> fun, std::vector< std::string > names) |
| Set the transform_model_fun object. More...
|
|
std::vector< double > | transform_model (double *data, size_t k) |
|
|
MapVec_type< double, size_t > | keys2support |
| Map of types of arrays to support sets. More...
|
|
std::vector< std::vector< double > > | params_last |
| Vector of the previously used parameters. More...
|
|
std::vector< double > | normalizing_constants |
|
std::vector< bool > | first_calc_done |
|
bool | delete_counters = false |
|
bool | delete_rules = false |
|
bool | delete_rules_dyn = false |
|
std::function< std::vector< double >double *, size_t k)> | transform_model_fun = nullptr |
| Transformation of the model. More...
|
|
std::vector< std::string > | transform_model_term_names |
|
|
|
std::mt19937 * | rengine = nullptr |
|
bool | delete_rengine = false |
|
|
stats_target holds the observed sufficient statistics for each array in the dataset. array_frequency contains the frequency with which each of the target stats_target (arrays) shows in the support. array2support maps array indices (0, 1, ...) to the corresponding support.
Each vector of stats_support has the data stored in a row-wise order, with each row starting with the weights, e.g., in a model with k terms the first k + 1 elements of stats_support would be:
- weights
- term 1
- term 2
- ...
- term k
|
std::vector< double > | stats_support |
| Sufficient statistics of the model (support) More...
|
|
std::vector< size_t > | stats_support_sizes |
| Number of vectors included in the support. More...
|
|
std::vector< size_t > | stats_support_sizes_acc |
| Accumulated number of vectors included in the support. More...
|
|
std::vector< size_t > | stats_support_n_arrays |
| Number of arrays included per support. More...
|
|
std::vector< std::vector< double > > | stats_target |
| Target statistics of the model. More...
|
|
std::vector< double > | stats_likelihood |
|
std::vector< size_t > | arrays2support |
|
|
This is useful in the case of using simulations or evaluating functions that need to account for the full set of states.
|
bool | with_pset = false |
|
std::vector< std::vector< Array_Type > > | pset_arrays |
| Arrays of the support(s) More...
|
|
std::vector< double > | pset_stats |
| Statistics of the support(s) More...
|
|
std::vector< double > | pset_probs |
| Probabilities of the support(s) More...
|
|
std::vector< size_t > | pset_sizes |
| Number of vectors included in the support. More...
|
|
std::vector< size_t > | pset_locations |
| Accumulated number of vectors included in the support. More...
|
|
|
Arguments are recycled to save memory and computation.
|
Counters< Array_Type, Data_Counter_Type > * | counters |
|
Rules< Array_Type, Data_Rule_Type > * | rules |
|
Rules< Array_Type, Data_Rule_Dyn_Type > * | rules_dyn |
|
Support< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type > | support_fun |
|
StatsCounter< Array_Type, Data_Counter_Type > | counter_fun |
|
template<typename Array_Type = BArray<>, typename Data_Counter_Type = bool, typename Data_Rule_Type = bool, typename Data_Rule_Dyn_Type = bool>
class Model< Array_Type, Data_Counter_Type, Data_Rule_Type, Data_Rule_Dyn_Type >
General framework for discrete exponential models. This class allows generating discrete exponential models in the form of a linear exponential model:
\[ \frac{ \exp{\left(\theta^{\mbox{t}}c(A)\right)} }{ \sum_{A'\in \mathcal{A}}\exp{\left(\theta^{\mbox{t}}c(A')\right)} } \]
This implementation aims to reduce the number of times that the support needs to be computed. Models included here use more than a single array, and thus allow the function to recycle support sets as needed. For example, if we are looking at directed graphs all of the same size and without vertex level features, i.e. a model that only counts edges, triangles, etc. then the support needs to be fully computed only once.
- Template Parameters
-
Array_Type | Class of BArray object. |
Data_Counter_Type | Any type. |
Data_Rule_Type | Any type. |
Definition at line 34 of file model-bones.hpp.