コード例 #1
0
SparseMatrix::SparseMatrix(const SparseMatrix& mat, int num_rows, int num_cols, int first_row, int first_col) {
  _allocate_SparseMatrix(num_rows, num_cols, num_rows, num_cols);
  for (int row=0; row<num_rows; row++) {
    // copy parts of rowvectors
    *_rows[row] = SparseVector(*mat._rows[row+first_row], num_rows, first_row);
  }
}
コード例 #2
0
 SparseVector TrigStateModel::observation_matrix(int t) const {
   Vector trig(state_dimension());
   for (int i = 0; i < frequencies_.size(); ++i) {
     trig[2 * i] = cos(frequencies_[i] * t);
     trig[2 * i + 1] = sin(frequencies_[i] * t);
   }
   return SparseVector(trig);
 }
コード例 #3
0
 void DRSM::add_forecast_data(const Matrix &predictors) {
   if (ncol(predictors) != xdim_) {
     report_error("Forecast data has the wrong number of columns");
   }
   for (int i = 0; i < nrow(predictors); ++i) {
     sparse_predictor_vectors_.push_back(SparseVector(predictors.row(i)));
     sparse_predictor_matrices_.push_back(
         new DenseMatrix(Matrix(1, xdim_, predictors.row(i))));
   }
 }
コード例 #4
0
 DRSM::DynamicRegressionStateModel(const Matrix &X)
     : xdim_(ncol(X)),
       initial_state_mean_(xdim_, 0.0),
       initial_state_variance_(xdim_, 1.0),
       transition_matrix_(new IdentityMatrix(xdim_)) {
   setup_models_and_transition_variance_matrix();
   sparse_predictor_vectors_.reserve(nrow(X));
   for (int i = 0; i < nrow(X); ++i) {
     sparse_predictor_vectors_.push_back(SparseVector(X.row(i)));
     sparse_predictor_matrices_.push_back(
         new DenseMatrix(Matrix(1, xdim_, X.row(i))));
   }
   compute_predictor_variance();
 }
コード例 #5
0
 //============================================================================
 DRSM::DynamicRegressionStateModel(const std::vector<Matrix> &predictors)
     : xdim_(check_columns(predictors)),
       initial_state_mean_(xdim_, 0.0),
       initial_state_variance_(xdim_, 1.0),
       transition_matrix_(new IdentityMatrix(xdim_)) {
   setup_models_and_transition_variance_matrix();
   for (int i = 0; i < predictors.size(); ++i) {
     const Matrix &X(predictors[i]);
     sparse_predictor_matrices_.push_back(new DenseMatrix(X));
     for (int j = 0; j < X.nrow(); ++j) {
       sparse_predictor_vectors_.push_back(SparseVector(X.row(j)));
     }
   }
   compute_predictor_variance();
 }
コード例 #6
0
 void DRSM::add_multiplexed_forecast_data(
     const std::vector<Matrix> &predictors) {
   if (predictors.empty()) {
     report_error("Forecast data is empty.");
   }
   for (int t = 0; t < predictors.size(); ++t) {
     NEW(DenseMatrix, predictor_matrix)(predictors[t]);
     if (!sparse_predictor_matrices_.empty() &&
         predictor_matrix->ncol() != sparse_predictor_matrices_[0]->ncol()) {
       report_error(
           "Multiplexed forecast data has the wrong "
           "number of columns.");
     }
     sparse_predictor_matrices_.push_back(predictor_matrix);
     sparse_predictor_vectors_.push_back(SparseVector(predictors[t].row(0)));
   }
 }
コード例 #7
0
SparseVector multadd_ss(const SparseVector &a, const SparseVector &b, base_type factor)
{
    vector<pair<size_t, base_type>> words;

    SparseVector::const_iterator iter_a = a.begin();
    SparseVector::const_iterator iter_b = b.begin();

    while (iter_a!=a.end() && iter_b!=b.end())
    {
        if (iter_a->first > iter_b->first)
        {
            words.push_back(make_pair(iter_b->first, factor*iter_b->second));
            iter_b++;
        } else {
            if (iter_a->first < iter_b->first)
            {
                words.push_back(*iter_a);
                iter_a++;
            } else {
                // indices equal
                base_type weight = iter_a->second + factor*iter_b->second;
                if (weight!=0)
                    words.push_back(make_pair(iter_a->first, weight));
                iter_a++;
                iter_b++;
            }
        }
    }

    while (iter_b!=b.end())
    {
        words.push_back(make_pair(iter_b->first, factor*iter_b->second));
        iter_b++;
    }

    while (iter_a!=a.end())
    {
        words.push_back(*iter_a);
        iter_a++;
    }

    return(SparseVector(words));
}