Learn R Programming

gmgm (version 1.1.2)

aggregation: Aggregate particles to obtain inferred values

Description

This function aggregates particles to obtain inferred values. Assuming that the particles have been propagated to a given time slice \(t\), the weighted average of the samples is computed to estimate the state of the system at \(t\) or at previous time slices (Koller and Friedman, 2009).

Usage

aggregation(part, nodes, col_seq = NULL, col_weight = "weight", lag = 0)

Value

If lag has one element, a data frame (tibble) containing the aggregated values of the inferred nodes and their observation sequences (if col_seq is not NULL). If lag has two or more elements, a list of data frames (tibbles) containing these values for each time lag.

Arguments

part

A data frame containing the particles propagated to time slice \(t\), as obtained from function particles or propagation.

nodes

A character vector containing the inferred nodes.

col_seq

A character vector containing the column names of part that describe the observation sequence. If NULL (the default), all the particles belong to a single sequence.

col_weight

A character string corresponding to the column name of part that describes the particle weight.

lag

A non-negative integer vector containing the time lags \(l_1, l_2, \dots\) such that the samples of time slices \(t - l_1, t - l_2, \dots\) are aggregated.

References

Koller, D. and Friedman, N. (2009). Probabilistic Graphical Models: Principles and Techniques. The MIT Press.

See Also

aggregation, particles

Examples

Run this code
# \donttest{
library(dplyr)
set.seed(0)
data(gmdbn_air, data_air)
evid <- data_air %>%
  group_by(DATE) %>%
  slice(1:3) %>%
  ungroup()
evid$NO2[sample.int(150, 30)] <- NA
evid$O3[sample.int(150, 30)] <- NA
evid$TEMP[sample.int(150, 30)] <- NA
evid$WIND[sample.int(150, 30)] <- NA
aggreg <- particles(data.frame(DATE = unique(evid$DATE))) %>%
  propagation(gmdbn_air, evid, col_seq = "DATE", n_times = 3) %>%
  aggregation(c("NO2", "O3", "TEMP", "WIND"), col_seq = "DATE", lag = c(0, 1))# }

Run the code above in your browser using DataLab