I am working on a project, and I've been trying to come up with a custom loss/score function. Would really appreciate some help So, the loss function needs to be a function of (say) two variables A and B. It needs to be continous and differentiable in terms of A. Basically, I have a set of precomputed values (B), and during training, after every forward pass, I get a value A. A can vary from 0 to 1. And B can vary from 0 to (say) a bit large value, 10.

Now, this is how I want the loss function to work :

A - high, B - high
=> Ideal situation. Loss should be a small value i.e. No change in A required.

A - high, B - low
=> Loss should be such that it moves towards decreasing the value of A.

A - low, B - high
=> Loss should be such that it moves towards increasing the value of A. 

A - low, B - low
=> Ideal situation. Loss should be a small value i.e. No change in A required.
Instead of computing $A$, make your algorithm compute $10\times A.$
Then use your favourite loss function for continuous variables. The most common one is the squared $L^2$-norm $l(10\times A, B) = (10\times A-B)^2.$

Here is a plot of $l$ that I made with Wolfram Alpha:.