stanbkt.fits.MCMCFit#
- class stanbkt.fits.MCMCFit(verbose=VerbosityLevel.INFO, fits=None, fit_metadata=None, cache_summary=True, summary_percentiles=(2.5, 97.5), _summary_cache=None)#
Bases:
FitBaseFit class using Markov Chain Monte Carlo (MCMC) sampling.
This class wraps CmdStanPy’s MCMC sampler to fit BKT models using full Bayesian inference via Hamiltonian Monte Carlo sampling.
Inherits all state management from
BaseFit.- Parameters:
verbose (VerbosityLevel)
fit_metadata (FitMetadata | None)
cache_summary (bool)
- add_fit(kc, fit, overwrite_kcs=False, group2index=None, groups=None)#
Add a fit for a knowledge component to the model’s fit state.
- Parameters:
kc (
str) – Knowledge component identifier.fit (
Union[CmdStanMCMC,CmdStanMLE,CmdStanVB,CmdStanPathfinder]) – CmdStan fit object to add for the KC.overwrite_kcs (
bool) – Whether to overwrite existing fits for KCs that are being added again.group2index (
dict[str,int] |None) – Optional mapping from group ID to 1-based index used for this KC’s fit.groups (
set[str] |None) – Optional set of group IDs used for this KC’s fit.
- Raises:
ValueError – If the fit’s method is incompatible with the model’s fit method, or if a fit for the KC already exists and
overwrite_kcs=False.- Return type:
- diagnose()#
Generate MCMC diagnostic information.
Provides convergence diagnostics (Rhat, effective sample size, etc.) for the fitted MCMC chains. This method is not yet implemented.
- get_fit(kc)#
Get the fit for a knowledge component.
- Parameters:
kc (
str) – Knowledge component identifier.- Returns:
CmdStan fit object for the specified KC.
- Return type:
Union[CmdStanMCMC,CmdStanMLE,CmdStanVB,CmdStanPathfinder]- Raises:
KeyError – If no fit exists for the specified KC.
- get_fit_save_entry(kc)#
Return persisted fit metadata entry for a KC, if available.
- has_kc(kc)#
Check if a fit exists for a knowledge component.
- log(msg, level=VerbosityLevel.INFO)#
Log a message if verbosity level permits.
- Parameters:
msg (
str) – Message to log.level (
VerbosityLevel) – Verbosity level of this message. Message is printed if self.verbose >= level. Lower enum values = higher verbosity.
- set_verbosity(level)#
Set the verbosity level for logging.
- Parameters:
level (
VerbosityLevel) – New verbosity level.- Raises:
ValueError – If level is not a valid VerbosityLevel.