{
  "id": 6734,
  "title": "Logistic regression layer cost function?",
  "url": "/competitions/galaxy-zoo-the-galaxy-challenge/discussion/6734",
  "author_name": "",
  "post_date": "2014-01-01T02:31:02.847Z",
  "votes": null,
  "comment_count": 5,
  "views": 2246,
  "content": "<p>I've been using this competition to work through the&nbsp;<a href=\"http://deeplearning.net/tutorial/logreg.html\">deep learning tutorial</a>&nbsp;using Theano. The tutorial using the MNIST dataset, which of course has discrete classes.</p>\n<p>In this case, we're learning and predicting the probabilities themselves. The tutorial uses negative log likelihood for a cost function, defined as</p>\n<p><code>-T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])</code></p>\n<p>Since we're trying to minimize the difference between the output of p_y_given_x and y (predict the correct likelihood interval), I tried this cost function:</p>\n<p><code> return -T.mean(T.log(T.abs_(self.p_y_given_x - y)))<br></code></p>\n<p>But that failed to converge.</p>\n<p>&nbsp;</p>\n<p>Am I thinking about this wrong? I'm having trouble coming up with another cost function.</p>",
  "messages": [
    {
      "id": "36887",
      "postDate": "01/01/2014 02:31:02",
      "content": "<p>I've been using this competition to work through the&nbsp;<a href=\"http://deeplearning.net/tutorial/logreg.html\">deep learning tutorial</a>&nbsp;using Theano. The tutorial using the MNIST dataset, which of course has discrete classes.</p>\n<p>In this case, we're learning and predicting the probabilities themselves. The tutorial uses negative log likelihood for a cost function, defined as</p>\n<p><code>-T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])</code></p>\n<p>Since we're trying to minimize the difference between the output of p_y_given_x and y (predict the correct likelihood interval), I tried this cost function:</p>\n<p><code> return -T.mean(T.log(T.abs_(self.p_y_given_x - y)))<br></code></p>\n<p>But that failed to converge.</p>\n<p>&nbsp;</p>\n<p>Am I thinking about this wrong? I'm having trouble coming up with another cost function.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "36890",
      "postDate": "01/01/2014 11:12:51",
      "content": "<p>Since the cost function the competition is being evaluated with is RMSE, it's a good idea to just use that, in my opinion :) There's no need to use a surrogate loss because the (R)MSE is easy to optimize.</p>\n<p>Also, due to the decision tree weighting scheme used, only the targets for questions 1 and 6 can really be thought of as probabilities. The other columns are products of probabilities.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "36894",
      "postDate": "01/01/2014 17:52:14",
      "content": "<p>Thanks for the tips. I was mistaken about my contrived cost function not converging at all. A combination of two things made it appear to be randomly fluctuating: my impatience to let it run long enough before deciding that it was not converging, and also I was running on a very small sample (40 images) with a batch size of 20, which gave it the appears of flip-flopping, because indeed it was.</p>\n<p>However, you are absolutely right about not using a proxy cost function. RSME is the way to go.</p>\n<p>Are you doing anything special in regards to the solutions being results of a decision tree or can I rely on the network to figure that out by just training with the RSME across all the solutions?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "36896",
      "postDate": "01/01/2014 19:51:44",
      "content": "<p>At the moment it seems that the data does not actually obey this decision tree structure all that well in practice ( see this post:&nbsp;http://www.kaggle.com/c/galaxy-zoo-the-galaxy-challenge/forums/t/6706/is-question-6-also-answered-for-stars-artifacts-answer-1-3/36798#post36798 ).</p>\n<p>So far I've tried both approaches taking into account these constraints, and approaches ignoring them, for now there is no clear winner.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "36900",
      "postDate": "01/02/2014 01:13:36",
      "content": "<p>What do you use for your class memberships for the training set for this sort of model?</p>\n<p>I see how to use the RMSE in place of the negative_log_likelihood method, but the model itself predicts which&nbsp;<em>class</em> each image falls into, and we are not determining a class but instead 37 values between 0 and 1. &nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "36901",
      "postDate": "01/02/2014 01:23:08",
      "content": "<p>The output of p_y_given_x gives the probabilities for classes 1-37: just what you want. Normally, a prediction function would just take the argmax of that.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 36890,
      "author_name": "sedielem",
      "author_url": "",
      "post_date": "01/01/2014 11:12:51",
      "content": "<p>Since the cost function the competition is being evaluated with is RMSE, it's a good idea to just use that, in my opinion :) There's no need to use a surrogate loss because the (R)MSE is easy to optimize.</p>\n<p>Also, due to the decision tree weighting scheme used, only the targets for questions 1 and 6 can really be thought of as probabilities. The other columns are products of probabilities.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 36894,
      "author_name": "zacstewart",
      "author_url": "",
      "post_date": "01/01/2014 17:52:14",
      "content": "<p>Thanks for the tips. I was mistaken about my contrived cost function not converging at all. A combination of two things made it appear to be randomly fluctuating: my impatience to let it run long enough before deciding that it was not converging, and also I was running on a very small sample (40 images) with a batch size of 20, which gave it the appears of flip-flopping, because indeed it was.</p>\n<p>However, you are absolutely right about not using a proxy cost function. RSME is the way to go.</p>\n<p>Are you doing anything special in regards to the solutions being results of a decision tree or can I rely on the network to figure that out by just training with the RSME across all the solutions?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 36896,
      "author_name": "sedielem",
      "author_url": "",
      "post_date": "01/01/2014 19:51:44",
      "content": "<p>At the moment it seems that the data does not actually obey this decision tree structure all that well in practice ( see this post:&nbsp;http://www.kaggle.com/c/galaxy-zoo-the-galaxy-challenge/forums/t/6706/is-question-6-also-answered-for-stars-artifacts-answer-1-3/36798#post36798 ).</p>\n<p>So far I've tried both approaches taking into account these constraints, and approaches ignoring them, for now there is no clear winner.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 36900,
      "author_name": "erikgregory",
      "author_url": "",
      "post_date": "01/02/2014 01:13:36",
      "content": "<p>What do you use for your class memberships for the training set for this sort of model?</p>\n<p>I see how to use the RMSE in place of the negative_log_likelihood method, but the model itself predicts which&nbsp;<em>class</em> each image falls into, and we are not determining a class but instead 37 values between 0 and 1. &nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 36901,
      "author_name": "zacstewart",
      "author_url": "",
      "post_date": "01/02/2014 01:23:08",
      "content": "<p>The output of p_y_given_x gives the probabilities for classes 1-37: just what you want. Normally, a prediction function would just take the argmax of that.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "36887": "",
    "36890": "",
    "36894": "",
    "36896": "",
    "36900": "",
    "36901": ""
  },
  "source": "meta"
}