stan-dev / stan-dev/math

L1 and L2 norms (Euclidean and taxicab lengths)

Open
#2,562 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature good first issue
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Description

We should have L1 and L2 norm functions in the Stan language. They have to be implemented in the math library first, which is what this PR is for. We want the functions, but ideally we want custom derivatives.

real norm1(vector x);
real norm1(row_vector x);

real norm2(vector x);
real norm2(row_vector x);

The definitions are:

norm1(x)  =def=  sum(abs(x))
norm2(x)  =def=  sqrt(sum(square(x)))

The derivatives are:

d/dx norm1(x) = signum(x)
d/dx norm2(x) = x / norm2(x)
  • implement norm1 and norm2 in the Stan Math library with autodiff test framework tests
  • replace other uses that calculate vector lengths with norm2
    • unit_vector constrain
    • ???
Current Version:

v4.1.0

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 with the Stan Math library entry points for norm1 and norm2 and its autodiff test framework. Implement vector and row_vector forms using the definitions and derivatives in the issue, then verify autodiff tests; replacing existing vector-length calculations is an additional follow-up scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.