Reduce loss function to get max-valued solution instead of min-valued solution

Asgard: <p>My model is used to predict values based on an minimising a loss function L. But, the loss function doesn’t have a single global minima value, but rather a large number of places where it achieves global minima.</p>
<p>So, the model is based like this:</p>
<p>Model Input is <code>[nXn]</code> tensor (<strong>let’s say</strong>: <code>inp=[ [i_11, i_12, i_13, ..., i_1n],[i_21, i_22, ..., i_2n],...,[i_n1,i_n2, ..., i_nn] ]</code>) and model output is <code>[nX1]</code> tensor (<strong>let’s say:</strong> <code>out1=[o_1, o_2,..., o_n ]</code>)</p>
<p>Output tensor is <code>out1</code> is passed in a function f to get <code>out2</code> (<strong>let’s say:</strong> <code>f(o_1, o_2, o_3,..., o_n)=[O_1, O_2, O_3, ..., O_n]</code> )</p>
<p>These 2 values (i.e., <code>out1</code> and <code>out2</code>) are minimised using MSELoss i.e., <code>Loss = ||out1 - out2||</code></p>
<p>Now, there are a lot of values for <code>[o_1, o_2, ..., o_n]</code> for which the Loss goes to minimum.</p>
<p>But, I want the values of <code>[o_1, o_2, ..., o_n]</code> for which <code>|o_1| + |o_2| + |o_3| + ... + |o_n|</code> is <strong>maximum</strong></p>
<p>Right now, the weights are initialised randomly:</p>
<pre><code class="lang-python">self.weight = torch.nn.parameter.Parameter(torch.FloatTensor(in_features, out_features)) for some value of in_features and out_features
</code></pre>
<p>But by doing this, I am getting the values of <code>[o_1, o_2, ..., o_n]</code> for which <code>|o_1| + |o_2| + |o_3| + ... + |o_n|</code> is <strong>minimum</strong>.</p>
<p>I know this problem can be solved by without using deep-learning, but I am trying to get the results like this for some task computation.</p>
<p>Is there a way to change this to get the largest values predicted at the output of the neural net?</p>
<p>Or is there any other technique (backpropagation change) to change it to get the desired largest valued output?</p>
<p>Thanks in advance.</p>
<p><strong>EDIT 1:</strong></p>
<p>Based on the <a href="https://stackoverflow.com/a/62911805/7447425" rel="nofollow noopener">answer</a>, <code>out1=[o_1, o_2,..., o_n ]</code> is tending to zero-valued tensor. In the initial epochs, <code>out2=[O_1, O_2, O_3, ..., O_n]</code> takes very large values, but subsequently comes down to lower values.</p>
<p>A snippet of code below will give the idea:</p>
<pre><code class="lang-python">import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np


class Model(nn.Module):
    def __init__(self, inp_l, hid_l, out_l=1):
        super(Model, self).__init__()
     
        self.lay1 = nn.Linear(inp_l ,hid_l)
        self.lay2 = nn.Linear(hid_l ,out_l)
        self.dp = nn.Dropout(p=0.5)
        
    def forward(self, inp):
                
        self.out1= torch.tensor([]).float()
        
        for row in range(x.shape[0]):
            y = self.lay1(inp[row])
            y = F.relu(y)
            y = self.dp(y.float())
            y = self.lay2(y)
            y = F.relu(y)
            self.out1= torch.cat((self.out1, y))
            
        return self.out1.view(inp.shape[0],-1)

def function_f(inp, out1):
    '''
    Some functional computation is done to return out2.
    '''
    return out2

def train_model(epoch):
    model.train()
    t = time.time()
    optimizer.zero_grad()
    out1 = model(inp)
    
    out2 = function_f(inp, out1)
    
    loss1 = ((out1-out2)**2).mean()
    loss2 = -out1.abs().mean()
    loss_train = loss1 + loss2
    
    loss_train.backward(retain_graph=True)

    optimizer.step()
    
    if epoch%40==0:
        print('Epoch: {:04d}'.format(epoch+1),
                  'loss_train: {:.4f}'.format(loss_train.item()),
                  'time: {:.4f}s'.format(time.time() - t))

model= Model(inp_l=10, hid_l=5, out_l=1)
optimizer = optim.Adam(model.parameters(), lr=0.001)

inp = torch.randint(100, (10, 10))

for ep in range(100):
       train_model(ep)

</code></pre>
<p>But, out1 value goes to trivial solution i.e., zero-valued tensor which is the minimum valued solution. As mentioned before EDIT, I want to get the max-valued solution.</p>
<p>Thank you.</p>