Hello David,

> and last but not least in order to better understand how ublas works:
> - what is the difference between matrix& , matrix_expression& and matrix_reference

matrix is the class that represent a matrix, as you would probably expect it. It has its storage, indexing etc.
matrix_expression is what makes possible "expression templates" in ublas. i.e. when you have two matrices A, B and you add them:
A+B;
ublas will not actually do the addition but rather create a referenced abstract tree to that operation: a matrix_expression that holds what operations need to be done in order to evaluate it. This is only evaluated when you for example do:
C=A+B;
The benefit from that is performance, since temporaries are avoided and operations are done only once (or almost).
matrix_reference is a reference to a Matrix expression.

You will most probably need matrix and matrix_expression in your programs.
Best Regards
Nasos


From: david.bellot@gmail.com
Date: Wed, 18 Nov 2009 20:52:43 +0100
To: ublas@lists.boost.org; guwi17@gmx.de
Subject: Re: [ublas] [newbie] submatrix and rest of a matrix

Hi Gunter,

indeed, my drawing was false. I'm not very good with ascii art. I wanted to split in 3 with the rows not the column, but the problem remains the same :-)

In fact, I use indirect_array to generate my submatrices now and it works pretty well.

So finally, in order to be a little bit matlab like (in my case it would be very convenient) can I do the following, I didn't find anything that allow to do that directly from the library:

(1) initialize an indirect_array with a vector<int> or something like that,
(2) initialize an indirect_array and do some kind of composition with range like
indirect_array ia(range1, range2, range3, ... etc)

and last but not least in order to better understand how ublas works:
- what is the difference between matrix& , matrix_expression& and matrix_reference

Thanks for your help. Very appreciated.

Cheers,
David

On Wed, Nov 18, 2009 at 20:33, Gunter Winkler <guwi17@gmx.de> wrote:
Hello David,

please read below:

David Bellot schrieb:
> Hi Ublas users,
>
> this is a newbie question:
>
> I am implementing a cross validation algorithm and for that purpose I
> need to split up a big matrix X1 and a big vector Y1 many times in
> different way. The idea is to use a percentage of the initial dataset
> (X1 and Y1) to fit a model and the rest of this dataset to test it.
>
> Let's say my fitting procedure is
>
> double fit(const matrix<double>& X, const vector<double>& y)
>
> and initially I have my big dataset defined as
> matrix<double> X1;
> vector<double> Y1;
>
> during the loop of the cross-validation algo, I split up X1 and Y1 in
> the following manner to obtain a Xtraining and Ytraining dataset and
> Xtest and Ytest dataset:
>
> |------------------------------------|
> |    Xtraining   | Xtest | Xtraining |
> |                |       |           |
> |                |       |           |
> |------------------------------------|
>
> |------------------------------------|
> | Ytraining      | Ytest | Ytraining |
> |------------------------------------|
This looks like you split the matrix into 3 sets of columns and the
vector into 3 sets of corresponding elements.
>
> Of course, Xtest and Ytest is at a different position at each step of
> the loop.
> Xtest and Ytest are easy to obtain with a matrix_range<matrix<double> >
> However Xtraining and Ytraining require a copy of the data to a
> temporary matrix (and vector).
Why do you need a copy? The indirect_array a able to select a set of
columns and rows from a matrix.

>
> So how can I do that efficiently (indirect_array ? other ?) and do I
> need to redefine the prototype of my fit function ?
>

mfg
Gunter

_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: david.bellot@gmail.com



--
David Bellot, PhD
david.bellot@gmail.com
http://david.bellot.free.fr



Hotmail: Trusted email with powerful SPAM protection. Sign up now.