'TensorFlow: How to rank a tensor?
Question
Hello! Is there any way to modify a Tensor into a ranked version of itself without using eval?
For example, [6, 4, 5] -> [3, 1, 2]?
Context
I'm interested in using rank correlation as a cost function, and my bandaid solution has been to use session.run(tensor) to get the numpy values, and then to modify that for rank correlation.
The issue thus far has been that the weights and biases don't change during training, leading me to assume that TensorFlow isn't calculating a meaningful gradient.
I've varied my learning rate between a number of values between (500 and 3e-8) to see if that was the issue. No luck, weights and biases remain unchanged.
Solution 1:[1]
Using argsort two times produces the ranks. You can use:
tf.argsort(tf.argsort(a))
The above code produces ranks based on indexes beginning at zero. You can add 1 to it to get the ranks based on the indexes beginning at one.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Radheshyam Verma |
