scalarProduct: Calculate the scalar product for functional data objects

scalarProductR Documentation

Calculate the scalar product for functional data objects

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 \mathcal{T}, the scalar product is defined as

\int_\mathcal{T} f(t) g(t) \mathrm{d}t

and for multivariate functions f,g on domains \mathcal{T}_1, \ldots, \mathcal{T}_p, it is defined as

\sum_{j = 1}^p \int_{\mathcal{T}_j} f^{(j)}(t) g^{(j)}(t) \mathrm{d}t.

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

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

# 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 May 29, 2024, 6:08 a.m.