pymc-devs / pymc-devs/pytensor
Reconsider min implementation as negative of max
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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