% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classifiers.R
\name{bayes_depth_classify}
\alias{bayes_depth_classify}
\alias{print.fd_bayes_fit}
\title{Bayesian Kernel-Density Classifier on Signed Depth}
\usage{
bayes_depth_classify(
  X_train,
  y_train,
  X_test = NULL,
  priors = NULL,
  bw_method = "nrd0",
  grid = NULL,
  type = c("tukey", "simplicial")
)

\method{print}{fd_bayes_fit}(x, ...)
}
\arguments{
\item{X_train}{Numeric matrix (\eqn{n_{\mathrm{train}} \times M}).}

\item{y_train}{Integer vector of labels (0/1).}

\item{X_test}{Numeric matrix of test curves. If \code{NULL} the training
set is used.}

\item{priors}{Named numeric vector with elements \code{"0"} and \code{"1"}
giving prior probabilities. Defaults to empirical class proportions.}

\item{bw_method}{Bandwidth selection method passed to
\code{\link[stats]{density}}: \code{"nrd0"} (default), \code{"nrd"},
\code{"ucv"}, \code{"bcv"}, or \code{"SJ"}.}

\item{grid}{Numeric vector of length \eqn{M} (time grid).}

\item{type}{Depth variant.}

\item{x}{A \code{"fd_bayes_fit"} object.}

\item{...}{Ignored.}
}
\value{
An object of class \code{"fd_bayes_fit"} with components:
\describe{
\item{predicted}{Predicted class labels.}
\item{prob}{Matrix with columns \code{prob_0} and \code{prob_1}:
posterior probabilities.}
\item{log_odds}{Log-odds
\eqn{\log(f_0\pi_0 / f_1\pi_1)}.}
\item{sd_train}{The \code{"fd_signed_depth"} object for the training
set.}
}

Invisibly returns \code{x}.
}
\description{
Classifies functional curves via Bayes' rule applied to the signed depths.
Class-conditional densities \eqn{f_g(\mathrm{sdp})} are estimated by
kernel density estimation; prior probabilities are estimated from class
frequencies or supplied by the user.
}
\details{
The posterior probability that a new observation belongs to class \eqn{g}
is
\deqn{P(g \mid \mathrm{sdp}_0) =
  \frac{f_g(\mathrm{sdp}_0)\,\pi_g}
  {\sum_{g'} f_{g'}(\mathrm{sdp}_0)\,\pi_{g'}}.}
}
\examples{
set.seed(11)
M <- 80; N <- 100
t  <- seq(0, 1, length.out = M)
X0 <- t(replicate(50, sin(2 * pi * t) + rnorm(M, sd = 0.4)))
X1 <- t(replicate(50, cos(2 * pi * t) + rnorm(M, sd = 0.4)))
X  <- rbind(X0, X1)
y  <- rep(0:1, each = 50)
fit <- bayes_depth_classify(X, y)
table(fit$predicted, y)

}
