コード例 #1
0
 /**
  * Adds the diagonal of the Hessia of the expected log-likelihoood of
  * the specified data point to the Hessian diagonal h.
  */
 void add_hessian_diag(const table<T>& phead, const uint_vector& tail, T w,
                       table<T>& h) const {
   assert(phead.arity() + tail.size() == h.arity());
   std::size_t index = h.offset().linear(tail, phead.arity());
   for (std::size_t i = 0; i < phead.size(); ++i) {
     h[index + i] -= phead[i] * w / (f[index + i] * f[index + i]);
   }
 }
コード例 #2
0
 /**
  * Adds the gradient of the expected log-likelihood of the specified
  * data point to the gradient table g.
  *
  * \param phead the distribution over a leading set of indices of f
  * \param tail a fixed assignment to the remaining indices of f
  * \param w the weight of the data point
  */
 void add_gradient(const table<T>& phead, const uint_vector& tail, T w,
                   table<T>& g) const {
   assert(phead.arity() + tail.size() == g.arity());
   std::size_t index = g.offset().linear(tail, phead.arity());
   for (std::size_t i = 0; i < phead.size(); ++i) {
     g[index + i] += phead[i] * w;
   }
 }
コード例 #3
0
ファイル: table.hpp プロジェクト: chongbingbao/libgm
 /**
  * Restricts the given table to an assignment to all the dimensions
  * >= n, where n is the arity of this table. The parameter x_start is
  * the linear index of the first element in the input table that should
  * be copied. This table must be preallocated, and its first n
  * dimensions must match the first n dimensions of the input table.
  */
 void restrict(const table& x, std::size_t x_start) {
   assert(arity() <= x.arity());
   assert(std::equal(shape_.begin(), shape_.end(), x.shape_.begin()));
   assert(x_start + size() <= x.size());
   std::copy(x.data() + x_start, x.data() + x_start + size(), data());
 }