Hi there! I am customizing my own loss function using torch.sort() and torch.take() functions. However, with the custom loss function, a fully-connected feed-forward neural network (nothing special, with linear, ReLU and batch norm layers) does not learn well on the dataset. Therefore, I am wondering if there exist some issues with my loss function, e.g., the gradients are not back-propagated due to the use of these two functions. I checked the official document and also read some threads on Internet, but I don’t find any answers for that, unfortunately.
By the way, my motivation of defining my loss function is to penalize the violation of monotonicity of two series of data. For example, I got two tensors x, y which contain the time-series of two variables, and I knew that y should increase/decrease as x increases/decreases. Hence, I sorted x (in ascending order) and recorded the index (which was done by torch.sort()), and re-ordered y using that index (which was done by torch.take()). Lastly, I just needed to check the difference between the consecutive pair of data in sorted y from which monotonicity can be checked.
I really appreciate any feedback and thanks in advance for your time!