norm_vec: Compute the norm of a vector

Description Usage Arguments Details Value Author(s) Examples

Description

Computes the norm of a vector with size adjustment.

Usage

1
norm_vec(x, norm = c("L1", "L2", "Linf"))

Arguments

x

A numeric vector.

norm

The type of norm. See details.

Details

This function calculates the norm of a vector. It is slightly different from the ordinary norm function in that L1-norm and L2-norm are adjusted by the length of vector, n. To be specific, define a vector x = (x_1,x_2,...,x_n). The L1-norm is defined as

||x||_1 = (|x_1| + |x_2| + ... + |x_n|)/n.

The L2-norm is defined as

||x||_2 = (√{(x_1)^2 + (x_2)^2 + ... + (x_n)^2)/n.}

The Linf-norm is defined as

||x||_{∞} = \max(|x_1|,|x_2|,...,|x_n|).

Note that a matrix X will be coerced to a vector.

Value

A non-negative number.

Author(s)

Debin Qiu, Jeongyoun Ahn

Examples

1
2
3
4
5
6
7
8
9
x <- 1:10
# "L1" norm, same as norm(as.matrix(x), "1")*length(x)
norm_vec(x)

# "L2" norm
norm_vec(x, "L2")

# "Linf" norm, same as norm(as.matrix(x),"I")
norm_vec(x, "Linf")

deman007/grpss documentation built on May 15, 2019, 3:22 a.m.