You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In general, to my understanding, moving from SEXP objects to some types of classes in C++ like std::vector or arma::vec is in general efficient as, if the argument is marked as by reference &, the underlying data structure doesn't change. On the other hand, this operation does seem to take some time as when computing likelihood function of more complex models in which the full enumeration is needed the full iteration takes about half a second (anecdotally), which builds up.
Moreover, a certain bottle-neck is in memory allocation. Memory allocation happens at various stages, in particular:
For each element of the vector of sufficient statistics (which may be reduced b/c using iso-statistics).
For each parameter/network when computing the gradient.
These two can imply allocating and deallocating large arrays several times throughout the optimization process, as each call to the likelihood function right now requires it so.
The solution
In an ideal world, we would allocate memory only once and then reuse those structures again and again. This should reduce the overhead time associated with this operation significantly.
Likewise, it would be nice if we need to pass all the arrays used to compute the likelihood function only once, at the first call of the function. Since we are not modifying any of these elements (read-only during the optimization), we can keep them stored in a pointer at C++.
For this, we would need to create a class holding the following information:
(std::vector< arma::mat >) The support of the sufficient statistics, one per network.
(std::vector< double >) The vector of exp() values associated with every realization of the sufficient statistic.
(std::vector< arma::uvec >) Vector of vectors of weights associated with each realization of the sufficient statistics.
(TBC)
The text was updated successfully, but these errors were encountered:
The problem
In general, to my understanding, moving from SEXP objects to some types of classes in C++ like std::vector or arma::vec is in general efficient as, if the argument is marked as by reference
&
, the underlying data structure doesn't change. On the other hand, this operation does seem to take some time as when computing likelihood function of more complex models in which the full enumeration is needed the full iteration takes about half a second (anecdotally), which builds up.Moreover, a certain bottle-neck is in memory allocation. Memory allocation happens at various stages, in particular:
These two can imply allocating and deallocating large arrays several times throughout the optimization process, as each call to the likelihood function right now requires it so.
The solution
In an ideal world, we would allocate memory only once and then reuse those structures again and again. This should reduce the overhead time associated with this operation significantly.
Likewise, it would be nice if we need to pass all the arrays used to compute the likelihood function only once, at the first call of the function. Since we are not modifying any of these elements (read-only during the optimization), we can keep them stored in a pointer at C++.
For this, we would need to create a class holding the following information:
std::vector< arma::mat >
) The support of the sufficient statistics, one per network.std::vector< double >
) The vector of exp() values associated with every realization of the sufficient statistic.std::vector< arma::uvec >
) Vector of vectors of weights associated with each realization of the sufficient statistics.(TBC)
The text was updated successfully, but these errors were encountered: