### MLE and MAP Point Estimates (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Calculates Maximum Likelihood Estimation (MLE) and Maximum A Posteriori (MAP) estimates for model parameters. MLE finds parameters that maximize the likelihood of the data, while MAP includes prior information to find parameters that maximize the posterior distribution. Both methods utilize multiple starting points for robustness. ```matlab % Maximum likelihood estimation data = MemDataset(1); model = StandardMixtureModel(); [mleParams, logLikelihood] = MLE(data, model); fprintf('MLE: g=%.3f, sd=%.3f (LL=%.2f)\n', mleParams(1), mleParams(2), logLikelihood); % Maximum a posteriori estimation (includes prior) [mapParams, logPosterior] = MAP(data, model); fprintf('MAP: g=%.3f, sd=%.3f\n', mapParams(1), mapParams(2)); % MLE/MAP use multiple starting points from model.start % Results are the best across all chains ``` -------------------------------- ### StandardMixtureModel: Two-Component Mixture Model in MATLAB Source: https://context7.com/visionlab/memtoolbox/llms.txt Implements the classic mixture model for visual working memory, combining a Von Mises distribution for remembered items and a uniform distribution for guesses. It returns a model structure containing guess rate (g) and standard deviation (sd) parameters, along with functions for PDF and starting points. Can also use Kappa parameterization. ```matlab % Create the standard mixture model model = StandardMixtureModel(); % Model structure contains: % model.name = 'Standard mixture model' % model.paramNames = {'g', 'sd'} % model.lowerbound = [0, 0] % model.upperbound = [1, Inf] % model.pdf - probability density function % model.start - starting points for optimization % Fit to data data.errors = [-12, 3, 38, 27, -29, 21, -22, 52, -2, -19, 21, 17, 38, 6]; fit = MemFit(data, StandardMixtureModel()); % Use Kappa parameterization instead of SD model = StandardMixtureModel('UseKappa', true); % Now model.paramNames = {'g', 'K'} where K is concentration parameter ``` -------------------------------- ### MCMC Posterior Sampling with Convergence Detection (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Performs Metropolis-Hastings MCMC to sample from the posterior distribution of model parameters. Includes automatic convergence detection using Gelman-Rubin diagnostics and allows control over sampling parameters like verbosity and burn-in. ```matlab % Basic MCMC sampling data = MemDataset(1); model = StandardMixtureModel(); posteriorSamples = MCMC(data, model); % posteriorSamples.vals - matrix of parameter samples (rows=samples, cols=params) % posteriorSamples.like - log-likelihood for each sample % posteriorSamples.chain - which chain each sample came from % Summarize posterior summary = MCMCSummarize(posteriorSamples); % summary.maxPosterior - MAP estimate % summary.posteriorMean - posterior mean % summary.lowerCredible - lower 95% CI % summary.upperCredible - upper 95% CI % Control MCMC behavior posteriorSamples = MCMC(data, model, ... 'Verbosity', 0, ... % Silent mode 'PostConvergenceSamples', 10000, ... % More samples after convergence 'BurnInSamplesBeforeCheck', 500); % Burn-in before checking convergence % Disable automatic convergence detection posteriorSamples = MCMC(data, model, ... 'ConvergenceVariance', Inf, ... 'BurnInSamplesBeforeCheck', 5000, ... 'PostConvergenceSamples', 15000); ``` -------------------------------- ### MemFit: General Purpose Model Fitting in MATLAB Source: https://context7.com/visionlab/memtoolbox/llms.txt The primary interface for fitting visual working memory models to data. It automatically detects input formats, fits specified models using MCMC, displays results with confidence intervals, and provides interactive visualizations. Supports basic usage with error data, fitting specific models, programmatic access to results, and silent mode. ```matlab % Basic usage: fit errors with default StandardMixtureModel errors = [-89, 29, -2, 6, -16, 65, 43, -12, 10, 0, 178, -42, 52, 1, -2]; fit = MemFit(errors); % Output: % Error histogram: [visual histogram] % Model: Standard mixture model % Parameters: g, sd % % parameter MAP estimate lower CI upper CI % --------- ------------ -------- -------- % g 0.100 0.012 0.287 % sd 15.234 11.432 19.876 % Fit with a specific model data = MemDataset(1); % Load included dataset model = StandardMixtureModel(); fit = MemFit(data, model); % Access fit results programmatically fprintf('Guess rate: %.3f [%.3f, %.3f]\n', ... fit.maxPosterior(1), fit.lowerCredible(1), fit.upperCredible(1)); fprintf('SD: %.3f [%.3f, %.3f]\n', ... fit.maxPosterior(2), fit.lowerCredible(2), fit.upperCredible(2)); % Silent mode (no output) fit = MemFit(data, model, 'Verbosity', 0); ``` -------------------------------- ### Plot Posterior Distributions of Model Parameters Source: https://context7.com/visionlab/memtoolbox/llms.txt Visualizes marginal and joint posterior distributions for model parameters from MCMC samples or grid search results. Useful for understanding parameter correlations and uncertainty. Requires MemDataset and a model object. ```matlab % From MCMC samples data = MemDataset(1); model = StandardMixtureModel(); posteriorSamples = MCMC(data, model, 'Verbosity', 0); PlotPosterior(posteriorSamples, model.paramNames); % From grid search fullPosterior = GridSearch(data, model, 'PosteriorSamples', posteriorSamples); PlotPosterior(fullPosterior, model.paramNames); % For models with many parameters model = SwapModel(); data = MemDataset(3); posteriorSamples = MCMC(data, model, 'Verbosity', 0); PlotPosterior(posteriorSamples, model.paramNames); % Shows: g vs B, g vs sd, B vs sd, and marginals for each ``` -------------------------------- ### Load Included MemToolbox Datasets Source: https://context7.com/visionlab/memtoolbox/llms.txt Provides access to real and simulated datasets included with the MemToolbox for testing and demonstration. Supports loading by index or by specific dataset names like 'vandenbergetal2012'. ```matlab % Available datasets (1-10) data1 = MemDataset(1); % Real: 3000+ trials, 3 items, subject 1 data2 = MemDataset(2); % Real: 3000+ trials, 3 items, subject 2 data3 = MemDataset(3); % Simulated: SwapModel data4 = MemDataset(4); % Simulated: StandardMixtureModel, condition 1 data5 = MemDataset(5); % Simulated: StandardMixtureModel, condition 2 data8 = MemDataset(8); % Simulated: Multiple set sizes with full fields data9 = MemDataset(9); % Simulated: VariablePrecisionModel % Van den Berg et al. (2012) data data = MemDataset('vandenbergetal2012', 1, 1); % color task, participant 1 data = MemDataset('vandenbergetal2012', 2, 1); % orientation task, participant 1 % Available color participants: 'cc','clc','ela','hml','jv','kw','mbc','mt','rjj','ss','stp','wc','wjm' % Available orientation participants: 'AA','ACO','ELA','RGG','TCS','WJM' ``` -------------------------------- ### Grid Search for Full Posterior Evaluation (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Evaluates the posterior distribution at a grid of parameter values, providing an exact computation for low-dimensional models. This function can also refine the grid using MCMC samples for improved accuracy and efficiency, and visualize the resulting posterior. ```matlab % Basic grid search data = MemDataset(1); model = StandardMixtureModel(); fullPosterior = GridSearch(data, model); % fullPosterior.logLikeMatrix - log posterior on grid % fullPosterior.propToLikeMatrix - proportional to posterior (not log) % fullPosterior.valuesUsed - parameter values at grid points % Control grid resolution fullPosterior = GridSearch(data, model, 'PointsPerParam', 50); % Refine grid using MCMC samples (faster, more accurate) posteriorSamples = MCMC(data, model, 'Verbosity', 0); fullPosterior = GridSearch(data, model, 'PosteriorSamples', posteriorSamples); % Visualize full posterior PlotPosterior(fullPosterior, model.paramNames); ``` -------------------------------- ### Visualize Model Fit to Data (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Plots the probability density function (PDF) of a model against a histogram of the observed data. This function can display the fit using point estimates (like MAP) or visualize uncertainty by showing the range of PDFs derived from posterior samples. Customization options include number of bins, PDF color, and axis label visibility. ```matlab % Basic plot data = MemDataset(1); model = StandardMixtureModel(); fit = MemFit(data, model, 'Verbosity', 0); PlotModelFit(model, fit.maxPosterior, data, 'NewFigure', true); % Plot with posterior uncertainty (shaded region) PlotModelFit(model, fit.posteriorSamples, data, 'NewFigure', true); % Customize appearance PlotModelFit(model, fit.maxPosterior, data, ... 'NewFigure', true, ... 'NumberOfBins', 60, ... 'PdfColor', [0.8, 0.2, 0.2], ... 'ShowNumbers', true, ... 'ShowAxisLabels', true); ``` -------------------------------- ### Split Dataset by Experimental Condition Source: https://context7.com/visionlab/memtoolbox/llms.txt Splits a dataset into subsets based on a specified condition field, allowing for separate analysis of different experimental conditions. Handles both numerical and string conditions. Requires data structure with a condition field. ```matlab % Data with multiple conditions data.errors = [10, 30, -30, 20, -12, 80, -5, 15, -45]; data.condition = [1, 1, 1, 2, 2, 2, 3, 3, 3]; % Split by condition [datasets, conditionOrder] = SplitDataByField(data, 'condition'); % datasets{1} contains condition 1 data, etc. % Fit each condition separately model = StandardMixtureModel(); for i = 1:length(datasets) fit{i} = MemFit(datasets{i}, model, 'Verbosity', 0); fprintf('Condition %d: g=%.3f, sd=%.3f\n', ... conditionOrder(i), fit{i}.maxPosterior(1), fit{i}.maxPosterior(2)); end % String conditions also work data.condition = {'easy', 'easy', 'easy', 'hard', 'hard', 'hard'}; [datasets, conditionOrder] = SplitDataByField(data, 'condition'); ``` -------------------------------- ### TwoAFC - Convert model for 2AFC data (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Converts any continuous report model into a format suitable for two-alternative forced choice (2AFC) or change detection experiments. It automatically detects 2AFC data format and can be combined with other model wrappers like WithBias and Orientation. ```matlab % 2AFC data format data.changeSize = [180, 180, 180, 180, 20, 20, 20, 20, 20, 20]; % difference in degrees data.afcCorrect = [1, 1, 1, 1, 0, 0, 0, 1, 1, 1]; % correct=1, incorrect=0 % Fit 2AFC model model = TwoAFC(StandardMixtureModel()); fit = MemFit(data, model); % Automatic detection: MemFit recognizes 2AFC data fit = MemFit(data); % Automatically uses TwoAFC(StandardMixtureModel()) % Combine with other wrappers model = TwoAFC(WithBias(StandardMixtureModel())); model = TwoAFC(Orientation(StandardMixtureModel(), 2)); ``` -------------------------------- ### Fit Multi-Subject Hierarchical Models Source: https://context7.com/visionlab/memtoolbox/llms.txt Fits multiple subjects simultaneously using a hierarchical model, where individual parameters are drawn from population-level distributions. Supports both independent and hierarchical fitting. Requires MemDataset and a model object. ```matlab % Load multiple subjects datasets = {MemDataset(1), MemDataset(2)}; model = StandardMixtureModel(); % Fit independently (default) fit = MemFit(datasets, model); % fit{1}, fit{2} contain separate fits % Fit hierarchically fit = MemFit(datasets, model, 'UseHierarchical', true); % Population-level parameters inform individual estimates % Manual hierarchical fitting hModel = Hierarchical(datasets, model); params = MAP(datasets, hModel); fit = OrganizeHierarchicalParams(hModel, params); % fit.populationMean - population mean for each parameter % fit.populationStd - population SD for each parameter % fit.subject{i} - parameters for each subject ``` -------------------------------- ### SwapModel: Three-Component Model with Misbinding in MATLAB Source: https://context7.com/visionlab/memtoolbox/llms.txt An extension of the standard mixture model that accounts for misbinding errors by incorporating distractor locations. It requires distractor information in the data structure and fits a model with parameters for guess rate (g), swap rate (B), and precision (sd). Supports manual data structure creation and handling of variable set sizes with NaN padding. ```matlab % Load data with distractor information data = MemDataset(3); % Simulated swap data % data.errors - response errors relative to target % data.distractors - distances of distractors from target (rows=distractors, cols=trials) % Fit the swap model % Parameters: g (guess rate), B (swap rate), sd (precision) model = SwapModel(); fit = MemFit(data, model); % Create data structure manually data.errors = [-5, 12, -178, 45, -30, 8, 165, -12]; data.distractors = [60, -45, 170, -90, 120, -30, 160, 80; % distractor 1 -120, 90, -50, 140, -60, 75, -170, -100]; % distractor 2 fit = MemFit(data, SwapModel()); % Handle variable set sizes with NaN padding data.errors = [-5, 12, -178, 45]; data.distractors = [60, -45, 170, -90; % always present NaN, 90, -50, 140]; % only present on trials 2,3,4 fit = MemFit(data, SwapModel()); ``` -------------------------------- ### VariablePrecisionModel - Model variability in memory precision across trials (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Models variability in memory precision across trials by drawing the standard deviation from a higher-order distribution. It supports Gaussian, GammaSD, and GammaPrecision distributions for the standard deviations. This model is useful for capturing nuanced response variability. ```matlab % Default: Gaussian distribution over SDs model = VariablePrecisionModel(); % Parameters: g (guess rate), mnSTD (mean SD), sdSTD (SD of SDs) data = MemDataset(9); % Simulated variable precision data fit = MemFit(data, model); % Alternative parameterizations model_gamma_sd = VariablePrecisionModel('HigherOrderDist', 'GammaSD'); model_gamma_prec = VariablePrecisionModel('HigherOrderDist', 'GammaPrecision'); % Fit and compare data = MemDataset(1); fit = MemFit(data, {VariablePrecisionModel(), StandardMixtureModel()}); ``` -------------------------------- ### WithBias - Add systematic bias to any model (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt A wrapper function that adds a shift/bias parameter (mu) to any existing model. This is useful when responses are systematically shifted from the true value. It can be chained with other wrappers and allows for custom prior distributions for the bias parameter. ```matlab % Add bias to standard mixture model model = WithBias(StandardMixtureModel()); % Now parameters are: mu (bias), g (guess rate), sd (precision) errors = [-89, 29, -2, 6, -16, 65, 43, -12, 10, 0, 178, -42, 52, 1, -2]; fit = MemFit(errors, model); % Chain with other wrappers model = TwoAFC(WithBias(StandardMixtureModel())); % Add custom prior for bias parameter biasModel = WithBias(StandardMixtureModel(), @(mu) normpdf(mu, 0, 10)); ``` -------------------------------- ### Orientation - Convert model for orientation data (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Wraps a model to specifically handle orientation data, which ranges from -90 to 90 degrees, unlike the default -180 to 180 range for color wheel data. This ensures correct interpretation and fitting for orientation-based experiments. It can be combined with other wrappers like WithBias and TwoAFC. ```matlab % Basic orientation model model = Orientation(StandardMixtureModel(), 2); % 2 = sd parameter is in degrees % Orientation data data.errors = [-12, 3, 38, 27, -29, 21, -22, 52, -2, -19, 21, 17]; % range: -90 to 90 fit = MemFit(data, model); % With bias (specify both mu and sd as degree parameters) model = Orientation(WithBias(StandardMixtureModel()), [1, 3]); % mu=1, sd=3 fit = MemFit(data, model); % For 2AFC orientation experiments model = TwoAFC(Orientation(StandardMixtureModel(), 2)); ``` -------------------------------- ### SlotModel - Capacity-limited slots model (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Models a fixed number of memory slots with equal precision. When the set size exceeds capacity, some items are guessed entirely. This model requires set size information for the data. It can be instantiated with default parameters or by manually providing error and set size data. ```matlab % SlotModel requires set size information data = MemDataset(8); % Data with multiple set sizes % data.errors - response errors % data.n - set size for each trial model = SlotModel(); % Parameters: capacity (number of slots), sd (precision) fit = MemFit(data, model); % Create data manually data.errors = [-5, 12, -30, 8, 180, -90, 45, -12, 170, -5]; data.n = [2, 2, 2, 4, 4, 4, 6, 6, 6, 6]; % set sizes fit = MemFit(data, SlotModel()); ``` -------------------------------- ### Model Comparison using AIC, AICc, and BIC (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Computes Akaike Information Criterion (AIC), Corrected AIC (AICc), and Bayesian Information Criterion (BIC) for comparing different models. Lower values of these criteria indicate better model fits, balancing goodness-of-fit with model complexity. The function can also be used with MemFit to obtain DIC. ```matlab % Compare multiple models data = MemDataset(1); models = {StandardMixtureModel(), ... WithBias(StandardMixtureModel()), ... VariablePrecisionModel()}; [AIC, BIC, logLike, AICc] = ModelComparison_AIC_BIC(data, models); % Display results fprintf('Model\t\t\tAIC\tBIC\tLogLike\n'); fprintf('Standard Mixture\t%.1f\t%.1f\t%.1f\n', AIC(1), BIC(1), logLike(1)); fprintf('With Bias\t\t%.1f\t%.1f\t%.1f\n', AIC(2), BIC(2), logLike(2)); fprintf('Variable Precision\t%.1f\t%.1f\t%.1f\n', AIC(3), BIC(3), logLike(3)); % Lower AIC/BIC = better model % Difference of 10+ is strong evidence % Use MemFit for interactive comparison with DIC fit = MemFit(data, models); % Computes AIC, AICc, BIC, and optionally DIC ``` -------------------------------- ### FixParameterValue - Constrain model parameters to fixed values (MATLAB) Source: https://context7.com/visionlab/memtoolbox/llms.txt Constrains any parameter in a model to a fixed value, which is useful for testing specific hypotheses or simplifying model complexity. Parameters can be fixed by name or by their index. This allows for direct comparison between models with fixed versus free parameters. ```matlab % Fix guess rate to 0 (no guessing model) model = FixParameterValue(StandardMixtureModel(), 'g', 0); % Remaining parameter: sd only data = MemDataset(1); fit = MemFit(data, model); % Fix by parameter index instead of name model = FixParameterValue(StandardMixtureModel(), 1, 0.1); % g = 0.1 % Compare fixed vs. free models model1 = StandardMixtureModel(); model2 = FixParameterValue(StandardMixtureModel(), 'g', 0); fit = MemFit(data, {model1, model2}); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.