Skip to content

L1 and L2 norms (Euclidean and taxicab lengths) #2562

Open
@bob-carpenter

Description

@bob-carpenter

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions