Validates that a fitter object correctly implements the bayesim Fitter interface. This function checks that the object is a valid S7 Fitter class instance with all required properties and methods implemented.
Value
The validated fitter object (invisibly) if valid, otherwise raises an error with details about what failed
Details
The validation performs the following checks:
Property Checks:
Object is an S7 Fitter class
nameproperty exists and is charactersupports_predictionsproperty exists and is logicalsupports_log_likproperty exists and is logicalsupports_looproperty exists and is logical
Method Checks:
fit()method is implementedextract_draws()method is implementedpredict_fit()method is implementedlog_lik()method is implementedloo()method is implementeddiagnostics()method is implemented
Smoke Test (when smoke_test = TRUE):
Creates simple lm-like test data
Calls
fit()and verifiesbayesim_fit_resultstructureCalls
extract_draws()and verifies matrix with colnamesIf
supports_predictions, callspredict_fit()and verifies outputIf
supports_log_lik, callslog_lik()and verifies matrix outputCalls
diagnostics()and verifies list output
Examples
# Validate the built-in MockFitter (basic check only)
validate_fitter(MockFitter())
# Full validation with smoke test
validate_fitter(MockFitter(), smoke_test = TRUE, verbose = TRUE)
#> Checking S7 Fitter class...
#> [OK] Object is an S7 Fitter class
#> Checking required properties...
#> [OK] Property 'name' exists: mock
#> [OK] Property 'supports_predictions' exists: TRUE
#> [OK] Property 'supports_log_lik' exists: TRUE
#> [OK] Property 'supports_loo' exists: TRUE
#> Checking required S7 methods...
#> [OK] Method 'fit()' is implemented
#> [OK] Method 'extract_draws()' is implemented
#> [OK] Method 'predict_fit()' is implemented
#> [OK] Method 'log_lik()' is implemented
#> [OK] Method 'loo()' is implemented
#> [OK] Method 'diagnostics()' is implemented
#> Running smoke test with sample data...
#> Testing fit()...
#> [OK] fit() returns valid bayesim_fit_result
#> Testing extract_draws()...
#> [OK] extract_draws() returns matrix with colnames
#> Testing predict_fit()...
#> [OK] predict_fit() returns valid predictions
#> Testing log_lik()...
#> [OK] log_lik() returns valid matrix
#> Testing diagnostics()...
#> [OK] diagnostics() returns list
#> Smoke test completed successfully!
#> Validation passed!
# Use in your fitter tests
if (FALSE) { # \dontrun{
my_fitter <- MyCustomFitter()
validate_fitter(my_fitter, smoke_test = TRUE)
cat("Fitter is valid!\n")
} # }