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

Saving LU decomposition to a file

Tags: None
(comma "," separated)
User avatar
dzenanz
Registered Member
Posts
35
Karma
0
OS

Saving LU decomposition to a file

Mon Mar 07, 2011 3:02 pm
Hi guys,

I had been using solution to matrix equation by computing inverse matrix and saving it to a file, in order not to recompute it every time (takes many seconds).

Now I suspect there might be a stability issue, so I want to switch to LU decomposition. But I ran into a problem of saving/loading PartialPivLU class.

Code: Select all
void updateWeightMatrix(Eigen::MatrixXd& weights, Eigen::PartialPivLU<Eigen::MatrixXd>& LU, ...)
//this function caches calls to createWeightMatrix and LU decomposition of W*Wtransposed
{
    //levelInfo="1_0" etc
    QFile fdw("./cache/W_"+levelInfo);
    QFile flu("./cache/LU_"+levelInfo);
    QFile fp("./cache/P_"+levelInfo);
    if (fdw.exists()&&flu.exists()&&fp.exists())
    {
        weights.resize(freeCount, countVertices);
        fdw.open(QIODevice::ReadOnly);
        fdw.read((char *)weights.data(), freeCount*countVertices*sizeof(double));
        fdw.close();
        LU=Eigen::PartialPivLU<Eigen::MatrixXd> (freeCount);//LU.resize(freeCount, freeCount);
        LU.initialize(); //is there something like this? what are the alternatives?
        flu.open(QIODevice::ReadOnly);
        flu.read((char *)LU.matrixLU().data(), freeCount*freeCount*sizeof(double));
        flu.close();
        fp.open(QIODevice::ReadOnly);
        fp.read((char *)LU.permutationP().indices().data(), freeCount*sizeof(double));
        fp.close();
    }
    else
    {
        Eigen::MatrixXd t=createWeightMatrix(...);
        weights=t;
        t*=t.transpose();
        LU.compute(t);
        fdw.open(QIODevice::WriteOnly);
        fdw.write((char *)weights.data(), freeCount*countVertices*sizeof(double));
        fdw.close();
        flu.open(QIODevice::WriteOnly);
        flu.write((char *)LU.matrixLU().data(), freeCount*freeCount*sizeof(double));
        flu.close();
        fp.open(QIODevice::WriteOnly);
        fp.write((char *)LU.permutationP().indices().data(), freeCount*sizeof(double));
        fp.close();
    }   
}

The problem is LU.initialize() does not exist. What approach do you recommend to take for saving PartialPivLU class?

Regards,
Dženan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Actually if you compile without Eigen's assertion (-DEIGEN_NO_DEBUG) then your code should work fine. So indeed, what you are missing here is as stupid as a kind of markInitialized() or finalize() method setting the m_initialized member to true, but it would be weird for us to add such a function without a clean way to specify manually the LU matrix and the permutation... In the meantime, perhaps you can patch your copy of Eigen.
User avatar
dzenanz
Registered Member
Posts
35
Karma
0
OS

Re: Saving LU decomposition to a file

Tue Mar 08, 2011 10:13 am
Thanks for advice Gael.

I implemented the markInitialized() method. But now I constantly run into heap corruption errors (debug mode in VS2008). There is something broken with my installation, so I cannot run my app in release mode (error: QWidget: Must construct a QApplication before a QPaintDevice).

And what about the determinant? I guess it is not important if I never call it? Should I also save row transpositions too, in the same way as permutationP?

EDIT: Heap corruption errors were coming from use of double instead of int for saving and loading permutationP.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora