pymc-devs / pymc-devs/pytensor

Reconsider min implementation as negative of max

Open
#904 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

maintenance Op implementation
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

For historical reasons pt.min returns pt.neg(pt.max(pt.neg(x))). This seems to have been the case mostly to avoid having to define Min Op and its gradient. There is a later "uncanonicalize" phase that converts those expressions to min, suggesting we prefer them, but don't put it in place because of the lack of gradient.

We should reassess this as is adds some unwelcome complexity. The L_op implementation (cleaned up in #901) works directly for min. R_op, on the other hand uses Argmax (not sure why this is needed in the forward but not backward pass, CC @aseyboldt), so a similar Min.R_op may need to use Argmin. Similar to Min that's currently implemented as Argmax of negative of x, which is probably fine? We could also consider a direct Argmin but that is not as ubiquitous and hence less annoying.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the current pt.min implementation through pt.neg(pt.max(pt.neg(x))) and the later uncanonicalize phase. Compare the existing Min L_op and R_op behavior, including Argmax and the possible Argmin alternative. Done means reaching a decided implementation approach with corresponding gradient behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.