This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Increment a matrix with unknown size

Tags: None
(comma "," separated)
hazemkrichene
Registered Member
Posts
7
Karma
0

Increment a matrix with unknown size

Thu Jan 04, 2018 11:07 am
I'm working on a growing up algorithm where i have to generated vectors "theta" in a matrix "collection". "theta" is a vector of size 10, and i will update N (unknown) time the values of "theta" (optimization algorithm). I implemented this solution:

Code: Select all
MatrixXd Theta_Collection;
int row_collection = 0;       
while (convergence)
{
        theta -= a_r*inv_D0*(E - Z_obs); //update of theta
    Theta_Collection.row(row_collection) = theta; //save the value of theta in a matrix
    row_collection++;
 }


This algorithm is not working! Any solution with Eigen for that please?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
For that precise purpose, better collect them in a std::vector<VectorXd>, and in case you need to need see them as a MatrixXd at the end:

typedef Matrix<double,10,1> Vec10;
std::vector<Vec10> Theta_Collection;
while(...) { Theta_Collection.push_back(theta); }
auto view = MatrixXd::map(Theta_Collection[0].data(), 10, Theta_Collection.size());

Note that the last line won't work if you use a VectorXd instead of a fixed size object.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]