Questions tagged [objective-functions]

For questions related to the concept of loss (or cost) function in the context of machine learning.

Filter by
Sorted by
Tagged with
20 votes
3 answers
25k views

How can we process the data from both the true distribution and the generator?

I'm struggling to understand the GAN loss function as provided in Understanding Generative Adversarial Networks (a blog post written by Daniel Seita). In the standard cross-entropy loss, we have an ...
tryingtolearn's user avatar
10 votes
1 answer
4k views

Loss jumps abruptly when I decay the learning rate with Adam optimizer in PyTorch

I'm training an auto-encoder network with Adam optimizer (with amsgrad=True) and ...
imflash217's user avatar
9 votes
1 answer
7k views

What is the difference between the triplet loss and the contrastive loss?

What is the difference between the triplet loss and the contrastive loss? They look same to me. I don't understand the nuances between the two. I have the following queries: When to use what? What ...
Exploring's user avatar
  • 343
8 votes
1 answer
2k views

How is the DQN loss derived from (or theoretically motivated by) the Bellman equation, and how is it related to the Q-learning update?

I'm doing a project on Reinforcement Learning. I programmed an agent that uses DDQN. There are a lot of tutorials on that, so the code implementation was not that hard. However, I have problems ...
Yves Boutellier's user avatar
8 votes
1 answer
1k views

What's the advantage of log_softmax over softmax?

Previously I have learned that the softmax as the output layer coupled with the log-likelihood cost function (the same as the ...
user1024's user avatar
  • 181
7 votes
4 answers
9k views

Can the mean squared error be negative?

I'm new to machine learning. I was watching a Prof. Andrew Ng's video about gradient descent from the machine learning online course. It said that we want our cost function (in this case, the mean ...
Borna Ghahnoosh's user avatar
7 votes
2 answers
8k views

What is the difference between a loss function and reward/penalty in Deep Reinforcement Learning?

In Deep Reinforcement Learning (DRL) I am having difficulties in understanding the difference between a Loss function, a reward/penalty and the integration of both in DRL. Loss function: Given an ...
Theo Deep's user avatar
  • 185
7 votes
1 answer
1k views

What loss function to use when labels are probabilities?

What loss function is most appropriate when training a model with target values that are probabilities? For example, I have a 3-output model. I want to train it with a feature vector $x=[x_1, x_2, \...
Thomas Johnson's user avatar
7 votes
1 answer
15k views

What is an objective function?

Local search algorithms are useful for solving pure optimization problems, in which the aim is to find the best state according to an objective function. My question is what is the objective function?
Abbas Ali's user avatar
  • 566
7 votes
2 answers
2k views

Why does TensorFlow docs discourage using softmax as activation for the last layer?

The beginner colab example for tensorflow states: Note: It is possible to bake this tf.nn.softmax in as the activation function for the last layer of the network....
galah92's user avatar
  • 173
7 votes
1 answer
2k views

How to deal with losses on different scales in multi-task learning?

Say I'm training a model for multiple tasks by trying to minimize sum of losses $L_1 + L_2$ via gradient descent. If these losses are on a different scale, the one whose range is greater will dominate ...
SpiderRico's user avatar
  • 1,000
7 votes
2 answers
889 views

How should we interpret this figure that relates the perceptron criterion and the hinge loss?

I am currently studying the textbook Neural Networks and Deep Learning by Charu C. Aggarwal. Chapter 1.2.1.2 Relationship with Support Vector Machines says the following: The perceptron criterion is ...
The Pointer's user avatar
6 votes
1 answer
1k views

Why is the evidence equal to the KL divergence plus the loss?

Why is the equation $$\log p_{\theta}(x^1,...,x^N)=D_{KL}(q_{\theta}(z|x^i)||p_{\phi}(z|x^i))+\mathbb{L}(\phi,\theta;x^i)$$ true, where $x^i$ are data points and $z$ are latent variables? I was ...
user8714896's user avatar
6 votes
1 answer
5k views

What is the cost function of a transformer?

The paper Attention Is All You Need describes the transformer architecture that has an encoder and a decoder. However, I wasn't clear on what the cost function to minimize is for such an architecture. ...
user3667125's user avatar
  • 1,570
6 votes
1 answer
409 views

What is the formula used to calculate the loss in the FaceNet model?

The FaceNet model returns the loss of the predictions and ground-truth classes. How is this loss calculated?
TheReal__Mike's user avatar
6 votes
2 answers
4k views

What are the advantages of the Kullback-Leibler over the MSE/RMSE?

I've recently encountered different articles that are recommending to use the KL divergence instead of the MSE/RMSE (as the loss function), when trying to learn a probability distribution, but none of ...
razvanc92's user avatar
  • 1,128
5 votes
3 answers
307 views

Which function $(\hat{y} - y)^2$ or $(y - \hat{y})^2$ should I use to compute the gradient?

The MSE can be defined as $(\hat{y} - y)^2$, which should be equal to $(y - \hat{y})^2$, but I think their derivative is different, so I am confused of what derivative will I use for computing my ...
Jerico Bayod's user avatar
5 votes
3 answers
5k views

In logistic regression, why is the binary cross-entropy loss function convex?

I am studying logistic regression for binary classification. The loss function used is cross-entropy. For a given input $x$, if our model outputs $\hat{y}$ instead of $y$, the loss is given by $$\text{...
hanugm's user avatar
  • 3,840
5 votes
1 answer
156 views

Why is the mean used to compute the expectation in the GAN loss?

From Goodfellow et al. (2014), we have the adversarial loss: $$ \min_G \, \max_D V (D, G) = \mathbb{E}_{x∼p_{data}(x)} \, [\log \, D(x)] + \, \mathbb{E}_{z∼p_z(z)} \, [\log \, (1 − D(G(z)))] \, \text{...
A is for Ambition's user avatar
5 votes
1 answer
320 views

Loss function for choosing a subset of objects

I'm trying to train a neural net to choose a subset from some list of objects. The input is a list of objects $(a,b,c,d,e,f)$ and for each list of objects the label is a list composed of 0/1 - 1 for ...
Gilad Deutsch's user avatar
5 votes
2 answers
2k views

How to calculate the advantage in policy gradient functions?

From my understanding of the REINFORCE policy gradient method, we gently nudge the probabilities of actions based on the advantages. More specifically, the positive advantages increase the ...
Bob Kimani's user avatar
5 votes
1 answer
1k views

Why is the Jensen-Shannon divergence preferred over the KL divergence in measuring the performance of a generative network?

I have read articles on how Jensen-Shannon divergence is preferred over Kullback-Leibler in measuring how good a distribution mapping is learned in a generative network because of the fact that JS-...
ashenoy's user avatar
  • 1,409
5 votes
2 answers
1k views

Why does the clipped surrogate objective work in Proximal Policy Optimization?

In Proximal Policy Optimization Algorithms (2017), Schulman et al. write With this scheme, we only ignore the change in probability ratio when it would make the objective improve, and we include it ...
16Aghnar's user avatar
  • 601
5 votes
2 answers
5k views

How to check whether my loss function is convex or not?

Loss functions are useful in calculating loss and then we can update the weights of a neural network. The loss function is thus useful in training neural networks. Consider the following excerpt from ...
hanugm's user avatar
  • 3,840
5 votes
4 answers
2k views

How to stop DQN Q function from increasing during learning?

Following the DQN algorithm with experience replay: Store transition $\left(\phi_{t}, a_{t}, r_{t}, \phi_{t+1}\right)$ in $D$ Sample random minibatch of transitions $\left(\phi_{j}, a_{j}, r_{j}, \...
BestR's user avatar
  • 183
5 votes
1 answer
2k views

Which other loss functions for hierarchical multi-label classification could I use?

I am looking to try different loss functions for a hierarchical multi-label classification problem. So far, I have been training different models or submodels like multilayer perceptron (MLP) branch ...
Skinish's user avatar
  • 163
4 votes
3 answers
4k views

In which cases is the categorical cross-entropy better than the mean squared error?

In my code, I usually use the mean squared error (MSE), but the TensorFlow tutorials always use the categorical cross-entropy (CCE). Is the CCE loss function better than MSE? Or is it better only in ...
Dan D.'s user avatar
  • 1,283
4 votes
2 answers
132 views

Could error surface shape be useful to detect which local minima is better for generalization?

The following plot shows error function output based on system weights. Two equal local minima are shown in green pointers. Note that the red dots are not related to the question. Does the right one ...
hmojtaba's user avatar
4 votes
1 answer
375 views

What is the best way to combine or weight multiple losses with gradient descent?

I am optimizing a neural network with Adam using 3 different losses. Their scale is very different, and the current method is to either sum the losses and clip the gradient or to manually weight them ...
Simon's user avatar
  • 153
4 votes
1 answer
545 views

Is there a reason to choose regular momentum over Nesterov momentum for neural networks?

I've been reading about Nesterov momentum from here and it seems like a nice improvement over regular momentum with no extra cost whatsoever. However, is this really the case? Are there instances ...
SpiderRico's user avatar
  • 1,000
4 votes
1 answer
1k views

What are the necessary mathematical properties to be a loss function in gradient based optimizations?

Loss functions are used in training neural networks. I am interested in knowing the mathematical properties that are necessary for a loss function to participate in gradient descent optimization. I ...
hanugm's user avatar
  • 3,840
4 votes
1 answer
3k views

What's the difference between RMSE and Euclidean distance, and when to use a custom loss? [closed]

I'm searching for a loss function that fits my project. Actually, I have two questions, but they are in the same direction. I take a look at the definition of the root mean squared error (RMSE) and ...
basilisk's user avatar
  • 213
4 votes
1 answer
162 views

Why is the "square error function" sometimes defined with the constant 1/2 and sometimes with the constant 1/m?

Depending on the source, I find people using different variations of the "squared error function". How come that be? Here, it is defined as $$ E_{\text {total }}=\sum \frac{1}{2}(\text {...
Sebastian Nielsen's user avatar
4 votes
1 answer
5k views

How to understand 'losses' in Spacy's custom NER training engine?

From the tid-bits, I understand of neural networks (NN), the Loss function is the difference between predicted output and expected output of the NN. I am following this tutorial, the losses are ...
The White Cloud's user avatar
4 votes
1 answer
1k views

Alphazero policy head loss not decreasing

I am now working on training an alphazero player for a board game. The implementation of board game is mine, MCTS for alphazero was taken elsewhere. Due to complexity of the game, it takes a much ...
ytolochko's user avatar
  • 365
4 votes
1 answer
181 views

How to define a loss function for a classifier where the confusion between some classes is more important than the confusion between others?

I have a dataset of images belonging to $N$ classes, $A_1, A_2...A_n,B_1,B_2...B_m$ and I want to train a CNN to classify them. The classes can be considered as subclasses of two broader classes $A$ ...
firion's user avatar
  • 269
4 votes
2 answers
7k views

How do I calculate the gradient of the hinge loss function?

With reference to the research paper entitled Sentiment Embeddings with Applications to Sentiment Analysis, I am trying to implement its sentiment ranking model in Python, for which I am required to ...
Raj Shrivastava's user avatar
4 votes
1 answer
3k views

What is the impact of scaling the KL divergence and reconstruction loss in the VAE objective function?

Variational autoencoders have two components in their loss function. The first component is the reconstruction loss, which for image data, is the pixel-wise difference between the input image and ...
rich's user avatar
  • 151
4 votes
1 answer
291 views

How to add weights to one specific input feature to ensure fair training in the network?

I am trying to create a multiclass product-rating network based on product reviews and other input features. Two of the other input features are "product category" and "gender". However, I want to ...
nvrs's user avatar
  • 43
4 votes
1 answer
559 views

Why does the binary cross-entropy work better than categorical cross-entropy in a multi-class single label problem?

I was just doing a simple NN example with the fashion MNIST dataset, where I was getting 97% accuracy, when I noticed that I was using Binary cross-entropy instead of categorical cross-entropy by ...
joão correia's user avatar
4 votes
1 answer
648 views

What loss function should one use for object detection, knowing that the input image contains exactly one target object?

What loss function should one use, knowing that the input image contains exactly one target object? I am currently using MSE to predict the center of ROI coordinates and its width and height. All ...
don_pablito's user avatar
4 votes
0 answers
39 views

How do weights changes handles during back-propagation when there are unknown labels

I have a question about how weights are updated during back-propagation for some of my samples that have unknown labels (please note, unknown, not missing). The reason they are unknown is because this ...
user9317212's user avatar
4 votes
2 answers
2k views

How do we design a neural network such that the $L_1$ norm of the outputs is less than or equal to 1?

What are some ways to design a neural network with the restriction that the $L_1$ norm of the output values must be less than or equal to 1? In particular, how would I go about performing back-...
Kevvy Kim's user avatar
  • 141
3 votes
2 answers
7k views

In variational autoencoders, why do people use MSE for the loss?

In VAEs, we try to maximize the ELBO = $\mathbb{E}_q [\log\ p(x|z)] + D_{KL}(q(z \mid x), p(z))$, but I see that many implement the first term as the MSE of the image and its reconstruction. Here's a ...
IttayD's user avatar
  • 219
3 votes
3 answers
2k views

What's the function that SGD takes to calculate the gradient?

I'm struggling to fully understand the stochastic gradient descent algorithm. I know that gradient descent allows you to find the local minimum of a function. What I don't know is what exactly that ...
Orly's user avatar
  • 71
3 votes
2 answers
298 views

Where is the mistake in my derivation of the GAN loss function?

I was pondering on the loss function of GAN, and the following thing turned out \begin{aligned} L(D, G) & = \mathbb{E}_{x \sim p_{r}(x)} [\log D(x)] + \mathbb{E}_{x \sim p_g(x)} [\log(1 - D(x)] \...
Enes's user avatar
  • 314
3 votes
1 answer
3k views

What are the major differences between cost, loss, error, fitness, utility, objective, criterion functions?

I find the terms cost, loss, error, fitness, utility, objective, criterion functions to be interchangeable, but any kind of minor difference explained is appreciated.
Stephen Philip's user avatar
3 votes
1 answer
214 views

What loss function should I use if I only care about the accuracy of one class?

CrossEntropyLoss optimizes the overall classification accuracy as $$ {n_{\text{correct}} \over N} $$ What loss function should I use if I only care about increasing the true positive rate of one class?...
em1971's user avatar
  • 155
3 votes
1 answer
402 views

Why is the exponential loss used in this case?

I am reading the paper Tracking-by-Segmentation With Online Gradient Boosting Decision Tree. In Section 2.1, the paper says Given training examples, $\left\{\left(\mathbf{x}_{i}, y_{i}\right) \mid \...
Zhang Liao's user avatar
3 votes
1 answer
3k views

Are the training loss and validation loss plotted per sample or per batch?

I am using a CNN to train on some data, where training size = 21700 samples, and test size is 653 samples, and say I am using a batch_size of 500 (I am accounting for samples out of batch size as well)...
Burple's user avatar
  • 33

1
2 3 4 5 6