jeudi 13 juin 2019

Using `std::generate` or `std::fill` to fill an `arma::mat`

I'm trying to write a wrapper around the gmm_full and gmm_diag to have them as mvnorm_distribution. I need this specific setup because I'm dealing with an input file, and would like to have everything working more or less the same as std::*_distributions. I have my wrapper and it works as I would like but I have a hard time filling an arma::mat via any of the std algorithms. Basically, I have something like this:

arma::vec gen() {
    // gmm_full model initilization
    return model.generate();
}

void main() {
    arma::mat m(dim, N);
    std::generate(m.begin_col(0), m.end_col(N-1), gen);
}

So far, I realized that either the std::generate or m.being_col() are not working as I was expecting. I was thinking that I'll get a vector and can fill it, or that's what std::generate would do but apparently that's not the case. I see in the example that I have to dereference the column but then I cannot do it on std::generate. I've both std::fill and std::transform but I have no success so far.

One solution would be to write a generator class and pass every value one by one, but then that's not what I want really. I was wondering if anyone can help me with this. I'm also aware of the model.generate(N) but I'd like to have the distribution wrapped and use it like other std::*_distributions, so it would not solve my problem, or it does and I don't know how to use it.

P.S. This is technically a follow up on this question that I've asked earlier.




Aucun commentaire:

Enregistrer un commentaire