% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lisi.R
\name{compute_simpson_index}
\alias{compute_simpson_index}
\title{Compute Simpson index from a KNN graph}
\usage{
compute_simpson_index(
  D,
  knn_idx,
  batch_labels,
  perplexity = 15,
  tol = 1e-05,
  max_iter = 50
)
}
\arguments{
\item{D}{Numeric matrix of nearest-neighbor distances with neighbors in rows
and cells in columns.}

\item{knn_idx}{Integer matrix of nearest-neighbor indices with the same shape as \code{D}.
One-based indices are expected; zero-based indices are also accepted and converted automatically.}

\item{batch_labels}{Integer-like label vector of length equal to the number of cells.}

\item{perplexity}{Effective neighborhood size.
Defaults to \code{15}.}

\item{tol}{Tolerance used in the binary search for the target perplexity.
Defaults to \code{1e-5}.}

\item{max_iter}{Maximum number of binary-search iterations.
Defaults to \code{50}.}
}
\value{
A numeric vector containing the local Simpson index for each cell.
}
\description{
Given nearest-neighbor distances, nearest-neighbor indices,
and a categorical label for each cell,
compute the local Simpson index of each cell after matching the target perplexity.
}
\examples{
D <- matrix(
  c(0.1, 0.2, 0.2, 0.1,
    0.3, 0.4, 0.4, 0.3),
  nrow = 2,
  byrow = TRUE
)
knn_idx <- matrix(
  c(2, 1, 4, 3,
    3, 4, 2, 1),
  nrow = 2,
  byrow = TRUE
)
batch_labels <- c(1, 1, 2, 2)
compute_simpson_index(D, knn_idx, batch_labels, perplexity = 2)
}
