| Title: | Learning Hybrid Bayesian Networks using Mixtures of Truncated Basis Functions |
|---|---|
| Description: | Learning, manipulation and evaluation of mixtures of truncated basis functions (MoTBFs), which include mixtures of polynomials (MOPs) and mixtures of truncated exponentials (MTEs). MoTBFs are a flexible framework for modelling hybrid Bayesian networks (I. Pérez-Bernabé, A. Salmerón, H. Langseth (2015) <doi:10.1007/978-3-319-20807-7_36>; H. Langseth, T.D. Nielsen, I. Pérez-Bernabé, A. Salmerón (2014) <doi:10.1016/j.ijar.2013.09.012>; I. Pérez-Bernabé, A. Fernández, R. Rumí, A. Salmerón (2016) <doi:10.1007/s10618-015-0429-7>). The package provides functionality for learning univariate, multivariate and conditional densities, with the possibility of incorporating prior knowledge. Structural learning of hybrid Bayesian networks is also provided. A set of useful tools is provided, including plotting, printing and likelihood evaluation. This package makes use of S3 objects, with two new classes called 'motbf' and 'jointmotbf'. |
| Authors: | Inmaculada Pérez-Bernabé [aut], Antonio Salmerón [aut], Thomas D. Nielsen [aut], Ángel T. Sáez-Ruiz [aut], Ana D. Maldonado [aut, cre] (ORCID: <https://orcid.org/0000-0001-8253-2526>) |
| Maintainer: | Ana D. Maldonado <[email protected]> |
| License: | GPL-3 |
| Version: | 2.0.1 |
| Built: | 2026-10-07 09:31:29 UTC |
| Source: | https://github.com/cran/MoTBFs |
This function builds a string with the structure of a 'mop' function.
asMOPString(parameters)asMOPString(parameters)
parameters |
A |
A "character" string with a 'mop' structure.
param <- c(1,2,3,4) asMOPString(param) param <- 3.4 asMOPString(param)param <- c(1,2,3,4) asMOPString(param) param <- 3.4 asMOPString(param)
This function builds a string with the structure of an 'mte' function.
asMTEString(parameters, num = 5)asMTEString(parameters, num = 5)
parameters |
A |
num |
A |
A "character" string with an 'mte' structure.
param <- -5.8 asMTEString(param) param <- c(5.2,0.3,-3,4) asMTEString(param)param <- -5.8 asMTEString(param) param <- c(5.2,0.3,-3,4) asMTEString(param)
Computes the Bayesian information criterion value (BIC) of a mixture of truncated basis functions. The BIC score is the log likelihood penalized by the number of parameters of the function and the number of records of the evaluated data.
BICMoTBF(Px, X)BICMoTBF(Px, X)
Px |
A function of class |
X |
A |
A "numeric" value corresponding to the BIC score.
## Data X <- rexp(10000) ## Data test Xtest <- rexp(1000) Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", nparam = 10); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 11); f2 ## BIC values BICMoTBF(Px = f1, X = Xtest) BICMoTBF(Px = f2, X = Xtest)## Data X <- rexp(10000) ## Data test Xtest <- rexp(1000) Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", nparam = 10); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 11); f2 ## BIC values BICMoTBF(Px = f1, X = Xtest) BICMoTBF(Px = f2, X = Xtest)
Compute the BIC score using more than one probability functions.
BICMultiFunctions(Px, X)BICMultiFunctions(Px, X)
Px |
A list of objects of class |
X |
A list with as many |
The "numeric" BIC value.
## Data X <- rnorm(500) Y <- rnorm(500, mean=1) data <- data.frame(X=X, Y=Y) ## Data as a "list" Xlist <- sapply(data, list) ## Learning as a "list" Plist <- lapply(data, univMoTBF, POTENTIAL_TYPE="MOP") Plist ## BIC value BICMultiFunctions(Px=Plist, X=Xlist)## Data X <- rnorm(500) Y <- rnorm(500, mean=1) data <- data.frame(X=X, Y=Y) ## Data as a "list" Xlist <- sapply(data, list) ## Learning as a "list" Plist <- lapply(data, univMoTBF, POTENTIAL_TYPE="MOP") Plist ## BIC value BICMultiFunctions(Px=Plist, X=Xlist)
Clean the memory. Delete all the objects in memory and a garbage collection takes place.
clean(envir = globalenv(), n = 2)clean(envir = globalenv(), n = 2)
envir |
The currently active environment; by default It is the gloval environment. |
n |
Number of garbage collection repetitions; by default |
## Run to clean the environment clean() clean(n=2)## Run to clean the environment clean() clean(n=2)
"jointmotbf" objectExtracts the parameters of a joint MoTBF density.
## S3 method for class 'jointmotbf' coef(object, ...)## S3 method for class 'jointmotbf' coef(object, ...)
object |
An object of class |
... |
Other arguments, unnecessary for this function. |
A "numeric" vector with the parameters of the function.
## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint function dim <-c(2,4) P <- jointmotbf.fit(data, dimensions = dim) P$Time ## Coefficients coef(P)## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint function dim <-c(2,4) P <- jointmotbf.fit(data, dimensions = dim) P$Time ## Coefficients coef(P)
It extracts the parameters of the learned mixtures of polynomial models.
coeffMOP(fx) coeffPol(fx)coeffMOP(fx) coeffPol(fx)
fx |
An |
coeffMOP() return the coefficients of the terms in the function.
coeffPol() returns the coefficients of the potential of the polynomial basis in the function.
An array with the parameters of the function.
coef.motbf and univMoTBF
## 1. EXAMPLE data <- rchisq(1000, df=5) fx1 <- univMoTBF(data, POTENTIAL_TYPE = "MOP") hist(data, prob=TRUE, main="") plot(fx1, xlim=range(data), col="red", add=TRUE) coeffMOP(fx1) ## coef(fx1) coeffPol(fx1) ## 2. EXAMPLE data <- rexp(1000, rate=1/2) fx2 <- univMoTBF(data, POTENTIAL_TYPE = "MOP") hist(data, prob=TRUE, main="") plot(fx2, xlim=range(data), col="red", add=TRUE) coeffMOP(fx2) ## coef(fx2) coeffPol(fx2)## 1. EXAMPLE data <- rchisq(1000, df=5) fx1 <- univMoTBF(data, POTENTIAL_TYPE = "MOP") hist(data, prob=TRUE, main="") plot(fx1, xlim=range(data), col="red", add=TRUE) coeffMOP(fx1) ## coef(fx1) coeffPol(fx1) ## 2. EXAMPLE data <- rexp(1000, rate=1/2) fx2 <- univMoTBF(data, POTENTIAL_TYPE = "MOP") hist(data, prob=TRUE, main="") plot(fx2, xlim=range(data), col="red", add=TRUE) coeffMOP(fx2) ## coef(fx2) coeffPol(fx2)
Extracts the parameters of the learned mixtures of truncated basis functions.
## S3 method for class 'motbf' coef(object, ...)## S3 method for class 'motbf' coef(object, ...)
object |
An object of class |
... |
other arguments. |
A numeric vector with the parameters of the function.
univMoTBF, coeffMOP and coeffMTE
## Data X <- rchisq(2000, df = 5) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); f1 ## Coefficients coef(f1) ## Learning f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 10); f2 ## Coefficients coef(f2) ## Learning f3 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", nparam=10); f3 ## Coefficients coef(f3) ## Plots plot(NULL, xlim = range(X), ylim = c(0,0.2), xlab="X", ylab="density") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) plot(f3, xlim = range(X), col = 3, add = TRUE) hist(X, prob = TRUE, add= TRUE)## Data X <- rchisq(2000, df = 5) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); f1 ## Coefficients coef(f1) ## Learning f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 10); f2 ## Coefficients coef(f2) ## Learning f3 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", nparam=10); f3 ## Coefficients coef(f3) ## Plots plot(NULL, xlim = range(X), ylim = c(0,0.2), xlab="X", ylab="density") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) plot(f3, xlim = range(X), col = 3, add = TRUE) hist(X, prob = TRUE, add= TRUE)
It extracts the parameters of the learned mixtures of truncated exponential models.
coeffMTE(fx) coeffExp(fx)coeffMTE(fx) coeffExp(fx)
fx |
An |
coeffMOP() return the coefficients of the terms in the function.
coeffPol() returns the coefficients of the potential of the exponential basis in the function.
An array with the parameters of the function.
coef.motbf and univMoTBF
## 1. EXAMPLE data <- rnorm(1000, mean=5) fx1 <- univMoTBF(data, POTENTIAL_TYPE = "MTE") hist(data, prob=TRUE, main="") plot(fx1, xlim=range(data), col="red", add=TRUE) coeffMTE(fx1) ## coef(fx1) coeffExp(fx1) ## 2. EXAMPLE data <- rexp(1000, rate=1/2) fx2 <- univMoTBF(data, POTENTIAL_TYPE = "MTE") hist(data, prob=TRUE, main="") plot(fx2, xlim=range(data), col="red", add=TRUE) coeffMTE(fx2) ## coef(fx2) coeffExp(fx2)## 1. EXAMPLE data <- rnorm(1000, mean=5) fx1 <- univMoTBF(data, POTENTIAL_TYPE = "MTE") hist(data, prob=TRUE, main="") plot(fx1, xlim=range(data), col="red", add=TRUE) coeffMTE(fx1) ## coef(fx1) coeffExp(fx1) ## 2. EXAMPLE data <- rexp(1000, rate=1/2) fx2 <- univMoTBF(data, POTENTIAL_TYPE = "MTE") hist(data, prob=TRUE, main="") plot(fx2, xlim=range(data), col="red", add=TRUE) coeffMTE(fx2) ## coef(fx2) coeffExp(fx2)
Converts 'motbf' and 'jointmotbf' objects into character string expressions or executable R functions.
## S3 method for class 'motbf' as.character(x, ...) ## S3 method for class 'motbf' as.function(x, ...) ## S3 method for class 'jointmotbf' as.character(x, ...) ## S3 method for class 'jointmotbf' as.function(x, ...)## S3 method for class 'motbf' as.character(x, ...) ## S3 method for class 'motbf' as.function(x, ...) ## S3 method for class 'jointmotbf' as.character(x, ...) ## S3 method for class 'jointmotbf' as.function(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. Not used currently. |
as.character: Returns a character string representing the mathematical expression of the object.
as.function: Returns an executable R function that accepts numeric arguments to evaluate the MoTBF expression.
## Example 1 X <- rchisq(5000, df = 3) P <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); P as.function(P)(10) ## Example 2 data <- data.frame(X = rnorm(100), Y = rexp(100)) dim <- c(3,2) P <- jointmotbf.fit(data, dimensions = dim) density <- as.function(P)(data[,1], data[,2]) sum(log(density))## Example 1 X <- rchisq(5000, df = 3) P <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); P as.function(P)(10) ## Example 2 data <- data.frame(X = rnorm(100), Y = rexp(100)) dim <- c(3,2) P <- jointmotbf.fit(data, dimensions = dim) density <- as.function(P)(data[,1], data[,2]) sum(log(density))
Collection of functions used for learning conditional MoTBFs, computing the internal BIC, selecting the parents that get the best BIC value, and other internal functions required to learn the conditional densities.
conditionalMethod( data, nameParents, nameChild, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) conditional( data, nameParents, nameChild, domainChild, domainParents, numIntervals, mm, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) select( data, nameParents, nameChild, domainChild, domainParents, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) learn.tree.Intervals( data, nameParents, nameChild, domainParents, domainChild, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) BICscoreMoTBF(conditionalfunction, data, nameParents, nameChild)conditionalMethod( data, nameParents, nameChild, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) conditional( data, nameParents, nameChild, domainChild, domainParents, numIntervals, mm, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) select( data, nameParents, nameChild, domainChild, domainParents, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) learn.tree.Intervals( data, nameParents, nameChild, domainParents, domainChild, numIntervals, POTENTIAL_TYPE, maxParam = NULL, s = NULL, priorData = NULL, scale = FALSE ) BICscoreMoTBF(conditionalfunction, data, nameParents, nameChild)
data |
An object of class |
nameParents |
A |
nameChild |
A |
numIntervals |
A positive integer indicating the maximum number of intervals for splitting the domain of the parent variables. |
POTENTIAL_TYPE |
A |
maxParam |
A positive integer which indicates the maximum number of coefficients in the
function. If specified, the output is the function which gets the best BIC with, at most,
this number of parameters. By default, it is set to |
s |
A |
priorData |
An object of class |
scale |
A |
domainChild |
A |
domainParents |
An object of class |
mm |
One of the inputs and the output of the recursive internal function |
conditionalfunction |
The output of the internal function |
The main function, conditionalMethod(), fits truncated basis functions for the conditioned variable
for each configuration of splits of the parent variables. The domain of the parent variables is splitted
in different intervals and univariate functions are fitted in these
ranges. The remaining above described functions are internal to the main function.
The main function conditionalMethod returns a list with the name of the parents,
the different intervals and the fitted densities
## Dataset X <- rnorm(1000) Y <- rbeta(1000, shape1 = abs(X)/2, shape2 = abs(X)/2) Z <- rnorm(1000, mean = Y) data <- data.frame(X = X, Y = Y, Z = Z) ## Conditional Method parents <- c("X","Y") child <- "Z" intervals <- 2 potential <- "MTE" fMTE <- conditionalMethod(data, nameParents = parents, nameChild = child, numIntervals = intervals, POTENTIAL_TYPE = potential) printConditional(fMTE) ############################################################################## potential <- "MOP" fMOP <- conditionalMethod(data, nameParents = parents, nameChild = child, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 15) printConditional(fMOP) ############################################################################## ############################################################################## ## Internal functions: Not needed to run ##################################### ############################################################################## domainP <- lapply(parents, function(i)range(data[,i])) names(domainP) = parents domainC <- range(data[, child]) t <- conditional(data, nameParents = parents, nameChild = child, domainParents = domainP, domainChild = domainC, numIntervals = intervals, mm = NULL, POTENTIAL_TYPE = potential) printConditional(t) selection <- select(data, nameParents = parents, nameChild = child, domainParents = domainP, domainChild = domainC, numIntervals = intervals, POTENTIAL_TYPE = potential) parent1 <- selection$parent; parent1 domainParent1 <- range(data[,parent1]) treeParent1 <- learn.tree.Intervals(data, nameParents = parent1, nameChild = child, domainParents = domainParent1, domainChild = domainC, numIntervals = intervals, POTENTIAL_TYPE = potential) BICscoreMoTBF(treeParent1, data, nameParents = parent1, nameChild = child) ############################################################################### ################################################################################# Dataset X <- rnorm(1000) Y <- rbeta(1000, shape1 = abs(X)/2, shape2 = abs(X)/2) Z <- rnorm(1000, mean = Y) data <- data.frame(X = X, Y = Y, Z = Z) ## Conditional Method parents <- c("X","Y") child <- "Z" intervals <- 2 potential <- "MTE" fMTE <- conditionalMethod(data, nameParents = parents, nameChild = child, numIntervals = intervals, POTENTIAL_TYPE = potential) printConditional(fMTE) ############################################################################## potential <- "MOP" fMOP <- conditionalMethod(data, nameParents = parents, nameChild = child, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 15) printConditional(fMOP) ############################################################################## ############################################################################## ## Internal functions: Not needed to run ##################################### ############################################################################## domainP <- lapply(parents, function(i)range(data[,i])) names(domainP) = parents domainC <- range(data[, child]) t <- conditional(data, nameParents = parents, nameChild = child, domainParents = domainP, domainChild = domainC, numIntervals = intervals, mm = NULL, POTENTIAL_TYPE = potential) printConditional(t) selection <- select(data, nameParents = parents, nameChild = child, domainParents = domainP, domainChild = domainC, numIntervals = intervals, POTENTIAL_TYPE = potential) parent1 <- selection$parent; parent1 domainParent1 <- range(data[,parent1]) treeParent1 <- learn.tree.Intervals(data, nameParents = parent1, nameChild = child, domainParents = domainParent1, domainChild = domainC, numIntervals = intervals, POTENTIAL_TYPE = potential) BICscoreMoTBF(treeParent1, data, nameParents = parent1, nameChild = child) ############################################################################### ###############################################################################
Computes the confusion matrix for a given fitted model object.
confusionMatrix(x, ...) ## S3 method for class 'motbf_fit_cv' confusionMatrix(x, digits = 4, ...)confusionMatrix(x, ...) ## S3 method for class 'motbf_fit_cv' confusionMatrix(x, digits = 4, ...)
x |
An object used to select the appropriate method, such as one of class |
... |
Further arguments. Not used currently. |
digits |
An integer indicating the number of decimal places to round the results. |
A matrix or table containing the confusion matrix.
Collection of functions for discretizing, standardizing, converting factors to characters and other usufull methods for pre-processing datasets.
whichDiscrete(dataset, discreteVariables) discreteVariables_as.character(dataset, discreteVariables) standardizeDataset(dataset) discretizeVariablesEWdis(dataset, numIntervals, factor = FALSE, binary = FALSE) discreteVariablesStates(namevariables, discreteData) nstates(DiscreteVariablesStates) quantileIntervals(X, numIntervals) scaleData(dataset, scale)whichDiscrete(dataset, discreteVariables) discreteVariables_as.character(dataset, discreteVariables) standardizeDataset(dataset) discretizeVariablesEWdis(dataset, numIntervals, factor = FALSE, binary = FALSE) discreteVariablesStates(namevariables, discreteData) nstates(DiscreteVariablesStates) quantileIntervals(X, numIntervals) scaleData(dataset, scale)
dataset |
A dataset of class |
discreteVariables |
A |
numIntervals |
Number of bins used to discretize the continuous variables. |
factor |
A boolean value indicating if the variables should be considered as
|
binary |
By default it is set to |
namevariables |
an array with the names of the varibles. |
discreteData |
A discretized dataset of class |
DiscreteVariablesStates |
The output of the function |
X |
A |
scale |
A |
whichDiscrete() selects the position of the discrete variables.
discreteVariables_as.character() transforms the values of the discrete variables into character values.
standardizeDataset() standardizes all the variables in a data set.
discretizeVariablesEWdis() discretizes the continuous variables in a dataset using
equal width binning.
discreteVariablesStates() extracts the states of the qualitative variables.
nstates() computes the number of different values of the discrete variables.
quantileIntervals() gets the quantiles of a variable taking into account the number of intervals
into which its domain is splitted.
## dataset: 2 continuous variables, 1 discrete variable. data <- data.frame(X = rnorm(100),Y = rexp(100,1/2), Z = as.factor(rep(c("s","a"), 50))) disVar <- "Z" ## Discrete variable class(data[,disVar]) ## factor data <- discreteVariables_as.character(dataset = data, discreteVariables = disVar) class(data[,disVar]) ## character whichDiscrete(dataset = data, discreteVariables = "Z") standData <- standardizeDataset(dataset = data) disData <- discretizeVariablesEWdis(dataset = data, numIntervals = 3) l <- discreteVariablesStates(namevariables = names(data), discreteData = disData) nstates(DiscreteVariablesStates = l) ## Continuous variables quantileIntervals(X = data[,1], numIntervals = 4) quantileIntervals(X = data[,2], numIntervals = 10)## dataset: 2 continuous variables, 1 discrete variable. data <- data.frame(X = rnorm(100),Y = rexp(100,1/2), Z = as.factor(rep(c("s","a"), 50))) disVar <- "Z" ## Discrete variable class(data[,disVar]) ## factor data <- discreteVariables_as.character(dataset = data, discreteVariables = disVar) class(data[,disVar]) ## character whichDiscrete(dataset = data, discreteVariables = "Z") standData <- standardizeDataset(dataset = data) disData <- discretizeVariablesEWdis(dataset = data, numIntervals = 3) l <- discreteVariablesStates(namevariables = names(data), discreteData = disData) nstates(DiscreteVariablesStates = l) ## Continuous variables quantileIntervals(X = data[,1], numIntervals = 4) quantileIntervals(X = data[,2], numIntervals = 10)
Compute the derivative of an "motbf" object with 'mop' subclass.
derivMOP(fx)derivMOP(fx)
fx |
An |
The derivative which is also an "motbf" function.
univMoTBF for learning and derivMoTBF for
general "motbf" models.
## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMOP(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMOP(Px) ## Not run: ## 3. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMOP(Px) ## Error in derivMOP(Px): fx is an 'motbf' function but not 'mop' subclass. class(Px) subclass(Px) ## End(Not run)## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMOP(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMOP(Px) ## Not run: ## 3. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMOP(Px) ## Error in derivMOP(Px): fx is an 'motbf' function but not 'mop' subclass. class(Px) subclass(Px) ## End(Not run)
Compute the derivative of a one-dimensional mixture of truncated basis function.
derivMoTBF(fx)derivMoTBF(fx)
fx |
An object of class |
The derivative of the MoTBF function, which is also
an object of class "motbf".
univMoTBF, derivMOP and derivMTE
## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMoTBF(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMoTBF(Px) ## 3. EXAMPLE X <- rchisq(1000, df = 3) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMoTBF(Px) ## Not run: ## 4. EXAMPLE Px <- "x+2" class(Px) derivMoTBF(Px) ## Error in derivMoTBF(Px): "fx is not an 'motbf' function." ## End(Not run)## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMoTBF(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMoTBF(Px) ## 3. EXAMPLE X <- rchisq(1000, df = 3) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMoTBF(Px) ## Not run: ## 4. EXAMPLE Px <- "x+2" class(Px) derivMoTBF(Px) ## Error in derivMoTBF(Px): "fx is not an 'motbf' function." ## End(Not run)
Compute the derivative of an "motbf" object with 'mte' subclass.
derivMTE(fx)derivMTE(fx)
fx |
An |
The derivative which is also an "motbf" function.
univMoTBF for learning and derivMoTBF for
general "motbf" models.
## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMTE(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMTE(Px) ## Not run: ## 3. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMTE(Px) ## Error in derivMTE(Px): fx is an 'motbf' function but not 'mte' subclass. class(Px) subclass(Px) ## End(Not run)## 1. EXAMPLE X <- rexp(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMTE(Px) ## 2. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MTE") derivMTE(Px) ## Not run: ## 3. EXAMPLE X <- rnorm(1000) Px <- univMoTBF(X, POTENTIAL_TYPE="MOP") derivMTE(Px) ## Error in derivMTE(Px): fx is an 'motbf' function but not 'mte' subclass. class(Px) subclass(Px) ## End(Not run)
Get the dimension of "motbf" and "jointmotbf" densities.
This function is deprecated; use "getMotbfDim" instead.
dimensionFunction(P)dimensionFunction(P)
P |
An object of class |
Dimension of the function.
univMoTBF and jointMoTBF
This function returns the states of all discrete node from a list obtained from motbf.fit.
discreteStatesFromBN(bn)discreteStatesFromBN(bn)
bn |
A list of lists obtained from motbf.fit. |
discreteStatesFromBN returns a list of length equal to the number of discrete nodes in the network. Each element of the list corresponds to a node and contains a character vector indicating the states of the node.
## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn a BN bn <- motbf.fit(dag, data, POTENTIAL_TYPE = "MTE") ## Get the states of the discrete nodes discreteStatesFromBN(bn)## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn a BN bn <- motbf.fit(dag, data, POTENTIAL_TYPE = "MTE") ## Get the states of the discrete nodes discreteStatesFromBN(bn)
This data set contains information of Escherichia coli. It is a bacterium of the genus Escherichia that is commonly found in the lower intestine of warm-blooded organism.
A data frame with 336 rows, 8 variables and the class.
Accession number for the SWISS-PROT database.
McGeoch's method for signal sequence recognition.
Von Heijne's method for signal sequence recognition.
Von Heijne's Signal Peptidase II consensus sequence score. Binary attribute.
Presence of charge on N-terminus of predicted lipoproteins. Binary attribute.
Score of discriminant analysis of the amino acid content of outer membrane and periplasmic proteins.
Score of the ALOM membrane spanning region prediction program.
Score of ALOM program after excluding putative cleavable signal regions from the sequence.
Class variable. 8 possibles states.
http://archive.ics.uci.edu/ml/datasets/Ecoli
Evaluates a univariate ("mop", "mte") or joint distribution ("jointmotbf") at a specific point.
eval.motbf(P, values)eval.motbf(P, values)
P |
An object of class |
values |
A list with the name of the variables equal to the values to be evaluated. |
If all the variables in the equation are evaluated, then a "numeric" value
is returned. Otherwise, an "univmotbf" object or a "jointmotbf" object is returned.
#' ## 1. EXAMPLE ## Dataset with 2 variables X <- data.frame(rnorm(100), rexp(100)) ## Joint function dim <- c(3,3) # dim <- c(5,4) P <- jointmotbf.fit(X, dimensions = dim) ## Evaluation val <- list(x = -1.5, y = 3) eval.motbf(P, values = val) val <- list(x = -1.5) eval.motbf(P, values = val) val <- list(y = 3) eval.motbf(P, values = val) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Dataset with 3 variables X <- data.frame(x = rnorm(100), y = rexp(100), z = rnorm(100, 1)) ## Joint function dim <- c(2,1,3) P <- jointmotbf.fit(X, dimensions = dim) P ## Evaluation val <- list(x = 0.8, y = -2.1, z = 1.2) eval.motbf(P, values = val) val <- list(x = 0.8, y = 1.2) eval.motbf(P, values = val) val <- list(y = -2.1) eval.motbf(P, values = val)#' ## 1. EXAMPLE ## Dataset with 2 variables X <- data.frame(rnorm(100), rexp(100)) ## Joint function dim <- c(3,3) # dim <- c(5,4) P <- jointmotbf.fit(X, dimensions = dim) ## Evaluation val <- list(x = -1.5, y = 3) eval.motbf(P, values = val) val <- list(x = -1.5) eval.motbf(P, values = val) val <- list(y = 3) eval.motbf(P, values = val) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Dataset with 3 variables X <- data.frame(x = rnorm(100), y = rexp(100), z = rnorm(100, 1)) ## Joint function dim <- c(2,1,3) P <- jointmotbf.fit(X, dimensions = dim) P ## Evaluation val <- list(x = 0.8, y = -2.1, z = 1.2) eval.motbf(P, values = val) val <- list(x = 0.8, y = 1.2) eval.motbf(P, values = val) val <- list(y = -2.1) eval.motbf(P, values = val)
Evaluates a "jointmotbf" object at a specific point.
This function is deprecated; use "eval.mop" instead.
evalJointFunction(P, values)evalJointFunction(P, values)
P |
A |
values |
A list with the name of the variables equal to the values to be evaluated. |
If all the variables in the equation are evaluated then a "numeric" value
is returned. Otherwise, an "motbf" object or a "jointmotbf" object is returned.
Computes the expected value (mean) of a Mixture of Polynomials (MoP) function over its domain.
expectedValueMOP(fx)expectedValueMOP(fx)
fx |
An object of class |
A numeric value representing the expected value of the distribution.
Computes the expected value (mean) of a Mixture of Truncated Exponentials (MTE) function over its domain.
expectedValueMTE(fx)expectedValueMTE(fx)
fx |
An object of class |
A numeric value representing the expected value of the distribution.
This function returns the conditional probability function of a node given an MoTBF-bayesian network and the value of its parents.
findConditional(node, bn, evi = NULL)findConditional(node, bn, evi = NULL)
node |
A |
bn |
A list of lists obtained from MoTBFs_Learning, containing the conditional functions. |
evi |
A |
A list containing the conditional distribution of the target variable.
## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- MoTBFs_Learning(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MTE") ## Specify the evidence set and node of interest evi <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE) node = "alm2" ## Get the conditional distribution findConditional(node, bn, evi)## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- MoTBFs_Learning(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MTE") ## Specify the evidence set and node of interest evi <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE) node = "alm2" ## Get the conditional distribution findConditional(node, bn, evi)
Generate a prior dataset taking in to account the relationships between the varibles in a given network.
generateNormalPriorData(graph, data, size, means, deviations = NULL)generateNormalPriorData(graph, data, size, means, deviations = NULL)
graph |
A network of the class |
data |
An object of class |
size |
A positive integer indicating the number of records to generate for each variable in the dataset. |
means |
A |
deviations |
A |
A normal prior data set of class "data.frame".
## Data data(ecoli) data <- ecoli[,-c(1,9)] ## remove sequece.name and class X <- TrainingandTestData(data, percentage_test = 0.95) Xtraining <- X$Training Xtest <- X$Test ## DAG dag <- LearningHC(data) plot(dag) ## Means and desviations colnames(data) m <- sapply(data, function(x){ifelse(is.numeric(x), mean(x),NA)}) d <- sapply(data, function(x){ifelse(is.numeric(x), sd(x),NA)}) ## Prior Dataset n <- 5600 priorData <- generateNormalPriorData(dag, data = Xtraining, size = n, means = m) summary(priorData) ncol(priorData) nrow(priorData) class(priorData)## Data data(ecoli) data <- ecoli[,-c(1,9)] ## remove sequece.name and class X <- TrainingandTestData(data, percentage_test = 0.95) Xtraining <- X$Training Xtest <- X$Test ## DAG dag <- LearningHC(data) plot(dag) ## Means and desviations colnames(data) m <- sapply(data, function(x){ifelse(is.numeric(x), mean(x),NA)}) d <- sapply(data, function(x){ifelse(is.numeric(x), sd(x),NA)}) ## Prior Dataset n <- 5600 priorData <- generateNormalPriorData(dag, data = Xtraining, size = n, means = m) summary(priorData) ncol(priorData) nrow(priorData) class(priorData)
get_approx_posterior() returns an approximation to the posterior probability distribution
of a target variable given a set of observed variables. The inference process is based on sample generation. See details.
get_approx_posterior( bn, target, evidence = NULL, size = 100, parallel = FALSE, ... )get_approx_posterior( bn, target, evidence = NULL, size = 100, parallel = FALSE, ... )
bn |
An object of class |
target |
A character string equal to the name of the variable of interest. |
evidence |
A |
size |
A non-negative integer giving the number of random samples to generate from |
parallel |
|
... |
Optional arguments passed on to the |
If any node is observed, i.e., argument evidence is not NULL,
samples are generated from the Bayesian network using the likelihood weighting algorithm.
Otherwise, i.e., no node is observed, samples are generated using the forward sampling algorithm.
A list of two elements: 1) the posterior probability distribution of the target variable, and
2) a data.frame with the generated sample, whose weights are attached as an attribute called weights (if evidence is not NULL).
Henrion, M. (1988). Propagating uncertainty in Bayesian networks by probabilistic logic sampling. In Machine Intelligence and Pattern Recognition (Vol. 5, pp. 149-163). North-Holland.
## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP") ## Specify the evidence set and target variable obs <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE) node <- "alm2" ## Get the posterior distribution of 'node' given "evidence" and the generated sample get_approx_posterior(bn, target = node, evidence = obs, size = 10, maxParam = 15)## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP") ## Specify the evidence set and target variable obs <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE) node <- "alm2" ## Get the posterior distribution of 'node' given "evidence" and the generated sample get_approx_posterior(bn, target = node, evidence = obs, size = 10, maxParam = 15)
Compute the parents of each variable in the graph.
getChildParentsFromGraph(graph, nameVars = NULL)getChildParentsFromGraph(graph, nameVars = NULL)
graph |
A directed acyclic graph of the class |
nameVars |
A character array containing the names of the variables in the graph.
This parameter is only used when |
A list where each element is a vector containing the name of a variable and its parents in the graph.
## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- LearningHC(ecoli) dag1 plot(dag1) getChildParentsFromGraph(dag1) ## DAG2 dag2 <- LearningHC(ecoli, numIntervals = 10) dag2 plot(dag2) getChildParentsFromGraph(dag2)## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- LearningHC(ecoli) dag1 plot(dag1) getChildParentsFromGraph(dag1) ## DAG2 dag2 <- LearningHC(ecoli, numIntervals = 10) dag2 plot(dag2) getChildParentsFromGraph(dag2)
Compute the coefficients for the linear opinion pool
getCoefficients(fPI, rangeNewPriorData, fD, data, domain, coeffversion)getCoefficients(fPI, rangeNewPriorData, fD, data, domain, coeffversion)
fPI |
The function fitted to the prior data, of class |
rangeNewPriorData |
An array of length 2 with the new domain of the prior function. |
fD |
The function fitted to the original data, of class |
data |
A |
domain |
A |
coeffversion |
A |
coeffversion can be:
"1" coef1 and coef2 are the sum of the probabilities of one of the function over the sum of all probabilities, respectively;
"2" coef1 and coef2 are the solution of a linear optimization problem which tries to maximize the sum 1 for each row of probabilities;
"3" coef1 and coef2 are the difference of the log-likelihood of the evaluated model and a random uniform model over the sum of both differences, respectively;
"4" coef1 and coef2 are the difference of the log-likelihood of the evaluated model and a ramdom positive MoTBF model over the sum of both differences, respectively.
A "numeric" value of length 2 giving the coefficients which are the weigth of the two function to combine.
## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Learning confident <- 5 type <- "MOP" f <- learnMoTBFpriorInformation(priorData = priordata, data = X, s = confident, POTENTIAL_TYPE = type, returnAll = TRUE) attributes(f) ## Coefficients: linear opinion pool getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 4) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 1) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 3) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 2)## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Learning confident <- 5 type <- "MOP" f <- learnMoTBFpriorInformation(priorData = priordata, data = X, s = confident, POTENTIAL_TYPE = type, returnAll = TRUE) attributes(f) ## Coefficients: linear opinion pool getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 4) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 1) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 3) getCoefficients(fPI = f$priorFunction, rangeNewPriorData = f$domain, fD = f$dataFunction, data = X, domain = range(X), coeffversion = 2)
Get the Directed acyclic graph (DAG) from a Bayesian network (BN)
getDAG(bn)getDAG(bn)
bn |
An object of class |
An object of class bn (same class as in bnlearn package).
Get the dimension of "motbf" and "jointmotbf" densities.
getMotbfDim(P)getMotbfDim(P)
P |
An object of class |
Dimension of the function.
## 1. EXAMPLE ## Data X <- rnorm(2000) ## Univariate function f <- univMoTBF(X, POTENTIAL_TYPE = "MOP") getMotbfDim(f) ## 2. EXAMPLE ## Dataset with 2 variables X <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(2,3) P <- jointmotbf.fit(X, dimensions = dim) ## Dimension of the joint function getMotbfDim(P)## 1. EXAMPLE ## Data X <- rnorm(2000) ## Univariate function f <- univMoTBF(X, POTENTIAL_TYPE = "MOP") getMotbfDim(f) ## 2. EXAMPLE ## Dataset with 2 variables X <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(2,3) P <- jointmotbf.fit(X, dimensions = dim) ## Dimension of the joint function getMotbfDim(P)
Get the names of the variables involved in a "univmotbf" or jointmotbf object.
getMotbfVar(P)getMotbfVar(P)
P |
An object of class |
A "character" vector with the names of the variables in the function.
# 1. EXAMPLE ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint function dim <-c(3,2) P <- jointmotbf.fit(data, dimensions = dim) P ## Variables getMotbfVar(P) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100), X3 = rnorm(100)) ## Joint function dim <- c(2,1,3) P <- jointmotbf.fit(data, dimensions = dim) ## Variables getMotbfVar(P)# 1. EXAMPLE ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint function dim <-c(3,2) P <- jointmotbf.fit(data, dimensions = dim) P ## Variables getMotbfVar(P) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100), X3 = rnorm(100)) ## Joint function dim <- c(2,1,3) P <- jointmotbf.fit(data, dimensions = dim) ## Variables getMotbfVar(P)
Generates a non normalized (i.e. not integrating to 1) positive MoTBF function.
getNonNormalisedRandomMoTBF(degree, POTENTIAL_TYPE = "MOP")getNonNormalisedRandomMoTBF(degree, POTENTIAL_TYPE = "MOP")
degree |
A |
POTENTIAL_TYPE |
A |
A "numeric" vector of length 2 giving the coefficients.
getNonNormalisedRandomMoTBF(8, POTENTIAL_TYPE = "MOP") getNonNormalisedRandomMoTBF(11, POTENTIAL_TYPE = "MTE")getNonNormalisedRandomMoTBF(8, POTENTIAL_TYPE = "MOP") getNonNormalisedRandomMoTBF(11, POTENTIAL_TYPE = "MTE")
Learn the structure of a hybrid Bayesian network, using a fixed method (Naive Bayes, NB), a restricted method (Tree augmented Naive Bayes, TAN), or an unrestricted method (the hill climbing, HC, score-based local search method).
getStructure(data, method, target = NULL)getStructure(data, method, target = NULL)
data |
A dataset with discrete and continuous variables. If the discrete
variables are not of class |
method |
A |
target |
An optional parameter only used in the case of NB and TAN to specify the class variable. |
getStructure() automatically converts non-numeric variables into factors
before calling function hc() from the bnlearn package. In the case of TAN, it converts
all numeric and non-numeric variables into factors (using 4 equal width intervals)
before calling tree.bayes() from the bnlearn package.
The output is a "bn" object containing the learned graph.
## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- getStructure(ecoli, method = "HC") dag1 plot(dag1) ## DAG2 dag2 <- getStructure(ecoli, method = "TAN", target = "mcg") dag2 plot(dag2)## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- getStructure(ecoli, method = "HC") dag1 plot(dag1) ## DAG2 dag2 <- getStructure(ecoli, method = "TAN", target = "mcg") dag2 plot(dag2)
Compute the BIC score and the loglikelihood from the fitted MoTBFs functions in a hybrid Bayesian network, i.e., from objects of class motbf.fit.
logLikelihood.MoTBFBN(object, data) BiC.MoTBFBN(object, data)logLikelihood.MoTBFBN(object, data) BiC.MoTBFBN(object, data)
object |
The output of the 'motbf.fit()' function |
data |
The dataset of class |
A numeric value giving the log-likelihood of the BN.
## Dataset Ecoli require(MoTBFs) data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN intervals <- 3 potential <- "MOP" P1 <- MoTBFs_Learning(graph = dag, data = data, POTENTIAL_TYPE=potential, numIntervals = intervals, maxParam = 5) logLikelihood.MoTBFBN(P1, data) ##BIC$LogLikelihood BIC <- BiC.MoTBFBN(P1, data) BIC$BIC ## Learning BN intervals <- 2 potential <- "MTE" P2 <- MoTBFs_Learning(graph = dag, data = data, POTENTIAL_TYPE=potential, numIntervals = intervals, maxParam = 10) logLikelihood.MoTBFBN(P2, data) ##BIC$LogLikelihood BIC <- BiC.MoTBFBN(P2, data) BIC$BIC## Dataset Ecoli require(MoTBFs) data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN intervals <- 3 potential <- "MOP" P1 <- MoTBFs_Learning(graph = dag, data = data, POTENTIAL_TYPE=potential, numIntervals = intervals, maxParam = 5) logLikelihood.MoTBFBN(P1, data) ##BIC$LogLikelihood BIC <- BiC.MoTBFBN(P1, data) BIC$BIC ## Learning BN intervals <- 2 potential <- "MTE" P2 <- MoTBFs_Learning(graph = dag, data = data, POTENTIAL_TYPE=potential, numIntervals = intervals, maxParam = 10) logLikelihood.MoTBFBN(P2, data) ##BIC$LogLikelihood BIC <- BiC.MoTBFBN(P2, data) BIC$BIC
Integrate a "jointmotbf" object over an non defined domain. It is able to
get the integral of a joint function over a set of variables or over all
the variables in the function.
This function is deprecated; use "integrate.motbf" instead.
integralJointMoTBF(P, var = NULL)integralJointMoTBF(P, var = NULL)
P |
A |
var |
A |
A multiintegral of a joint function of class "jointmotbf".
Method to calculate the non-defined integral of an "motbf" object of 'mop' subclass.
This function is deprecated; use "integrate.motbf" instead.
integralMOP(fx)integralMOP(fx)
fx |
An |
The non-defined integral of the function.
univMoTBF for learning and integralMoTBF
for a more complete function to get defined and non-defined integrals
of class "motbf".
Compute the integral of a one-dimensional mixture of truncated basis function
over a bounded or unbounded interval.
This function is deprecated; use "integrate.motbf" instead.
integralMoTBF(fx, min = NULL, max = NULL)integralMoTBF(fx, min = NULL, max = NULL)
fx |
An object of class |
min |
The lower integration limit. By default it is NULL. |
max |
The upper integration limit. By default it is NULL. |
If the limits of the interval, min and max are NULL, then the output is the expression of the indefinite integral. If only 'min' contains a numeric value, then the expression of the integral is evaluated at this point.
integralMoTBF() returns either the indefinite integral of the MoTBF
function, which is also an object of class "motbf", or the definite integral,
wich is a "numeric" value.
univMoTBF, integralMOP and integralMTE
Method to calculate the non-defined integral of an "motbf" object of 'mte'
subclass. This function is deprecated; use "integrate.motbf" instead.
integralMTE(fx)integralMTE(fx)
fx |
An |
The non-defined integral of the function.
univMoTBF for learning and integralMoTBF
for a more complete function to get defined and non-defined integrals
of class "motbf".
Compute the integral of a one-dimensional mixture of truncated basis function
(objects of class "mop" or "mte") over a bounded or unbounded interval,
or compute the indefinite integral of a joint function (object of class "jointmotbf")
over a subset of variables or over all the variables in the function.
integrate.motbf(f, ...)integrate.motbf(f, ...)
f |
An object of class |
... |
optional arguments to be passed to subsequent methods for the integrate.motfb() function. See details. |
This function is a wrapper of internal functions integrateMOP(), integrateMTE() and integrateJointmotbf().
If f is of class "mop" or "mte", valid optional arguments are 'lower'
(the lower integration limit) and 'upper' (the upper integration limit),
which represent the limits of the interval to compute the definite integral.
If 'lower' and 'upper' are not specified, then the output is the expression of the indefinite integral.
On the other hand, if f is of class "jointmotbf", the only valid optional argument is 'var', which
is a "character" vector containing the name of the variables that will be integrated out.
If not specified, then all the variables are integrated out.
Note that integrate.motfb() deprecates the following functions, included in previous versions of the package: integralMTE, integralMOP, integralMoTBF and integralJointMoTBF.
If f is of class "mop" or "mte", integrate.motfb() returns
either the indefinite integral of the MoTBF function, which is also an object of classes "motbf",
"univmotbf", and either "mop" or "mte"); or the definite integral, which is a "numeric" value.
If f is of class "jointmotbf", integrate.motfb() returns a multi-integral of the joint function,
which is also of class "jointmotbf".
univMoTBF and jointMoTBF
## 1. EXAMPLE ## Univariate MOP integral X <- rexp(1000) fx <- univMoTBF(X, POTENTIAL_TYPE = "MOP", scale = FALSE) integrate.motbf(fx) integrate.motbf(fx, 2, 6) ## 2. EXAMPLE ## Univariate MOP integral and plot of result Y <- rnorm(1000) fy <- univMoTBF(Y, POTENTIAL_TYPE = "MOP") Fy <- integrate.motbf(fy) plot(Fy) integrate.motbf(fy, min(Y), max(Y)) ## 3. EXAMPLE ## Univariate MTE integral Z <- rchisq(1000, df = 3) fz <- univMoTBF(Z, POTENTIAL_TYPE = "MTE", scale = FALSE) integrate.motbf(fz) integrate.motbf(fz, lower = 2, upper = 5) ## Not run: ## 4. EXAMPLE Px <- "1+x+5" class(Px) integrate.motbf(Px) ## Error in integrate.motbf(Px) : Argument "f" is not of class "motbf" ## End(Not run) ## 5. EXAMPLE: Joint MOP integral ## Dataset with 2 variables data <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(2, 3) P <- jointmotbf.fit(data, dimensions = dim) ## Integral integrate.motbf(P) integrate.motbf(P, var = "x") integrate.motbf(P, var = "y") ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Dataset with 3 variables data <- data.frame(x = rnorm(50), y = rnorm(50), z = rnorm(50)) ## Joint function dim <- c(2,2,3) P = jointmotbf.fit(data, dimensions = dim) ## Integral integrate.motbf(P) integrate.motbf(P, var="x") integrate.motbf(P, var=c("x","z"))## 1. EXAMPLE ## Univariate MOP integral X <- rexp(1000) fx <- univMoTBF(X, POTENTIAL_TYPE = "MOP", scale = FALSE) integrate.motbf(fx) integrate.motbf(fx, 2, 6) ## 2. EXAMPLE ## Univariate MOP integral and plot of result Y <- rnorm(1000) fy <- univMoTBF(Y, POTENTIAL_TYPE = "MOP") Fy <- integrate.motbf(fy) plot(Fy) integrate.motbf(fy, min(Y), max(Y)) ## 3. EXAMPLE ## Univariate MTE integral Z <- rchisq(1000, df = 3) fz <- univMoTBF(Z, POTENTIAL_TYPE = "MTE", scale = FALSE) integrate.motbf(fz) integrate.motbf(fz, lower = 2, upper = 5) ## Not run: ## 4. EXAMPLE Px <- "1+x+5" class(Px) integrate.motbf(Px) ## Error in integrate.motbf(Px) : Argument "f" is not of class "motbf" ## End(Not run) ## 5. EXAMPLE: Joint MOP integral ## Dataset with 2 variables data <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(2, 3) P <- jointmotbf.fit(data, dimensions = dim) ## Integral integrate.motbf(P) integrate.motbf(P, var = "x") integrate.motbf(P, var = "y") ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Dataset with 3 variables data <- data.frame(x = rnorm(50), y = rnorm(50), z = rnorm(50)) ## Joint function dim <- c(2,2,3) P = jointmotbf.fit(data, dimensions = dim) ## Integral integrate.motbf(P) integrate.motbf(P, var="x") integrate.motbf(P, var=c("x","z"))
This function allows to check whether a node is discrete or not
is.discrete(node, bn)is.discrete(node, bn)
node |
A character (name of node) or numeric (index of node in the bn list) input. |
bn |
A list of lists obtained from MoTBFs_Learning. |
is.discrete returns TRUE or FALSE depending on whether the node is discrete or not.
## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn BN bn <- MoTBFs_Learning(dag, data, POTENTIAL_TYPE = "MTE") ## Check wheter a node is discrete or not # Using its name is.discrete("D1", bn) # Using its index position is.discrete(3, bn)## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn BN bn <- MoTBFs_Learning(dag, data, POTENTIAL_TYPE = "MTE") ## Check wheter a node is discrete or not # Using its name is.discrete("D1", bn) # Using its index position is.discrete(3, bn)
Utility functions to check whether an object belongs to a specific MoTBF class, or to identify its underlying subclass ('mop' or 'mte').
is.motbf(x, class = "motbf") is.univmotbf(x, class = "univmotbf") is.jointmotbf(x, class = "jointmotbf") is.motbf_fit(x, class = "motbf_fit") is.motbf_fit_cv(x, class = "motbf_fit_cv") is.mte(x) is.mop(x) subclass(fx)is.motbf(x, class = "motbf") is.univmotbf(x, class = "univmotbf") is.jointmotbf(x, class = "jointmotbf") is.motbf_fit(x, class = "motbf_fit") is.motbf_fit_cv(x, class = "motbf_fit_cv") is.mte(x) is.mop(x) subclass(fx)
x |
An object to be checked. |
class |
Character string specifying the target class name. |
fx |
An object to determine the subclass for. |
is.*: Logical value (TRUE or FALSE) indicating if the object belongs to the checked class.
subclass: A character string ("mop" or "mte") specifying the underlying family of the object.
is.observed() checks whether a node belongs to the evidence set or not.
is.observed(node, evi)is.observed(node, evi)
node |
A |
evi |
A |
This function returns TRUE if "node" is included in "evi", or, otherwise, FALSE.
## Data frame of the evidence set obs <- data.frame(lip = "1", alm2 = 0.5, stringsAsFactors=FALSE) ## Check if x is in obs is.observed("x", obs)## Data frame of the evidence set obs <- data.frame(lip = "1", alm2 = 0.5, stringsAsFactors=FALSE) ## Check if x is in obs is.observed("x", obs)
is.root checks whether a node has parents or not.
is.root(node, dag)is.root(node, dag)
node |
A character string indicating the node's name. |
dag |
An object of class |
is.root returns TRUE or FALSE depending on whether the node is root or not.
## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Check if a node is root is.root("C1", dag)## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Check if a node is root is.root("C1", dag)
Function for learning joint MoTBFs.
The jointmotbf.fit() function is a wrapper of two internal (non-exported) functions:
getParamJoint() and fixParamJoint().
The first one gets the parameters by solving a quadratic optimization problem, minimizing
the mean squared error between the empirical joint CDF and the estimated CDF.
The density is obtained as the derivative of the estimated CDF.
The second one, fixParamJoint(), fixes the equation of the joint function using
the previously learned parameters and converting this "character" string into an
object of class "jointmotbf".
jointmotbf.fit( X, ranges = NULL, dimensions = NULL, fitPoints = 10, constraints = 10 )jointmotbf.fit( X, ranges = NULL, dimensions = NULL, fitPoints = 10, constraints = 10 )
X |
a dataset of class |
ranges |
a |
dimensions |
a |
fitPoints |
an |
constraints |
an |
jointmotbf.fit() returns a list with the following elements:
Function |
The analytical expression of the learned density. |
Domain |
A |
Iterations |
The number of iterations needed to solve the problem. |
Time |
The execution time. |
## 1. EXAMPLE ## Generate a multinormal dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint learnings dim <- c(2,3) P <- jointmotbf.fit(data, dimensions = dim) P attributes(P) class(P) ############################################################################### ## MORE EXAMPLES ############################################################## ############################################################################### ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100), X3 = rnorm(100)) ## Joint learnings dim <- c(3,2,3) P <- jointmotbf.fit(data, dimensions = dim) P attributes(P) class(P)## 1. EXAMPLE ## Generate a multinormal dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100)) ## Joint learnings dim <- c(2,3) P <- jointmotbf.fit(data, dimensions = dim) P attributes(P) class(P) ############################################################################### ## MORE EXAMPLES ############################################################## ############################################################################### ## Generate a dataset data <- data.frame(X1 = rnorm(100), X2 = rnorm(100), X3 = rnorm(100)) ## Joint learnings dim <- c(3,2,3) P <- jointmotbf.fit(data, dimensions = dim) P attributes(P) class(P)
Deprecated functions; use "jointmotbf.fit" instead.
parametersJointMoTBF(X, ranges = NULL, dimensions = NULL) jointMoTBF(object)parametersJointMoTBF(X, ranges = NULL, dimensions = NULL) jointMoTBF(object)
X |
A dataset of class |
ranges |
A |
dimensions |
A |
object |
A list with the output of the function |
Two functions for learning joint MoTBFs.
The first one, parametersJointMoTBF(),
gets the parameters by solving a quadratic optimization problem, minimizing
the mean squared error between the empirical joint CDF and the estimated CDF.
The density is obtained as the derivative od the estimated CDF.
The second one, jointMoTBF(), fixes the equation of the joint function using
the previously learned parameters and converting this "character" string into an
object of class "jointmotbf".
parametersJointMoTBF() returns a list with the following elements:
Parameters, which contains the computed coefficients of the resulting function;
Dimension, which is a "numeric" vector containing the number
of coefficients used for each variable;
Range contains a "numeric" matrix with the domain of each variable, by columns;
Iterations contains the number of iterations needed to solve the problem;
Time contains the execution time.
jointMoTBF() returns an object of class "jointmotbf", which is a list whose only visible element
is the analytical expression of the learned density. It also contains the other aforementioned elements,
which can be retrieved using attributes()
Learn the structure of a hybrid Bayesian network using the hill climbing local search method.
LearningHC(dataset, numIntervals = NULL)LearningHC(dataset, numIntervals = NULL)
dataset |
A dataset with discrete and continuous variables. If the discrete
variables are not of class |
numIntervals |
A |
LearningHC() automatically converts non-numeric variables into factors
before calling function hc() from the bnlearn package. LearningHC() can also
be used to discretize the dataset, using the equal width method, before calling hc().
The output is a "bn" object containing the learned graph.
## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- LearningHC(ecoli) dag1 plot(dag1) ## DAG2 dag2 <- LearningHC(ecoli, numIntervals = 10) dag2 plot(dag2)## Data data(ecoli) ecoli <- ecoli[,-1] ## Sequence Name ## DAG1 dag1 <- LearningHC(ecoli) dag1 plot(dag1) ## DAG2 dag2 <- LearningHC(ecoli, numIntervals = 10) dag2 plot(dag2)
Learns a univariate MoTBF function using prior information.
learnMoTBFpriorInformation( priorData, data, s, POTENTIAL_TYPE, domain = range(data), coeffversion = 4, restrictDomain = TRUE, maxParam = NULL, returnAll = FALSE, scale = TRUE )learnMoTBFpriorInformation( priorData, data, s, POTENTIAL_TYPE, domain = range(data), coeffversion = 4, restrictDomain = TRUE, maxParam = NULL, returnAll = FALSE, scale = TRUE )
priorData |
A |
data |
A |
s |
A |
POTENTIAL_TYPE |
A |
domain |
A |
coeffversion |
A |
restrictDomain |
A logical value. This argument allows to choose if the domain is used joining both domains,
the prior one and the data domain or trimming them. By default, |
maxParam |
A positive integer which indicates the maximum number of coefficients in the function.
If specified, the output is the function which gets the best BIC with, at most, this number of parameters.
By default, it is set to |
returnAll |
A logical value indicating whether to return all prior, data and posterior functions (TRUE) or only the posterior (FALSE). |
scale |
A |
If returnAll = TRUE, the function returns a list with the elements
coeffs |
An |
posteriorFunction |
The final function after combining. |
priorFunction |
The fit of the prior data. |
dataFunction |
The fit of the original data. |
rangeNewPriorData |
A |
## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Test data test <- rnorm(1000) testData <- test[test>=min(X)&test<=max(X)] ## Learning type <- "MOP" confident <- 3 ## confident <- 1,2,...,length(X) f <- learnMoTBFpriorInformation(priorData = priordata, data = X, s = confident, POTENTIAL_TYPE = type, returnAll = TRUE) attributes(f) ## Log-likelihood sum(log(as.function(f$dataFunction)(testData))) sum(log(as.function(f$posteriorFunction)(testData))) ## best loglikelihood## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Test data test <- rnorm(1000) testData <- test[test>=min(X)&test<=max(X)] ## Learning type <- "MOP" confident <- 3 ## confident <- 1,2,...,length(X) f <- learnMoTBFpriorInformation(priorData = priordata, data = X, s = confident, POTENTIAL_TYPE = type, returnAll = TRUE) attributes(f) ## Log-likelihood sum(log(as.function(f$dataFunction)(testData))) sum(log(as.function(f$posteriorFunction)(testData))) ## best loglikelihood
Computes the marginal densities from a "jointmotbf" object.
marginal.jointmotbf(P, var)marginal.jointmotbf(P, var)
P |
An object of class |
var |
A vector containing the names of the marginal variables (those being retained in 'P').
This argument accepts the |
If 'var' is an atomic vector, the marginal distribution of the variable specified in 'var' is computed
from the joint distribution and the result is an object of class "univmotbf", i.e., a univariate distribution.
If 'var' contains more than one variable, the joint distribution over this subset is computed, i.e.,
the variables NOT contained in 'var' are marginalized out and the result is an object of class "jointmotbf".
## 1. EXAMPLE ## Dataset with 2 variables data <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(4,3) P <- jointmotbf.fit(data, dimensions = dim) ## Marginal marginal.jointmotbf(P, var = "x") marginal.jointmotbf(P, var = 2) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Generate a dataset with 3 variables data <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100)) ## Joint function dim <- c(2,2,3) P <- jointmotbf.fit(data, dimensions = dim) ## Marginal marginal.jointmotbf(P, var = "x") marginal.jointmotbf(P, var = "y") marginal.jointmotbf(P, var = c("x", "z"))## 1. EXAMPLE ## Dataset with 2 variables data <- data.frame(x = rnorm(100), y = rnorm(100)) ## Joint function dim <- c(4,3) P <- jointmotbf.fit(data, dimensions = dim) ## Marginal marginal.jointmotbf(P, var = "x") marginal.jointmotbf(P, var = 2) ############################################################################## ## MORE EXAMPLES ############################################################# ############################################################################## ## Generate a dataset with 3 variables data <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100)) ## Joint function dim <- c(2,2,3) P <- jointmotbf.fit(data, dimensions = dim) ## Marginal marginal.jointmotbf(P, var = "x") marginal.jointmotbf(P, var = "y") marginal.jointmotbf(P, var = c("x", "z"))
Computes the marginal densities from a "jointmotbf"
object.
This function is deprecated; use "marginal.jointmotbf" instead.
marginalJointMoTBF(P, var)marginalJointMoTBF(P, var)
P |
An object of class |
var |
The |
The marginal of a "jointmotbf" function. The result is an object of class "motbf".
jointMoTBF and evalJointFunction
These functions fit mixtures of polynomials (MOPs). Least square optimization is used to minimize the quadratic error between the empirical cumulative distribution and the estimated one.
mop.learning(X, nparam, domain) bestMOP(X, domain, maxParam = NULL)mop.learning(X, nparam, domain) bestMOP(X, domain, maxParam = NULL)
X |
A |
nparam |
Number of parameters of the function. |
domain |
A |
maxParam |
A |
mop.learning():
The returned value $Function is the only visible element which contains the algebraic expression.
Using attributes the name of the others elements are shown and also they can be extracted with $.
The summary of the function also shows all these elements.
bestMOP():
The first returned value $bestPx contains the output of the mop.learning() function
with the number of parameters which gets the best BIC values, taking into account the
BIC score to penalize the functions. It evaluates the two next functions,
if the BIC score does not improve then the function with the last best BIC is returned.
mop.lerning() returns a list of n elements:
Function |
An |
Subclass |
|
Domain |
The range where the function is defined to be a legal density function. |
Iterations |
The number of iterations that the optimization problem takes to minimize the errors. |
Time |
The CPU time employed. |
bestMOP() returns a list including the polynomial function with the best BIC score,
the number of parameters and an array with
the BIC values of the evaluated functions.
univMoTBF A complete function for learning MOPs which includes extra options.
## 1. EXAMPLE data <- rnorm(1000) ## MOP with fix number of degrees fx <- mop.learning(data, nparam=7, domain=range(data)) fx hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MOP in terms of BIC fMOP <- bestMOP(data, domain=range(data)) attributes(fMOP) fMOP$bestPx hist(data, prob=TRUE, main="") plot(fMOP$bestPx, col=2, xlim=range(data), add=TRUE) ## 2. EXAMPLE data <- rbeta(4000, shape1=1/2, shape2=1/2) ## MOP with fix number of degrees fx <- mop.learning(data, nparam=6, domain=range(data)) fx hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MOP in terms of BIC fMOP <- bestMOP(data, domain=range(data), maxParam=6) attributes(fMOP) fMOP$bestPx attributes(fMOP$bestPx) hist(data, prob=TRUE, main="") plot(fMOP$bestPx, col=2, xlim=range(data), add=TRUE)## 1. EXAMPLE data <- rnorm(1000) ## MOP with fix number of degrees fx <- mop.learning(data, nparam=7, domain=range(data)) fx hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MOP in terms of BIC fMOP <- bestMOP(data, domain=range(data)) attributes(fMOP) fMOP$bestPx hist(data, prob=TRUE, main="") plot(fMOP$bestPx, col=2, xlim=range(data), add=TRUE) ## 2. EXAMPLE data <- rbeta(4000, shape1=1/2, shape2=1/2) ## MOP with fix number of degrees fx <- mop.learning(data, nparam=6, domain=range(data)) fx hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MOP in terms of BIC fMOP <- bestMOP(data, domain=range(data), maxParam=6) attributes(fMOP) fMOP$bestPx attributes(fMOP$bestPx) hist(data, prob=TRUE, main="") plot(fMOP$bestPx, col=2, xlim=range(data), add=TRUE)
Perform a TAN model of class MoTBF based on maximizing the Mutual Information.
fit_tan( target, data, fit.args = NULL, root = NULL, all = FALSE, mutualInfoCond = NULL, parallel = FALSE ) mutual_information_tan(data, target, fit.args = NULL, parallel = FALSE)fit_tan( target, data, fit.args = NULL, root = NULL, all = FALSE, mutualInfoCond = NULL, parallel = FALSE ) mutual_information_tan(data, target, fit.args = NULL, parallel = FALSE)
target |
A |
data |
A |
fit.args |
A |
root |
A |
all |
A |
mutualInfoCond |
A numeric matrix indicating the estimation of the
mutual information coefficientes for Chow-Liu- algorithm in TAN. If it is
|
parallel |
A |
The main function, fit_tan(), fits a MoTBF Tree Augmented Naive Bayes
model using the specified data.
The main function, fit_tan(), returns an object of class "motbf_fit".
When all=TRUE, it returns a list with the Bayesian network and the mutual
information matrix used to compute the maximun spanning tree.
Function mutual_information_tan() returns a symmetric numeric
matrix of dimensions , where is the number of
predictor variables. Row and column names correspond to the predictor
variables, and the entries contain the estimated conditional mutual
information values. This matrix is used to compute the TAN model.
data = iris data$Species = as.factor(data$Species) # Fit TAN model for classification tan = fit_tan("Species",data)data = iris data$Species = as.factor(data$Species) # Fit TAN model for classification tan = fit_tan("Species",data)
This function checks whether the density functions of a MoTBF-BN are of type MTE or MOP.
motbf_type(bn)motbf_type(bn)
bn |
A list of lists obtained from the function MoTBFs_Learning. |
A character string, specifying the subclass of MoTBF, i.e., either MTE or MOP.
## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- MoTBFs_Learning(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MTE") ## Get MoTBF sub-class motbf_type(bn)## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- MoTBFs_Learning(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MTE") ## Get MoTBF sub-class motbf_type(bn)
Random generation for mixtures of truncated basis functions defined in a specific domain. The inverse transform method is used.
rMoTBF(size, fx, domain = NULL) inversionMethod(size, fx, domain = NULL, data = NULL)rMoTBF(size, fx, domain = NULL) inversionMethod(size, fx, domain = NULL, data = NULL)
size |
A non-negative integer indicating the number of records to generate. |
fx |
An object of class |
domain |
A |
data |
A |
rMoTBF() returns a "numeric" vector containing the simulated values.
inversionMethod() returns a list with the simulated values and the results
of the two-sample Kolmogorov-Smirnov test, as well as the plot of the CDFs of the
original and simulated data.
## 1. EXAMPLE ## Data X <- rnorm(1000, mean = 5, sd = 3) ## Learning f <- univMoTBF(X, POTENTIAL_TYPE="MOP", nparam=10) plot(f, xlim = f$Domain) ## Random sample Y <- rMoTBF(size = 500, fx = f) ks.test(X,Y) ## Plots hist(Y, prob = TRUE, add = TRUE) ## 2. EXAMPLE ## Data X <- rweibull(5000, shape=2) ## Learning f <- univMoTBF(X, POTENTIAL_TYPE="MOP", nparam=10) plot(f, xlim = f$Domain) ## Random sample inv <- inversionMethod(size = 500, fx = f, data = X) attributes(inv) inv$test Y <- inv$sample ## Plots plot(f, xlim = f$Domain) hist(Y, prob = TRUE, add = TRUE)## 1. EXAMPLE ## Data X <- rnorm(1000, mean = 5, sd = 3) ## Learning f <- univMoTBF(X, POTENTIAL_TYPE="MOP", nparam=10) plot(f, xlim = f$Domain) ## Random sample Y <- rMoTBF(size = 500, fx = f) ks.test(X,Y) ## Plots hist(Y, prob = TRUE, add = TRUE) ## 2. EXAMPLE ## Data X <- rweibull(5000, shape=2) ## Learning f <- univMoTBF(X, POTENTIAL_TYPE="MOP", nparam=10) plot(f, xlim = f$Domain) ## Random sample inv <- inversionMethod(size = 500, fx = f, data = X) attributes(inv) inv$test Y <- inv$sample ## Plots plot(f, xlim = f$Domain) hist(Y, prob = TRUE, add = TRUE)
Perform a k-fold cross validation for Bayesian networks of class MoTBF.
motbf.cv( data, dag, loss, k = 10, target = NULL, seed = NULL, fit.args = NULL, loss.args = NULL, foldsIndex = NULL, ... )motbf.cv( data, dag, loss, k = 10, target = NULL, seed = NULL, fit.args = NULL, loss.args = NULL, foldsIndex = NULL, ... )
data |
an object of class |
dag |
a network of the class |
loss |
a character string indicating which loss function should be used. Currently, two options are available: 'logl', for the log-likelihood of the model; and 'pred', for the predictive error. See details. |
k |
an integer indicating the number of folds to split the data set. If k = 0, the train and test sets are the same data; if k = 1, hold-out validation is carried out, i.e., the data set is split in train (80% by default) and test (20% by default); finally, if k >=2, k-fold cross validation is carried out. |
target |
a character string indicating which node is the target. This argument might be NULL if the loss function chosen is the log-likelihood of the model ('logl'). |
seed |
an integer to specify the seed. The k-folds are created randomly, so one might expect slightly different results unless 'seed' is used. |
fit.args |
a list containing optional arguments used to fit the models. These arguments must be those accepted by function motbf.fit, i.e., 'numIntervals' (4), 'POTENTIAL_TYPE' ('MOP'), 'maxParam' (NULL), 's' (NULL), 'priorData' (NULL) or 'scale' (TRUE). If fit.args is left NULL, the default values (in brackets) for those arguments will be used. |
loss.args |
a list containing optional arguments related to the loss functions. Currently available arguments are: 'loss.matrix' and 'percentage_test'. See details. |
foldsIndex |
a list containing the test indexes for each fold of cross-validation. If is not null, |
... |
Additional arguments. Not used currently. |
If the basis function is MTE, the loss function is the log-likelihood of the model. On the other hand, if the basis function if MOP, the loss function might be either the predictive error ('pred') or the the log-likelihood of the model ('logl').
Details on the loss argument:
'logl'The log-likelihood of the model is computed. This measure is available for both basis functions, MTE and MOP.
'pred'This option is only available for MOPs. The predictive error (root mean squared error) or classification accuracy is computed as the loss function, depending on the nature of the target variable (continuous or discrete, respectively). The program will guess which type the target variable is and compute the corresponding measure.
Details on the loss.args argument. Currently, two arguments can be specified within this list:
'p.test'Only used if k = 1.
This argument specifies the proportion of the data set that goes to the test set (between 0 and 1).
'loss.matrix'A squared matrix used to compute a weighted classification accuracy for discrete targets.
This matrix is multiplied by the confusion matrix element by element,
and the resulting matrix is used to compute the classification accuracy.
The loss matrix allows to increase the penalty of some user-specified errors.
If the loss matrix provided is a constant matrix of ones, the result is the standard classification accuracy.
Note that the diagonal of the loss matrix is regarded as a reward, while the off-diagonal is regarded as a cost.
An object of class "motbf.fit.cv". This is a list of "k" elements,
each of them containing the results of each fold. More specifically, each element contains:
a "data.frame" of the subset used to fit the model.
an object of class "motbf.fit", i.e., the model fitted.
the loss value computed for the fold.
If "pred" is chosen for the argument "loss", then each element of the "motbf.fit.cv" object
also contains:
a vector of predictions for the target variable.
a vector of observed records of the target variable.
################# ### EXAMPLE 1 ### ################# ## Perform 2-fold cross validation using the default model arguments ## and the log-likelihood as loss function # Load data data(ecoli) ecoli <- ecoli[,-c(1,9)] # Learn DAG dag <- LearningHC(ecoli) # Run cross validation cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'logl') cv ################# ### EXAMPLE 2 ### ################# ## Choose different arguments to fit the model parameters fit.args = list(numIntervals = 3, POTENTIAL_TYPE = 'MOP', maxParam = 4) # Run cross validation using the classification accuracy as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'lip', fit.args = fit.args) cv summary(cv) ################# ### EXAMPLE 3 ### ################# ## Specify a loss matrix to increase the penalty of classification errors lossFunctionMatrix = matrix(c(c(1,2), c(3, 1)),nrow = 2, ncol = 2, byrow = TRUE) # Run cross validation using the weighted classification accuracy as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'lip', loss.args = list(loss.matrix = lossFunctionMatrix)) cv summary(cv) ################# ### EXAMPLE 4 ### ################# # Run cross validation using the root mean squared error as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'mcg') cv################# ### EXAMPLE 1 ### ################# ## Perform 2-fold cross validation using the default model arguments ## and the log-likelihood as loss function # Load data data(ecoli) ecoli <- ecoli[,-c(1,9)] # Learn DAG dag <- LearningHC(ecoli) # Run cross validation cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'logl') cv ################# ### EXAMPLE 2 ### ################# ## Choose different arguments to fit the model parameters fit.args = list(numIntervals = 3, POTENTIAL_TYPE = 'MOP', maxParam = 4) # Run cross validation using the classification accuracy as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'lip', fit.args = fit.args) cv summary(cv) ################# ### EXAMPLE 3 ### ################# ## Specify a loss matrix to increase the penalty of classification errors lossFunctionMatrix = matrix(c(c(1,2), c(3, 1)),nrow = 2, ncol = 2, byrow = TRUE) # Run cross validation using the weighted classification accuracy as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'lip', loss.args = list(loss.matrix = lossFunctionMatrix)) cv summary(cv) ################# ### EXAMPLE 4 ### ################# # Run cross validation using the root mean squared error as loss function cv = motbf.cv(data = ecoli, dag, k = 2, loss = 'pred', target = 'mcg') cv
Learn mixtures of truncated basis functions in a full hybrid network.
motbf.fit( graph, data, numIntervals = 4, POTENTIAL_TYPE = "MOP", maxParam = NULL, s = NULL, priorData = NULL, scale = TRUE ) MoTBFs_Learning( graph, data, numIntervals = 4, POTENTIAL_TYPE = "MOP", maxParam = NULL, s = NULL, priorData = NULL, scale = TRUE )motbf.fit( graph, data, numIntervals = 4, POTENTIAL_TYPE = "MOP", maxParam = NULL, s = NULL, priorData = NULL, scale = TRUE ) MoTBFs_Learning( graph, data, numIntervals = 4, POTENTIAL_TYPE = "MOP", maxParam = NULL, s = NULL, priorData = NULL, scale = TRUE )
graph |
A network of the class |
data |
An object of class |
numIntervals |
A positive integer indicating the maximum number of intervals for splitting the domain of the continuous parent variables. By default, it is set to 4. |
POTENTIAL_TYPE |
A |
maxParam |
A positive integer which indicates the maximum number of coefficients in the function.
If specified, the output is the function which gets the best BIC with, at most, this number of parameters.
By default, it is set to |
s |
A |
priorData |
An object of class |
scale |
A |
If the variable is discrete then it computes the probabilities and the size of each leaf.
Children that have discrete parents have as many functions as configurations of the parents.
Children that have continuous parents have as many functions as the number indicated in the
argument "numIntervals" for each parent. Children that have mixed parents, combine both methods.
The BIC criterion is used to decide the number of splitting points of the parent domains and to choose
the number of basis functions used.
A list of lists. Each list contains two elements
Child |
A |
functions |
A list of three elements: the name of the parents; a |
## Dataset Ecoli require(MoTBFs) data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN intervals <- 3 potential <- "MOP" bn1 <- motbf.fit(graph = dag, data = data, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 5) bn1 ## Learning BN intervals <- 4 potential <- "MTE" bn2 <- motbf.fit(graph = dag, data = data, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 15) bn2## Dataset Ecoli require(MoTBFs) data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN intervals <- 3 potential <- "MOP" bn1 <- motbf.fit(graph = dag, data = data, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 5) bn1 ## Learning BN intervals <- 4 potential <- "MTE" bn2 <- motbf.fit(graph = dag, data = data, numIntervals = intervals, POTENTIAL_TYPE = potential, maxParam = 15) bn2
Export a discrete BN created with motbf.fit to an object of class "bn" of package bnlearn.
motbf2bnlearn(bn)motbf2bnlearn(bn)
bn |
An object of class |
An object of class bn.
Export a discrete BN created with motbf.fit to an object of class "grain" of package gRain
motbf2grain(bn)motbf2grain(bn)
bn |
An object of class |
An object of class grain.
These functions fit mixtures of truncated exponentials (MTEs). Least square optimization is used to minimize the quadratic error between the empirical cumulative distribution function and the estimated one.
mte.learning(X, nparam, domain) bestMTE(X, domain, maxParam = NULL)mte.learning(X, nparam, domain) bestMTE(X, domain, maxParam = NULL)
X |
A |
nparam |
Number of parameters of the resulting density function. |
domain |
A |
maxParam |
A |
mte.learning():
The returned value $Function is the only visible element which contains the algebraic expression.
Using attributes the name of the others elements are shown and also they can be abstract with $.
The summary of the function also shows all this elements.
bestMTE():
The first returned value $bestPx contains the output of the mte.learning() function
with the number of parameters which gets the best BIC value, taking into account the
Bayesian information criterion (BIC) to penalize the functions. It evaluates the two next functions,
if the BIC doesn't improve then the function with the last best BIC is returned.
mte.lerning() returns a list of n elements:
Function |
An |
Subclass |
|
Domain |
The range where the function is defined to be a legal density function. |
Iterations |
The number of iterations that the optimization problem employed to minimize the errors. |
Time |
The CPU time consumed. |
bestMTE() returns a list including the MTE function with the best BIC score,
the number of parameters, the best BIC value and an array contained
the BIC values of the evaluated functions.
univMoTBF A complete function for learning MoTBFs which includes extra options.
## 1. EXAMPLE data <- rchisq(1000, df=3) ## MTE with fix number of parameters fx <- mte.learning(data, nparam=7, domain=range(data)) hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MTE in terms of BIC fMTE <- bestMTE(data, domain=range(data)) attributes(fMTE) fMTE$bestPx hist(data, prob=TRUE, main="") plot(fMTE$bestPx, col=2, xlim=range(data), add=TRUE) ## 2. EXAMPLE data <- rexp(1000, rate=1/3) ## MTE with fix number of parameters fx <- mte.learning(data, nparam=8, domain=range(data)) ## Message: The nearest function with odd number of coefficients hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MTE in terms of BIC fMTE <- bestMTE(data, domain=range(data), maxParam=10) attributes(fMTE) fMTE$bestPx attributes(fMTE$bestPx) hist(data, prob=TRUE, main="") plot(fMTE$bestPx, col=2, xlim=range(data), add=TRUE)## 1. EXAMPLE data <- rchisq(1000, df=3) ## MTE with fix number of parameters fx <- mte.learning(data, nparam=7, domain=range(data)) hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MTE in terms of BIC fMTE <- bestMTE(data, domain=range(data)) attributes(fMTE) fMTE$bestPx hist(data, prob=TRUE, main="") plot(fMTE$bestPx, col=2, xlim=range(data), add=TRUE) ## 2. EXAMPLE data <- rexp(1000, rate=1/3) ## MTE with fix number of parameters fx <- mte.learning(data, nparam=8, domain=range(data)) ## Message: The nearest function with odd number of coefficients hist(data, prob=TRUE, main="") plot(fx, col=2, xlim=range(data), add=TRUE) ## Best MTE in terms of BIC fMTE <- bestMTE(data, domain=range(data), maxParam=10) attributes(fMTE) fMTE$bestPx attributes(fMTE$bestPx) hist(data, prob=TRUE, main="") plot(fMTE$bestPx, col=2, xlim=range(data), add=TRUE)
Computes the new domain of two datasets.
newRangePriorData(fPI, priorData, N, domain, s, POTENTIAL_TYPE)newRangePriorData(fPI, priorData, N, domain, s, POTENTIAL_TYPE)
fPI |
The function fitted to the prior data, of class |
priorData |
A |
N |
A |
domain |
A |
s |
A |
POTENTIAL_TYPE |
A |
A "numeric" array which contains the new domain of the prior function.
## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Learning type = "MTE" fPrior <- univMoTBF(priordata, POTENTIAL_TYPE = type) ## New range confident <- 5 ## confident <- 1,2,...,length(X) domain <- range(X) N <- length(X) newRange <- newRangePriorData(fPrior, priorData = priordata, N = N, domain = domain, s = confident, POTENTIAL_TYPE = type) newRange## Data X <- rnorm(15) ## Prior Data priordata <- rnorm(5000) ## Learning type = "MTE" fPrior <- univMoTBF(priordata, POTENTIAL_TYPE = type) ## New range confident <- 5 ## confident <- 1,2,...,length(X) domain <- range(X) N <- length(X) newRange <- newRangePriorData(fPrior, priorData = priordata, N = N, domain = domain, s = confident, POTENTIAL_TYPE = type) newRange
Compute the number of variables which are in a jointmotbf object.
This function is deprecated; use "getMotbfVar" instead.
nVariables(P)nVariables(P)
P |
An |
A "character" vector with the names of the variables in the function.
'motbf' objectsDraws an 'motbf' function.
## S3 method for class 'motbf' plot(x, ...) ## S3 method for class 'univmotbf' plot(x, xlim = NULL, ylim = NULL, type = "l", add = FALSE, ...) ## S3 method for class 'piecewisemop' plot(x, xlim = NULL, ylim = NULL, ...) ## S3 method for class 'motbf.fit.node' plot(x, panels = TRUE, ...) ## S3 method for class 'jointmotbf' plot( x, type = "contour", ranges = NULL, orientation = c(5, -30), data = NULL, filled = TRUE, ticktype = "simple", main = NULL, ... )## S3 method for class 'motbf' plot(x, ...) ## S3 method for class 'univmotbf' plot(x, xlim = NULL, ylim = NULL, type = "l", add = FALSE, ...) ## S3 method for class 'piecewisemop' plot(x, xlim = NULL, ylim = NULL, ...) ## S3 method for class 'motbf.fit.node' plot(x, panels = TRUE, ...) ## S3 method for class 'jointmotbf' plot( x, type = "contour", ranges = NULL, orientation = c(5, -30), data = NULL, filled = TRUE, ticktype = "simple", main = NULL, ... )
x |
An object of class |
... |
Further arguments to be passed as for plot. |
xlim, ylim
|
Numeric vectors of length 2 specifying x and y axis limits. By default |
type |
Character string specifying the plot type, as for plot. For |
add |
Logical; if |
panels |
Logical; if |
ranges |
A |
orientation |
A |
data |
An object of class |
filled |
A logical argument; it is only used if |
ticktype |
A |
main |
Title string for the plot. Used in |
A plot of the specificated function.
## 1. univmotbf - Example for univariate distributions ## Data X <- rexp(2000) f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP") f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 10) ## Plots plot(NULL, xlim = range(X), ylim = c(0,0.8), xlab="X", ylab="density") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) ## 2. jointmotbf - Example for join distributions ## Data X <- data.frame(rnorm(500), rnorm(500)) ## Joint function dim <- c(3,3) P <- jointmotbf.fit(X, dimensions = dim) ## Plots plot(P) plot(P, type = "perspective", orientation = c(90,0))## 1. univmotbf - Example for univariate distributions ## Data X <- rexp(2000) f1 <- univMoTBF(X, POTENTIAL_TYPE = "MOP") f2 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", maxParam = 10) ## Plots plot(NULL, xlim = range(X), ylim = c(0,0.8), xlab="X", ylab="density") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) ## 2. jointmotbf - Example for join distributions ## Data X <- data.frame(rnorm(500), rnorm(500)) ## Joint function dim <- c(3,3) P <- jointmotbf.fit(X, dimensions = dim) ## Plots plot(P) plot(P, type = "perspective", orientation = c(90,0))
Plot conditional MoTBF densities.
plotConditional( conditionalFunction, data, nameChild = NULL, points = FALSE, color = NULL, ... )plotConditional( conditionalFunction, data, nameChild = NULL, points = FALSE, color = NULL, ... )
conditionalFunction |
the output of function conditionalMethod. A list containing the the interval of the parent and the final conditional density (MTE or MOP). |
data |
An object of class |
nameChild |
A |
points |
A logical value. If |
color |
If not specified, a default palette is used. |
... |
Additional graphical parameters passed to filled.contour(). |
If the number of parents is greater than one, then the error message "It is not possible to plot the conditional function." is reported.
A plot of the conditional density function.
## Data X <- rnorm(1000) Y <- rnorm(1000, mean=X) data <- data.frame(X=X,Y=Y) cov(data) ## Conditional Learning parent <- "X" child <- "Y" intervals <- 5 potential <- "MTE" P <- conditionalMethod(data, nameParents=parent, nameChild=child, numIntervals=intervals, POTENTIAL_TYPE=potential) plotConditional(conditionalFunction=P, data=data) plotConditional(conditionalFunction=P, data=data, points=TRUE)## Data X <- rnorm(1000) Y <- rnorm(1000, mean=X) data <- data.frame(X=X,Y=Y) cov(data) ## Conditional Learning parent <- "X" child <- "Y" intervals <- 5 potential <- "MTE" P <- conditionalMethod(data, nameParents=parent, nameChild=child, numIntervals=intervals, POTENTIAL_TYPE=potential) plotConditional(conditionalFunction=P, data=data) plotConditional(conditionalFunction=P, data=data, points=TRUE)
Predict from an MoTBF Bayesian Network
## S3 method for class 'motbf_fit' predict( object, target, data, method = NULL, prob = FALSE, parallel = FALSE, ... )## S3 method for class 'motbf_fit' predict( object, target, data, method = NULL, prob = FALSE, parallel = FALSE, ... )
object |
An object of class "motbf_fit" |
target |
A character string indicating the variable to be predicted |
data |
A data frame containing the predictive variables |
method |
A character string indicating the method to perform the inference. Options are NULL, "ve" (variable elimination) and "fs" (forward sampling). |
prob |
A logical value. If TRUE, the probabilities used for classification are returned as an attribute. |
parallel |
A logical value. If TRUE, parallelization is carried out. |
... |
Additional arguments used if method = "fs". |
Delete rows of a dataset which contains anomalous values.
preprocessedData(data, strangeElements)preprocessedData(data, strangeElements)
data |
A dataset of class |
strangeElements |
A |
print method for class "motbf".Print object of class motbf
print method for class "motbf".
Print a single node of a BN. This function is called by print.motbf_fit, but not exported.
Print the results of a k-fold cross validation
## S3 method for class 'motbf' print(x, ...) ## S3 method for class 'motbf_fit' print(x, ...) ## S3 method for class 'motbf.fit.node' print(x, ...) ## S3 method for class 'motbf_fit_cv' print(x, ...) ## S3 method for class 'univmotbf' print(x, ...) ## S3 method for class 'piecewisemop' print(x, ...) ## S3 method for class 'jointmotbf' print(x, ...)## S3 method for class 'motbf' print(x, ...) ## S3 method for class 'motbf_fit' print(x, ...) ## S3 method for class 'motbf.fit.node' print(x, ...) ## S3 method for class 'motbf_fit_cv' print(x, ...) ## S3 method for class 'univmotbf' print(x, ...) ## S3 method for class 'piecewisemop' print(x, ...) ## S3 method for class 'jointmotbf' print(x, ...)
x |
An object of class |
... |
optional arguments passed to print for other classes created in the MoTBFs package. Currently, no optional arguments are supported. |
The following classes are created in the MoTBFs package:
the generic class common to all objects created in the package
the class corresponding to MTE or MOP univariate distributions. An object of class univmotbf is the output of function univMoTBF().
the class corresponding to MOP univariate distributions defined by multiple sub-functions with different domain. When calling variableElimination(), the output might be of this class.
the class corresponding to joint distributions. An object of class jointmotbf is the output of function jointMOP()
the class corresponding to fully fitted Bayesian network models (either discrete, continuous or hybrid). An object of class motbf_fit is the output of function motbf.fit().
the class corresponding to k-fold cross validation results. An object of class motbf.fit.cv is the output of function motbf.cv().
the class corresponding to a single node of a Bayesian Network.
## Dataset Ecoli data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN P <- motbf.fit(graph = dag, data = data, numIntervals = 3, POTENTIAL_TYPE = "MOP", maxParam = 15) P## Dataset Ecoli data(ecoli) data <- ecoli[,-c(1)] ## remove variable sequence ## Directed acyclic graph dag <- LearningHC(data) ## Learning BN P <- motbf.fit(graph = dag, data = data, numIntervals = 3, POTENTIAL_TYPE = "MOP", maxParam = 15) P
Print the description of an MoTBF demnsity for one variable conditional on another variable.
printConditional(conditionalFunction)printConditional(conditionalFunction)
conditionalFunction |
the output of the function |
The results of the conditional function are shown.
## Data X <- rexp(500) Y <- rnorm(500, mean=X) data <- data.frame(X=X,Y=Y) cov(data) ## Conditional Learning parent <- "X" child <- "Y" intervals <- 5 potential <- "MOP" P <- conditionalMethod(data, nameParents=parent, nameChild=child, numIntervals=intervals, POTENTIAL_TYPE=potential) printConditional(P)## Data X <- rexp(500) Y <- rnorm(500, mean=X) data <- data.frame(X=X,Y=Y) cov(data) ## Conditional Learning parent <- "X" child <- "Y" intervals <- 5 potential <- "MOP" P <- conditionalMethod(data, nameParents=parent, nameChild=child, numIntervals=intervals, POTENTIAL_TYPE=potential) printConditional(P)
Compute the probabilities of a discrete variable from a data set using Laplace correction.
probDiscreteVariable(x)probDiscreteVariable(x)
x |
a |
Laplace correction is used to avoid the zero probability problem, with as smoothing factor.
Therefore, the probability for each state, , is computed as
for ,
where is the number of records of state ,
is the total number of records, and
is the total number of states.
A list of 2 elements:
coeff |
a named vector that contains the probabilities. |
sizeDataLeaf |
a vector containing the number of records in each leaf of the discrete tree. |
## Simulate discrete variable x <- factor(sample(c('yes', 'no', 'maybe'), 500, replace = TRUE), levels = c('yes', 'no', 'maybe')) ## Compute probabilities p <- probDiscreteVariable(x) p## Simulate discrete variable x <- factor(sample(c('yes', 'no', 'maybe'), 500, replace = TRUE), levels = c('yes', 'no', 'maybe')) ## Compute probabilities p <- probDiscreteVariable(x) p
Compute conditional probability queries from a sample.
query(sample, event, evidence)query(sample, event, evidence)
sample |
A |
event |
A expression describing the event of interest |
evidence |
A expression describing the conditioning evidence. |
The conditional probability: P(event|evidence).
data("ecoli", package = "MoTBFs") dat <- ecoli[,-c(1,4,5,9)] # Build DAG dag <- LearningHC(dat) # Learn BN parameters bn = motbf.fit(dag, dat) # Get sample from bn sam = sample_motbfs(bn, 50) # Compute P(mcg > 0.6 | aac < 0.8 & alm2 < 0.3) query(sam, event = (mcg >0.6), evidence = (aac<0.8 & alm2 <0.3))data("ecoli", package = "MoTBFs") dat <- ecoli[,-c(1,4,5,9)] # Build DAG dag <- LearningHC(dat) # Learn BN parameters bn = motbf.fit(dag, dat) # Get sample from bn sam = sample_motbfs(bn, 50) # Compute P(mcg > 0.6 | aac < 0.8 & alm2 < 0.3) query(sam, event = (mcg >0.6), evidence = (aac<0.8 & alm2 <0.3))
The function r.data.frame() initializes a data frame with as many columns as nodes in the MoTBF-network. It also asings each column its data type, i.e., numeric or character. In the case of character columns, the states of the variable are extracted from the "bn" argument and included as levels.
r.data.frame(bn)r.data.frame(bn)
bn |
A list of lists obtained from the function MoTBFs_Learning. |
An object of class "data.frame", which contains the data type of each column and has no rows.
## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn a BN bn <- motbf.fit(dag, data, POTENTIAL_TYPE = "MTE") ## Initialize a data.frame containing 3 columns (x, y and z) with their attributes. r.data.frame(bn)## Create a dataset # Continuous variables x <- rnorm(100) y <- rnorm(100) # Discrete variable z <- sample(letters[1:2],size = 100, replace = TRUE) data <- data.frame(C1 = x, C2 = y, D1 = z, stringsAsFactors = FALSE) ## Get DAG dag <- LearningHC(data) ## Learn a BN bn <- motbf.fit(dag, data, POTENTIAL_TYPE = "MTE") ## Initialize a data.frame containing 3 columns (x, y and z) with their attributes. r.data.frame(bn)
Standardize the numeric columns of a data.frame.
rescale_data(data, v_mean = NULL, v_sd = NULL)rescale_data(data, v_mean = NULL, v_sd = NULL)
data |
data.frame containing the variables to be standardized. |
v_mean |
vector of means of the data.frame. The value for the non-numeric columns should be NA. If not given, it is computed from data. |
v_sd |
vector of standard deviations of the data.frame. The value for the non-numeric columns should be NA. If not given, it is computed from data. |
A data.frame with scaled data. Non-numeric columns are also returned in their original position.
A collection of function to reescale an MoTBF function to the original offset and scale. This is useful when data was standardized previously to learning.
rescaledMoTBFs(fx, data = NULL) rescaledMOP(fx, data = NULL) rescaledMTE(fx, data) ToStringRe_MTE(parameters, data, num = 1) meanMOP(fx) rescale_motbf_fit(object, POTENTIAL_TYPE, data)rescaledMoTBFs(fx, data = NULL) rescaledMOP(fx, data = NULL) rescaledMTE(fx, data) ToStringRe_MTE(parameters, data, num = 1) meanMOP(fx) rescale_motbf_fit(object, POTENTIAL_TYPE, data)
fx |
A function of class |
data |
the original data set (non-scaled) |
parameters |
A |
num |
A |
object |
and object of class motbf_fit that has been learned with scaled data |
POTENTIAL_TYPE |
the potential of the model (either "MOP" or "MTE") |
An "motbf" function of the original data.
## 1. EXAMPLE X <- rchisq(1000, df = 8) ## data modX <- scale(X) ## scale data ## Learning f <- univMoTBF(modX, POTENTIAL_TYPE = "MOP", nparam=10) plot(f, xlim = range(modX), col=2) hist(modX, prob = TRUE, add = TRUE) ## Rescale origF <- rescaledMoTBFs(f, X) plot(origF, xlim = range(X), col=2) hist(X, prob = TRUE, add = TRUE) expectedValueMOP(origF) mean(X) ## 2. EXAMPLE X <- rweibull(1000, shape = 20, scale= 10) ## data modX <- as.numeric(scale(X)) ## scale data ## Learning f <- univMoTBF(modX, POTENTIAL_TYPE = "MTE", nparam = 9) plot(f, xlim = range(modX), col=2, main="") hist(modX, prob = TRUE, add = TRUE) ## Rescale origF <- rescaledMoTBFs(f, X) plot(origF, xlim = range(X), col=2) hist(X, prob = TRUE, add = TRUE) expectedValueMTE(origF) mean(X)## 1. EXAMPLE X <- rchisq(1000, df = 8) ## data modX <- scale(X) ## scale data ## Learning f <- univMoTBF(modX, POTENTIAL_TYPE = "MOP", nparam=10) plot(f, xlim = range(modX), col=2) hist(modX, prob = TRUE, add = TRUE) ## Rescale origF <- rescaledMoTBFs(f, X) plot(origF, xlim = range(X), col=2) hist(X, prob = TRUE, add = TRUE) expectedValueMOP(origF) mean(X) ## 2. EXAMPLE X <- rweibull(1000, shape = 20, scale= 10) ## data modX <- as.numeric(scale(X)) ## scale data ## Learning f <- univMoTBF(modX, POTENTIAL_TYPE = "MTE", nparam = 9) plot(f, xlim = range(modX), col=2, main="") hist(modX, prob = TRUE, add = TRUE) ## Rescale origF <- rescaledMoTBFs(f, X) plot(origF, xlim = range(X), col=2) hist(X, prob = TRUE, add = TRUE) expectedValueMTE(origF) mean(X)
Generate a multivariate normal data vector taking into account the real data and the relationships with other variables in the dataset.
rnormMultiv(n, dataParents, dataChild)rnormMultiv(n, dataParents, dataChild)
n |
A |
dataParents |
A data set of class |
dataChild |
A |
A "numeric" vector giving the prior data values.
## Data data(ecoli) data <- ecoli[,-c(1,9)] ## remove sequece.name and class ## DAG dag <- LearningHC(data) plot(dag) getChildParentsFromGraph(dag) ## 1. Random sample parents <- "mcg" child <- "alm1" n <- 1000 rnormMultiv(n, dataParents = data.frame(data[,parents]), dataChild = data[,child]) ## 2. Random sample parents <- "alm1" child <- "aac" n <- 256 rnormMultiv(n, dataParents = data.frame(data[,parents]), dataChild = data[,child])## Data data(ecoli) data <- ecoli[,-c(1,9)] ## remove sequece.name and class ## DAG dag <- LearningHC(data) plot(dag) getChildParentsFromGraph(dag) ## 1. Random sample parents <- "mcg" child <- "alm1" n <- 1000 rnormMultiv(n, dataParents = data.frame(data[,parents]), dataChild = data[,child]) ## 2. Random sample parents <- "alm1" child <- "aac" n <- 256 rnormMultiv(n, dataParents = data.frame(data[,parents]), dataChild = data[,child])
This function generates a sample from an MoTBF Bayesian network.
sample_motbfs(bn, n, parallel = FALSE, evidence = NULL)sample_motbfs(bn, n, parallel = FALSE, evidence = NULL)
bn |
An object of class motbf_fit, obtained from the function motbf.fit. |
n |
A non-negative integer giving the number of instances to be generated. |
parallel |
A |
evidence |
A data.frame of one row containing the values for the observed variables. As a default, it is NULL. |
A data.frame containing the generated sample. Is evidence is not NULL, attribute 'w' contains the weight of each sample.
data("ecoli", package = "MoTBFs") dat <- ecoli[,-c(1,4,5,9)] # Build DAG dag <- LearningHC(dat) # Learn BN parameters bn = motbf.fit(dag, dat) # Get sample from bn sam = sample_motbfs(bn, 50)data("ecoli", package = "MoTBFs") dat <- ecoli[,-c(1,4,5,9)] # Build DAG dag <- LearningHC(dat) # Learn BN parameters bn = motbf.fit(dag, dat) # Get sample from bn sam = sample_motbfs(bn, 50)
Collection of functions for subsetting a "data.frame" by rows or columns, and
to create training and test partitions.
splitFolds(data, k) TrainingandTestData(data, percentage_test, discreteVariables = NULL) splitdata(data, nameVariable, min, max)splitFolds(data, k) TrainingandTestData(data, percentage_test, discreteVariables = NULL) splitdata(data, nameVariable, min, max)
data |
A dataset of class |
k |
The number of folds for k-fold cross validation, used in splitFolds function. |
percentage_test |
The proportion of data that goes to the test set (between 0 and 1), used in TrainingandTestData function. |
discreteVariables |
A |
nameVariable |
A |
min, max
|
Boundary values to filter out, used in splitdata function. |
TrainingandTestData() returns a list of 2 elements containing the train and test datasets.
splitdata() returns a subset of observations.
## Dataset X <- rnorm(1000) Y <- rchisq(1000, df = 8) Z <- rep(letters[1:10], times = 1000/10) data <- data.frame(X = X, Y = Y, Z = Z) ## Training and Test Datasets TT <- TrainingandTestData(data, percentage_test = 0.2) TT$Training TT$Test ## Subset Dataset splitdata(data, nameVariable = "X", min = 2, max= 3)## Dataset X <- rnorm(1000) Y <- rchisq(1000, df = 8) Z <- rep(letters[1:10], times = 1000/10) data <- data.frame(X = X, Y = Y, Z = Z) ## Training and Test Datasets TT <- TrainingandTestData(data, percentage_test = 0.2) TT$Training TT$Test ## Subset Dataset splitdata(data, nameVariable = "X", min = 2, max= 3)
"motbf" object by describing its main features.Summarize an "motbf" object by describing its main features.
## S3 method for class 'motbf' summary(object, ...) ## S3 method for class 'motbf_fit_cv' summary(object, ...) ## S3 method for class 'univmotbf' summary(object, ...) ## S3 method for class 'summary.univmotbf' print(x, ...) ## S3 method for class 'piecewisemop' summary(object, ...) ## S3 method for class 'summary.piecewisemop' print(x, ...) ## S3 method for class 'jointmotbf' summary(object, ...) ## S3 method for class 'summary.jointmotbf' print(x, ...)## S3 method for class 'motbf' summary(object, ...) ## S3 method for class 'motbf_fit_cv' summary(object, ...) ## S3 method for class 'univmotbf' summary(object, ...) ## S3 method for class 'summary.univmotbf' print(x, ...) ## S3 method for class 'piecewisemop' summary(object, ...) ## S3 method for class 'summary.piecewisemop' print(x, ...) ## S3 method for class 'jointmotbf' summary(object, ...) ## S3 method for class 'summary.jointmotbf' print(x, ...)
object |
An object of class |
... |
further arguments passed to or from other methods. |
x |
An object of class |
The summary of an "motbf" object. It contains a list of
elements with the most important information of the object.
## Subclass 'MOP' X <- rnorm(1000) P <- univMoTBF(X, POTENTIAL_TYPE="MOP") ## or POTENTIAL_TYPE="MTE" summary(P) attributes(sP <- summary(P)) attributes(sP) sP$Function sP$Subclass sP$Iterations ## Subclass 'MTE' X <- rnorm(1000) P <- univMoTBF(X, POTENTIAL_TYPE="MTE") summary(P) attributes(sP <- summary(P)) attributes(sP) sP$Function sP$Subclass sP$Iterations## Subclass 'MOP' X <- rnorm(1000) P <- univMoTBF(X, POTENTIAL_TYPE="MOP") ## or POTENTIAL_TYPE="MTE" summary(P) attributes(sP <- summary(P)) attributes(sP) sP$Function sP$Subclass sP$Iterations ## Subclass 'MTE' X <- rnorm(1000) P <- univMoTBF(X, POTENTIAL_TYPE="MTE") summary(P) attributes(sP <- summary(P)) attributes(sP) sP$Function sP$Subclass sP$Iterations
This data set if one of the several databases about Thyroid avalaible at the UCI repository. The task is to detect is a given patient is normal (1) or suffers from hyperthyroidism (2) or hypothyroidism (3) .
A data frame with 7200 rows, 21 variables and the class.
Age of the patient (0.01–0.97). Continuous variable.
Sex of the patient, 0 (Male) 1 (Female). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
0 (FALSE) 1 (TRUE). Binary variable.
amount of TSH (0.0–0.53). Continuous variable.
amount of T3 (0.0005–0.18). Continuous variable.
amount of TT4 (0.002–0.6). Continuous variable.
amount of T4U (0.017–0.233). Continuous variable.
amount of FTI (0.002–0.642). Continuous variable.
1 (normal) 2 (hyperthyroidism) 3 (hypothyroidism). Class variable.
http://archive.ics.uci.edu/ml/datasets/Thyroid+Disease
Function for fitting univariate mixture of truncated basis functions. Least square optimization is used to minimize the quadratic error between the empirical cumulative distribution and the estimated one.
univMoTBF( x, POTENTIAL_TYPE, evalRange = NULL, nparam = NULL, maxParam = NULL, scale = TRUE )univMoTBF( x, POTENTIAL_TYPE, evalRange = NULL, nparam = NULL, maxParam = NULL, scale = TRUE )
x |
A |
POTENTIAL_TYPE |
A |
evalRange |
A |
nparam |
The exact number of basis functions to be used. By default, it is |
maxParam |
A |
scale |
A |
univMoTBF() returns an object of class "motbf". This object is a list containing several elements,
including its mathematical expression and other hidden elements related to the learning task.
The processing time is one of the values returned by this function and it can be extracted by $Time.
Although the learning process is always the same for a particular data sample,
the processing can vary inasmuch as it depends on the CPU.
## 1. EXAMPLE ## Data X <- rnorm(5000) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE"); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); f2 ## Plots hist(X, prob = TRUE, main = "") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) ## Data test Xtest <- rnorm(1000) ## Filtered data test Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Log-likelihood sum(log(as.function(f1)(Xtest))) sum(log(as.function(f2)(Xtest))) ## 2. EXAMPLE ## Data X <- rchisq(5000, df = 5) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", nparam = 11); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", maxParam = 10); f2 ## Plots hist(X, prob = TRUE, main = "") plot(f1, xlim = range(X), col = 3, add = TRUE) plot(f2, xlim = range(X), col = 4, add = TRUE) ## Data test Xtest <- rchisq(1000, df = 5) ## Filtered data test Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Log-likelihood sum(log(as.function(f1)(Xtest))) sum(log(as.function(f2)(Xtest)))## 1. EXAMPLE ## Data X <- rnorm(5000) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE"); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); f2 ## Plots hist(X, prob = TRUE, main = "") plot(f1, xlim = range(X), col = 1, add = TRUE) plot(f2, xlim = range(X), col = 2, add = TRUE) ## Data test Xtest <- rnorm(1000) ## Filtered data test Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Log-likelihood sum(log(as.function(f1)(Xtest))) sum(log(as.function(f2)(Xtest))) ## 2. EXAMPLE ## Data X <- rchisq(5000, df = 5) ## Learning f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", nparam = 11); f1 f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", maxParam = 10); f2 ## Plots hist(X, prob = TRUE, main = "") plot(f1, xlim = range(X), col = 3, add = TRUE) plot(f2, xlim = range(X), col = 4, add = TRUE) ## Data test Xtest <- rchisq(1000, df = 5) ## Filtered data test Xtest <- Xtest[Xtest>=min(X) & Xtest<=max(X)] ## Log-likelihood sum(log(as.function(f1)(Xtest))) sum(log(as.function(f2)(Xtest)))
Computes an upper bound of the expected loglikelihood of a dataset given a randomly generated MoTBF density.
UpperBoundLogLikelihood(f, data, min, max)UpperBoundLogLikelihood(f, data, min, max)
f |
A function to evaluate of class |
data |
A |
min |
A |
max |
A |
A "numeric" value which is the log-likelihood of the evaluated ramdom function.
data <- rnorm(20) f <- getNonNormalisedRandomMoTBF(degree = 8, POTENTIAL_TYPE = "MOP") UpperBoundLogLikelihood(f, data, min = -2.5, max = 3.2) data <- rexp(20) f <- getNonNormalisedRandomMoTBF(degree = 8, POTENTIAL_TYPE = "MTE") UpperBoundLogLikelihood(f, data, min = 0, max = 5)data <- rnorm(20) f <- getNonNormalisedRandomMoTBF(degree = 8, POTENTIAL_TYPE = "MOP") UpperBoundLogLikelihood(f, data, min = -2.5, max = 3.2) data <- rexp(20) f <- getNonNormalisedRandomMoTBF(degree = 8, POTENTIAL_TYPE = "MTE") UpperBoundLogLikelihood(f, data, min = 0, max = 5)
Compute the posterior distribution of a variable of interest given some evidence. The variable elimination algorithm is used.
variableElimination(bn, target, evidence = NULL, elimOrder = NULL)variableElimination(bn, target, evidence = NULL, elimOrder = NULL)
bn |
An object of class |
target |
A character string equal to the name of the variable of interest. |
evidence |
A |
elimOrder |
The elimination order can be manually specified as a vector containing the names of the variables, in the desired order. If elimOrder is not specified, the topological order is computed. |
The posterior probability distribution of the target variable as an object of
class univmotbf or piecewisemop if target is continuous,
or a matrix if target is discrete.
## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP") ## Specify the evidence set and target variable obs <- data.frame(lip = "0.48", alm1 = 0.55, stringsAsFactors=FALSE) node <- "alm2" ve = variableElimination(bn, target = node, evidence = obs)## Dataset data("ecoli", package = "MoTBFs") data <- ecoli[,-c(1,9)] ## Get directed acyclic graph dag <- LearningHC(data) ## Learn bayesian network bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP") ## Specify the evidence set and target variable obs <- data.frame(lip = "0.48", alm1 = 0.55, stringsAsFactors=FALSE) node <- "alm2" ve = variableElimination(bn, target = node, evidence = obs)
Perform variable selection for Bayesian networks of class MoTBF.
variableSelection( data, dag, loss, target = NULL, order = NULL, method = "forward", fit.args = NULL, loss.args = NULL, cv.args = NULL, verbose = TRUE )variableSelection( data, dag, loss, target = NULL, order = NULL, method = "forward", fit.args = NULL, loss.args = NULL, cv.args = NULL, verbose = TRUE )
data |
an object of class |
dag |
a character string indicating the structural learning algorithm to be applied to the training data. Available options are naive Bayes (NB), tree augmented naive Bayes (TAN) and hill-climbing (HC). |
loss |
a character string indicating which loss function should be used. Currently, two options are available: 'logl', for the log-likelihood of the model; and 'pred', for the predictive error. See details. |
target |
a character string indicating which node is the target. |
order |
a character vector indicating the order in which the predictive variables are included in the model. If it is NULL, the predictors are ordered regarding their mutual information with the target variable. |
method |
a character vector indicating the method used for the variable selection. Available methods are 'forward' (default), 'gf' (greedy forward selection) and 'iwsr' (Incremental Wrapper Sequential Subset with Replacement). |
fit.args |
a list containing optional arguments used to fit the models. These arguments must be those accepted by function motbf.fit, i.e., 'numIntervals' (4), 'POTENTIAL_TYPE' ('MOP'), 'maxParam' (NULL), 's' (NULL), 'priorData' (NULL) or 'scale' (TRUE). If fit.args is left NULL, the default values (in brackets) for those arguments will be used. |
loss.args |
a list containing optional arguments related to the loss functions. Currently available arguments are: 'loss.matrix' and 'percentage_test'. See details. |
cv.args |
a list containing optional arguments related to the cross-validation method. Currently available arguments are: 'k', 'seed'. See details. |
verbose |
Logical; if |
A filter-wrapper variable selection procedure is implemented.
Firstly, the explanatory variables are ordered according to their mutual information
with the target variable, unless argument 'order' is not null, in which case
the given order is followed.
Then, the first variable in the ordered set and the target are used to fit an initial model.
The model is validated by means of a k-fold cross validation (cv.args[[k]] >= 2).
However, it is possible to validate on a test set (cv.args[[k]] = 1), or on the same training set (cv.args[[k]] = 0).
The model is evaluated in terms of its log-likelihood (loss = 'logl') or its predictive accuracy (loss = 'pred').
In the latter case, the root mean squared error is computed for regression models,
whereas the classification accuracy is computed for classification models.
Afterwards, the remaining explanatory variables are included in the model, one by one, according to the aforementioned order,
and a new model is obtained. Whenever the inclusion of a variable increases the accuracy of the model
(increases its log-likelihood or classification error, or decreases its root mean squared error), it is kept; otherwise,
it is excluded from the model.
Details on the loss argument:
'logl'The log-likelihood of the model is computed. This measure is available for both basis functions, MTE and MOP.
'pred'This option is only available for MOPs. The predictive error (root mean squared error) or classification accuracy is computed as the loss function, depending on the nature of the target variable (continuous or discrete, respectively). The program will guess which type the target variable is and compute the corresponding measure.
Details on the loss.args argument. Currently, two arguments can be specified within this list:
'p.test'Only used if k = 1.
This argument specifies the proportion of the data set that goes to the test set (between 0 and 1).
'loss.matrix'A squared matrix used to compute a weighted classification accuracy for discrete targets.
This matrix is multiplied by the confusion matrix element by element,
and the resulting matrix is used to compute the classification accuracy.
The loss matrix allows to increase the penalty of some user-specified errors.
If the loss matrix provided is a constant matrix of ones, the result is the standard classification accuracy.
Note that the diagonal of the loss matrix is regarded as a reward, while the off-diagonal is regarded as a cost.
Details in the cv.args argument. Currently, two arguments can be specified within this list:
kan integer indicating the number of folds to split the data set. If k = 0, the train and test sets are the same data; if k = 1, hold-out validation is carried out, i.e., the data set is split in train (80% by default) and test (20% by default); finally, if k >=2, k-fold cross validation is carried out.
seedan integer to specify the seed. The k-folds are created randomly, so one might expect slightly different results unless 'seed' is used.
A list of 4 elements
a "data.frame" of the selected variables, including the target.
the index of the selected variables (with respect to the input dataset), including the target.
the loss value of the best model.
an object of class "motbf.fit.cv", containing the result of the cross-validation of the best model.
################# ### EXAMPLE 1 ### ################# # Perform variable selection on the iris dataset. # Use the TAN structure as DAG and the Species variable as target. vs = variableSelection(iris, dag = 'TAN', loss = 'pred', target = 'Species', cv.args = list(k = 1, seed = 1023)) # Check out the results of the best model. summary(vs$crossvalidation)################# ### EXAMPLE 1 ### ################# # Perform variable selection on the iris dataset. # Use the TAN structure as DAG and the Species variable as target. vs = variableSelection(iris, dag = 'TAN', loss = 'pred', target = 'Species', cv.args = list(k = 1, seed = 1023)) # Check out the results of the best model. summary(vs$crossvalidation)