scalarProduct: Calculate the scalar product for functional data objects

Description Usage Arguments Details Value See Also Examples

View source: R/funDataMethods.R

Description

This function calculates the scalar product between two objects of the class funData, irregFunData and multiFunData. For univariate functions f,g on a domain T, the scalar product is defined as

\int_T f(t) g(t) dt

and for multivariate functions f,g on domains T_1,…,T_p, it is defined as

∑_{j = 1}^p \int_T_j f^{(j)}(t) g^{(j)}(t) dt.

As seen in the formula, the objects must be defined on the same domain. The scalar product is calculated pairwise for all observations, thus the objects must also have the same number of observations or one object may have only one observation (for which the scalar product is calculated with all observations of the other object)). Objects of the classes funData and irregFunData can be combined, see integrate for details.

Usage

1
scalarProduct(object1, object2, ...)

Arguments

object1, object2

Two objects of classfunData, irregFunData or multiFunData, for that the scalar product is to be calculated.

...

Additional parameters passed to integrate. For multiFunData objects, one can also pass a weight argument. See Details.

Details

For multiFunData one can pass an optional vector weight for calculating a weighted scalar product. This vector must have the same number of elements as the multiFunData objects and have to be non-negative with at least one weight that is different from 0. Defaults to 1 for each element. See also norm.

Value

A vector of length nObs(object1) (or nObs(object2), if object1 has only one observation), containing the pairwise scalar product for each observation.

See Also

integrate, norm,

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# create two funData objectw with 5 observations on [0,1]
f <- simFunData(N = 5, M = 7, eValType = "linear",
                eFunType = "Fourier", argvals = seq(0,1,0.01))$simData
g <- simFunData(N = 5, M = 4, eValType = "linear",
                eFunType = "Poly", argvals = seq(0,1,0.01))$simData
                
# calculate the scalar product
scalarProduct(f,g)

# the scalar product of an object with itself equals the squared norm
all.equal(scalarProduct(f,f), norm(f, squared = TRUE))

# This works of course also for multiFunData objects...
m <- multiFunData(f,g)
all.equal(scalarProduct(m,m), norm(m, squared = TRUE))

# ...and for irregFunData objects
i <- as.irregFunData(sparsify(f, minObs = 5, maxObs = 10))
all.equal(scalarProduct(i,i), norm(i, squared = TRUE))

# Scalar product between funData and irregFunData objects
scalarProduct(i,f)

# Weighted scalar product for multiFunData objects
scalarProduct(m,m, weight = c(1,2))

funData documentation built on Oct. 9, 2018, 5:04 p.m.