title: Is it possible to train a neural netowrk using a loss function on unseen data (data different from input data)?
body: <p>Normally, a loss function may be defined as
  L(y_hat, y) or L(f(X), y), where f is the neural network, X is the input data, y is the target.
  Is it possible to implement (preferably in PyTorch) a loss function that depends not only on the input data X, but also on X' (X != X)?</p>
  <p>For example, let's say I have a neural network f, input data (X,y) and X'. Can I construct a loss function such that</p>
  <ol>
  <li>f(X) is as close as possible to y, and also</li>
  <li>f(X') &gt; f(X)?</li>
  </ol>
  <p>The first part can be easily implemented (PyTorch: nn.MSELoss()), the second part seems to be way harder.</p>
  <p>P.S: this question is a reformulation of <a href="https://stackoverflow.com/questions/63926325/multiple-regression-while-avoiding-line-intersections-using-neural-nets">Multiple regression while avoiding line intersections using neural nets</a>, which was closed. In the original data, input data and photos with a theoretical example are available.</p>