Opened 14 years ago

Closed 8 years ago

#381 closed request (fixed)

Generalize Kernel_MEV

Reported by: Peter Owned by: Peter
Priority: major Milestone: yat 0.12
Component: utility Version: trunk
Keywords: Cc:


A matrix that calculates its element on the fly. It holds two ranges:

RandomAccessIterator1 first1_;
RandomAccessIterator1 last1_;
RandomAccessIterator2 first2_;
RandomAccessIterator2 last2_;

and a functor, func_, defining how to calculate the element

Result operator()(size_t row, size_t column)
{ return funct_( *(first1_+row), *(first2_+column) ); }

Change History (8)

comment:1 Changed 9 years ago by Peter

Milestone: yat 0.x+yat 0.12

This ticket was mentioned as related in description of ticket #782.

comment:2 Changed 9 years ago by Peter

Owner: changed from Jari Häkkinen to Peter
Status: newassigned

comment:3 Changed 9 years ago by Peter

A similar use case is when data is stored in a Matrix. See e.g. Kernel_MEV or a HC with large number of cluster points e.g in expression analysis when clustering genes and calculating the genesXgenes distance matrix takes too much memory. In that case Object(i,j) should return the distance between column i and j (or the rows). One could implement that case as special case if we one had random access iterator that points to column vectors of the matrix. Otherwise we could have a entirely separate class, but it feels like repeating a lot of code. I would prefer to have one class and perhaps provide a helper function

make_matrix(Container2D, Functor)

and a convenient typedef to hide funky declarations like

MyMatrix<WeirdIterator1, WeirdIterator2, Functor>(Matrix, Functor);

comment:4 Changed 8 years ago by Peter

Let me summarize the general case (then it's easy to see the special cases above).

A Matrix basically has three features:

size_t rows(void) const;
size_t columns(void) const;
T operator()(size_t row, size_t column) const;

The last one is the interesting one and if we assume that we can factorize it (in some sense) we can write the operator as

BinaryFunctor(View1[row], View2[column]);

where View classes that hold data (or a pointer/reference to it) and behave like std::vector. Functor takes two arguments of type ARG1 and ARG2, respectively, and obviously the return type from ViewX must be convertible to ARGX. The View classes also need to have a function size(void) that be used to implement rows(void) and columns(void). View could for example be std::string or a view class that looks into a sub-string. In that case it could, for example make sense to have BinaryFunctor that takes char and return a double which could be used in e.g. the Aligner (#782). Another example is that the View returns VectorConstView e.g. if it return a column view and BinaryFunctor is a KernelFunction we get back the special case of Kernel_MEV.

comment:5 Changed 8 years ago by Peter

Define those Views in a Concept and extend the Range class appropriately.

comment:6 in reply to:  5 Changed 8 years ago by Peter

Replying to peter:

Define those Views in a Concept and extend the Range class appropriately.

There is nothing in current Range class that enforce random access; we should not introduce such a requirement.

comment:8 Changed 8 years ago by Peter

Resolution: fixed
Status: assignedclosed

(In [3190]) new class KernelMatrix?. closes #381

Note: See TracTickets for help on using tickets.