Changed behavior of log(gamma(x))

This commit is contained in:
Waldir Leoncio 2019-12-16 16:36:51 +01:00
parent 27a296ad00
commit 002c0db3f9
4 changed files with 35 additions and 6 deletions

View file

@ -1,3 +1,5 @@
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export(admix1)
export(calculatePopLogml)
export(learn_simple_partition) export(learn_simple_partition)

View file

@ -4,16 +4,17 @@
#' for the mean parameter. #' for the mean parameter.
#' @param points points #' @param points points
#' @param fii fii #' @param fii fii
#' @export
calculatePopLogml <- function(points, fii) { calculatePopLogml <- function(points, fii) {
n <- length(points) n <- length(points)
fuzzy_ones <- sum(points) fuzzy_ones <- sum(points)
fuzzy_zeros <- n - fuzzy_ones fuzzy_zeros <- n - fuzzy_ones
val = log(gamma(1)) - val <- log_gamma(1) -
log(gamma(1 + n / fii)) + log_gamma(1 + n / fii) +
log(gamma(0.5 + fuzzy_ones / fii)) + log_gamma(0.5 + fuzzy_ones / fii) +
log(gamma(0.5 + fuzzy_zeros / fii)) - log_gamma(0.5 + fuzzy_zeros / fii) -
log(gamma(0.5)) - log_gamma(0.5) -
log(gamma(0.5)) log_gamma(0.5)
return(val) return(val)
} }

8
R/log_gamma.R Normal file
View file

@ -0,0 +1,8 @@
#' @title Log Gamma
#' @description Equal to log(gamma(x)) with special handling of x < 0 for
#' Matlab compatibility
#' @param x number
#' @return log(gamma(x)) for x > 0, Inf otherwise
log_gamma <- function(x) {
ifelse(x > 0, log(gamma(x)), Inf)
}

18
man/log_gamma.Rd Normal file
View file

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/log_gamma.R
\name{log_gamma}
\alias{log_gamma}
\title{Log Gamma}
\usage{
log_gamma(x)
}
\arguments{
\item{x}{number}
}
\value{
log(gamma(x)) for x > 0, Inf otherwise
}
\description{
Equal to log(gamma(x)) with special handling of x < 0 for
Matlab compatibility
}