exponentiate.fd: Powers of a functional data ('fd') object

View source: R/exponentiate.fd.R

exponentiate.fdR Documentation

Powers of a functional data ('fd') object

Description

Exponentiate a functional data object where feasible.

Usage

## S3 method for class 'fd'
e1 ^ e2
exponentiate.fd(e1, e2, tolint=.Machine$double.eps^0.75,
  basisobj=e1$basis,
  tolfd=sqrt(.Machine$double.eps)*
          sqrt(sum(e1$coefs^2)+.Machine$double.eps)^abs(e2),
  maxbasis=NULL, npoints=NULL)

Arguments

e1

object of class 'fd'.

e2

a numeric vector of length 1.

basisobj

reference basis

tolint

if abs(e2-round(e2))<tolint, we assume e2 is an integer. This simplifies the algorithm.

tolfd

the maximum error allowed in the difference between the direct computation eval.fd(e1)^e2 and the computed representation.

maxbasis

The maximum number of basis functions in growing referencebasis to achieve a fit within tolfd. Default = 2*nbasis12+1 where nbasis12 = nbasis of e1^floor(e2).

npoints

The number of points at which to compute eval.fd(e1)^e2 and the computed representation to evaluate the adequacy of the representation. Default = 2*maxbasis-1. For a max Fourier basis, this samples the highest frequency at all its extrema and zeros.

Details

If e1 has a B-spline basis, this uses the B-spline algorithm.

Otherwise it throws an error unless it finds one of the following special cases:

  • e2 = 0 Return an fd object with a constant basis that is everywhere 1

  • e2 is a positive integer to within tolint Multiply e1 by itself e2 times

  • e2 is positive and e1 has a Fourier basis e120 <- e1^floor(e2)

    outBasis <- e120$basis

    rng <- outBasis$rangeval

    Time <- seq(rng[1], rng[2], npoints)

    e1.2 <- predict(e1, Time)^e2

    fd1.2 <- smooth.basis(Time, e1.2, outBasis)$

    d1.2 <- (e1.2 - predict(fd1.2, Time))

    if(all(abs(d1.2)<tolfd))return(fd1.2)

    Else if(outBasis$nbasis<maxbasis) increase the size of outBasis and try again.

    Else write a warning with the max(abs(d1.2)) and return fd1.2.

Value

A function data object approximating the desired power.

See Also

arithmetic.fd basisfd, basisfd.product

Examples

##
## sin^2
##

basis3 <- create.fourier.basis(nbasis=3)
oldpar <- par(no.readonly=TRUE)
plot(basis3)
# max = sqrt(2), so
# integral of the square of each basis function (from 0 to 1) is 1
integrate(function(x)sin(2*pi*x)^2, 0, 1) # = 0.5

# sin(theta)
fdsin <- fd(c(0,sqrt(0.5),0), basis3)
plot(fdsin)

fdsin2 <- fdsin^2

# check
fdsinsin <- fdsin*fdsin
# sin^2(pi*time) = 0.5*(1-cos(2*pi*theta) basic trig identity
plot(fdsinsin) # good


all.equal(fdsin2, fdsinsin)

par(oldpar)


fda documentation built on May 31, 2023, 9:19 p.m.