-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit, added BB discretizer
- Loading branch information
Showing
8 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Package: rPID | ||
Title: rPID - Partial information decompostion in R | ||
Version: 0.0.0.9000 | ||
Authors@R: person("Jens", "Preussner", email = "jens.preussner@mpi-bn.mpg.de", role = c("aut", "cre")) | ||
Description: Implements methods for calulating entropy, mutual information and higher order measures from information theory. | ||
Depends: R (>= 3.3.2) | ||
License: MIT | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Imports: rPython | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(bayesian_blocks) | ||
export(discretize.bb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#' Discretize a matrix using the bayesian blocks algorithm | ||
#' | ||
#' @param X Numerical matrix to be discretized column-wise. | ||
#' @param ... Additional parameters passed to bayesian_blocks | ||
#' | ||
#' @return A discretized matrix | ||
#' | ||
#' @export | ||
discretize.bb <- function(X, ...) { | ||
X <- as.matrix(X) | ||
|
||
ret <- apply(X, 2, function(x, ...) { | ||
bins <- bayesian_blocks(x, ...) | ||
bins[which.min(bins)] <- min(x) | ||
as.numeric(cut(x, breaks = bins, include.lowest = T)) | ||
}, ...) | ||
|
||
ret | ||
} | ||
|
||
#' Wrapper for astroML.density_estimation.bayesian_blocks | ||
#' | ||
#' @param t A numeric | ||
#' @param x A numeric | ||
#' @param sigma Data error | ||
#' @param fitness Fitness function | ||
#' @param kwargs A named list of ot <ther parameters | ||
#' | ||
#' @return array containing the (N+1) bin edges | ||
#' | ||
#' @export | ||
bayesian_blocks <- function(t, x=NULL, sigma=NULL, fitness="events", kwargs = list()) { | ||
if (!is.numeric(t)) { | ||
t <- as.numeric(t) | ||
} | ||
|
||
rPython::python.assign("t", t) | ||
rPython::python.exec("x = None") | ||
rPython::python.exec("sigma = None") | ||
|
||
if (!is.null(x)) { | ||
x <- as.numeric(x) | ||
rPython::python.assign("x", x) | ||
} | ||
if (!is.null(sigma)) { | ||
sigma <- as.numeric(sigma) | ||
rPython::python.assign("sigma", sigma) | ||
} | ||
|
||
fi <- match.arg(fitness, c("events", "regular_events", "measures")) | ||
rPython::python.assign("fitness", fi) | ||
|
||
rPython::python.exec("from astroML.density_estimation import bayesian_blocks") | ||
rPython::python.exec("bins = bayesian_blocks(t=t, x=x, sigma=sigma, fitness=fitness)") | ||
bins <- rPython::python.method.call("bins","tolist") | ||
bins | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: No | ||
SaveWorkspace: No | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source | ||
PackageRoxygenize: rd,collate,namespace |