I am currently working on creating a version of Orthogonal Matching Pursuit (OMP) that can be performed simultaneously on different patches, utilizing the power of TensorFlow for optimization through static graph compilation.
I have provided the pseudocode for a single step of the main loop of the algorithm below:
support = tf.TensorArray(dtype=tf.int64, size=1, dynamic_size=True)
# For each element in patches, compute the projection on the dictionary using only TensorFlow API
dot_products = tf.abs(tf.matmul(A, patches, transpose_a=True))
max_index = tf.argmax(dot_products, axis=1)
support = support.write(i, max_index + 1)
support = support.write(i + 1, max_index + 1)
idx = support.stack()
non_zero_rows = tf.reduce_all(tf.not_equal(idx, 0), axis=1)
idx = tf.boolean_mask(idx, non_zero_rows) - 1
A_tilde = tf.gather(A, idx, axis=1)
m, n = A.shape
selected_atoms = tf.matmul(A_tilde, A_tilde, transpose_a=True)
After obtaining selected_atoms, which is a 3D tensor consisting of l matrices of size nxm, I need to solve the least square problem
|patches - selected_atoms * x_coeff| ** 2
To do this, I need to compute the inverse of selected_atoms.T @ selected_atoms. Is there a method using TensorFlow's API to simultaneously compute the l inverse matrices and store them in a 3D tensor of shape lxnxm? I would greatly appreciate any guidance.
Thank you.
To get the pseudoinverse, can use the pinv function, it does what you want (for least squares, pseudo-inverse is well-defined whereas inverse might not be).
the function call returns:
If you only want the coefficients of the regression, you don't need to store pseudo_inverse, but the pinv*patches (which might save a lot of memory) see: http://www.seas.ucla.edu/~vandenbe/133A/lectures/ls.pdf