Proposal: Automatic object(s) to vector (matrix) encoding and vector (matrix) to object(s) decoding

As many of you know, a vector in Mathematics is any object that respects the vector axioms/interface. In other words it has more to do with which functions it implements, e.g. vector addition and scalar multiplication, than with form.

Therefore, it makes mathematical sense that finding eigen-objects for any vectorish object should be as simple as finding eigenvectors in the narrow column-of-numbers sense. However, the implementations of the algorithms of linear algebra are largely dependent on the column representation of an object, and are obviously not so easy to re-define/re-implement for any vectorish object definition. So maybe we can meet halfway!

I propose making a function that takes in any object (or vector of objects) of type T with numeric data only at the lowest levels, and then walks down its structure tree and vectorizes it, while remembering which vector element maps to which field or sub-field in the type, and then returns the vector (matrix) representation and the mapping vector of symbols/expressions. Then after performing all sorts of vector operations, a decoding function can attempt to retrieve object representation(s) of the resulting vector (matrix). Of course some assumptions may have to be made, like all fields at the lowest level must be Real valued and not have type assertion as Int to allow vector reasoning, and whether vectorization of a vector of objects happens row-first or column-first, and so on. Other tricks may have to be made for mathematical functions, like finding the superset of all terms and filling in 0 for the coefficient of the absent terms, and so on and so forth.

Ideally, calling eig(faces’ * faces) where faces is a vector of Face objects (basically images) should give us the eigenfaces, just as calling eig(v’ v) where v is a simple vector of vectors (actually a matrix) gives the eigenvectors. Similarly, eigen-trees, eigen-shapes, eigen-functions, norms, singular features, other decompositions, etc. can all be automatically defined for arbitrary objects that have this vector/matrix trait (mental reference to Traits.jl ;)).

I think Julia is one of the most suitable programming languages if not THE most suitable one to implement such mechanism in, using its powerful metaprogramming and operator overloading.

do it

3 Likes

I will see what I can do.