SEMEstimator#
- class pgmpy.estimators.SEMEstimator(model)[source]#
Bases:
objectBase class of SEM estimators. All the estimators inherit this class.
- fit(data, method, opt='adam', init_values='random', exit_delta=0.0001, max_iter=1000, **kwargs)[source]#
Estimate the parameters of the model from the data.
- Parameters:
- data: pandas DataFrame or pgmpy.data.Data instance
The data from which to estimate the parameters of the model.
- method: str (“ml”|”uls”|”gls”|”2sls”)
The fitting function to use. ML : Maximum Likelihood ULS: Unweighted Least Squares GLS: Generalized Least Squares 2sls: 2-SLS estimator
- init_values: str or dict
Options for str: random | std | iv dict: dictionary with keys B and zeta.
- **kwargs: dict
Extra parameters required in case of some estimators. GLS:
W: np.array (n x n) where n is the number of observe variables.
- 2sls:
x: y:
- Returns:
- pgmpy.model.SEM instance: Instance of the model with estimated parameters
References
[1]Bollen, K. A. (2010). Structural equations with latent variables. New York: Wiley.
- gls_loss(params, loss_args)[source]#
Method to compute the Weighted Least Squares fitting function. The optimizer calls this method after each iteration with updated params to compute the new loss.
The fitting function for ML is: .. math:: F_{ULS} = tr { [(S - Sigma(theta)) W^{-1}]^2 }
- Parameters:
- params: dict
params contain all the variables which are updated in each iteration of the optimization.
- loss_args: dict
loss_args contain all the variable which are not updated in each iteration but are required to compute the loss.
- Returns:
- torch.tensor: The loss value for the given params and loss_args
- ml_loss(params, loss_args)[source]#
Method to compute the Maximum Likelihood loss function. The optimizer calls this method after each iteration with updated params to compute the new loss.
The fitting function for ML is: .. math:: F_{ML} = log |\Sigma(\theta)| + tr(S Sigma^{-1}(theta)) - log S - (p+q)
- Parameters:
- params: dict
params contain all the variables which are updated in each iteration of the optimization.
- loss_args: dict
loss_args contain all the variable which are not updated in each iteration but are required to compute the loss.
- Returns:
- torch.tensor: The loss value for the given params and loss_args
- uls_loss(params, loss_args)[source]#
Method to compute the Unweighted Least Squares fitting function. The optimizer calls this method after each iteration with updated params to compute the new loss.
The fitting function for ML is: .. math:: F_{ULS} = tr[(S - Sigma(theta))^2]
- Parameters:
- params: dict
params contain all the variables which are updated in each iteration of the optimization.
- loss_args: dict
loss_args contain all the variable which are not updated in each iteration but are required to compute the loss.
- Returns:
- torch.tensor: The loss value for the given params and loss_args