Factors module
The factors are usually represented as conditional probability functions and are a component of a Bayesian network.
Abstract Types
The FactorType and Factor classes are abstract and both of them need to be implemented to create a new
factor type. Each Factor is always associated with a specific FactorType.
- class pybnesian.FactorType
A representation of a
Factortype.- __init__(self: pybnesian.FactorType) None
Initializes a new
FactorType
- __str__(self: pybnesian.FactorType) str
- new_factor(self: pybnesian.FactorType, model: BayesianNetworkBase or ConditionalBayesianNetworkBase, variable: str, evidence: List[str], *args, **kwargs) pybnesian.Factor
Create a new corresponding
Factorfor amodelwith the givenvariableandevidence.Note that
evidencemight be different frommodel.parents(variable).- Parameters:
- Returns:
A corresponding
Factorwith the givenvariableandevidence.
- class pybnesian.Factor
- __init__(self: pybnesian.Factor, variable: str, evidence: list[str]) None
Initializes a new
Factorwith a givenvariableandevidence.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
- __str__(self: pybnesian.Factor) str
- data_type(self: pybnesian.Factor) pyarrow.DataType
Returns the
pyarrow.DataTypethat represents the type of data handled by theFactor.For a continuous Factor, this usually returns
pyarrow.float64()orpyarrow.float32(). The discrete factor is usually apyarrow.dictionary().- Returns:
the
pyarrow.DataTypephysical data type representation of theFactor.
- evidence(self: pybnesian.Factor) list[str]
Gets the evidence variable list.
- Returns:
Evidence variable list.
- fit(self: pybnesian.Factor, df: DataFrame) None
Fits the
Factorwith the data indf.- Parameters:
df – DataFrame to fit the
Factor.
- fitted(self: pybnesian.Factor) bool
Checks whether the factor is fitted.
- Returns:
True if the factor is fitted, False otherwise.
- logl(self: pybnesian.Factor, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]
Returns the log-likelihood of each instance in the DataFrame
df.- Parameters:
df – DataFrame to compute the log-likelihood.
- Returns:
A
numpy.ndarrayvector with dtypenumpy.float64, where the i-th value is the log-likelihod of the i-th instance ofdf.
- sample(self: pybnesian.Factor, n: int, evidence_values: DataFrame | None = None, seed: int | None = None) pyarrow.Array
Samples
nvalues from thisFactor. This method returns apyarrow.Arraywithnvalues with the same type returned byFactor.data_type().If this
Factorhas evidence variables, the DataFrameevidence_valuescontainsninstances for each evidence variable. Each sampled instance must be conditioned onevidence_values.- Parameters:
n – Number of instances to sample.
evidence_values – DataFrame of evidence values to condition the sampling.
seed – A random seed number. If not specified or
None, a random seed is generated.
- save(self: pybnesian.Factor, filename: str) None
Saves the
Factorin a pickle file with the given name.- Parameters:
filename – File name of the saved graph.
- slogl(self: pybnesian.Factor, df: DataFrame) float
Returns the sum of the log-likelihood of each instance in the DataFrame
df. That is, the sum of the result ofFactor.logl().- Parameters:
df – DataFrame to compute the sum of the log-likelihood.
- Returns:
The sum of log-likelihood for DataFrame
df.
- type(self: pybnesian.Factor) pybnesian.FactorType
Returns the corresponding
FactorTypeof thisFactor.- Returns:
FactorTypecorresponding to thisFactor.
- variable(self: pybnesian.Factor) str
Gets the variable modelled by this
Factor.- Returns:
Variable name.
Continuous Factors
Linear Gaussian CPD
- class pybnesian.LinearGaussianCPDType
Bases:
FactorTypeLinearGaussianCPDTypeis the corresponding CPD type ofLinearGaussianCPD.- __init__(self: pybnesian.LinearGaussianCPDType) None
Instantiates a
LinearGaussianCPDType.
- class pybnesian.LinearGaussianCPD
Bases:
FactorThis is a linear Gaussian CPD:
\[\hat{f}(\text{variable} \mid \text{evidence}) = \mathcal{N}(\text{variable}; \text{beta}_{0} + \sum_{i=1}^{|\text{evidence}|} \text{beta}_{i}\cdot \text{evidence}_{i}, \text{variance})\]It is parametrized by the following attributes:
- Variables:
beta – The beta vector.
variance – The variance.
>>> from pybnesian import LinearGaussianCPD >>> cpd = LinearGaussianCPD("a", ["b"]) >>> assert not cpd.fitted() >>> cpd.beta array([], dtype=float64) >>> cpd.beta = np.asarray([1., 2.]) >>> assert not cpd.fitted() >>> cpd.variance = 0.5 >>> assert cpd.fitted() >>> cpd.beta array([1., 2.]) >>> cpd.variance 0.5
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.LinearGaussianCPD, variable: str, evidence: list[str]) -> None
Initializes a new
LinearGaussianCPDwith a givenvariableandevidence.The
LinearGaussianCPDis left unfitted.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
__init__(self: pybnesian.LinearGaussianCPD, variable: str, evidence: list[str], beta: numpy.ndarray[numpy.float64[m, 1]], variance: float) -> None
Initializes a new
LinearGaussianCPDwith a givenvariableandevidence.The
LinearGaussianCPDis fitted withbetaandvariance.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
beta – Vector of parameters.
variance – Variance of the linear Gaussian CPD.
- property beta
The beta vector of parameters. The beta vector is a
numpy.ndarrayvector of typenumpy.float64with sizelen(evidence) + 1.beta[0]is always the intercept coefficient andbeta[i]is the corresponding coefficient for the variableevidence[i-1]fori > 0.
- cdf(self: pybnesian.LinearGaussianCPD, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]
Returns the cumulative distribution function values of each instance in the DataFrame
df.- Parameters:
df – DataFrame to compute the log-likelihood.
- Returns:
A
numpy.ndarrayvector with dtypenumpy.float64, where the i-th value is the cumulative distribution function value of the i-th instance ofdf.
Conditional Kernel Density Estimation (CKDE)
- class pybnesian.CKDEType
Bases:
FactorTypeCKDETypeis the corresponding CPD type ofCKDE.- __init__(self: pybnesian.CKDEType) None
Instantiates a
CKDEType.
- class pybnesian.CKDE
Bases:
FactorA conditional kernel density estimator (CKDE) is the ratio of two KDE models [Semiparametric]:
\[\hat{f}(\text{variable} \mid \text{evidence}) = \frac{\hat{f}_{K}(\text{variable}, \text{evidence})}{\hat{f}_{K}(\text{evidence})}\]where \(\hat{f}_{K}\) is a
KDEestimation.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.CKDE, variable: str, evidence: list[str]) -> None
Initializes a new
CKDEwith a givenvariableandevidence.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
__init__(self: pybnesian.CKDE, variable: str, evidence: list[str], bandwidth_selector: pybnesian.BandwidthSelector) -> None
Initializes a new
CKDEwith a givenvariableandevidence.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
bandwidth_selector – Procedure to fit the bandwidth.
- cdf(self: pybnesian.CKDE, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]
Returns the cumulative distribution function values of each instance in the DataFrame
df.- Parameters:
df – DataFrame to compute the log-likelihood.
- Returns:
A
numpy.ndarrayvector with dtypenumpy.float64, where the i-th value is the cumulative distribution function value of the i-th instance ofdf.
- kde_joint(self: pybnesian.CKDE) pybnesian.KDE
Gets the joint \(\hat{f}_{K}(\text{variable}, \text{evidence})\)
KDEmodel.- Returns:
Joint KDE model.
- kde_marg(self: pybnesian.CKDE) pybnesian.KDE
Gets the marginalized \(\hat{f}_{K}(\text{evidence})\)
KDEmodel.- Returns:
Marginalized KDE model.
- num_instances(self: pybnesian.CKDE) int
Gets the number of training instances (\(N\)).
- Returns:
Number of training instances.
Discrete Factors
- class pybnesian.DiscreteFactorType
Bases:
FactorTypeDiscreteFactorTypeis the corresponding CPD type ofDiscreteFactor.- __init__(self: pybnesian.DiscreteFactorType) None
Instantiates a
DiscreteFactorType.
- class pybnesian.DiscreteFactor
Bases:
FactorThis is a discrete factor implemented as a conditional probability table (CPT).
- __init__(self: pybnesian.DiscreteFactor, variable: str, evidence: list[str]) None
Initializes a new
DiscreteFactorwith a givenvariableandevidence.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
Hybrid Factors
- class pybnesian.CLinearGaussianCPD
Bases:
FactorA conditional linear Gaussian CPD defines a
LinearGaussianCPDfor each discrete configuration of its parents.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.CLinearGaussianCPD, variable: str, evidence: list[str]) -> None
Initializes a new
CLinearGaussianCPDwith a givenvariableandevidence.The
CLinearGaussianCPDis left unfitted.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
__init__(self: pybnesian.CLinearGaussianCPD, variable: str, evidence: list[str], beta: numpy.ndarray[numpy.float64[m, 1]], variance: float) -> None
Initializes a new
CLinearGaussianCPDwith a givenvariableandevidence. EachLinearGaussianCPDwill be constructed using the providedbetaandvariance.Note that
CLinearGaussianCPDis left unfitted because some data is needed to extract the categories of the discrete variables. You should callfit.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
beta – Vector of parameters for each
LinearGaussianCPD.variance – Variance for each
LinearGaussianCPD.
__init__(self: pybnesian.CLinearGaussianCPD, variable: str, evidence: list[str], args: dict[pybnesian.Assignment, tuple[numpy.ndarray[numpy.float64[m, 1]], float]]) -> None
Initializes a new
CLinearGaussianCPDwith a givenvariableandevidence. TheLinearGaussianCPDof each discrete configuration can be constructed using differentbetaandvariance.Note that
CLinearGaussianCPDis left unfitted because some data is needed to extract the categories of the discrete variables. You should callfit. If some discrete configuration is not provided, theLinearGaussianCPDwill be fitted withLinearGaussianCPD.fit- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
args – Dict of of
betaandvariancefor each discreteAssignment.
- conditional_factor(self: pybnesian.CLinearGaussianCPD, assignment: pybnesian.Assignment) pybnesian.Factor
Return the corresponding
LinearGaussianCPDfor the given discreteassignment- Parameters:
assignment – A discrete
Assignment.
- class pybnesian.HCKDE
Bases:
FactorThe hybrid conditional kernel density estimation (HCKDE) [HybridSemiparametric] defines a
CKDEfor each discrete configuration of its parents.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.HCKDE, variable: str, evidence: list[str]) -> None
Initializes a new
HCKDEwith a givenvariableandevidence.The
HCKDEis left unfitted.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
__init__(self: pybnesian.HCKDE, variable: str, evidence: list[str], bandwidth_selector: pybnesian.BandwidthSelector) -> None
Initializes a new
HCKDEwith a givenvariableandevidence. EachHCKDEwill be constructed using the providedbandwidth_selector.Note that
HCKDEis left unfitted because some data is needed to extract the categories of the discrete variables and to fit eachCKDE. You should callHCKDE.fit.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
bandwidth_selector – A
BandwidthSelectorto use for eachCKDE.
__init__(self: pybnesian.HCKDE, variable: str, evidence: list[str], bandwidth_selector: dict[pybnesian.Assignment, tuple[pybnesian.BandwidthSelector]]) -> None
Initializes a new
HCKDEwith a givenvariableandevidence. TheCKDEof each discrete configuration can be constructed using differentbandwidth_selector.Note that
HCKDEis left unfitted because some data is needed to extract the categories of the discrete variables and to fit eachCKDE. You should callHCKDE.fit. If some discrete configuration is not provided, theCKDEwill be fitted with theNormalRereferenceRule.- Parameters:
variable – Variable name.
evidence – List of evidence variable names.
args – Dict of
bandwidth_selectorsfor each discreteAssignment.
- conditional_factor(self: pybnesian.HCKDE, assignment: pybnesian.Assignment) pybnesian.Factor
Return the corresponding
CKDEfor the given discreteassignment- Parameters:
assignment – A discrete
Assignment.
Other Types
This types are not factors, but are auxiliary types for other factors.
Kernel Density Estimation
- class pybnesian.BandwidthSelector
A
BandwidthSelectorestimates the bandwidth of a kernel density estimation (KDE) model.If the bandwidth matrix cannot be calculated because the data has a singular covariance matrix, you should raise a
SingularCovarianceData.- __init__(self: pybnesian.BandwidthSelector) None
Initializes a
BandwidthSelector.
- __str__(self: pybnesian.BandwidthSelector) str
- bandwidth(self: pybnesian.BandwidthSelector, df: DataFrame, variables: list[str]) numpy.ndarray[numpy.float64[m, n]]
Selects the bandwidth of a set of variables for a
KDEwith a given datadf.- Parameters:
df – DataFrame to select the bandwidth.
variables – A list of variables.
- Returns:
A float or numpy matrix of floats representing the bandwidth matrix.
- diag_bandwidth(self: pybnesian.BandwidthSelector, df: DataFrame, variables: list[str]) numpy.ndarray[numpy.float64[m, 1]]
Selects the bandwidth vector of a set of variables for a
ProductKDEwith a given datadf.- Parameters:
df – DataFrame to select the bandwidth.
variables – A list of variables.
- Returns:
A numpy vector of floats. The i-th entry is the bandwidth \(h_{i}^{2}\) for the
variables[i].
- class pybnesian.ScottsBandwidth
Bases:
BandwidthSelectorSelects the bandwidth using the Scott’s rule [Scott]:
\[\hat{h}_{i} = \hat{\sigma}_{i}\cdot N^{-1 / (d + 4)}.\]This is a simplification of the normal reference rule.
- __init__(self: pybnesian.ScottsBandwidth) None
Initializes a
ScottsBandwidth.
- class pybnesian.NormalReferenceRule
Bases:
BandwidthSelectorSelects the bandwidth using the normal reference rule:
\[\hat{h}_{i} = \left(\frac{4}{d + 2}\right)^{1 / (d + 4)}\hat{\sigma}_{i}\cdot N^{-1 / (d + 4)}.\]- __init__(self: pybnesian.NormalReferenceRule) None
Initializes a
NormalReferenceRule.
- class pybnesian.UCV
Bases:
BandwidthSelectorSelects the bandwidth using the Unbiased Cross Validation (UCV) criterion (also known as least-squares cross validation).
See Equation (3.8) in [MVKSA]:
\[\text{UCV}(\mathbf{H}) = N^{-1}\lvert\mathbf{H}\rvert^{-1/2}(4\pi)^{-d/2} + \{N(N-1)\}^{-1}\sum\limits_{i, j:\ i \neq j}^{N}\{(1 - N^{-1})\phi_{2\mathbf{H}} - \phi_{\mathbf{H}}\}(\mathbf{t}_{i} - \mathbf{t}_{j})\]where \(N\) is the number of training instances, \(\phi_{\Sigma}\) is the multivariate Gaussian kernel function with covariance \(\Sigma\), \(\mathbf{t}_{i}\) is the \(i\)-th training instance, and \(\mathbf{H}\) is the bandwidth matrix.
- __init__(self: pybnesian.UCV) None
Initializes a
UCV.
- class pybnesian.KDE
This class implements Kernel Density Estimation (KDE) for a set of variables:
\[\hat{f}(\text{variables}) = \frac{1}{N\lvert\mathbf{H} \rvert} \sum_{i=1}^{N} K(\mathbf{H}^{-1}(\text{variables} - \mathbf{t}_{i}))\]where \(N\) is the number of training instances, \(K()\) is the multivariate Gaussian kernel function, \(\mathbf{t}_{i}\) is the \(i\)-th training instance, and \(\mathbf{H}\) is the bandwidth matrix.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.KDE, variables: list[str]) -> None
Initializes a KDE with the given
variables. It uses theNormalReferenceRuleas the default bandwidth selector.- Parameters:
variables – List of variable names.
__init__(self: pybnesian.KDE, variables: list[str], bandwidth_selector: pybnesian.BandwidthSelector) -> None
Initializes a KDE with the given
variablesandbandwidth_selectorprocedure to fit the bandwidth.- Parameters:
variables – List of variable names.
bandwidth_selector – Procedure to fit the bandwidth.
- property bandwidth
Bandwidth matrix (\(\mathbf{H}\))
- data_type(self: pybnesian.KDE) pyarrow.DataType
Returns the
pyarrow.DataTypethat represents the type of data handled by theKDE.It can return
pyarrow.float64orpyarrow.float32.- Returns:
the
pyarrow.DataTypephysical data type representation of theKDE.
- dataset(self: pybnesian.KDE) DataFrame
Gets the training dataset for this KDE (the \(\mathbf{t}_{i}\) instances).
- Returns:
Training instance.
- fit(self: pybnesian.KDE, df: DataFrame) None
Fits the
KDEwith the data indf. It estimates the bandwidth \(\mathbf{H}\) automatically using the provided bandwidth selector.- Parameters:
df – DataFrame to fit the
KDE.
- fitted(self: pybnesian.KDE) bool
Checks whether the model is fitted.
- Returns:
True if the model is fitted, False otherwise.
- logl(self: pybnesian.KDE, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]
Returns the log-likelihood of each instance in the DataFrame
df.- Parameters:
df – DataFrame to compute the log-likelihood.
- Returns:
A
numpy.ndarrayvector with dtypenumpy.float64, where the i-th value is the log-likelihod of the i-th instance ofdf.
- num_instances(self: pybnesian.KDE) int
Gets the number of training instances (\(N\)).
- Returns:
Number of training instances.
- num_variables(self: pybnesian.KDE) int
Gets the number of variables.
- Returns:
Number of variables.
- save(self: pybnesian.KDE, filename: str) None
Saves the
KDEin a pickle file with the given name.- Parameters:
filename – File name of the saved graph.
- slogl(self: pybnesian.KDE, df: DataFrame) float
Returns the sum of the log-likelihood of each instance in the DataFrame
df. That is, the sum of the result ofKDE.logl.- Parameters:
df – DataFrame to compute the sum of the log-likelihood.
- Returns:
The sum of log-likelihood for DataFrame
df.
- variables(self: pybnesian.KDE) list[str]
Gets the variable names:
- Returns:
List of variable names.
- class pybnesian.ProductKDE
This class implements a product Kernel Density Estimation (KDE) for a set of variables:
\[\hat{f}(x_{1}, \ldots, x_{d}) = \frac{1}{N\cdot h_{1}\cdot\ldots\cdot h_{d}} \sum_{i=1}^{N} \prod_{j=1}^{d} K\left(\frac{(x_{j} - t_{ji})}{h_{j}}\right)\]where \(N\) is the number of training instances, \(d\) is the dimensionality of the product KDE, \(K()\) is the multivariate Gaussian kernel function, \(t_{ji}\) is the value of the \(j\)-th variable in the \(i\)-th training instance, and \(h_{j}\) is the bandwidth parameter for the \(j\)-th variable.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ProductKDE, variables: list[str]) -> None
Initializes a ProductKDE with the given
variables.- Parameters:
variables – List of variable names.
__init__(self: pybnesian.ProductKDE, variables: list[str], bandwidth_selector: pybnesian.BandwidthSelector) -> None
Initializes a ProductKDE with the given
variablesandbandwidth_selectorprocedure to fit the bandwidth.- Parameters:
variables – List of variable names.
bandwidth_selector – Procedure to fit the bandwidth.
- property bandwidth
Vector of bandwidth values (\(h_{j}^{2}\)).
- data_type(self: pybnesian.ProductKDE) pyarrow.DataType
Returns the
pyarrow.DataTypethat represents the type of data handled by theProductKDE.It can return
pyarrow.float64orpyarrow.float32.- Returns:
the
pyarrow.DataTypephysical data type representation of theProductKDE.
- dataset(self: pybnesian.ProductKDE) DataFrame
Gets the training dataset for this ProductKDE (the \(\mathbf{t}_{i}\) instances).
- Returns:
Training instance.
- fit(self: pybnesian.ProductKDE, df: DataFrame) None
Fits the
ProductKDEwith the data indf. It estimates the bandwidth vector \(h_{j}\) automatically using the provided bandwidth selector.- Parameters:
df – DataFrame to fit the
ProductKDE.
- fitted(self: pybnesian.ProductKDE) bool
Checks whether the model is fitted.
- Returns:
True if the model is fitted, False otherwise.
- logl(self: pybnesian.ProductKDE, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]
Returns the log-likelihood of each instance in the DataFrame
df.- Parameters:
df – DataFrame to compute the log-likelihood.
- Returns:
A
numpy.ndarrayvector with dtypenumpy.float64, where the i-th value is the log-likelihod of the i-th instance ofdf.
- num_instances(self: pybnesian.ProductKDE) int
Gets the number of training instances (\(N\)).
- Returns:
Number of training instances.
- num_variables(self: pybnesian.ProductKDE) int
Gets the number of variables.
- Returns:
Number of variables.
- save(self: pybnesian.ProductKDE, filename: str) None
Saves the
ProductKDEin a pickle file with the given name.- Parameters:
filename – File name of the saved graph.
- slogl(self: pybnesian.ProductKDE, df: DataFrame) float
Returns the sum of the log-likelihood of each instance in the DataFrame
df. That is, the sum of the result ofProductKDE.logl.- Parameters:
df – DataFrame to compute the sum of the log-likelihood.
- Returns:
The sum of log-likelihood for DataFrame
df.
- variables(self: pybnesian.ProductKDE) list[str]
Gets the variable names:
- Returns:
List of variable names.
- exception pybnesian.SingularCovarianceData
Bases:
ValueErrorThis exception signals that the data has a singular covariance matrix.
Other
- class pybnesian.UnknownFactorType
UnknownFactorTypeis the representation of an unknownFactorType. This factor type is assigned by default to each node in an heterogeneous Bayesian network.- __init__(self: pybnesian.UnknownFactorType) None
Instantiates an
UnknownFactorType.
- class pybnesian.Assignment
Assignmentrepresents the assignment of values to a set of variables.- __init__(self: pybnesian.Assignment, assignments: dict[str, AssignmentValue]) None
Initializes an
Assignmentfrom a dict that contains the value for each variable. The key of the dict is the name of the variable, and the value of the dict can be anstror afloatvalue.- Parameters:
assignments – Value assignments for each variable.
- empty(self: pybnesian.Assignment) bool
Checks whether the
Assignmentdoes not have assignments.- Returns:
True if the
Assignmentdoes not have assignments, False otherwise.
- has_variables(self: pybnesian.Assignment, variables: list[str]) bool
Checks whether the
Assignmentcontains assignments for all thevariables.- Parameters:
variables – Variable names.
- Returns:
True if the
Assignmentcontains values for all the given variables, False otherwise.
- insert(self: pybnesian.Assignment, variable: str, value: AssignmentValue) None
Inserts a new assignment for a
variablewith avalue.- Parameters:
variable – Variable name.
value – Value (
strorfloat) for the variable.
- remove(self: pybnesian.Assignment, variable: str) None
Removes the assignment for the
variable.- Parameters:
variable – Variable name.
- size(self: pybnesian.Assignment) int
Gets the number of assignments in the
Assignment.- Returns:
The number of assignments.
- value(self: pybnesian.Assignment, variable: str) AssignmentValue
Returns the assignment value for a given
variable.- Parameters:
variable – Variable name.
- Returns:
Value assignment of the variable.
- class pybnesian.Args
- __init__(self: pybnesian.Args, *args) None
The
Argsdefines a wrapper over *args. This class allows to distinguish between a tuple representing *args or a tuple parameter while usingArguments.Example:
Arguments({ 'a' : ((1, 2), {'param': 3}) }) # or Arguments({ 'a' : Args((1, 2), {'param': 3}) })
defines an *args with 2 arguments: a tuple (1, 2) and a dict {‘param’: 3}. No **kwargs is defined.
Arguments({ 'a' : (Args(1, 2), Kwargs(param = 3)) })
defines an *args with 2 arguments: 1 and 2. It also defines a **kwargs with param = 3.
- class pybnesian.Kwargs
- __init__(self: pybnesian.Kwargs, **kwargs) None
The
Kwargsdefines a wrapper over **kwargs. This class allows to distinguish between a dict representing **kwargs or a dict parameter while usingArguments.See Example Args/Kwargs.
- class pybnesian.Arguments
The
Argumentsclass collects different arguments to constructFactor.The
Argumentsobject is constructed from a dictionary that associates eachFactorconfiguration with a set of arguments.The keys of the dictionary can be:
A 2-tuple (
name,factor_type) defines arguments for aFactorof variablenamewithFactorTypefactor_type.An str defines arguments for a
Factorof variablename.A
FactorTypedefines arguments for aFactorwithFactorTypefactor_type.
The values of the dictionary can be:
When searching for the defined arguments in
Argumentsfor a given factor withnameandfactor_type, the most specific configurations have preference over more general ones.If a 2-tuple (
name,factor_type) configuration exists, the corresponding arguments are returned.Else, if a
nameconfiguration exists, the corresponding arguments are returned.Else, if a
factor_typeconfiguration exists, the corresponding arguments are returned.Else, empty *args and **kwargs are returned.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.Arguments) -> None
Initializes an empty
Arguments.__init__(self: pybnesian.Arguments, dict_arguments: dict) -> None
Initializes a new
Argumentswith the given configurations and arguments.- Parameters:
dict_arguments – A dictionary { configurations : arguments} that associates each
Factorconfiguration with a set of arguments.
- args(self: pybnesian.Arguments, node: str, node_type: factors::FactorType) tuple[*args, **kwargs]
Returns the *args and **kwargs defined for a
nodewith a givennode_type.- Parameters:
node – A node name.
node_type –
FactorTypefornode.
- Returns:
2-tuple containing
(*args, **kwargs)
Bibliography
Scott, D. W. (2015). Multivariate Density Estimation: Theory, Practice and Visualization. 2nd Edition. Wiley
José E. Chacón and Tarn Duong. (2018). Multivariate Kernel Smoothing and Its Applications. CRC Press.
David Atienza and Concha Bielza and Pedro Larrañaga. Semiparametric Bayesian networks. Information Sciences, vol. 584, pp. 564-582, 2022.
David Atienza and Pedro Larrañaga and Concha Bielza. Hybrid semiparametric Bayesian networks. TEST, vol. 31, pp. 299-327, 2022.