From 002c0db3f99ac834c8714b2c5cc1872d8b8bf095 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Mon, 16 Dec 2019 16:36:51 +0100 Subject: [PATCH] Changed behavior of log(gamma(x)) --- NAMESPACE | 2 ++ R/calculatePopLogml.R | 13 +++++++------ R/log_gamma.R | 8 ++++++++ man/log_gamma.Rd | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 R/log_gamma.R create mode 100644 man/log_gamma.Rd diff --git a/NAMESPACE b/NAMESPACE index 470a155..e8c117d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,5 @@ # Generated by roxygen2: do not edit by hand +export(admix1) +export(calculatePopLogml) export(learn_simple_partition) diff --git a/R/calculatePopLogml.R b/R/calculatePopLogml.R index e58017e..bcd7a44 100644 --- a/R/calculatePopLogml.R +++ b/R/calculatePopLogml.R @@ -4,16 +4,17 @@ #' for the mean parameter. #' @param points points #' @param fii fii +#' @export calculatePopLogml <- function(points, fii) { n <- length(points) fuzzy_ones <- sum(points) fuzzy_zeros <- n - fuzzy_ones - val = log(gamma(1)) - - log(gamma(1 + n / fii)) + - log(gamma(0.5 + fuzzy_ones / fii)) + - log(gamma(0.5 + fuzzy_zeros / fii)) - - log(gamma(0.5)) - - log(gamma(0.5)) + val <- log_gamma(1) - + log_gamma(1 + n / fii) + + log_gamma(0.5 + fuzzy_ones / fii) + + log_gamma(0.5 + fuzzy_zeros / fii) - + log_gamma(0.5) - + log_gamma(0.5) return(val) } diff --git a/R/log_gamma.R b/R/log_gamma.R new file mode 100644 index 0000000..48b1ad6 --- /dev/null +++ b/R/log_gamma.R @@ -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) +} diff --git a/man/log_gamma.Rd b/man/log_gamma.Rd new file mode 100644 index 0000000..e0957ea --- /dev/null +++ b/man/log_gamma.Rd @@ -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 +}