inner_prod: Inner Product

Description Usage Arguments Details Examples

Description

Computes the inner product of two vectors (or two matrices) with a specified metric

Usage

1
  inner_prod(x, y, metric = NULL)

Arguments

x

numeric vector or matrix

y

numeric vector or matrix

metric

either NULL, a numeric vector, or a numeric square matrix

Details

x and y must be of same length or dimension.
If metric = NULL this means the identity metric.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# two vectors
u = 1:10
v = seq(0, 1, length.out = 10)

# identity metric
inner_prod(u, v)

# metric as vector
inner_prod(u, v, metric = rep(1/length(u), length(u)))

# metric as matrix
inner_prod(u, v, metric = diag(1/5, length(v)))

# two matrices
A = matrix(1:12, 4, 3)
B = matrix(seq(0, 1, length.out = 12), 4, 3)

inner_prod(A, B)
inner_prod(A, B, rep(0.3, 4))
inner_prod(A, B, metric = diag(1/2, nrow(A)))

gastonstat/matrixkit documentation built on May 16, 2019, 5:45 p.m.