Exemple #1
0
// Assemble lower-triangular matrix from log-diagonal and lower triangle and multiply by vector v
// [ exp(q0)        0        0        0 ]
// [      l0  exp(q2)        0        0 ]
// [      l1       l2  exp(q3)        0 ]
// [      l3       l4       l5  exp(q4) ]
VectorD Qtimesv(VectorD const& q, Vector const& l, VectorD const& v)
{
  VectorD ret(v.size());
  for (size_t i = 0; i < size_t(v.size()); ++i) {
    // let li = vectorSlice (Card i) (tri(i - 1)) l
    // let vi = vectorSlice (Card i) 0 v
    // vectorSum (li.*vi) + exp(q[i])*v[i]
    size_t lstart = tri(i - 1);
    double out = exp(q[i]) * v[i];
    for (size_t k = 0; k < i; ++k)
      out += l[lstart + k] * v[k];
    ret[i] = out;
  }
  return ret;
}
VectorD SparseMatrix::multiply_vector(VectorD& v)
{
    VectorD res(v.size(), 0.0);
    for(map<pair<int, int>, double>::iterator it = values.begin(); it != values.end(); it++)
    {
        int row = it->first.first;
        int col = it->first.second;
        double val = it->second;
        res[row] += val*v[col];
    }
    return res;
}