Learn R Programming

wavefunction (version 1.0.0)

dwavefunction: Wave Function Density

Description

Evaluate the density of a wave function model

Usage

dwavefunction(x, w, log = FALSE, amplitude = FALSE)

Arguments

x

a numeric vector

w

a vector of coefficients from wavefunction_fit

log

if TRUE, returns the log density instead of the density

amplitude

if TRUE, returns the amplitude (or the log of the absolute value of the amplitude) instead of the density. The density is the squared amplitude, but the amplitude may be positive or negative.

Value

a numeric vector of the same length as x

Details

The elements of the returned vector \(p\) are (when log and amplitude are FALSE): $$ p_i = \left(\sum_{k=0}^K \frac{w_{k+1}}{(\sqrt{\pi}2^k k!)^{1/2}} H_k(x_i) \right)^2 e^{-x_i^2} $$ Here, \(K\) is the maximum degree, equal to length(w)-1, and \(H_k\) is the Hermite polynomial of degree \(k\). Note that w, being an R vector, is one-indexed, so \(w_k\) is associated with the Hermite polynomial of degree \(k-1\).

See Also

Madeleine B. Thompson, “Wave function representation of probability distributions,” 2017, https://arxiv.org/abs/1712.07764.

Examples

Run this code
# NOT RUN {
  x <- rnorm(100)
  w <- wavefunction_fit(x, degree = 6)
  p <- dwavefunction(x, w)
# }

Run the code above in your browser using DataLab