MATLAB: Ind2vec with quaterions matlab

ind2vecMATLABquaterion

i need to implement a function ind2vec but for a quaterion not for a reeal number but i don't have any idea because i m implementing a quaterionic neural network

Best Answer

I think you are misunderstanding the role of ind2vec() and vec2ind()
In neural network work, you frequently have a class number for each target. "This input belongs to class #3. The next input belongs to class #1". Those class numbers are arbitrary integers. They could also be categorical variables, or class labels, or any other system in which targets with the same value belong to the same group and do not belong to the same group as any target that uses a different value.
The simplest representation is to use increasing positive integers to distinguish the groups. Remember, the actual value of the integer has no meaning, just that all of the inputs that belong together use the same value. It is these sequential positive integers that are the inputs for ind2vec() .
For reasons I have not researched, it turns out that some neural network routines prefer not to use integers to represent class membership, and instead use binary vectors in which exactly one item is 1 and the rest are 0, with all of the inputs that are in the same class having the same position in the vector set to 1. This is conceptually a completely equivalent method to using positive integers, but perhaps there are some practical reasons for using it -- it might make the matrix algebra easier for example. It is this list of binary values with one member of the list turned on for input that is the output of ind2vec() . If you look at full() of the ind2vec() result you can see this easily.
There is therefore no reason to worry about how to convert this to use quaternion inputs or outputs: class grouping designations are not quaternions in either representation.
If you are digging into the mechanics of calculating neural network values and you find that there is some place where you are multiplying by these binary values, then I suppose there could be reason to want a quanterion representation. If that happens to be what you are doing, then for each position that would currently have a 0, you should use a quaternion that gives a 0 output after multiplication -- probably the all-zero quaterion. And for the positions that would currently have a 1, you would want to use the identity quaternion.
For example,
function qarr = ind2qvec(ind)
Zq = {[0 0 0 0]}; %nulling quaternion
Iq = {[1 1 1 1]}; %whatever the identity quaternion is
maxind = max(ind);
numind = length(ind);
qarr = repmat(Zq, maxind, numind);
for K = 1 : numind
qarr(ind(K), K) = Iq;
end