### Example Profile Configuration File Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www1/mpicxx.html An example of a profile configuration file (e.g., myprof.conf) used with the '-profile=' option. It defines pre-linked libraries, post-linked libraries, and include paths for custom profiling libraries. ```bash PROFILE_PRELIB="-L/usr/local/myprof/lib -lmyprof" PROFILE_INCPATHS="-I/usr/local/myprof/include" ``` -------------------------------- ### Example of creating a profile configuration file Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www1/mpicc.html This example shows how to create a profile configuration file (e.g., myprof.conf) to specify custom libraries and include paths for MPI profiling. This file is read by mpicc when the -profile option is used with the corresponding name. ```bash # myprof.conf PROFILE_PRELIB="-L/usr/local/myprof/lib -lmyprof" PROFILE_INCPATHS="-I/usr/local/myprof/include" ``` -------------------------------- ### WPI Model Setup Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/paradigms/in_development/ParadigmWPI.html Initializes the machine learning setup for the WPI paradigm. It validates the model type and calculates dimensions for trials, channels, and wavelet coefficients. ```MATLAB function [X,y,B,pot,tau,G] = wpi_setup(self,trials,targets,shape,opts,scales,args) [n,f] = size(trials); c = shape(1); w = shape(2); s = length(scales); t = w/s/2; if strcmp(opts.ptype,'regression') error('Currently, only the classification model is implemented.'); end end ``` -------------------------------- ### Example Usage of run_writevisualization Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/online_plugins/Simulated/run_writevisualization.html Examples showing how to call the function with different parameters, including custom visualization functions and update rates. ```MATLAB run_writevisualization('mymodel','mystream'); run_writevisualization('mymodel','mystream',@myvisualizer); run_writevisualization('Model','mymodel','SourceStream','mystream','VisFunction',@myvisualizer,'UpdateFrequency',25); ``` -------------------------------- ### GET /gui_chooseapproach Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_chooseapproach.html Initializes or raises the singleton GUI for selecting an approach. ```APIDOC ## GET /gui_chooseapproach ### Description Initializes the GUI_CHOOSEAPPROACH interface. If an instance is already running, it raises that instance to the foreground. ### Method GET ### Endpoint gui_chooseapproach(varargin) ### Parameters #### Query Parameters - **Property** (string) - Optional - Property name for GUI configuration. - **Value** (any) - Optional - Value corresponding to the property. ### Request Example { "Property": "Visible", "Value": "on" } ### Response #### Success Response (200) - **H** (handle) - The handle to the GUI_CHOOSEAPPROACH figure. #### Response Example { "handle": "figure_handle_object" } ``` -------------------------------- ### GUI Creation Function: Figure1 Setup Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_loadset.html Callback function executed during the creation of the main figure window. Used for initial setup of the figure. ```matlab function figure1_CreateFcn(hObject, eventdata, handles) % No specific implementation shown ``` -------------------------------- ### SuperGUI Example Usage Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/arguments/private/supergui.html Demonstrates how to use the supergui function to create a simple GUI with a radio button and a push button. This example shows the basic structure for defining horizontal geometry and the list of UI elements. ```matlab figure; supergui( 'geomhoriz', { 1 1 }, 'uilist', { ... { 'style', 'radiobutton', 'string', 'radio' }, ... { 'style', 'pushbutton' , 'string', 'push' } } ); ``` -------------------------------- ### Initialize BCILAB Environment with Custom Paths Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Demonstrates how to start BCILAB with specified data and cache directories. This is useful for managing data organization and performance. ```matlab env_startup('data','C:\Data', 'cache','C:\Data\Temp'); ``` ```matlab env_startup('data',{'C:\Data','F:\Data2'}, 'cache','C:\Data\Temp'); ``` -------------------------------- ### MATLAB: Setup and Start Timer Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/visualization/vis_filtered.html Initializes and starts a timer object for periodic execution. The timer is configured to refresh at a rate determined by 'opts.refreshrate' and executes the 'on_timer' function. It includes a short delay before starting and is tagged for identification. ```matlab th = timer('Period', 1.0/opts.refreshrate,'ExecutionMode','fixedRate','TimerFcn',@[on_timer](#_sub2 "subfunction on_timer(varargin)"),'StartDelay',0.2,'Tag',[visname '_timer']); start(th); ``` -------------------------------- ### Get Datatype Extent in C - MPI_Type_extent Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www3/MPI_Type_extent.html The MPI_Type_extent function returns the extent of a given MPI datatype. The extent is the number of bytes between the start of one instance of the datatype and the start of the next instance in memory. This function is thread- and interrupt-safe. It is deprecated in MPI-2 and MPI_Type_get_extent should be used instead. ```c int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint *extent) ``` -------------------------------- ### FUNCTION env_startup Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Initializes the BCILAB toolbox environment with optional directory and caching settings. ```APIDOC ## FUNCTION env_startup ### Description Starts the BCILAB toolbox by setting up global data structures and loading necessary dependencies. This function is typically called by wrappers like bcilab.m. ### Method MATLAB Function Call ### Endpoint env_startup(Options...) ### Parameters #### Options (Name-Value Pairs) - **data** (string/cell) - Optional - Path(s) where data sets are stored. - **store** (string) - Optional - Path where data shall be stored (requires write permissions). - **temp** (string) - Optional - Directory for miscellaneous outputs like AMICA models. - **private** (string) - Optional - Path to a private plugin directory. - **cache** (string/cell) - Optional - Path or configuration for intermediate data caching. ### Request Example % Initialize with default settings env_startup() % Initialize as a worker node env_startup('worker', true) ### Response #### Success Response - **status** (void) - Initializes global environment variables and loads dependencies. ``` -------------------------------- ### Configure and Verify MATLAB MEX Compiler Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/helpers/hlp_trycompile.html Checks for existing MEX compiler configurations and guides the user through the setup process if no compiler is found. It includes platform-specific advice for Windows, Linux, and macOS environments. ```matlab if isempty(compiler_selected) if hlp_matlab_version() >= 708 try cconf = mex.getCompilerConfigurations; compiler_selected = true; catch disp('To compile this feature, you first need to select a compiler.'); if ispc disp_once('Ensure a supported compiler like Visual Studio is installed.'); elseif isunix disp_once('On Linux/UNIX, use the GCC compiler suite.'); else disp_once('On Mac OS, ensure Xcode/GCC is installed.'); end mex -setup cconf = mex.getCompilerConfigurations; compiler_selected = true; end end end ``` -------------------------------- ### Get State Event IDs for MPE Logging (C) Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www4/MPE_Log_get_state_eventIDs.html Retrieves a pair of event numbers to define a state using MPE_Describe_state(). This function is provided to ensure unique event numbers are used and is thread-safe. It takes pointers to integers which will be populated with the starting and ending event IDs. ```c int MPE_Log_get_state_eventIDs( int *statedef_startID, int *statedef_finalID ) ``` -------------------------------- ### Initialize gui_producevisualization GUI Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_producevisualization.html This snippet shows the primary function signature and the initialization structure for the MATLAB GUIDE singleton GUI. It sets up the GUI state and handles input arguments for the opening function. ```matlab function varargout = gui_producevisualization(varargin) % GUI_PRODUCEVISUALIZATION MATLAB code for gui_producevisualization.fig gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_producevisualization_OpeningFcn, ... 'gui_OutputFcn', @gui_producevisualization_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end ``` -------------------------------- ### Makefile Configuration for MATLAB MEX File (Linux) Source: https://github.com/sccn/bcilab/blob/devel/dependencies/glm-ie_v1.5/pls/lbfgsb/README.html Example Makefile configuration for building a MATLAB MEX file on a Linux system. This specifies the MEX executable, platform suffix, MATLAB installation path, specific versions of C++ and Fortran compilers, and necessary compilation flags for position-independent code and threading. ```makefile MEX = mex MEXSUFFIX = mexglx MATLAB_HOME = /cs/local/generic/lib/pkg/matlab-7.2 CXX = g++-3.4.5 F77 = g77-3.4.5 CFLAGS = -O3 -fPIC -pthread FFLAGS = -O3 -fPIC -fexceptions ``` -------------------------------- ### Parameter Search for Epoch Extraction in BCI Training Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/offline_analysis/bci_train.html This example shows how to use the 'search' function within bci_train to find optimal parameters for epoch extraction. It defines search ranges for the start and end times of epochs, allowing the function to explore different time windows for signal processing. This is crucial when reaction times or event durations are variable. ```matlab calib = io_loadset('data sets/john/gestures.eeg'); myapproach = {'CSP', 'SignalProcessing',{'EpochExtraction',[search(0.25:0.1:0.75),search(1.5:0.5:4.5)]}}; [loss,model,stats] = bci_train('Data',calib, 'Approach',myapproach}, 'TargetMarkers',{'left-imag','right-imag'}) ``` -------------------------------- ### Bipolar Colormap Example Source: https://github.com/sccn/bcilab/blob/devel/dependencies/SIFT-private/external/mobilab/bipolar_colormap/html/colormap_investigation.html An example demonstrating the use of the 'bipolar' function to generate an optimized colormap, similar to the 'brew2' example. ```matlab map = bipolar(m, 0.5); % (gives the optimized brew2 that we get here) ``` -------------------------------- ### Set Up User Directories and MATLAB Path Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Creates essential directories within the user's '.bcilab' folder (e.g., 'code', 'logs', 'models') and adds the 'code' subdirectories to the MATLAB path. It also ensures the 'env_add.m' file exists in the dependencies folder. ```matlab home_basedir = [hlp_homedir filesep '.bcilab' filesep]; home_codedirs = {['code' filesep 'filters'],['code' filesep 'dataset_editing'], ... ['code' filesep 'machine_learning'], ['code' filesep 'paradigms'], ['code' filesep 'scripts']}; home_miscdirs = {'models','approaches','code',['code' filesep 'dependencies'],'logs',['logs' filesep 'workers']}; for d = [home_codedirs home_miscdirs] try subdir = [home_basedir d{1}]; if ~exist(subdir,'dir') mkdir(subdir); end catch e disp(['Could not create directory: ' subdir ': ' e.message]); end end % and add the code directories to the path for d = home_codedirs addpath(genpath([home_basedir d{1}])); end % add the env_add.m file to the dependencies folder add_file = [home_basedir 'code' filesep 'dependencies' filesep 'env_add.m']; if ~exist(add_file,'file') try f = fopen(add_file,'w'); fwrite(f,' '); fclose(f); catch e disp(['Could not create file ' add_file ': ' e.message]); end end ``` -------------------------------- ### UTL_GRIDSEARCH Example Usage (MATLAB) Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/utils/utl_gridsearch.html Illustrative examples of how to use the UTL_GRIDSEARCH function in MATLAB. These examples demonstrate different ways to specify the function, input domains, and options for the grid search. ```matlab % For the four equivalent calls, utl_gridsearch(@f, 1:2, {'a',{'b'},5:7,{5:7}}, [], {}, 'xy', {[1 2 3]}); utl_gridsearch('direct', @f, 1:2, {'a',{'b'},5:7,{5:7}}, [], {}, 'xy', {[1 2 3]}); utl_gridsearch('clauses', @f, search(1,2), search('a',{'b'},5:7,{5:7}), [], {}, search('x','y'), [1 2 3]); utl_gridsearch({'argform','clauses', 'func',@f}, search(1,2), search('a',{'b'},5:7,{5:7}), [], {}, search('x','y'), [1 2 3]); % ... the following 16 = 2x4x1x1x2x1 executions of f are compared: f(1,'a',[],{},'x', [1 2 3]) f(1,'a',[],{},'y', [1 2 3]) f(1,{'b'},[],{},'x', [1 2 3]) f(1,{'b'},[],{},'y', [1 2 3]) f(1,5:7,[],{},'x', [1 2 3]) f(1,5:7,[],{},'y', [1 2 3]) f(1,{5:7},[],{},'x', [1 2 3]) f(1,{5:7},[],{},'y', [1 2 3]) f(2,'a',[],{},'x', [1 2 3]) f(2,'a',[],{},'y', [1 2 3]) f(2,{'b'},[],{},'x', [1 2 3]) f(2,{'b'},[],{},'y', [1 2 3]) f(2,5:7,[],{},'x', [1 2 3]) f(2,5:7,[],{},'y', [1 2 3]) f(2,{5:7},[],{},'x', [1 2 3]) f(2,{5:7},[],{},'y', [1 2 3]) ``` -------------------------------- ### Initialize BCILAB Calibration GUI Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_calibratemodel.html This snippet initializes the MATLAB GUIDE-based GUI. It sets up the singleton state and defines the opening and output functions required for the interface lifecycle. ```MATLAB gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_calibratemodel_OpeningFcn, ... 'gui_OutputFcn', @gui_calibratemodel_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end ``` -------------------------------- ### ml_trainsvm Output and Examples Source: https://github.com/sccn/bcilab/wiki/BCILAB-documentation Describes the output 'Model' of the ml_trainsvm function and provides usage examples. ```APIDOC ### Output - **Model**: A predictive model structure containing: - `classes`: The class labels predicted by the model. - `sc_info`: Scaling information used during training. ### Examples - Learn a linear SVM model: ```matlab model = ml_trainsvm(trials, labels, 1); ``` ### See Also - `ml_predictsvm()` ``` -------------------------------- ### Create a simple input GUI Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/arguments/private/inputgui.html Demonstrates how to initialize a basic GUI with a text label and an editable text box using the inputgui function. ```matlab res = inputgui('geometry', { 1 1 }, 'uilist', ... { { 'style' 'text' 'string' 'Enter a value' } ... { 'style' 'edit' 'string' '' } }); ``` -------------------------------- ### Install and Configure mlUnit Source: https://github.com/sccn/bcilab/blob/devel/dependencies/mlunit-1.5.1/readme.txt Commands to install the mlUnit framework and add it to the MATLAB search path. ```matlab cd $HOME/mlunit/src; install(mlunit); addpath('$HOME/mlunit/src'); ``` -------------------------------- ### GUI Initialization and Main Function Call - MATLAB Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_producevisualization.html Handles the initial setup and main function call for the 'gui_producevisualization' GUI. It defines the GUI's opening, output, layout, and callback functions, and then calls the main GUI function to manage its execution. ```MATLAB gui_State = guihandles(gcbf); % Use a private static variable to keep track of which callbacks have already been registered persistent hGUICallbacks if isempty(hGUICallbacks) hGUICallbacks = struct('gui_OpeningFcn', false, 'gui_OutputFcn', false, 'gui_LayoutFcn', false, 'gui_Callback', false); end % Check if the callback has already been registered if ~hGUICallbacks.gui_Callback setappdata(gui_State.figure1, 'gui_Callback', @gui_Callback); hGUICallbacks.gui_Callback = true; end % Define the GUI's callback functions callbacks = { ... 'gui_OpeningFcn', @gui_producevisualization_OpeningFcn, ... 'gui_OutputFcn', @gui_producevisualization_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', @gui_Callback}; % Initialize GUI state if necessary if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT ``` -------------------------------- ### Verify Iso2mesh Installation Source: https://github.com/sccn/bcilab/blob/devel/dependencies/SIFT-private/external/iso2mesh/doc/INSTALL.txt Command to verify that the Iso2mesh toolbox is correctly installed and accessible within the Matlab or Octave environment. ```Matlab rehash; which vol2mesh; ``` -------------------------------- ### Initialize BCILAB Environment with Custom Paths Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Demonstrates how to initialize the BCILAB environment by specifying custom data and cache directories. This allows for flexible file management and storage configurations. ```MATLAB env_startup('data','C:\\Data', 'cache','C:\\Data\\Temp'); env_startup('data',{'C:\\Data','F:\\Data2'}, 'cache','C:\\Data\\Temp'); ``` -------------------------------- ### Start BCILAB as a Worker Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Starts the BCILAB toolbox in worker mode, enabling it to perform tasks in a distributed or parallel environment. ```matlab env_startup('worker',true) ``` -------------------------------- ### Initialize Background Prediction and Writing Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/online_analysis/onl_write_background.html Demonstrates how to initialize the background processing pipeline using a callback function and a data stream. The first example uses minimal arguments, while the second specifies custom output formats and update frequencies. ```MATLAB % Basic usage: send model outputs to a destination onl_write_background(@send_outputs_to_destination, 'mystream'); % Advanced usage: specify custom output format and update frequency onl_write_background(@send_outputs_to_destination, 'mystream', 'lastmodel', 'expectation', 25); % Explicit argument passing onl_write_background('ResultWriter', @send_outputs_to_destination, 'MatlabStream', 'mystream', 'Model', 'lastmodel', 'OutputFormat', 'expectation', 'UpdateFrequency', 25); ``` -------------------------------- ### Customized Example: Working-Memory Load Prediction Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/offline_analysis/bci_train.html A detailed example demonstrating how to customize the toolbox for predicting working-memory load using the n-back task. ```APIDOC ## Customized Example: Working-Memory Load Prediction ### Objective To obtain an online prediction of a person's working-memory load. ### Starting Point Use a calibration data set from an n-back task where conditions are marked with events like 'n1', 'n2', etc., indicating the number of items in memory. ### Paradigm Basis Spec-CSP (`paradigms/ParadigmSpecCSP`). ### Customizations 1. **Frequency Band Relaxation**: Include the theta band (e.g., [10]) in the analysis, relaxing the default narrow band focus. 2. **Data Epoch Selection**: Modify the default epoch selection from `0.5-3.5` seconds after an event to `[-2.5 2.5]` seconds for better time coverage relative to the task events. ### Default Behavior Modification - The default Spec-CSP paradigm focuses on a specific frequency band. - By default, it selects data epochs at 0.5-3.5 seconds following selected events. - The customization aims to broaden the frequency analysis and adjust the time window for epoch selection. ``` -------------------------------- ### Initialize gui_saveapproach GUI Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_saveapproach.html This snippet shows the primary entry point and initialization logic for the gui_saveapproach MATLAB function, which uses the GUIDE framework to manage the GUI state and callbacks. ```MATLAB function varargout = gui_saveapproach(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_saveapproach_OpeningFcn, ... 'gui_OutputFcn', @gui_saveapproach_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end ``` -------------------------------- ### Initialize Build Slave and Monitoring Loop Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_buildslave.html Sets up the build slave environment by disabling specific warnings, logging the start of the process, and entering a continuous monitoring loop. It uses an `onCleanup` object to ensure proper cleanup actions are performed upon exit. ```matlab % turn off a few warnings if ispc warning off MATLAB:FILEATTRIB:SyntaxWarning; end warning off MATLAB:DELETE:FileNotFound; % run... quicklog(o.log,'===== Now running as build slave ====='); cleaner = onCleanup(@cleanup); ``` -------------------------------- ### Start BCILAB as a Parallel Worker Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html Starts the BCILAB toolbox as a worker, potentially for parallel processing. This can be configured with specific engine and pool settings. ```matlab env_startup('parallel',{'engine','BLS', 'pool',{'computer1','computer2','computer3'}}) ``` -------------------------------- ### MATLAB GUI Initialization - gui_reviewapproach Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_reviewapproach.html Initializes the GUI for the review approach function. This includes setting up the GUI state, handling input arguments, and calling the main GUI function. It defines callbacks for various GUI elements and manages the GUI's lifecycle. ```MATLAB function varargout = gui_reviewapproach(varargin) % bring up a modal configuration panel for the given approach % [Approach,Action] = gui_configapproach(Approach) % % In: % Approach : an approach; struct with fields 'paradigm' and 'parameters' (and optionally 'description' and 'name') % or cell array {paradigm, parameter1, parameter2, ...} % % DoSave: Whether to bring up a save approach gui, after clicking okay (default: false) % % % Out: % Result : a (re-)configured version of the Approach, or the unmodified input Approach (though possibly reformatted) if the user pressed 'Cancel' % Action : either 'OK' or 'Cancel' % % Christian Kothe, Swartz Center for Computational Neuroscience, UCSD % 2010-10-25 % Last Modified by GUIDE v2.5 14-Aug-2013 15:38:29 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_reviewapproach_OpeningFcn, ... 'gui_OutputFcn', @gui_reviewapproach_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before gui_reviewapproach is made visible. function gui_reviewapproach_OpeningFcn(hObject, eventdata, handles, varargin) % Choose default command line output for gui_reviewapproach handles.output = 'Cancel'; ``` -------------------------------- ### Initialize BCILAB Environment (MATLAB) Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/environment/env_startup.html The env_startup function initializes the BCILAB toolbox by setting up global data structures and loading dependency toolboxes. It accepts optional name-value pairs to configure directory paths for data, storage, temporary files, and private plugins. It also allows fine-grained control over caching mechanisms, including cache directory, time limits, free space requirements, and memory capacity. Additionally, it supports configuration for parallel computing engines. ```matlab function env_startup(varargin) % Start the BCILAB toolbox, i.e. set up global data structures and load dependency toolboxes. % env_startup(Options...) % Does all steps necessary for loading the toolbox -- the functions bcilab.m and eegplugin_bcilab.m % are wrappers around this function which provide a higher level of convenience (configuration files % in particular). Directly calling this function is not recommended. % % In: % Options... : optional name-value pairs; allowed names are: % --- directory settings --- % 'data': Path where data sets are stored, used by data loading/saving routines. % (default: path/to/bcilab/userdata) % Note: this may also be a cell array of directories, in which case references % to data:/ are looked up in all of the specified directories, and the % best match is taken. % 'store': Path in which data shall be stored. Write permissions necessary (by default % identical to the data path) % 'temp': temp directory (for misc outputs, e.g., AMICA models and dipole fits) % (default: path/to/bcilab-temp, or path/to/cache/bcilab_temp if a cache % directory was specified) % 'private': optional private plugin directory, separate from bcilab/*; can have % the same directory structure as ~/.bcilab/ (default: []) % --- caching settings --- % 'cache': Path where intermediate data sets are cached. Should be located on a fast % (local) drive with sufficient free capacity. % * if this is left unspecified or empty, the cache is disabled % * if this is a directory, it is used as the default cache location % * a fine-grained cache setup can be defined by specifying a cell array of % cache locations, where each cache location is a cell array of name-value % pairs, with possible names: % 'dir': directory of the cache location (e.g. '/tmp/bcilab_tmp/'), mandatory % 'time': only computations taking more than this many seconds may be stored % in this location, but if a computation takes so long that another % cache location with a higher time applies, that other location is % preferred. For example, the /tmp directory may take computations % that take at least a minute, the home directory may take % computations that take at least an hour, the shared /data/results % location of the lab may take computations that take at least 12 % hours (default: 30 seconds) % 'free': minimum amount of space to keep free on the given location, in GiB, % or, if smaller than 1, free is taken as the fraction of total % space to keep free. (default: 80) % 'tag': arbitrary identifier for the cache location (default: 'location_i', % for the i'th location) must be a valid MATLAB struct field name, % only for display purposes % 'mem_capacity': capacity of the memory cache (default: 2) % if this is smaller than 1, it is taken as a fraction of the total % free physical memory at startup time, otherwise it is in GB % 'data_reuses' : estimated number of reuses of a data set being computed (default: 3) % ... depending on disk access speeds, this determines whether it makes % sense to cache the data set % --- parallel computing settings --- % 'parallel' : parallelization options; cell array of name-value pairs, with names: % 'engine': parallelization engine to use, can be 'local', % 'ParallelComputingToolbox', or 'BLS' (BCILAB Scheduler) % (default: 'local') % (implementation details omitted for brevity) end ``` -------------------------------- ### Usage Examples for Ridge and Logistic Regression Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/machine_learning/ml_trainridge.html Examples showing how to invoke training functions with specific scaling options and parameter search ranges for model optimization. ```MATLAB model = ml_trainlogreg(trials,targets,0.1,'scaling','center'); model = utl_searchmodel({trials,targets},'args',{{'ridge',search(2.^(-5:1:10)),'scaling','center'}}); ``` -------------------------------- ### Help Button Callback (pushbutton7) Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_configpaths.html Callback function for 'pushbutton7', the help button. It opens the BCILAB startup documentation using the 'env_doc' function. ```matlab function pushbutton7_Callback(hObject, eventdata, handles) % help button env_doc env_startup ``` -------------------------------- ### Initialize gui_configcache GUI Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_configcache.html This snippet demonstrates the initialization logic for the gui_configcache singleton GUI. It sets up the GUI state structure, including references to opening and output functions, and handles input arguments to route callbacks. ```MATLAB function varargout = gui_configcache(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_configcache_OpeningFcn, ... 'gui_OutputFcn', @gui_configcache_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end ``` -------------------------------- ### BCILAB FBCSP Training Example Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/paradigms/ParadigmFBCSP.html Example of how to train a model using the FBCSP approach in BCILAB. This function takes data and specifies target markers to train the model. ```matlab % [loss,model,stats] = bci_train('Data',data, 'Approach','ParadigmFBCSP, 'TargetMarkers',{'n1','n2','n3'}) ``` -------------------------------- ### Train RVM Model Examples Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/machine_learning/ml_trainrvm.html Demonstrates how to initialize and train an RVM model using different configurations, including classification, regression, and kernel parameter optimization. ```matlab % learn a standard Relevance Vector Machine classifier model = ml_trainrvm(trials,targets) % as before, but this time use a regression approach model = ml_trainrvm(trials,targets,'ptype','regression') % use a Laplacian kernel model = ml_trainrvm(trials,targets,'kernel','laplace') % find the optimal kernel scale using parameter search model = utl_searchmodel({trials,targets},'args',{{'rvm','gamma',seach(2.^(-16:2:4))}}) ``` -------------------------------- ### Install Subversion Client (Red Hat/Fedora/CentOS) Source: https://github.com/sccn/bcilab/blob/devel/dependencies/SIFT-private/external/iso2mesh/doc/Download_and_License.txt Command to install the subversion client on Red Hat-based Linux systems like Fedora and CentOS. This is necessary for SVN operations. ```bash su -c 'yum install subversion' ``` -------------------------------- ### Install Subversion Client (Debian/Ubuntu) Source: https://github.com/sccn/bcilab/blob/devel/dependencies/SIFT-private/external/iso2mesh/doc/Download_and_License.txt Command to install the subversion client on Debian-based Linux systems like Ubuntu. This is a prerequisite for downloading development snapshots using SVN. ```bash sudo apt-get install subversion ``` -------------------------------- ### GUI Callback: Pushbutton5 - Help Documentation Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_loadset.html Triggers the display of help documentation for the 'io_loadset' function, likely accessed via a help button. ```matlab function pushbutton5_Callback(hObject, eventdata, handles) % help button env_doc io_loadset ``` -------------------------------- ### Execute Environment Startup Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_configcluster.html Callback function for a pushbutton that initiates environment startup. It calls the 'env_doc' and 'env_startup' functions, likely to set up the working environment for subsequent operations. ```matlab function pushbutton3_Callback(hObject, eventdata, handles) env_doc env_startup end ``` -------------------------------- ### Fortran Datatype Example Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www3/MPI_Type_create_indexed_block.html An example of using MPI_TYPE_CREATE_INDEXED_BLOCK in Fortran. It demonstrates how to define indices as displacements and the potential pitfall of off-by-one errors if not considering zero-based vs. one-based indexing. ```fortran integer a(100) integer blens(10), indices(10) do i=1,10 10 indices(i) = 1 + (i-1)*10 call MPI_TYPE_CREATE_INDEXED_BLOCK(10,1,indices,MPI_INTEGER,newtype,ierr) call MPI_TYPE_COMMIT(newtype,ierr) call MPI_SEND(a,1,newtype,...) ``` -------------------------------- ### Integrate BCILAB with BCI2000 Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/online_plugins/BCI2000/run_pipebci2000.html This function installs the necessary configuration files into the BCI2000 directory to allow the MatlabSignalProcessing module to interface with BCILAB. It requires the path to the BCI2000 installation directory as an input argument. ```MATLAB function run_pipebci2000(varargin) % Integrate BCILAB into the BCI2000 real-time system. % run_pipebci2000(BCI2000Directory) % This function makes BCILAB usable as a Signal Processing module within the BCI2000 real-time % experimentation environment. It installs a custom bci_Construct.m in the BCI2000 prog directory. ``` -------------------------------- ### par_worker - Start BCILAB Worker Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/parallel/par_worker.html Starts a BCILAB worker process that listens on a specified port or a range of ports. It handles various configuration options for network communication, timeouts, and resource allocation. ```APIDOC ## POST /par_worker ### Description Starts a BCILAB worker process. This process listens on a specified network port to receive tasks and send results. It can be configured with various network and timing parameters. ### Method POST ### Endpoint /par_worker ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **port** (integer) - Optional - The base port number to listen on. If 0 or not provided, a default port (23547) is used. - **portrange** (integer) - Optional - The number of successive ports to try if the base port is occupied. Defaults to 0, which means it tries as many ports as there are CPU cores. - **timeout_heartbeat** (integer) - Optional - Timeout for heartbeat signals. Defaults to 0. - **backlog** (integer) - Optional - The maximum queue length for incoming connection indications. Defaults to 1. - **timeout_accept** (integer) - Optional - Timeout for accepting connections. Defaults to 3 seconds. - **timeout_dialout** (integer) - Optional - Timeout for establishing outgoing connections. Defaults to 10 seconds. - **timeout_send** (integer) - Optional - Timeout for sending data. Defaults to 10 seconds. - **timeout_recv** (integer) - Optional - Timeout for receiving data. Defaults to 5 seconds. - **min_keepalive** (integer) - Optional - Minimum keep-alive time in seconds. Defaults to 300 seconds. - **receive_buffer** (integer) - Optional - Size of the receive buffer in bytes. Defaults to 64000 bytes. - **retries_send** (integer) - Optional - Number of retries for sending data. Defaults to 2. - **retry_wait** (integer) - Optional - Wait time between send retries in seconds. Defaults to 2 seconds. - **linger_send** (integer) - Optional - Linger time for sending in seconds. Defaults to 3 seconds. - **update_check** (array) - Optional - Specifies update check behavior. - **matlabthreads** (integer) - Optional - Maximum number of MATLAB threads to use. Defaults to 4. - **token** (string) - Optional - Authentication token. Defaults to 'dsfjk45djf'. - **verbosity** (integer) - Optional - Verbosity level for output messages. Defaults to 1. - **max_java_memory** (integer) - Optional - Maximum Java heap memory in bytes. Defaults to 2^26. ### Request Example ```json { "port": 51123, "portrange": 5, "timeout_accept": 5, "timeout_recv": 3, "timeout_send": 15 } ``` ### Response #### Success Response (200) - **port** (integer) - The actual port the worker is listening on. - **pid** (integer) - The process ID of the worker. #### Response Example ```json { "port": 51123, "pid": 12345 } ``` ``` -------------------------------- ### Configure MPI Profiling with mpif90 Source: https://github.com/sccn/bcilab/blob/devel/dependencies/amica-2011-08-23/mpich2-1.3.2-install/share/doc/www1/mpif90.html This example shows how to use the -profile option with mpif90 to include a custom MPI profiling library. It demonstrates creating a configuration file (myprof.conf) to specify pre-linking libraries and include paths, then using the -profile argument to apply these settings. ```bash PROFILE_PRELIB="-L/usr/local/myprof/lib -lmyprof" PROFILE_INCPATHS="-I/usr/local/myprof/include" mpif90 -profile=myprof ... ``` -------------------------------- ### Initialize BCILAB in MATLAB Source: https://github.com/sccn/bcilab/wiki/BCILAB-documentation These code snippets demonstrate how to load and initialize the BCILAB toolbox in MATLAB. The 'old BCILAB' method uses a 'startup' command, while the 'new BCILAB' method uses a direct 'bcilab' command. Ensure you navigate to the correct BCILAB directory before executing these commands. ```matlab % old BCILAB cd your/path/to/bcilab startup ``` ```matlab % new BCILAB cd your/path/to/bcilab bcilab ``` -------------------------------- ### Initialize GUI and Load Approaches (MATLAB) Source: https://github.com/sccn/bcilab/blob/devel/build/docs/code/gui/gui_chooseapproach.html Initializes the GUI state and loads available experimental approaches from the base workspace. It scans for structures and cells that define paradigms, parameters, and timestamps, populating a list for user selection. If no approaches are found, an error message is displayed. ```matlab function gui_chooseapproach_OpeningFcn(hObject, eventdata, handles, varargin) % retrieve the known workspace approaches approaches = {}; names = {}; times = []; vars = evalin('base','whos'); % scan for approaches in struct format for v=find(strcmp({vars.class},'struct')) var = evalin('base',vars(v).name); if isfield(var,{'paradigm','parameters'}) % list it approaches{end+1} = var; if isfield(var,'timestamp') times(end+1) = var.timestamp; else times(end+1) = 0; end if isfield(var,'name') names{end+1} = [vars(v).name ' ("' var.name '")']; else names{end+1} = [vars(v).name ' (based on ' char(var.paradigm) ')']; end end end % get list of permitted paradigm names tmp = [gui_listapproaches](); paradigm_names = cellfun(@(x){x.paradigm(9:end)},tmp{2}); % scan for approaches in cell format for v=find(strcmp({vars.class},'cell')) var = evalin('base',vars(v).name); if length(var)>1 && ischar(var{1}) && ((strncmp(var{1},'Paradigm',8) && length(var{1})>8 && any(strcmp(var{1}(9:end),paradigm_names))) || any(strcmp(var{1},paradigm_names))) approaches{end+1} = struct('paradigm',quickif(strncmp(var{1},'Paradigm',8),var{1},['Paradigm',var{1}]),'name',vars(v).name,'parameters',{var(2:end)},'description',''); times(end+1) = 0; names{end+1} = [vars(v).name ' (based on ' approaches{end}.paradigm ')']; end end handles.approaches = approaches; handles.approachnames = names; guidata(hObject,handles); if ~isempty(handles.approaches) % populate the popup menu with approaches... set(handles.popupmenu1,'String',handles.approachnames); % preferably select the newest one... selected_id = argmax(times); if isempty(selected_id) selected_id = 1; end set(handles.popupmenu1,'Value',selected_id); guidata(hObject, handles); if length(handles.approaches) > 1 % UIWAIT makes gui_chooseapproach wait for user response (see UIRESUME) uiwait(handles.figure1); else handles.output = handles.approaches{1}; guidata(hObject, handles); end else % error dialog, if there is no approach errordlg2('You first need to create an approach before you can operate on it.'); % return nothing, if there is no approach handles.output = []; % Update handles structure guidata(hObject, handles); end ```