0
$\begingroup$

I am trying to convert a vector of floats into a matrix similar to one hot encoding, but I want this to happen in non-discrete space to retain gradients. Therefore I am only able to use keras backend functions.

For example I want the vector

Vector: 0, 2, 2.5, 3

to be converted into a matrix like this:

Matrix: 1, 0, 0, 0; 0, 0, 1, 0; 0, 0, 0.5, 0.5; 0, 0, 0, 1

But I have no clue how this procedure is called, as it is certainly not one-hot-encoding, or how this could be implemented.

Edit: After spending an afternoon outside, I came up with a more algorithmic definition. I am not sure if my notation is correct and most importantly how I implement it, but I think it makes the question more clear:

let v be a vector of size n x 1 let M be a matrix of size n x k define contents of M via this formula: M_{i,j} = max((1 - |j - v_i |), 0)

to get the gradient of v for backpropagation use: \nabla v_i = \sum_{j=0}^{k} \nabla M_{i,j}*j

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.