# Maximize a cost function

**URL:** <https://discuss.pytorch.org/t/maximize-a-cost-function/4051>\
**Category:** Uncategorized\
**Created:** [June 15, 2017, 6:26pm UTC](https://discuss.pytorch.org/t/maximize-a-cost-function/4051 "2017-06-15T18:26:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakehanne](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/87869e/32.png) [@lakehanne](https://discuss.pytorch.org/u/lakehanne)\
**Post date:** [June 15, 2017, 6:26pm UTC](https://discuss.pytorch.org/t/maximize-a-cost-function/4051/1 "2017-06-15T18:26:54Z")

</div>

In the optim class, we always call `optimizer.step()` which I assume computes the loss after a minimization process. If we want to maximize a cost function, do we simply negate `optimizer.step()`?

---

<div class="post-metadata">

**Author:** ![fmassa](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fmassa/32/58_2.png) [@fmassa](https://discuss.pytorch.org/u/fmassa)\
**Post date:** [June 15, 2017, 7:22pm UTC](https://discuss.pytorch.org/t/maximize-a-cost-function/4051/2 "2017-06-15T19:22:07Z")

</div>

You negate your loss function, and you should be fine

---

<div class="post-metadata">

**Author:** ![lakehanne](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/87869e/32.png) [@lakehanne](https://discuss.pytorch.org/u/lakehanne)\
**Post date:** [June 15, 2017, 11:20pm UTC](https://discuss.pytorch.org/t/maximize-a-cost-function/4051/3 "2017-06-15T23:20:42Z")

</div>

It’s a None object. Isn’t it?
