├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── cfg_defaults.m ├── demo ├── data │ ├── X.mat │ ├── Y.mat │ ├── wX.mat │ └── wY.mat └── demo_simul_paper.m ├── documentation ├── COPYING ├── demo │ ├── full_demo.docx │ └── full_demo.pdf ├── docs │ ├── analysis.md │ ├── assets │ │ └── brain_icon.png │ ├── background.md │ ├── cfg.md │ ├── figures │ │ ├── demo_proj_teid_split6.png │ │ ├── demo_weightX_split6.png │ │ ├── demo_weightY_split6.png │ │ ├── example_fmri_proj.png │ │ ├── example_fmri_weight_bar.png │ │ ├── example_fmri_weight_brain.png │ │ ├── example_simul_paropt.png │ │ ├── example_simul_plot.png │ │ ├── example_simul_weight_stemx.png │ │ ├── example_simul_weight_stemy.png │ │ ├── example_smri_paropt.png │ │ ├── example_smri_proj.png │ │ ├── example_smri_weight_bar.png │ │ ├── example_smri_weight_brain.png │ │ ├── flowchart.png │ │ ├── folders.png │ │ ├── framework_ML.png │ │ ├── framework_STAT.png │ │ ├── functions.png │ │ ├── overview.png │ │ ├── overview_analysis.png │ │ ├── overview_visualization.png │ │ ├── plot_proj_simple.png │ │ ├── visualization_behav_vert.png │ │ ├── visualization_brain_conn_node.png │ │ ├── visualization_brain_edge.png │ │ ├── visualization_brain_node.png │ │ ├── visualization_proj_advanced.png │ │ ├── visualization_proj_simple.png │ │ └── visualization_stem.png │ ├── full_demo.md │ ├── getting_started.md │ ├── index.md │ ├── mfiles │ │ ├── cfg_defaults.md │ │ ├── cleanup_files.md │ │ ├── example_fmri.md │ │ ├── example_simulation.md │ │ ├── example_smri.md │ │ ├── generate_data.md │ │ ├── plot_paropt.md │ │ ├── plot_proj.md │ │ ├── plot_weight.md │ │ ├── res_defaults.md │ │ ├── set_path.md │ │ └── update_dir.md │ ├── res.md │ └── visualization.md ├── makefile ├── matdoc.py ├── matdocparser.py ├── matdocparser.pyc ├── material-theme │ └── LICENSE ├── mkdocs.yml ├── overrides │ └── assets │ │ └── images │ │ ├── docs_CI-CD │ │ ├── chapter-one.png │ │ ├── content.png │ │ ├── hugo.png │ │ ├── images.png │ │ ├── material-mkdocs.png │ │ └── title-page.png │ │ ├── favicon.ico │ │ ├── index │ │ ├── eisvogel_chapter1.png │ │ ├── eisvogel_content.png │ │ ├── eisvogel_images.png │ │ ├── eisvogel_title_page.png │ │ └── web_page.png │ │ ├── logo-red.svg │ │ └── logo.svg └── site │ ├── 404.html │ ├── analysis │ └── index.html │ ├── assets │ ├── brain_icon.png │ ├── images │ │ └── favicon.png │ ├── javascripts │ │ ├── bundle.17f42bbf.min.js │ │ ├── bundle.17f42bbf.min.js.map │ │ ├── lunr │ │ │ ├── min │ │ │ │ ├── lunr.ar.min.js │ │ │ │ ├── lunr.da.min.js │ │ │ │ ├── lunr.de.min.js │ │ │ │ ├── lunr.du.min.js │ │ │ │ ├── lunr.es.min.js │ │ │ │ ├── lunr.fi.min.js │ │ │ │ ├── lunr.fr.min.js │ │ │ │ ├── lunr.hi.min.js │ │ │ │ ├── lunr.hu.min.js │ │ │ │ ├── lunr.it.min.js │ │ │ │ ├── lunr.ja.min.js │ │ │ │ ├── lunr.jp.min.js │ │ │ │ ├── lunr.multi.min.js │ │ │ │ ├── lunr.nl.min.js │ │ │ │ ├── lunr.no.min.js │ │ │ │ ├── lunr.pt.min.js │ │ │ │ ├── lunr.ro.min.js │ │ │ │ ├── lunr.ru.min.js │ │ │ │ ├── lunr.stemmer.support.min.js │ │ │ │ ├── lunr.sv.min.js │ │ │ │ ├── lunr.th.min.js │ │ │ │ ├── lunr.tr.min.js │ │ │ │ ├── lunr.vi.min.js │ │ │ │ └── lunr.zh.min.js │ │ │ ├── tinyseg.js │ │ │ └── wordcut.js │ │ └── workers │ │ │ ├── search.cefbb252.min.js │ │ │ └── search.cefbb252.min.js.map │ └── stylesheets │ │ ├── main.82f3c0b9.min.css │ │ ├── main.82f3c0b9.min.css.map │ │ ├── palette.9204c3b2.min.css │ │ └── palette.9204c3b2.min.css.map │ ├── background │ └── index.html │ ├── cfg │ └── index.html │ ├── figures │ ├── demo_proj_teid_split6.png │ ├── demo_weightX_split6.png │ ├── demo_weightY_split6.png │ ├── example_fmri_proj.png │ ├── example_fmri_weight_bar.png │ ├── example_fmri_weight_brain.png │ ├── example_simul_paropt.png │ ├── example_simul_plot.png │ ├── example_simul_weight_stemx.png │ ├── example_simul_weight_stemy.png │ ├── example_smri_paropt.png │ ├── example_smri_proj.png │ ├── example_smri_weight_bar.png │ ├── example_smri_weight_brain.png │ ├── flowchart.png │ ├── folders.png │ ├── framework_ML.png │ ├── framework_STAT.png │ ├── functions.png │ ├── overview.png │ ├── overview_analysis.png │ ├── overview_visualization.png │ ├── plot_proj_simple.png │ ├── visualization_behav_vert.png │ ├── visualization_brain_conn_node.png │ ├── visualization_brain_edge.png │ ├── visualization_brain_node.png │ ├── visualization_proj_advanced.png │ ├── visualization_proj_simple.png │ └── visualization_stem.png │ ├── full_demo │ └── index.html │ ├── getting_started │ └── index.html │ ├── index.html │ ├── mfiles │ ├── cfg_defaults │ │ └── index.html │ ├── cleanup_files │ │ └── index.html │ ├── example_fmri │ │ └── index.html │ ├── example_simulation │ │ └── index.html │ ├── example_smri │ │ └── index.html │ ├── generate_data │ │ └── index.html │ ├── plot_paropt │ │ └── index.html │ ├── plot_proj │ │ └── index.html │ ├── plot_weight │ │ └── index.html │ ├── res_defaults │ │ └── index.html │ ├── set_path │ │ └── index.html │ └── update_dir │ │ └── index.html │ ├── res │ └── index.html │ ├── search │ └── search_index.json │ ├── sitemap.xml │ ├── sitemap.xml.gz │ └── visualization │ └── index.html ├── examples ├── example_fmri.m ├── example_simulation.m └── example_smri.m ├── fileio ├── cleanup_files.m ├── compile_files.m ├── exist_file.m ├── getfname.m ├── loadmat.m ├── loadmat_struct.m ├── parse_input.m ├── parse_struct.m ├── renamemat.m ├── savemat.m └── select_file.m ├── machines ├── LICENSE ├── rcca.m └── spls.m ├── misc ├── calc_permid.m ├── calc_proj.m ├── calc_splits.m ├── concat_data.m ├── deflate_data.m ├── generate_data.m ├── get_featid.m ├── get_hyperparam.m ├── impute_mat.m ├── load_data.m ├── main.m ├── permute_data.m ├── preproc_data.m ├── process_metric.m ├── qc_data.m ├── run_machine.m ├── run_model.m ├── save_results.m └── stat_inference.m ├── plot ├── plot_paropt.m ├── plot_proj.m ├── plot_proj_2d.m ├── plot_proj_2d_cmap.m ├── plot_proj_2d_group.m ├── plot_weight.m ├── plot_weight_behav_horz.m ├── plot_weight_behav_text.m ├── plot_weight_behav_vert.m ├── plot_weight_brain_conn_node.m ├── plot_weight_brain_cortex.m ├── plot_weight_brain_edge.m ├── plot_weight_brain_module.m ├── plot_weight_brain_node.m └── plot_weight_stem.m ├── res_defaults.m ├── set_path.m ├── test ├── data │ ├── X.mat │ └── Y.mat ├── framework │ └── spls_holdout1-0.20_subsamp5-0.20_REF │ │ ├── cfg_1.mat │ │ ├── grid │ │ ├── level1 │ │ │ └── allgrid_1.mat │ │ └── level2 │ │ │ └── allgrid_1.mat │ │ ├── inmat_1.mat │ │ ├── load │ │ └── preproc │ │ │ ├── preprocx_split_1_1.mat │ │ │ ├── preprocx_split_1_subsample_1_1.mat │ │ │ ├── preprocx_split_1_subsample_2_1.mat │ │ │ ├── preprocx_split_1_subsample_3_1.mat │ │ │ ├── preprocx_split_1_subsample_4_1.mat │ │ │ ├── preprocx_split_1_subsample_5_1.mat │ │ │ ├── preprocy_split_1_1.mat │ │ │ ├── preprocy_split_1_subsample_1_1.mat │ │ │ ├── preprocy_split_1_subsample_2_1.mat │ │ │ ├── preprocy_split_1_subsample_3_1.mat │ │ │ ├── preprocy_split_1_subsample_4_1.mat │ │ │ └── preprocy_split_1_subsample_5_1.mat │ │ ├── outmat_1.mat │ │ ├── perm │ │ ├── level1 │ │ │ └── allperm_1.mat │ │ ├── level2 │ │ │ └── allperm_1.mat │ │ └── permmat_100_1.mat │ │ └── res │ │ ├── level1 │ │ ├── model_1.mat │ │ ├── param_1.mat │ │ ├── res_1.mat │ │ └── results_table.txt │ │ └── level2 │ │ ├── model_1.mat │ │ ├── param_1.mat │ │ ├── res_1.mat │ │ └── results_table.txt ├── get_data.m ├── test_algorithms.m └── test_pipeline.m └── util ├── assign_defaults.m ├── calc_distance.m ├── calc_exvar.m ├── calc_stability.m ├── cov2.m ├── deflation.m ├── fastsvd.m ├── ffd_val_str.m ├── fix_fileend.m ├── init_brainnet.m ├── mean_center_features.m ├── norm_features.m ├── normalize2MNI.m ├── postproc_weight.m └── update_dir.m /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-python@v2 12 | with: 13 | python-version: 3.x 14 | - run: pip install mkdocs-material mkdocs-with-pdf 15 | - run: pip install --upgrade beautifulsoup4==4.9.3 16 | - run: cd documentation 17 | - name: Deploy website 18 | working-directory: ./documentation 19 | run: | 20 | make build-mfiles 21 | mkdocs gh-deploy --force 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | demo/framework/ 3 | documentation/.python-version 4 | documentation/.venv 5 | examples/example_fmri/ 6 | examples/example_simulation/ 7 | examples/example_smri/ 8 | external/ 9 | manuscript/ 10 | projects/ 11 | scripts/ 12 | *.asv 13 | *.m~ 14 | -------------------------------------------------------------------------------- /demo/data/X.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/demo/data/X.mat -------------------------------------------------------------------------------- /demo/data/Y.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/demo/data/Y.mat -------------------------------------------------------------------------------- /demo/data/wX.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/demo/data/wX.mat -------------------------------------------------------------------------------- /demo/data/wY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/demo/data/wY.mat -------------------------------------------------------------------------------- /demo/demo_simul_paper.m: -------------------------------------------------------------------------------- 1 | function demo_simul_paper 2 | % demo_simul_paper 3 | % 4 | % # Syntax 5 | % demo_simul_paper 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | 29 | 30 | %----- Analysis 31 | 32 | % Set path for analysis 33 | set_path; 34 | 35 | % Project folder 36 | cfg.dir.project = fileparts(mfilename('fullpath')); 37 | 38 | % Machine settings 39 | cfg.machine.name = 'spls'; 40 | cfg.machine.metric = {'trcorrel' 'correl' 'simwx' 'simwy' ... 41 | 'trexvarx' 'trexvary'}; 42 | cfg.machine.param.crit = 'correl'; 43 | cfg.machine.simw = 'correlation-Pearson'; 44 | 45 | % Framework settings 46 | cfg.frwork.name = 'holdout'; 47 | cfg.frwork.split.nout = 10; 48 | cfg.frwork.split.nin = 10; 49 | 50 | % Deflation settings 51 | cfg.defl.name = 'pls-modeA'; 52 | 53 | % Environment settings 54 | cfg.env.comp = 'local'; 55 | 56 | % % Number of permutations 57 | cfg.stat.nperm = 1000; 58 | 59 | % Update cfg with defaults 60 | cfg = cfg_defaults(cfg); 61 | 62 | % Run analysis 63 | main(cfg); 64 | 65 | % Clean up analysis files to save disc space 66 | cleanup_files(cfg); 67 | 68 | %----- Visualization 69 | 70 | % Set path for plotting 71 | set_path('plot'); 72 | 73 | % Load res 74 | res.dir.frwork = cfg.dir.frwork; 75 | res.frwork.level = 1; 76 | res = res_defaults(res, 'load'); 77 | 78 | % Plot data projections 79 | plot_proj(res, {'X' 'Y'}, res.frwork.level, 'osplit', ... 80 | res.frwork.split.best, 'training+test', '2d_group', ... 81 | 'gen.figure.ext', '.svg', ... 82 | 'gen.figure.Position', [0 0 500 400], ... 83 | 'gen.axes.Position', [0.1798 0.1560 0.7252 0.7690], ... 84 | 'gen.axes.XLim', [-5 4.9], 'gen.axes.YLim', [-4.2 5], ... 85 | 'gen.axes.FontSize', 22, 'gen.legend.FontSize', 22, ... 86 | 'gen.legend.Location', 'best', ... 87 | 'proj.scatter.SizeData', 120, ... 88 | 'proj.scatter.MarkerFaceColor', [0.3 0.3 0.9;0.9 0.3 0.3], ... 89 | 'proj.scatter.MarkerEdgeColor', 'k', 'proj.lsline', 'on', ... 90 | 'proj.xlabel', 'Modality 1 latent variable', ... 91 | 'proj.ylabel', 'Modality 2 latent variable'); 92 | 93 | % Plot X weights as stem plot 94 | plot_weight(res, 'X', 'simul', res.frwork.split.best, 'stem', ... 95 | 'gen.figure.ext', '.svg', ... 96 | 'gen.figure.Position', [0 0 500 400], ... 97 | 'gen.axes.Position', [0.1798 0.1560 0.7252 0.7690], ... 98 | 'gen.axes.YLim', [-1.1 1.2], ... 99 | 'gen.axes.YTick', [-1:0.5:1.2], ... 100 | 'gen.axes.FontSize', 22, 'gen.legend.FontSize', 22, ... 101 | 'gen.legend.Location', 'NorthEast', ... 102 | 'simul.xlabel', 'Modality 1 variables', ... 103 | 'simul.ylabel', 'Weight', 'simul.weight.norm', 'minmax'); 104 | 105 | % Plot Y weights as stem plot 106 | plot_weight(res, 'Y', 'simul', res.frwork.split.best, 'stem', ... 107 | 'gen.figure.ext', '.svg', ... 108 | 'gen.figure.Position', [0 0 500 400], ... 109 | 'gen.axes.Position', [0.1798 0.1560 0.7252 0.7690], ... 110 | 'gen.axes.YLim', [-1.1 1.2], ... 111 | 'gen.axes.YTick', [-1:0.5:1.2], ... 112 | 'gen.axes.FontSize', 22, 'gen.legend.FontSize', 22, ... 113 | 'gen.legend.Location', 'NorthEast', ... 114 | 'simul.xlabel', 'Modality 2 variables', ... 115 | 'simul.ylabel', 'Weight', 'simul.weight.norm', 'minmax'); -------------------------------------------------------------------------------- /documentation/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-16 The MatConvNet Team. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms are permitted 5 | provided that the above copyright notice and this paragraph are 6 | duplicated in all such forms and that any documentation, advertising 7 | materials, and other materials related to such distribution and use 8 | acknowledge that the software was developed by the MatConvNet 9 | Team. The name of the MatConvNet Team may not be used to endorse or 10 | promote products derived from this software without specific prior 11 | written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT 12 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 14 | PURPOSE. 15 | -------------------------------------------------------------------------------- /documentation/demo/full_demo.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/demo/full_demo.docx -------------------------------------------------------------------------------- /documentation/demo/full_demo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/demo/full_demo.pdf -------------------------------------------------------------------------------- /documentation/docs/assets/brain_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/assets/brain_icon.png -------------------------------------------------------------------------------- /documentation/docs/figures/demo_proj_teid_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/demo_proj_teid_split6.png -------------------------------------------------------------------------------- /documentation/docs/figures/demo_weightX_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/demo_weightX_split6.png -------------------------------------------------------------------------------- /documentation/docs/figures/demo_weightY_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/demo_weightY_split6.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_fmri_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_fmri_proj.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_fmri_weight_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_fmri_weight_bar.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_fmri_weight_brain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_fmri_weight_brain.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_simul_paropt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_simul_paropt.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_simul_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_simul_plot.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_simul_weight_stemx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_simul_weight_stemx.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_simul_weight_stemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_simul_weight_stemy.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_smri_paropt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_smri_paropt.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_smri_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_smri_proj.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_smri_weight_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_smri_weight_bar.png -------------------------------------------------------------------------------- /documentation/docs/figures/example_smri_weight_brain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/example_smri_weight_brain.png -------------------------------------------------------------------------------- /documentation/docs/figures/flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/flowchart.png -------------------------------------------------------------------------------- /documentation/docs/figures/folders.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/folders.png -------------------------------------------------------------------------------- /documentation/docs/figures/framework_ML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/framework_ML.png -------------------------------------------------------------------------------- /documentation/docs/figures/framework_STAT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/framework_STAT.png -------------------------------------------------------------------------------- /documentation/docs/figures/functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/functions.png -------------------------------------------------------------------------------- /documentation/docs/figures/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/overview.png -------------------------------------------------------------------------------- /documentation/docs/figures/overview_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/overview_analysis.png -------------------------------------------------------------------------------- /documentation/docs/figures/overview_visualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/overview_visualization.png -------------------------------------------------------------------------------- /documentation/docs/figures/plot_proj_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/plot_proj_simple.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_behav_vert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_behav_vert.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_brain_conn_node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_brain_conn_node.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_brain_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_brain_edge.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_brain_node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_brain_node.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_proj_advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_proj_advanced.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_proj_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_proj_simple.png -------------------------------------------------------------------------------- /documentation/docs/figures/visualization_stem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/docs/figures/visualization_stem.png -------------------------------------------------------------------------------- /documentation/docs/mfiles/cfg_defaults.md: -------------------------------------------------------------------------------- 1 | __cfg_defaults__ 2 | 3 | Set defaults in your configuration (`cfg`) structure which will define 4 | the settings of your analysis (e.g., machine, framework, statistical 5 | inference). Use this function to update and add all necessary defaults to 6 | your `cfg`. If you defined anything in your `cfg` before calling the 7 | function, it won't overwrite those values. The path to the project folder 8 | should be always defined in your `cfg` or passed as varargin, otherwise 9 | the function throws an error. All the other fields are optional and can 10 | be filled up by `cfg_defaults`. 11 | 12 | No results will be stored in the cfg structure. See [res_defaults](../res_defaults) 13 | for more information on results. 14 | 15 | !!! note "Warning" 16 | 17 | We strongly advise to inspect the output of `cfg_defaults` to make 18 | sure that the defaults are set as expected. 19 | 20 | ## Syntax 21 | cfg = cfg_defaults(cfg, varargin) 22 | 23 | ## Inputs 24 | * **cfg** [*struct*] 25 | 26 | * **varargin** [*name-value pairs*] 27 | 28 | additional parameters can be set via name-value pairs with dot notation 29 | supported (e.g., 'frwork.split.nout', 5) 30 | 31 | ## Outputs 32 | * **cfg** [*struct*] 33 | 34 | configuration structure that has been updated with defaults 35 | 36 | ## Examples 37 | % Example 1 38 | [X, Y, wX, wY] = generate_data(1000, 100, 100, 10, 10, 1); 39 | 40 | --- 41 | See also: [cfg](../../cfg), [res_defaults](../res_defaults/) 42 | 43 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/cleanup_files.md: -------------------------------------------------------------------------------- 1 | __cleanup_files__ 2 | 3 | Cleans up unnecessary duplicate and intermediate files created during 4 | analysis to save disc space. 5 | 6 | ## Syntax 7 | cleanup_files(cfg) 8 | 9 | ## Inputs 10 | * **cfg** [*struct*] 11 | 12 | ## Examples 13 | % Example 1 14 | load cfg; 15 | cleanup_files(cfg); 16 | 17 | --- 18 | See also: [cfg](../../cfg) 19 | 20 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/generate_data.md: -------------------------------------------------------------------------------- 1 | __generate_data__ 2 | 3 | Generates data via a sparse latent variable model based on 4 | [Witten et al. 2009](https://doi.org/10.2202/1544-6115.1470). The 5 | generated data has two modalities with `nexamples` samples and `nfeatx` 6 | and `nfeaty` variables, respectively. The `activex` and `activey` inputs 7 | define the number of variables in the two data modalities that are 8 | associated with a Gaussian latent variable. 9 | 10 | ## Syntax 11 | generate_data(nexamples, nfeatx, nfeaty, activex, activey, noise) 12 | 13 | ## Inputs 14 | * **nexamples** [*int*] 15 | 16 | number of examples in generated data 17 | 18 | * **nfeatx** [*int*] 19 | 20 | number of features in generated data $\mathbf{X}$ 21 | 22 | * **nfeaty** [*int*] 23 | 24 | number of features in generated data $\mathbf{Y}$ 25 | 26 | * **activex** [*int*] 27 | 28 | number of active features in generated data $\mathbf{X}$ 29 | associated with the latent variable 30 | 31 | * **activey** [*int*] 32 | 33 | number of active features in generated data $\mathbf{Y}$ 34 | associated with the latent variable 35 | 36 | * **noise** [*float*] 37 | 38 | noise level in the generative model 39 | 40 | ## Outputs 41 | * **X** [*2D numeric array*] 42 | 43 | generated data $\mathbf{X}$ with `nexamples` rows and `nfeatx` 44 | columns 45 | 46 | * **Y** [*2D numeric array*] 47 | 48 | generated data $\mathbf{Y}$ with `nexamples` rows and `nfeaty` 49 | columns 50 | 51 | * **wX** [*numeric array*] 52 | 53 | true weights used to generate data $\mathbf{X}$ from the latent 54 | variable, which has `activex` non-zero values 55 | 56 | * **wY** [*numeric array*] 57 | 58 | true weights used to generate data $\mathbf{Y}$ from the latent 59 | variable, which has `activey` non-zero values 60 | 61 | ## Examples 62 | % Example 1 63 | [X, Y, wX, wY] = generate_data(1000, 100, 100, 10, 10, 1); 64 | 65 | --- 66 | Author: James Chapman 67 | 68 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/plot_paropt.md: -------------------------------------------------------------------------------- 1 | __plot_paropt__ 2 | 3 | It plots the grid search results of the hyperparameter optimization. 4 | 5 | ## Syntax 6 | plot_paropt(res, split, metrics, varargin) 7 | 8 | ## Inputs 9 | * **res** [*struct*] 10 | 11 | res structure containing information about results and plot specifications 12 | 13 | * **split** [*int*] 14 | 15 | index of data split to be used 16 | 17 | * **metrics** [*'trcorrel', 'correl', 'trcovar', 'covar', 'trexvarx', 'exvarx', 'trexvary', 'exvary', 'simwx', 'simwy', 'simwxy', 'correl+simwxy'*] 18 | 19 | metrics to be plotted as a function of hyperparameter grid, each metric 20 | in a separate subplot 21 | 22 | * **varargin** [*name-value pairs*] 23 | 24 | additional options can be passed via name-value pairs with dot notation 25 | supported 26 | 27 | ## Examples 28 | % Plot hyperparameter surface for grid search results 29 | plot_paropt(res, 1, {'correl', 'simwx', 'simwy'}, ... 30 | 'gen.figure.Position', [500 600 1200 400], 'gen.axes.FontSize', 20, ... 31 | 'gen.axes.XScale', 'log', 'gen.axes.YScale', 'log'); 32 | 33 | ![hyperparameter_surface](../figures/example_simul_paropt.png) 34 | 35 | --- 36 | See also: [plot_proj](../plot_proj), [plot_weight](../plot_weight) 37 | 38 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/plot_proj.md: -------------------------------------------------------------------------------- 1 | __plot_proj__ 2 | 3 | It plots the projections of the data (i.e., latent variables). 4 | 5 | ## Syntax 6 | plot_proj(res, mod, level, sidvar, split, colour, func, varargin) 7 | 8 | ## Inputs 9 | * **res** [*struct*] 10 | 11 | res structure containing information about results and plot specifications 12 | 13 | * **mod** [*cell array*] 14 | 15 | modality of data to be used for plotting (i.e., `{'X', 'Y'}`) 16 | 17 | * **level** [*int or numeric array*] 18 | 19 | level of associative effect with same dimensionality as `mod` or 20 | automatically extended (e.g., from int to numeric array) 21 | 22 | * **sidvar** [*'osplit', 'otrid', 'oteid', 'isplit', 'itrid', 'iteid'*] 23 | 24 | specifies subjects to be used for plotting 25 | 26 | first letter can be 'o' for outer or 'i' for inner split, followed by 27 | either 'trid' for training, 'teid' for test or 'split' for both 28 | training and test data 29 | 30 | * **split** [*int or numeric array*] 31 | 32 | index of data split to be used with same dimensionality as `mod` or 33 | automatically extended (e.g., from int to numeric array) 34 | 35 | * **colour** [*'none', char*] 36 | 37 | `'none'` for scatterplot with same colour for all subjects or it can be 38 | used as a continuous colormap or for colouring different groups; there 39 | are three ways to define the colour 40 | 41 | specify a variable, which can be loaded from a data file (e.g., `Y.mat`) 42 | using the name of the variable defined in a label file (e.g., 43 | `LabelsY.csv`) 44 | 45 | use `'training+test'` to colour-code the training and test sets 46 | 47 | use any other string with a `'+'` sign (e.g., 'MDD+HC') to define the 48 | colour-code based on `group.mat` 49 | 50 | * **func** [*'2d', '2d_group', '2d_cmap'*] 51 | 52 | name of the specific plotting function (after plot_proj_* prefix) to 53 | be called 54 | 55 | * **varargin** [*name-value pairs*] 56 | 57 | additional options can be passed via name-value pairs with dot notation 58 | supported 59 | 60 | ## Examples 61 | ### Simple plots 62 | Most often, we plot a brain latent variable vs. a behavioural latent variable 63 | for a specific level (i.e., associative effect). 64 | 65 | % Plot data projections coloured by groups 66 | plot_proj(res, {'X' 'Y'}, res.frwork.level, 'osplit', res.frwork.split.best, ... 67 | 'training+test', '2d_group', 'gen.axes.FontSize', 20, ... 68 | 'gen.legend.FontSize', 20, 'gen.legend.Location', 'NorthWest', ... 69 | 'proj.scatter.SizeData', 120, 'proj.scatter.MarkerEdgeColor', 'k', ... 70 | 'proj.scatter.MarkerFaceColor', [0.3 0.3 0.9; 0.9 0.3 0.3]); 71 | 72 | ![projection_plot](../figures/plot_proj_simple.png) 73 | 74 | ### Multi-level plots 75 | To plot projections aggregated over multiple levels, all you need to 76 | specify is res.proj.multi_level = 1 and provide a 2D cell array of input 77 | variable 'mod'. Input variables 'level' and 'split' should have the same 78 | dimensionality or they will be extended automatically from 1-D or 2-D arrays 79 | (e.g. level = repmat(level, size(mod))). 80 | 81 | % Plot data projections across levels (and averaged across modalities 82 | % in a level after standardization) 83 | plot_proj(res, {'X' 'Y'; 'X' 'Y'}, [1 1; 2 2], 'osplit', res.frwork.split.best, ... 84 | 'none', '2d', 'proj.multi_label', 1); 85 | 86 | --- 87 | See also: [plot_paropt](../plot_paropt), [plot_weight](../plot_weight/) 88 | 89 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/plot_weight.md: -------------------------------------------------------------------------------- 1 | __plot_weight__ 2 | 3 | It plots the model weights in specific figures based on the modality of 4 | the data. 5 | 6 | ## Syntax 7 | plot_weight(res, mod, modtype, split, func, varargin) 8 | 9 | ## Inputs 10 | * **res** [*struct*] 11 | 12 | res structure containing information about results and plot specifications 13 | 14 | * **mod** [*'X', 'Y'*] 15 | 16 | modality of data to be used for plotting 17 | 18 | * **modtype** [*'behav', 'conn', 'vbm', 'roi', 'simul'*] 19 | 20 | type of data 21 | 22 | * **split** [*int*] 23 | 24 | index of data split to be used 25 | 26 | * **func** [*'behav_horz', 'behav_vert', 'behav_text', 'brain_conn_node', 'brain_cortex', 'brain_edge', 'brain_module', 'brain_node', 'stem'*] 27 | 28 | name of the specific plotting function (after `plot_weight_*` prefix) to 29 | be called 30 | 31 | * **varargin** [*name-value pairs*] 32 | 33 | additional options can be passed via name-value pairs with dot notation 34 | supported (e.g., 'behav.weight.numtop', 20) 35 | 36 | ## Examples 37 | ### Modality independent 38 | % Plot Y weights as stem plot 39 | plot_weight(res, 'Y', 'simul', res.frwork.split.best, 'stem', ... 40 | 'gen.axes.YLim', [-0.2 1.2], 'simul.weight.norm', 'minmax', ... 41 | 'gen.axes.FontSize', 20, 'gen.legend.FontSize', 20); 42 | 43 | ![weight_stem](../figures/visualization_stem.png) 44 | 45 | ### Behaviour 46 | % Plot behavioural weights as vertical bar plot 47 | plot_weight(res, 'Y', 'behav', res.frwork.split.best, 'behav_vert', ... 48 | 'gen.axes.FontSize', 20, 'gen.legend.FontSize', 20, ... 49 | 'gen.axes.YLim', [-0.4 1.2], 'gen.weight.flip', 1, ... 50 | 'behav.weight.sorttype', 'sign', 'behav.weight.numtop', 20, ... 51 | 'behav.weight.norm', 'minmax'); 52 | 53 | ![weight_behav](../figures/visualization_behav_vert.png) 54 | 55 | ### ROI-wise sMRI 56 | % Plot ROI weights on a glass brain 57 | plot_weight(res, 'X', 'roi', 1, 'brain_node', ... 58 | 'roi.weight.sorttype', 'sign', 'roi.weight.numtop', 20, ... 59 | 'roi.out', 9000 + [reshape([1:10:81; 2:10:82], [], 1); ... 60 | reshape(100:10:170, [], 1)]); 61 | 62 | ![weight_roi](../figures/visualization_brain_node.png) 63 | 64 | ### fMRI connectivity edges 65 | % Plot connectivity weights on glass brain 66 | plot_weight(res, 'X', 'conn', res.frwork.split.best, 'brain_edge', ... 67 | 'conn.weight.sorttype', 'sign', 'conn.weight.numtop', 20); 68 | 69 | ![weight_conn_edge](../figures/visualization_brain_edge.png) 70 | 71 | --- 72 | See also: [plot_paropt](../plot_paropt), [plot_proj](../plot_proj) 73 | 74 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/res_defaults.md: -------------------------------------------------------------------------------- 1 | __res_defaults__ 2 | 3 | Set defaults in your results (`res`) structure including information about 4 | the results and settings for plotting. Use this function to update and 5 | add all necessary defaults to your `res`. If you have defined anything in 6 | `res` before calling the function, it won't overwrite those values. The 7 | path to the framework folder should be always defined in your `res` or 8 | passed as varargin, otherwise the function throws an error. All the other 9 | fields are optional and can be filled up by `res_defaults`. 10 | 11 | This function can be also called to load an existing `res*.mat` file. 12 | 13 | ## Syntax 14 | res = res_defaults(res, mode, varargin) 15 | 16 | ## Inputs 17 | * **res** [*struct*] 18 | 19 | results structure (more information below) 20 | 21 | * **mode** [*'init', 'load', 'projection', 'simul', 'behav', 'conn', 'vbm', 'roi', 'brainnet'*] 22 | 23 | mode of calling res_defaults, either referring to initialization ('init'), 24 | loading ('load'), type of plot ('projection', 'simul', 'behav', 'conn', 25 | 'vbm', 'roi') or settings for toolbox ('brainnet') 26 | 27 | * **varargin** [*name-value pairs*] 28 | 29 | additional parameters can be set via name-value pairs with dot notation 30 | supported (e.g., 'behav.weight.numtop', 20) 31 | 32 | ## Outputs 33 | * **res** [*struct*] 34 | 35 | result structure that has been updated with defaults 36 | 37 | ## Examples 38 | % Example 1 39 | res.dir.frwork = 'PATH/TO/YOUR/PROJECT/framework/ANALYSIS_NAME'; 40 | res.frwork.level = 1; 41 | res.env.fileend = '_1'; 42 | res = res_defaults(res, 'load'); 43 | 44 | % Example 2 45 | res = res_defaults([], 'load', 'dir.frwork', ... 46 | 'PATH/TO/YOUR/PROJECT/framework/ANALYSIS_NAME'); 47 | 48 | % Example 3 49 | res = res_defaults([], 'load', 'dir.frwork', ... 50 | 'PATH/TO/YOUR/PROJECT/framework/ANALYSIS_NAME'); 51 | res = res_defaults(res, 'behav'); 52 | 53 | --- 54 | See also: [res](../../res), [cfg_defaults](../cfg_defaults/) 55 | 56 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/set_path.md: -------------------------------------------------------------------------------- 1 | __set_path__ 2 | 3 | Adds essential folders to the path to initialize the toolkit for an 4 | analysis. For visualization, it needs to be called with specific folders 5 | to add plotting and other toolbox folders to the path. 6 | 7 | ## Syntax 8 | dir_toolkit = set_path(varargin) 9 | 10 | ## Inputs 11 | * **varargin** [*char*] 12 | 13 | folders passed as arguments will be added to the path 14 | 15 | `set_path` looks for folders under the toolkit folder and under the 16 | `external` folder. In the latter case it is sufficient to use the 17 | first few characters of the toolbox, e.g., `spm` instead of `spm12`. 18 | 19 | ## Outputs 20 | * **dir_toolkit** [*char*] 21 | 22 | full path to the toolkit folder 23 | 24 | ## Examples 25 | % Example 1 26 | set_path; 27 | 28 | % Example 2 29 | set_path('plot'); 30 | 31 | % Example 3 32 | set_path('plot', 'spm', 'brainnet'); 33 | 34 | --- 35 | -------------------------------------------------------------------------------- /documentation/docs/mfiles/update_dir.md: -------------------------------------------------------------------------------- 1 | __update_dir__ 2 | 3 | Updates the paths in `cfg` and all `res` files for the current computer. 4 | It is needed to run when switching between computers e.g., moving data 5 | from a cluster to a local computer. 6 | 7 | ## Syntax 8 | update_dir(dir_frwork, fileend) 9 | 10 | ## Inputs 11 | * **dir_frwork** [*char*] 12 | 13 | full path to the specific framework folder 14 | 15 | * **fileend** [*char*] 16 | 17 | suffix at the end of the `res*.mat` file from `cfg.env.fileend` 18 | 19 | ## Example 20 | % Example 1 21 | update_dir(, '_1'); 22 | 23 | --- 24 | See also: [cfg](../../cfg) 25 | 26 | -------------------------------------------------------------------------------- /documentation/makefile: -------------------------------------------------------------------------------- 1 | PYTHON3 = python3 2 | PYTHON2 = python2 3 | MKDOCS = mkdocs 4 | MFILES = ../plot/plot_paropt.md \ 5 | ../plot/plot_proj.md \ 6 | ../plot/plot_weight.md \ 7 | ../cfg_defaults.md \ 8 | ../misc/generate_data.md \ 9 | ../res_defaults.md \ 10 | ../examples/example_simulation.md \ 11 | ../examples/example_smri.md \ 12 | ../examples/example_fmri.md \ 13 | ../fileio/cleanup_files.md \ 14 | ../set_path.md \ 15 | ../util/update_dir.md 16 | 17 | mfiledir = docs/mfiles 18 | 19 | $(info mfiledir is $(mfiledir)) 20 | 21 | 22 | build-mfiles: $(MFILES) 23 | 24 | %.md: %.m matdoc.py matdocparser.py 25 | $(info $(@)) 26 | $(info $(@D)) 27 | mkdir -p $(mfiledir) 28 | $(PYTHON2) ./matdoc.py "$(<)" > "$(mfiledir)/$(notdir $(@))" 29 | 30 | serve: mkdocs.yml 31 | $(MKDOCS) serve 32 | 33 | build: mkdocs.yml 34 | ENABLE_PDF_EXPORT=1 $(MKDOCS) build 35 | 36 | build-demo: 37 | pandoc docs/full_demo.md --resource-path docs --filter pandoc-fignos --filter pandoc-tablenos --highlight-style tango -o demo/full_demo.pdf 38 | pandoc docs/full_demo.md --resource-path docs --highlight-style tango -o demo/full_demo.docx 39 | 40 | -------------------------------------------------------------------------------- /documentation/matdocparser.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/matdocparser.pyc -------------------------------------------------------------------------------- /documentation/material-theme/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2020 Martin Donath 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. -------------------------------------------------------------------------------- /documentation/mkdocs.yml: -------------------------------------------------------------------------------- 1 | # Project information 2 | site_name: CCA/PLS Toolkit 3 | repo_name: 'CCA_PLS_toolkit' 4 | repo_url: 'https://github.com/MLNL/cca_pls_toolkit/' 5 | 6 | # Plugins 7 | plugins: 8 | - search 9 | 10 | # Theme configuration 11 | theme: 12 | name: 'material' 13 | palette: 14 | primary: 'teal' 15 | accent: 'teal' 16 | font: 17 | text: 'Roboto' 18 | code: 'Roboto Mono' 19 | icon: 20 | repo: fontawesome/brands/github 21 | logo: assets/brain_icon.png 22 | favicon: assets/brain_icon.png 23 | 24 | # Latex 25 | extra_javascript: 26 | - https://polyfill.io/v3/polyfill.min.js?features=es6 27 | - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js 28 | 29 | # extensions 30 | markdown_extensions: 31 | - pymdownx.arithmatex: 32 | generic: true 33 | - codehilite 34 | - pymdownx.inlinehilite 35 | - pymdownx.snippets 36 | - pymdownx.superfences 37 | - pymdownx.highlight: 38 | auto_title: true 39 | - admonition 40 | - def_list 41 | - attr_list 42 | 43 | 44 | # Site structure 45 | nav: 46 | - Home: 'index.md' 47 | - Background: 'background.md' 48 | - Getting Started: 'getting_started.md' 49 | - Analysis: 'analysis.md' 50 | - Visualization: 'visualization.md' 51 | - Defaults: 52 | - cfg: 'cfg.md' 53 | - res: 'res.md' 54 | - Functions: 55 | - cfg_defaults: 'mfiles/cfg_defaults.md' 56 | - cleanup_files: 'mfiles/cleanup_files.md' 57 | - generate_data: 'mfiles/generate_data.md' 58 | - plot_paropt: 'mfiles/plot_paropt.md' 59 | - plot_proj: 'mfiles/plot_proj.md' 60 | - plot_weight: 'mfiles/plot_weight.md' 61 | - res_defaults: 'mfiles/res_defaults.md' 62 | - set_path: 'mfiles/set_path.md' 63 | - update_dir: 'mfiles/update_dir.md' 64 | - Examples: 65 | - Simulated data: 'mfiles/example_simulation.md' 66 | - Structural MRI data: 'mfiles/example_smri.md' 67 | - Functional MRI data: 'mfiles/example_fmri.md' 68 | - Full Demo: 'full_demo.md' 69 | 70 | -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/chapter-one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/chapter-one.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/content.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/hugo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/hugo.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/images.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/material-mkdocs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/material-mkdocs.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/docs_CI-CD/title-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/docs_CI-CD/title-page.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/favicon.ico -------------------------------------------------------------------------------- /documentation/overrides/assets/images/index/eisvogel_chapter1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/index/eisvogel_chapter1.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/index/eisvogel_content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/index/eisvogel_content.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/index/eisvogel_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/index/eisvogel_images.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/index/eisvogel_title_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/index/eisvogel_title_page.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/index/web_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/overrides/assets/images/index/web_page.png -------------------------------------------------------------------------------- /documentation/overrides/assets/images/logo-red.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /documentation/overrides/assets/images/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /documentation/site/assets/brain_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/assets/brain_icon.png -------------------------------------------------------------------------------- /documentation/site/assets/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/assets/images/favicon.png -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.hi.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.hi=function(){this.pipeline.reset(),this.pipeline.add(e.hi.trimmer,e.hi.stopWordFilter,e.hi.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.hi.stemmer))},e.hi.wordCharacters="ऀ-ःऄ-एऐ-टठ-यर-िी-ॏॐ-य़ॠ-९॰-ॿa-zA-Za-zA-Z0-90-9",e.hi.trimmer=e.trimmerSupport.generateTrimmer(e.hi.wordCharacters),e.Pipeline.registerFunction(e.hi.trimmer,"trimmer-hi"),e.hi.stopWordFilter=e.generateStopWordFilter("अत अपना अपनी अपने अभी अंदर आदि आप इत्यादि इन इनका इन्हीं इन्हें इन्हों इस इसका इसकी इसके इसमें इसी इसे उन उनका उनकी उनके उनको उन्हीं उन्हें उन्हों उस उसके उसी उसे एक एवं एस ऐसे और कई कर करता करते करना करने करें कहते कहा का काफ़ी कि कितना किन्हें किन्हों किया किर किस किसी किसे की कुछ कुल के को कोई कौन कौनसा गया घर जब जहाँ जा जितना जिन जिन्हें जिन्हों जिस जिसे जीधर जैसा जैसे जो तक तब तरह तिन तिन्हें तिन्हों तिस तिसे तो था थी थे दबारा दिया दुसरा दूसरे दो द्वारा न नके नहीं ना निहायत नीचे ने पर पहले पूरा पे फिर बनी बही बहुत बाद बाला बिलकुल भी भीतर मगर मानो मे में यदि यह यहाँ यही या यिह ये रखें रहा रहे ऱ्वासा लिए लिये लेकिन व वग़ैरह वर्ग वह वहाँ वहीं वाले वुह वे वो सकता सकते सबसे सभी साथ साबुत साभ सारा से सो संग ही हुआ हुई हुए है हैं हो होता होती होते होना होने".split(" ")),e.hi.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.hi.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var t=i.toString().toLowerCase().replace(/^\s+/,"");return r.cut(t).split("|")},e.Pipeline.registerFunction(e.hi.stemmer,"stemmer-hi"),e.Pipeline.registerFunction(e.hi.stopWordFilter,"stopWordFilter-hi")}}); -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.ja.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.ja=function(){this.pipeline.reset(),this.pipeline.add(e.ja.trimmer,e.ja.stopWordFilter,e.ja.stemmer),r?this.tokenizer=e.ja.tokenizer:(e.tokenizer&&(e.tokenizer=e.ja.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.ja.tokenizer))};var t=new e.TinySegmenter;e.ja.tokenizer=function(i){var n,o,s,p,a,u,m,l,c,f;if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t.toLowerCase()):t.toLowerCase()});for(o=i.toString().toLowerCase().replace(/^\s+/,""),n=o.length-1;n>=0;n--)if(/\S/.test(o.charAt(n))){o=o.substring(0,n+1);break}for(a=[],s=o.length,c=0,l=0;c<=s;c++)if(u=o.charAt(c),m=c-l,u.match(/\s/)||c==s){if(m>0)for(p=t.segment(o.slice(l,c)).filter(function(e){return!!e}),f=l,n=0;n=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},in_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e<=s&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},out_grouping:function(t,i,s){if(this.cursors||e>3]&1<<(7&e)))return this.cursor++,!0}return!1},out_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e>s||e>3]&1<<(7&e)))return this.cursor--,!0}return!1},eq_s:function(t,i){if(this.limit-this.cursor>1),f=0,l=o0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n+_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n+_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},find_among_b:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit_backward,o=0,h=0,c=!1;;){for(var a=s+(e-s>>1),f=0,l=o=0;m--){if(n-l==u){f=-1;break}if(f=r.charCodeAt(n-1-l)-_.s[m])break;l++}if(f<0?(e=a,h=l):(s=a,o=l),e-s<=1){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n-_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n-_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},replace_s:function(t,i,s){var e=s.length-(i-t),n=r.substring(0,t),u=r.substring(i);return r=n+s+u,this.limit+=e,this.cursor>=i?this.cursor+=e:this.cursor>t&&(this.cursor=t),e},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>r.length)throw"faulty slice operation"},slice_from:function(r){this.slice_check(),this.replace_s(this.bra,this.ket,r)},slice_del:function(){this.slice_from("")},insert:function(r,t,i){var s=this.replace_s(r,t,i);r<=this.bra&&(this.bra+=s),r<=this.ket&&(this.ket+=s)},slice_to:function(){return this.slice_check(),r.substring(this.bra,this.ket)},eq_v_b:function(r){return this.eq_s_b(r.length,r)}}}},r.trimmerSupport={generateTrimmer:function(r){var t=new RegExp("^[^"+r+"]+"),i=new RegExp("[^"+r+"]+$");return function(r){return"function"==typeof r.update?r.update(function(r){return r.replace(t,"").replace(i,"")}):r.replace(t,"").replace(i,"")}}}}}); -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.sv.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Lunr languages, `Swedish` language 3 | * https://github.com/MihaiValentin/lunr-languages 4 | * 5 | * Copyright 2014, Mihai Valentin 6 | * http://www.mozilla.org/MPL/ 7 | */ 8 | /*! 9 | * based on 10 | * Snowball JavaScript Library v0.3 11 | * http://code.google.com/p/urim/ 12 | * http://snowball.tartarus.org/ 13 | * 14 | * Copyright 2010, Oleg Mazko 15 | * http://www.mozilla.org/MPL/ 16 | */ 17 | 18 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.sv=function(){this.pipeline.reset(),this.pipeline.add(e.sv.trimmer,e.sv.stopWordFilter,e.sv.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sv.stemmer))},e.sv.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.sv.trimmer=e.trimmerSupport.generateTrimmer(e.sv.wordCharacters),e.Pipeline.registerFunction(e.sv.trimmer,"trimmer-sv"),e.sv.stemmer=function(){var r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,t=new function(){function e(){var e,r=w.cursor+3;if(o=w.limit,0<=r||r<=w.limit){for(a=r;;){if(e=w.cursor,w.in_grouping(l,97,246)){w.cursor=e;break}if(w.cursor=e,w.cursor>=w.limit)return;w.cursor++}for(;!w.out_grouping(l,97,246);){if(w.cursor>=w.limit)return;w.cursor++}o=w.cursor,o=o&&(w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(u,37),w.limit_backward=r,e))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.in_grouping_b(d,98,121)&&w.slice_del()}}function i(){var e=w.limit_backward;w.cursor>=o&&(w.limit_backward=o,w.cursor=w.limit,w.find_among_b(c,7)&&(w.cursor=w.limit,w.ket=w.cursor,w.cursor>w.limit_backward&&(w.bra=--w.cursor,w.slice_del())),w.limit_backward=e)}function s(){var e,r;if(w.cursor>=o){if(r=w.limit_backward,w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(m,5))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.slice_from("lös");break;case 3:w.slice_from("full")}w.limit_backward=r}}var a,o,u=[new r("a",-1,1),new r("arna",0,1),new r("erna",0,1),new r("heterna",2,1),new r("orna",0,1),new r("ad",-1,1),new r("e",-1,1),new r("ade",6,1),new r("ande",6,1),new r("arne",6,1),new r("are",6,1),new r("aste",6,1),new r("en",-1,1),new r("anden",12,1),new r("aren",12,1),new r("heten",12,1),new r("ern",-1,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",18,1),new r("or",-1,1),new r("s",-1,2),new r("as",21,1),new r("arnas",22,1),new r("ernas",22,1),new r("ornas",22,1),new r("es",21,1),new r("ades",26,1),new r("andes",26,1),new r("ens",21,1),new r("arens",29,1),new r("hetens",29,1),new r("erns",21,1),new r("at",-1,1),new r("andet",-1,1),new r("het",-1,1),new r("ast",-1,1)],c=[new r("dd",-1,-1),new r("gd",-1,-1),new r("nn",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1),new r("tt",-1,-1)],m=[new r("ig",-1,1),new r("lig",0,1),new r("els",-1,1),new r("fullt",-1,3),new r("löst",-1,2)],l=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,24,0,32],d=[119,127,149],w=new n;this.setCurrent=function(e){w.setCurrent(e)},this.getCurrent=function(){return w.getCurrent()},this.stem=function(){var r=w.cursor;return e(),w.limit_backward=r,w.cursor=w.limit,t(),w.cursor=w.limit,i(),w.cursor=w.limit,s(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return t.setCurrent(e),t.stem(),t.getCurrent()}):(t.setCurrent(e),t.stem(),t.getCurrent())}}(),e.Pipeline.registerFunction(e.sv.stemmer,"stemmer-sv"),e.sv.stopWordFilter=e.generateStopWordFilter("alla allt att av blev bli blir blivit de dem den denna deras dess dessa det detta dig din dina ditt du där då efter ej eller en er era ert ett från för ha hade han hans har henne hennes hon honom hur här i icke ingen inom inte jag ju kan kunde man med mellan men mig min mina mitt mot mycket ni nu när någon något några och om oss på samma sedan sig sin sina sitta själv skulle som så sådan sådana sådant till under upp ut utan vad var vara varför varit varje vars vart vem vi vid vilka vilkas vilken vilket vår våra vårt än är åt över".split(" ")),e.Pipeline.registerFunction(e.sv.stopWordFilter,"stopWordFilter-sv")}}); -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.th.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.th=function(){this.pipeline.reset(),this.pipeline.add(e.th.trimmer),r?this.tokenizer=e.th.tokenizer:(e.tokenizer&&(e.tokenizer=e.th.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.th.tokenizer))},e.th.wordCharacters="[฀-๿]",e.th.trimmer=e.trimmerSupport.generateTrimmer(e.th.wordCharacters),e.Pipeline.registerFunction(e.th.trimmer,"trimmer-th");var t=e.wordcut;t.init(),e.th.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t):t});var n=i.toString().replace(/^\s+/,"");return t.cut(n).split("|")}}}); -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.vi.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.vi=function(){this.pipeline.reset(),this.pipeline.add(e.vi.stopWordFilter,e.vi.trimmer)},e.vi.wordCharacters="[A-Za-ẓ̀͐́͑̉̃̓ÂâÊêÔôĂ-ăĐ-đƠ-ơƯ-ư]",e.vi.trimmer=e.trimmerSupport.generateTrimmer(e.vi.wordCharacters),e.Pipeline.registerFunction(e.vi.trimmer,"trimmer-vi"),e.vi.stopWordFilter=e.generateStopWordFilter("là cái nhưng mà".split(" "))}}); -------------------------------------------------------------------------------- /documentation/site/assets/javascripts/lunr/min/lunr.zh.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r(require("nodejieba")):r()(e.lunr)}(this,function(e){return function(r,t){if(void 0===r)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===r.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var i="2"==r.version[0];r.zh=function(){this.pipeline.reset(),this.pipeline.add(r.zh.trimmer,r.zh.stopWordFilter,r.zh.stemmer),i?this.tokenizer=r.zh.tokenizer:(r.tokenizer&&(r.tokenizer=r.zh.tokenizer),this.tokenizerFn&&(this.tokenizerFn=r.zh.tokenizer))},r.zh.tokenizer=function(n){if(!arguments.length||null==n||void 0==n)return[];if(Array.isArray(n))return n.map(function(e){return i?new r.Token(e.toLowerCase()):e.toLowerCase()});t&&e.load(t);var o=n.toString().trim().toLowerCase(),s=[];e.cut(o,!0).forEach(function(e){s=s.concat(e.split(" "))}),s=s.filter(function(e){return!!e});var u=0;return s.map(function(e,t){if(i){var n=o.indexOf(e,u),s={};return s.position=[n,e.length],s.index=t,u=n,new r.Token(e,s)}return e})},r.zh.wordCharacters="\\w一-龥",r.zh.trimmer=r.trimmerSupport.generateTrimmer(r.zh.wordCharacters),r.Pipeline.registerFunction(r.zh.trimmer,"trimmer-zh"),r.zh.stemmer=function(){return function(e){return e}}(),r.Pipeline.registerFunction(r.zh.stemmer,"stemmer-zh"),r.zh.stopWordFilter=r.generateStopWordFilter("的 一 不 在 人 有 是 为 以 于 上 他 而 后 之 来 及 了 因 下 可 到 由 这 与 也 此 但 并 个 其 已 无 小 我 们 起 最 再 今 去 好 只 又 或 很 亦 某 把 那 你 乃 它 吧 被 比 别 趁 当 从 到 得 打 凡 儿 尔 该 各 给 跟 和 何 还 即 几 既 看 据 距 靠 啦 了 另 么 每 们 嘛 拿 哪 那 您 凭 且 却 让 仍 啥 如 若 使 谁 虽 随 同 所 她 哇 嗡 往 哪 些 向 沿 哟 用 于 咱 则 怎 曾 至 致 着 诸 自".split(" ")),r.Pipeline.registerFunction(r.zh.stopWordFilter,"stopWordFilter-zh")}}); -------------------------------------------------------------------------------- /documentation/site/figures/demo_proj_teid_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/demo_proj_teid_split6.png -------------------------------------------------------------------------------- /documentation/site/figures/demo_weightX_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/demo_weightX_split6.png -------------------------------------------------------------------------------- /documentation/site/figures/demo_weightY_split6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/demo_weightY_split6.png -------------------------------------------------------------------------------- /documentation/site/figures/example_fmri_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_fmri_proj.png -------------------------------------------------------------------------------- /documentation/site/figures/example_fmri_weight_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_fmri_weight_bar.png -------------------------------------------------------------------------------- /documentation/site/figures/example_fmri_weight_brain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_fmri_weight_brain.png -------------------------------------------------------------------------------- /documentation/site/figures/example_simul_paropt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_simul_paropt.png -------------------------------------------------------------------------------- /documentation/site/figures/example_simul_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_simul_plot.png -------------------------------------------------------------------------------- /documentation/site/figures/example_simul_weight_stemx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_simul_weight_stemx.png -------------------------------------------------------------------------------- /documentation/site/figures/example_simul_weight_stemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_simul_weight_stemy.png -------------------------------------------------------------------------------- /documentation/site/figures/example_smri_paropt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_smri_paropt.png -------------------------------------------------------------------------------- /documentation/site/figures/example_smri_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_smri_proj.png -------------------------------------------------------------------------------- /documentation/site/figures/example_smri_weight_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_smri_weight_bar.png -------------------------------------------------------------------------------- /documentation/site/figures/example_smri_weight_brain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/example_smri_weight_brain.png -------------------------------------------------------------------------------- /documentation/site/figures/flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/flowchart.png -------------------------------------------------------------------------------- /documentation/site/figures/folders.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/folders.png -------------------------------------------------------------------------------- /documentation/site/figures/framework_ML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/framework_ML.png -------------------------------------------------------------------------------- /documentation/site/figures/framework_STAT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/framework_STAT.png -------------------------------------------------------------------------------- /documentation/site/figures/functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/functions.png -------------------------------------------------------------------------------- /documentation/site/figures/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/overview.png -------------------------------------------------------------------------------- /documentation/site/figures/overview_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/overview_analysis.png -------------------------------------------------------------------------------- /documentation/site/figures/overview_visualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/overview_visualization.png -------------------------------------------------------------------------------- /documentation/site/figures/plot_proj_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/plot_proj_simple.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_behav_vert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_behav_vert.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_brain_conn_node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_brain_conn_node.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_brain_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_brain_edge.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_brain_node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_brain_node.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_proj_advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_proj_advanced.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_proj_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_proj_simple.png -------------------------------------------------------------------------------- /documentation/site/figures/visualization_stem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/figures/visualization_stem.png -------------------------------------------------------------------------------- /documentation/site/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | None 5 | 2022-02-28 6 | daily 7 | 8 | 9 | None 10 | 2022-02-28 11 | daily 12 | 13 | 14 | None 15 | 2022-02-28 16 | daily 17 | 18 | 19 | None 20 | 2022-02-28 21 | daily 22 | 23 | 24 | None 25 | 2022-02-28 26 | daily 27 | 28 | 29 | None 30 | 2022-02-28 31 | daily 32 | 33 | 34 | None 35 | 2022-02-28 36 | daily 37 | 38 | 39 | None 40 | 2022-02-28 41 | daily 42 | 43 | 44 | None 45 | 2022-02-28 46 | daily 47 | 48 | 49 | None 50 | 2022-02-28 51 | daily 52 | 53 | 54 | None 55 | 2022-02-28 56 | daily 57 | 58 | 59 | None 60 | 2022-02-28 61 | daily 62 | 63 | 64 | None 65 | 2022-02-28 66 | daily 67 | 68 | 69 | None 70 | 2022-02-28 71 | daily 72 | 73 | 74 | None 75 | 2022-02-28 76 | daily 77 | 78 | 79 | None 80 | 2022-02-28 81 | daily 82 | 83 | 84 | None 85 | 2022-02-28 86 | daily 87 | 88 | 89 | None 90 | 2022-02-28 91 | daily 92 | 93 | 94 | None 95 | 2022-02-28 96 | daily 97 | 98 | 99 | None 100 | 2022-02-28 101 | daily 102 | 103 | -------------------------------------------------------------------------------- /documentation/site/sitemap.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/documentation/site/sitemap.xml.gz -------------------------------------------------------------------------------- /fileio/cleanup_files.m: -------------------------------------------------------------------------------- 1 | function cleanup_files(cfg) 2 | % cleanup_files 3 | % 4 | % Cleans up unnecessary duplicate and intermediate files created during 5 | % analysis to save disc space. 6 | % 7 | % # Syntax 8 | % cleanup_files(cfg) 9 | % 10 | % # Inputs 11 | % cfg:: struct 12 | % 13 | % 14 | % # Examples 15 | % 16 | % % Example 1 17 | % load cfg; 18 | % cleanup_files(cfg); 19 | % 20 | % --- 21 | % See also: [cfg](../../cfg) 22 | % 23 | %_______________________________________________________________________ 24 | % Copyright (C) 2022 University College London 25 | 26 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 27 | % $Id$ 28 | 29 | % This file is part of CCA/PLS Toolkit. 30 | % 31 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 32 | % it under the terms of the GNU General Public License as published by 33 | % the Free Software Foundation, either version 3 of the License, or 34 | % (at your option) any later version. 35 | % 36 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 37 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 39 | % GNU General Public License for more details. 40 | % 41 | % You should have received a copy of the GNU General Public License 42 | % along with CCA/PLS Toolkit. If not, see . 43 | 44 | lv = 1; 45 | while exist_file(cfg, fullfile(cfg.dir.frwork, 'res', sprintf('level%d', lv), 'res.mat')) 46 | % Load res file 47 | res = loadmat(cfg, fullfile(cfg.dir.frwork, 'res', sprintf('level%d', lv), 'res.mat'), 'res'); 48 | 49 | % Clean up data folder 50 | renamemat(cfg, fullfile(res.dir.frwork, 'inmat.mat')); 51 | renamemat(cfg, fullfile(res.dir.frwork, 'outmat.mat')); 52 | 53 | % Clean up grid folder 54 | if strcmp(cfg.frwork.name, 'holdout') 55 | renamemat(cfg, fullfile(res.dir.grid, 'allgrid.mat')); 56 | delete(fullfile(res.dir.grid, 'grid_*.mat')); 57 | end 58 | 59 | % Clean up load folder 60 | % if isdir(cfg.dir.load) 61 | % rmdir(cfg.dir.load, 's'); 62 | % end 63 | 64 | % Clean up perm folder 65 | renamemat(cfg, fullfile(res.dir.perm, 'allperm.mat')); 66 | renamemat(cfg, fullfile(res.dir.frwork, 'perm', sprintf('permmat_%d.mat', cfg.stat.nperm))); 67 | delete(fullfile(res.dir.perm, 'perm_*.mat')); 68 | 69 | % Clean up res folder 70 | renamemat(cfg, fullfile(res.dir.res, 'model.mat')); 71 | renamemat(cfg, fullfile(res.dir.res, 'param.mat')); 72 | renamemat(cfg, fullfile(res.dir.res, 'res.mat')); 73 | 74 | % Update fileend field 75 | res.env.fileend = '_1'; 76 | save(fullfile(res.dir.res, 'res_1.mat'), 'res') 77 | cfg.env.fileend = '_1'; 78 | renamemat(cfg, fullfile(res.dir.frwork, 'cfg.mat')); 79 | 80 | clear res 81 | lv = lv + 1; 82 | end 83 | -------------------------------------------------------------------------------- /fileio/compile_files.m: -------------------------------------------------------------------------------- 1 | function compile_files(res, files) 2 | % compile_files 3 | % 4 | % # Syntax 5 | % compile_files(res, files) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load cfg 29 | cfg = loadmat(res, fullfile(res.dir.frwork, 'cfg.mat'), 'cfg'); 30 | 31 | % Get option 32 | [pathstr, name, ext] = fileparts(files{1}); 33 | opt = regexp(name, '^[a-z]+', 'match'); 34 | opt = opt{:}; 35 | 36 | % Initialization 37 | S = cell2struct(cell(numel(cfg.machine.metric), numel(files)), cfg.machine.metric); 38 | 39 | % Load files 40 | for i=1:numel(files) 41 | if ~exist_file(res, fullfile(res.dir.(opt), ['all' opt '.mat'])) 42 | % Display progress based on verbosity level 43 | switch res.env.verbose 44 | case 1 45 | fprintf('%d\n', i); 46 | otherwise 47 | % display nothing at the moment 48 | end 49 | 50 | try 51 | S(i) = loadmat_struct(res, files{i}); 52 | catch 53 | % Display message based on verbosity level 54 | switch res.env.verbose 55 | case 1 56 | fprintf('%s was not loaded\n', files{i}); 57 | otherwise 58 | % display nothing at the moment 59 | end 60 | end 61 | else 62 | break 63 | end 64 | end 65 | 66 | % Compile files if no missing data 67 | if ~any(arrayfun(@(x) isempty(S(x).(cfg.machine.metric{1})), 1:numel(files))) 68 | if strcmp(opt, 'grid') 69 | name_value = parse_struct(S, 1); 70 | elseif strcmp(opt, 'perm') 71 | name_value = parse_struct(S, 2); 72 | end 73 | savemat(res, fullfile(res.dir.(opt), ['all' opt '.mat']), name_value{:}); 74 | end 75 | -------------------------------------------------------------------------------- /fileio/exist_file.m: -------------------------------------------------------------------------------- 1 | function [isfile, filename] = exist_file(cfg, fname, var) 2 | % exist_file 3 | % 4 | % # Syntax 5 | % [isfile, filename] = exist_file(cfg, fname, var) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % List file 29 | [pathstr, name, ext] = fileparts(fname); 30 | if isempty(cfg.env.fileend) 31 | filename = getfname(pathstr, ['^' name ext]); 32 | else 33 | filename = getfname(pathstr, ['^' name '_\d+' ext]); 34 | end 35 | 36 | % Check if file exists 37 | isfile = ~isempty(filename); 38 | if isfile 39 | filename = fullfile(pathstr, filename); 40 | else 41 | filename = ''; 42 | end 43 | 44 | % Additional check if variable exists in file without loading/putting it into memory 45 | if isfile && exist('var', 'var') 46 | obj = matfile(filename{1}); 47 | if ismember(var, who(obj)) 48 | isfile = 1; 49 | else 50 | isfile = 0; 51 | end 52 | end -------------------------------------------------------------------------------- /fileio/getfname.m: -------------------------------------------------------------------------------- 1 | function fname = getfname(folder, expression) 2 | % getfname 3 | % 4 | % It lists all the file/folder names to a cell array that match the 5 | % character pattern specified by the regular expression. 6 | % 7 | % # Syntax 8 | % fname = getfname(folder, expression) 9 | % 10 | % # Inputs 11 | % folder:: char 12 | % folder name in which we want to list files/subfolders 13 | % expression:: char 14 | % character pattern specified by regular expression 15 | % 16 | % # Outputs 17 | % fname:: cell array 18 | % cell array of file/folder names 19 | % 20 | %_______________________________________________________________________ 21 | % Copyright (C) 2022 University College London 22 | 23 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 24 | % $Id$ 25 | 26 | % This file is part of CCA/PLS Toolkit. 27 | % 28 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 29 | % it under the terms of the GNU General Public License as published by 30 | % the Free Software Foundation, either version 3 of the License, or 31 | % (at your option) any later version. 32 | % 33 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 34 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | % GNU General Public License for more details. 37 | % 38 | % You should have received a copy of the GNU General Public License 39 | % along with CCA/PLS Toolkit. If not, see . 40 | 41 | % List all files in the folder 42 | files = dir(folder); 43 | nfiles = numel(files); 44 | 45 | % Find files that match regular expression 46 | startid = cell(nfiles, 1); 47 | for i=1:nfiles 48 | startid{i} = regexp(files(i).name, expression); 49 | end 50 | fname = {files.name}'; 51 | fname = fname(~cellfun(@isempty, startid)); 52 | -------------------------------------------------------------------------------- /fileio/loadmat.m: -------------------------------------------------------------------------------- 1 | function varargout = loadmat(res, fname, varargin) 2 | % loadmat 3 | % 4 | % # Syntax 5 | % varargout = loadmat(res, fname, varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Parse fname 29 | [pathstr, name, ext] = fileparts(fname); 30 | if isempty(res.env.fileend) 31 | filename = getfname(pathstr, ['^' name ext]); 32 | else 33 | filename = getfname(pathstr, ['^' name '_\d+' ext]); 34 | end 35 | 36 | timestamp = clock; 37 | 38 | while ~isempty(filename) 39 | % Try loading data 40 | try 41 | S = load(fullfile(pathstr, filename{1})); 42 | varargout = cellfun(@(x) S.(x), varargin, 'un', 0); 43 | break; 44 | catch 45 | % Keep looping if file is temporarily unavailable 46 | if etime(clock, timestamp) < 60 47 | pause(10*rand); % wait a bit 48 | continue; 49 | % elseif etime(clock, datevec(f(ismember({f.name}, [name ext])).datenum)) < 600 50 | % fname % this branch might not work, so variables are displayed for debugging 51 | % f = dir(pathstr) 52 | % f(ismember({f.name}, [name ext])).datenum 53 | % continue; 54 | else 55 | delete(fullfile(pathstr, filename{1})); 56 | if res.env.verbose == 1 57 | fprintf('File corrupt: %s\n', fullfile(pathstr, filename{1})); 58 | end 59 | %error('File corrupt: %s\n', fullfile(pathstr, file(1).name)); 60 | filename(1) = []; 61 | end 62 | end 63 | end -------------------------------------------------------------------------------- /fileio/loadmat_struct.m: -------------------------------------------------------------------------------- 1 | function S = loadmat_struct(res, fname, varargin) 2 | % loadmat_struct 3 | % 4 | % # Syntax 5 | % S = loadmat_struct(res, fname, varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Parse fname 29 | [pathstr, name, ext] = fileparts(fname); 30 | if isempty(res.env.fileend) 31 | filename = getfname(pathstr, ['^' name ext]); 32 | else 33 | filename = getfname(pathstr, ['^' name '_\d+' ext]); 34 | end 35 | 36 | timestamp = clock; 37 | 38 | while ~isempty(filename) 39 | % Try loading data 40 | try 41 | S = load(fullfile(pathstr, filename{1}), varargin{:}); 42 | break; 43 | catch 44 | % Keep looping if file is temporarily unavailable 45 | if etime(clock, timestamp) < 60 46 | pause(10*rand); % wait a bit 47 | continue; 48 | else 49 | delete(fullfile(pathstr, filename{1})); 50 | if res.env.verbose == 1 51 | fprintf('File corrupt: %s\n', fullfile(pathstr, filename{1})); 52 | end 53 | filename(1) = []; 54 | end 55 | end 56 | end -------------------------------------------------------------------------------- /fileio/parse_input.m: -------------------------------------------------------------------------------- 1 | function S = parse_input(S, varargin) 2 | % parse_input 3 | % 4 | % Assigns Name-Value pairs in varargin to a structure with fields of 5 | % 'Name' and value of 'Value' 6 | % 7 | % Notes: 8 | % 1. dot delimited Name string can be used for nested structure 9 | % 2. this function is the inverse operation of parse_struct 10 | % 11 | % # Syntax 12 | % S = parse_input(S, varargin) 13 | % 14 | %_______________________________________________________________________ 15 | % Copyright (C) 2022 University College London 16 | 17 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 18 | % $Id$ 19 | 20 | % This file is part of CCA/PLS Toolkit. 21 | % 22 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 23 | % it under the terms of the GNU General Public License as published by 24 | % the Free Software Foundation, either version 3 of the License, or 25 | % (at your option) any later version. 26 | % 27 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 28 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | % GNU General Public License for more details. 31 | % 32 | % You should have received a copy of the GNU General Public License 33 | % along with CCA/PLS Toolkit. If not, see . 34 | 35 | % Initialize structure 36 | if isempty(S) 37 | S = struct(); 38 | elseif ~isstruct(S) && ~ishandle(S) 39 | error('parse_input accepts only structure input as first argument'); 40 | end 41 | 42 | if mod(numel(varargin), 2) 43 | error('parse_input accepts only Name-Value pairs'); 44 | else 45 | for i=1:2:numel(varargin) 46 | tags = strsplit(varargin{i}, '.'); 47 | subs = struct('type', '.', 'subs', tags); 48 | if istable(varargin{i+1}) % exception for tables 49 | S.(varargin{i}) = varargin{i+1}; 50 | else 51 | S = subsasgn(S, subs, varargin{i+1}); 52 | end 53 | end 54 | end -------------------------------------------------------------------------------- /fileio/parse_struct.m: -------------------------------------------------------------------------------- 1 | function name_value = parse_struct(S, dim, fields) 2 | % parse_input 3 | % 4 | % Decomposes structure with fields and values into a cell array with 5 | % 'Name' and 'Value' pairs 6 | % 7 | % Note: 8 | % This function is the inverse operation of parse_input 9 | % 10 | % # Syntax 11 | % S = parse_input(S, varargin) 12 | % 13 | %_______________________________________________________________________ 14 | % Copyright (C) 2022 University College London 15 | 16 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 17 | % $Id$ 18 | 19 | % This file is part of CCA/PLS Toolkit. 20 | % 21 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 22 | % it under the terms of the GNU General Public License as published by 23 | % the Free Software Foundation, either version 3 of the License, or 24 | % (at your option) any later version. 25 | % 26 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 27 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | % GNU General Public License for more details. 30 | % 31 | % You should have received a copy of the GNU General Public License 32 | % along with CCA/PLS Toolkit. If not, see . 33 | 34 | if ~exist('fields', 'var') 35 | fields = fieldnames(S); 36 | end 37 | 38 | % Check input dimensionality 39 | if ~exist('dim', 'var') 40 | dim = 1; 41 | end 42 | if numel(S) > 1 && size(S(1).(fields{1}), dim) ~= 1 43 | error('The current implementation assumes a structure array with 1D data.') 44 | end 45 | 46 | name_value = cell(2, numel(fields)); 47 | for i=1:numel(fields) 48 | if ~isempty(cat(dim, S(:).(fields{i}))) 49 | name_value{1,i} = fields{i}; 50 | name_value{2,i} = cat(dim, S(:).(fields{i})); 51 | end 52 | end 53 | name_value(:,all(cellfun(@isempty, name_value), 1)) = []; 54 | name_value = reshape(name_value, 1, []); 55 | -------------------------------------------------------------------------------- /fileio/renamemat.m: -------------------------------------------------------------------------------- 1 | function renamemat(cfg, fname) 2 | % renamemat 3 | % 4 | % # Syntax 5 | % renamemat(cfg, fname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Parse fname 29 | [pathstr, name, ext] = fileparts(fname); 30 | filename = getfname_fe(cfg, pathstr, name, ext); 31 | if ~isempty(filename) 32 | % Make sure we can load data 33 | loadmat(cfg, fullfile(pathstr, [name ext])); 34 | 35 | % Rename file 36 | filename = getfname_fe(cfg, pathstr, name, ext); % update in case some files have been deleted 37 | old_file = fullfile(pathstr, filename{1}); 38 | new_file = fullfile(pathstr, [name '_1' ext]); 39 | if ~strcmp(old_file, new_file) 40 | movefile(old_file, new_file); 41 | end 42 | 43 | % Delete additional files if exist 44 | filename = getfname_fe(cfg, pathstr, name, ext); % update in case some files have been renamed 45 | for i=2:numel(filename) 46 | delete(fullfile(pathstr, filename{i})); 47 | end 48 | end 49 | 50 | % --------------------------- Private functions --------------------------- 51 | 52 | function filename = getfname_fe(cfg, pathstr, name, ext) 53 | % get filename irrespective of file end 54 | 55 | if isempty(cfg.env.fileend) 56 | filename = getfname(pathstr, ['^' name ext]); 57 | else 58 | filename = getfname(pathstr, ['^' name '_\d+' ext]); 59 | end 60 | 61 | if isempty(filename) && cfg.env.verbose == 1 62 | fprintf('File not found: %s\n', [name ext]); 63 | end -------------------------------------------------------------------------------- /fileio/savemat.m: -------------------------------------------------------------------------------- 1 | function savemat(res, fname, varargin) 2 | % savemat 3 | % 4 | % Saves .mat data with flexible filename suffix. 5 | % 6 | % # Syntax 7 | % savemat(res, fname, varargin) 8 | % 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2022 University College London 11 | 12 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 13 | % $Id$ 14 | 15 | % This file is part of CCA/PLS Toolkit. 16 | % 17 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with CCA/PLS Toolkit. If not, see . 29 | 30 | % Parse input 31 | S = parse_input([], varargin{:}); 32 | 33 | % Parse fname 34 | [pathstr, name, ext] = fileparts(fname); 35 | 36 | if ~exist_file(res, fname) 37 | if res.env.save.compression 38 | % Save file with compression for memory-efficient storage 39 | save(fullfile(pathstr, [name res.env.fileend ext]), '-struct', 'S', '-v7.3'); 40 | else 41 | % Save file without compression to speed up saving/loading >2G files 42 | save(fullfile(pathstr, [name res.env.fileend ext]), '-struct', 'S', '-v7.3', '-nocompression'); 43 | end 44 | % end 45 | elseif isfield(S, 'cfg') 46 | cfg = loadmat(res, fullfile(pathstr, 'cfg.mat'), 'cfg'); 47 | if ~isequal(S.cfg, cfg) 48 | warning('cfg structures are not the same, be very cautious!'); 49 | check_fields('cfg', {S.cfg cfg}); 50 | end 51 | end 52 | 53 | 54 | % --------------------------- Private functions --------------------------- 55 | 56 | function check_fields(varname, var, varargin) 57 | % check_fields goes through all fields and subfields of var{1} and var{2} iteratively 58 | % and checks the discrepancy 59 | 60 | dfields = fieldnames(var{1}); 61 | 62 | for i=1:numel(dfields) 63 | % Loop through subfields iteratively 64 | if isfield(var{2}, dfields{i}) 65 | if isstruct(var{1}.(dfields{i})) 66 | check_fields(varname, {var{1}.(dfields{i}) var{2}.(dfields{i})}, dfields{i}, varargin{:}); 67 | 68 | % Check if fields are the same 69 | elseif ~isequal(var{1}.(dfields{i}), var{2}.(dfields{i})) 70 | fprintf('%s.%s with different value\n', varname, strjoin([fliplr(varargin) dfields(i)], '.')) 71 | end 72 | else 73 | % Missing field 74 | fprintf('%s.%s missing\n', varname, strjoin([fliplr(varargin) dfields(i)], '.')) 75 | end 76 | end -------------------------------------------------------------------------------- /fileio/select_file.m: -------------------------------------------------------------------------------- 1 | function fname = select_file(res, folder, str, ext, default) 2 | % select_file 3 | % 4 | % Wrapper to select file interactively using SPM GUI or set default. 5 | % 6 | % # Syntax 7 | % fname = select_file(res, folder, str, ext, default) 8 | % 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2022 University College London 11 | 12 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 13 | % $Id$ 14 | 15 | % This file is part of CCA/PLS Toolkit. 16 | % 17 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with CCA/PLS Toolkit. If not, see . 29 | 30 | % Wrapper to select file interactively with SPM or use default 31 | fname = []; 32 | if strcmp(res.gen.selectfile, 'interactive') 33 | fname = spm_select(1, ext, str, {}, folder); % GUI to get file 34 | end 35 | if isempty(fname) 36 | fname = default; 37 | end -------------------------------------------------------------------------------- /machines/rcca.m: -------------------------------------------------------------------------------- 1 | function [wX, wY] = rcca(data, featid, param) 2 | % rcca 3 | % 4 | % Implementation for PCA-CCA, CCA and Regularized CCA and PLS 5 | % 6 | % # Syntax 7 | % [wX, wY] = rcca(data, featid, param) 8 | % 9 | % --- 10 | % See also: [spls](../spls/), [fastsvd](../fastsvd/) 11 | % 12 | %_______________________________________________________________________ 13 | % Copyright (C) 2022 University College London 14 | 15 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 16 | % $Id$ 17 | 18 | % This file is part of CCA/PLS Toolkit. 19 | % 20 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 21 | % it under the terms of the GNU General Public License as published by 22 | % the Free Software Foundation, either version 3 of the License, or 23 | % (at your option) any later version. 24 | % 25 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 26 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | % GNU General Public License for more details. 29 | % 30 | % You should have received a copy of the GNU General Public License 31 | % along with CCA/PLS Toolkit. If not, see . 32 | 33 | % Calculate covariance/cross-covariance matrices 34 | BYY = (1-param.L2y) * data.LY(featid.y) + repmat(param.L2y, sum(featid.y), 1); 35 | BXX = (1-param.L2x) * data.LX(featid.x) + repmat(param.L2x, sum(featid.x), 1); 36 | RXY = data.RX(:,featid.x)' * data.RY(:,featid.y); 37 | 38 | % Solve standard eigenvalue problem 39 | [wY, lambda] = eigs(diag(1./sqrt(BYY)) * RXY' * diag(1./BXX) * RXY * diag(1./sqrt(BYY)), 1); 40 | lambda = real(sqrt(lambda)); 41 | 42 | % Compute weights 43 | wY = diag(1./sqrt(BYY)) * wY; 44 | wX = diag(1./BXX) * RXY * wY / lambda; -------------------------------------------------------------------------------- /misc/calc_permid.m: -------------------------------------------------------------------------------- 1 | function calc_permid(res, runtype) 2 | % calc_permid 3 | % 4 | % # Syntax 5 | % calc_permid(res, runtype) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load cfg 29 | cfg = loadmat(res, fullfile(res.dir.frwork, 'cfg.mat'), 'cfg'); 30 | 31 | % Initialize file 32 | file = fullfile(res.dir.frwork, runtype, sprintf('permmat_%d.mat', res.stat.nperm)); 33 | 34 | % Quit if permutations already generated 35 | if res.stat.nperm == 0 || res.frwork.level > 1 || exist_file(res, file) 36 | return 37 | end 38 | 39 | % Display options based on verbosity level 40 | switch res.env.verbose 41 | case 1 42 | fprintf('Generating permutations...\n'); 43 | tic 44 | case 2 45 | fprintf('\nGenerating permutations...\n'); 46 | case 3 47 | fprintf('Generating permutations...\n'); 48 | end 49 | 50 | % Add PALM to path 51 | set_path('palm'); 52 | 53 | % Set seed for reproducibility 54 | rng(cfg.env.seed.perm); 55 | 56 | % Define exchangeability blocks (EB) 57 | if cfg.data.block && ~isempty(cfg.data.EB.stat) 58 | load(fullfile(cfg.dir.project, 'data', 'EB.mat')); 59 | EB = EB(:,cfg.data.EB.stat); 60 | else 61 | EB = [ones(cfg.data.nsubj, 1) (1:cfg.data.nsubj)']; 62 | end 63 | 64 | % Initialize training/test separation in EB 65 | EB = [repmat(-1, cfg.data.nsubj, 1) EB]; 66 | 67 | % Create permutations respecting EB 68 | [otrid, oteid] = loadmat(res, fullfile(res.dir.frwork, 'outmat.mat'), 'otrid', 'oteid'); 69 | permid = cell(1, res.frwork.split.nall); 70 | for i=1:res.frwork.split.nall 71 | % EB at each iteration 72 | EBi = EB; 73 | 74 | % Training index 75 | trid = otrid(:,res.frwork.split.all(i)); 76 | 77 | % Update EB 78 | if strcmp(cfg.stat.perm, 'train') 79 | EBi = EBi(trid,2:end); % subsample training indexes 80 | 81 | elseif strcmp(cfg.stat.perm, 'train+test') 82 | EBi(:,2) = EB(:,2) .* (trid+1); % add training/test separation 83 | end 84 | 85 | % Permute 86 | if ~exist_file(res, file) 87 | pset = palm_quickperms([], EBi, cfg.stat.nperm+1); 88 | permid{i} = pset(:,2:end); % neutral permutation is ignored 89 | else 90 | break 91 | end 92 | end 93 | 94 | % Save permutations 95 | if ~isdir(fullfile(res.dir.frwork, runtype)) 96 | mkdir(fullfile(res.dir.frwork, runtype)) 97 | end 98 | savemat(res, file, 'permid', permid); 99 | 100 | % Display options based on verbosity level 101 | switch res.env.verbose 102 | case 1 103 | fprintf('done!\n'); 104 | toc 105 | case 2 106 | fprintf('done!\n'); 107 | end -------------------------------------------------------------------------------- /misc/calc_proj.m: -------------------------------------------------------------------------------- 1 | function P = calc_proj(data, weight, method) 2 | % calc_proj 3 | % 4 | % # Syntax 5 | % P = calc_proj(data, weight, method) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | if exist('method', 'var') && strcmp(method, 'isnan') 29 | % Compute projection with missing data 30 | P = NaN(size(data, 1), size(weight, 2)); 31 | for i = 1:size(weight, 2) 32 | P(:,i) = nansum(bsxfun(@times, data, weight(:,i)'), 2); 33 | end 34 | % elseif exist('method', 'var') && strcmp(method, 'scaled') 35 | % % Compute projection without missing data and scaling by the number of 36 | % % features 37 | % P = data * weight / sum(weight~=0); 38 | else 39 | % Compute projection without missing data 40 | P = data * weight; 41 | end -------------------------------------------------------------------------------- /misc/concat_data.m: -------------------------------------------------------------------------------- 1 | function data = concat_data(trdata, tedata, modality, trid, teid) 2 | % concat_data 3 | % 4 | % # Syntax 5 | % data = concat_data(trdata, tedata, modality, trid, teid) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Check input 29 | for f=1:numel(modality) 30 | if size(trdata.(modality{f}), 2) ~= size(tedata.(modality{f}), 2) 31 | error('Dimensions of training and test data do not match.') 32 | end 33 | end 34 | if size(trid, 1) ~= size(teid, 1) 35 | error('Dimensions of training and test indexes do not match.') 36 | end 37 | 38 | % Concatenate train and test data 39 | for f=1:numel(modality) 40 | % Initialize field 41 | data.(modality{f}) = NaN(size(trid, 1), size(trdata.(modality{f}), 2)); 42 | 43 | % Training data 44 | data.(modality{f})(trid,:) = trdata.(modality{f}); 45 | 46 | % Test data 47 | data.(modality{f})(teid,:) = tedata.(modality{f}); 48 | end 49 | -------------------------------------------------------------------------------- /misc/generate_data.m: -------------------------------------------------------------------------------- 1 | function [X, Y, wX, wY] = generate_data(nexamples, nfeatx, nfeaty, activex, activey, noise) 2 | % generate_data 3 | % 4 | % Generates data via a sparse latent variable model based on 5 | % [Witten et al. 2009](https://doi.org/10.2202/1544-6115.1470). The 6 | % generated data has two modalities with `nexamples` samples and `nfeatx` 7 | % and `nfeaty` variables, respectively. The `activex` and `activey` inputs 8 | % define the number of variables in the two data modalities that are 9 | % associated with a Gaussian latent variable. 10 | % 11 | % # Syntax 12 | % [X, Y, wX, wY] = generate_data(nexamples, nfeatx, nfeaty, activex, activey, noise) 13 | % 14 | % # Inputs 15 | % nexamples:: int 16 | % number of examples in generated data 17 | % nfeatx:: int 18 | % number of features in generated data $\mathbf{X}$ 19 | % nfeaty:: int 20 | % number of features in generated data $\mathbf{Y}$ 21 | % activex:: int 22 | % number of active features in generated data $\mathbf{X}$ 23 | % associated with the latent variable 24 | % activey:: int 25 | % number of active features in generated data $\mathbf{Y}$ 26 | % associated with the latent variable 27 | % noise:: float 28 | % noise level in the generative model 29 | % 30 | % # Outputs 31 | % X:: 2D numeric array 32 | % generated data $\mathbf{X}$ with `nexamples` rows and `nfeatx` 33 | % columns 34 | % Y:: 2D numeric array 35 | % generated data $\mathbf{Y}$ with `nexamples` rows and `nfeaty` 36 | % columns 37 | % wX:: numeric array 38 | % true weights used to generate data $\mathbf{X}$ from the latent 39 | % variable, which has `activex` non-zero values 40 | % wY:: numeric array 41 | % true weights used to generate data $\mathbf{Y}$ from the latent 42 | % variable, which has `activey` non-zero values 43 | % 44 | % # Examples 45 | % 46 | % % Example 1 47 | % [X, Y, wX, wY] = generate_data(1000, 100, 100, 10, 10, 1); 48 | % 49 | % --- 50 | % 51 | %_______________________________________________________________________ 52 | % Copyright (C) 2022 University College London 53 | 54 | % Written by James Chapman (cca-pls-toolkit@cs.ucl.ac.uk) 55 | % $Id$ 56 | 57 | % This file is part of CCA/PLS Toolkit. 58 | % 59 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 60 | % it under the terms of the GNU General Public License as published by 61 | % the Free Software Foundation, either version 3 of the License, or 62 | % (at your option) any later version. 63 | % 64 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 65 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 66 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 67 | % GNU General Public License for more details. 68 | % 69 | % You should have received a copy of the GNU General Public License 70 | % along with CCA/PLS Toolkit. If not, see . 71 | 72 | z = normrnd(0,1,nexamples,1); %generate a random gaussian latent variable 73 | wX=rand(1,nfeatx); %now generate some random weights that project from the latent variable space to the data space 74 | wY=rand(1,nfeaty); 75 | mask_x=zeros(1,nfeatx); %we mask off some of the variables so that only active_x and active_y are nonzero 76 | mask_y=zeros(1,nfeaty); 77 | mask_x(1:end,1:activex)=1; 78 | mask_x=mask_x(randperm(length(mask_x))); %permute them 79 | mask_y(1:end,1:activey)=1; 80 | mask_y=mask_y(randperm(length(mask_y))); 81 | wX=wX.*mask_x; %project to the data space by multiplying latent variable with weights 82 | wY=wY.*mask_y; 83 | X=z*wX; 84 | Y=z*wY; 85 | X=X+normrnd(0,noise,nexamples,nfeatx); %add some gaussian noise 86 | Y=Y+normrnd(0,noise,nexamples,nfeaty); -------------------------------------------------------------------------------- /misc/get_featid.m: -------------------------------------------------------------------------------- 1 | function featid = get_featid(data, param, mod) 2 | % get_featid 3 | % 4 | % # Syntax 5 | % featid = get_featid(data, param, mod) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | if isfield(param, (['VAR' lower(mod)])) 29 | % Reduce dimensionality by explained variance 30 | featid = cumsum(data.(['L' mod])) / sum(data.(['L' mod])) <= param.(['VAR' lower(mod)]); 31 | 32 | else 33 | % Keep all variance 34 | featid = true(size(data.(['L' mod]))); 35 | end 36 | 37 | if isfield(param, (['PCA' lower(mod)])) 38 | if sum(featid) < param.(['PCA' lower(mod)]) 39 | warning('Dimensionality of data %s is lower than number of PCA components', mod); 40 | else 41 | % Reduce dimensionality by number of PCA components 42 | featid(param.(['PCA' lower(mod)])+1:end) = false; 43 | end 44 | end -------------------------------------------------------------------------------- /misc/get_hyperparam.m: -------------------------------------------------------------------------------- 1 | function [param, S, bestid] = get_hyperparam(res, opt) 2 | % get_hyperparam 3 | % 4 | % # Syntax 5 | % [param, S, bestid] = get_hyperparam(res, opt) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load cfg 29 | if isfield(res.dir, 'frwork') 30 | cfg = loadmat(res, fullfile(res.dir.frwork, 'cfg.mat'), 'cfg'); 31 | else 32 | cfg = res; 33 | end 34 | 35 | % Number of hyperparameter levels 36 | p = cfg.machine.param.name; % shorthand variable 37 | num = zeros(1, numel(p)); 38 | for i=1:numel(p) 39 | num(i) = numel(cfg.machine.param.(p{i})); 40 | end 41 | 42 | % Compute design for hyperparameter combinations 43 | if strcmp(cfg.machine.param.type, 'factorial') 44 | design = fullfact(num); 45 | elseif strcmp(cfg.machine.param.type, 'matched') 46 | design = repmat(1:num(1), numel(p), 1)'; 47 | end 48 | 49 | switch opt 50 | case 'default' 51 | % Assign hyperparameters 52 | for i=1:size(design, 1) 53 | for j=1:size(design, 2) 54 | param(i).(p{j}) = cfg.machine.param.(p{j})(design(i,j)); 55 | end 56 | end 57 | 58 | case 'grid' 59 | % Load default params 60 | param = get_hyperparam(res, 'default'); 61 | nparams = numel(param); 62 | 63 | % Load compiled grid search file and format data 64 | if exist_file(cfg, fullfile(res.dir.grid, 'allgrid.mat')) 65 | S = loadmat_struct(res, fullfile(res.dir.grid, 'allgrid.mat')); 66 | for i=1:numel(cfg.machine.metric) 67 | S.(cfg.machine.metric{i}) = reshape(S.(cfg.machine.metric{i}), ... 68 | res.frwork.split.nall, nparams, []); 69 | end 70 | else 71 | error('allgrid.mat not available'); 72 | end 73 | 74 | % Calculate mean metric across subsamples 75 | fields = fieldnames(S); 76 | for i=1:numel(fields) 77 | S.(fields{i}) = real(nanmean(S.(fields{i}), 3)); 78 | end 79 | 80 | % Find best hyperparameter % deal with multiple values!!! 81 | bestid = zeros(1, res.frwork.split.nall); 82 | switch cfg.machine.param.crit 83 | case 'correl+simwxy' % minimum distance 84 | for i=1:res.frwork.split.nall 85 | [minval, bestid(i)] = min(calc_distance(S.correl(i,:), ... 86 | nanmean([S.simwx(i,:); S.simwy(i,:)], 1))); 87 | end 88 | 89 | case 'correl' % maximum test correlation 90 | mx_crr = max(S.(cfg.machine.param.crit), [], 2); 91 | for i=1:res.frwork.split.nall 92 | id = find(S.(cfg.machine.param.crit)(i,:) == mx_crr(i), 1); % sparsest solution if multiple values 93 | bestid(i) = id; 94 | end 95 | end 96 | param = param(bestid); 97 | end 98 | -------------------------------------------------------------------------------- /misc/impute_mat.m: -------------------------------------------------------------------------------- 1 | function data = impute_mat(cfg, data, trid, mod) 2 | % impute_mat 3 | % 4 | % # Syntax 5 | % data = impute_mat(cfg, data, trid, mod) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | if any(isnan(data.(mod)(:))) 29 | % Display message based on verbosity level 30 | switch cfg.env.verbose 31 | case 1 32 | fprintf('Proportion of missing elements in %s: %.2f%%\n', mod, ... 33 | numel(find(isnan(data.(mod)))) / numel(data.(mod)) * 100) 34 | otherwise 35 | % display nothing at the moment 36 | end 37 | else 38 | return 39 | end 40 | 41 | if strcmp(cfg.data.(mod).impute, 'median') 42 | % Replace all NaN with median of respective column 43 | for i=1:size(data.(mod), 2) 44 | data.(mod)(isnan(data.(mod)(:,i)),i) = nanmedian(data.(mod)(trid,i)); 45 | end 46 | else 47 | if any(isnan(data.(mod)(:))) && ismember(mod, {'X' 'C'}) 48 | error('%s matrix shouldn''t contain NaN or it should be imputed', mod); 49 | end 50 | end 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /misc/main.m: -------------------------------------------------------------------------------- 1 | function main(res) 2 | % main 3 | % 4 | % # Syntax 5 | % main(res) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | %----- 1. Initialize results 29 | 30 | if ~isfield(res.frwork, 'level') 31 | % Initialize results 32 | res = res_defaults([], 'init', 'frwork.level', 1, 'dir.frwork', res.dir.frwork, ... 33 | 'env.fileend', res.env.fileend, 'env.seed', res.env.seed, ... 34 | 'frwork.nlevel', res.frwork.nlevel, 'env.verbose', res.env.verbose); 35 | else 36 | % Update results 37 | res = res_defaults(res, 'init'); 38 | end 39 | 40 | % Display progress 41 | fprintf('Associative effect %d\n', res.frwork.level); 42 | 43 | %----- 2. Calculate data splits 44 | 45 | % Calculate outer train-test 46 | calc_splits(res, 'out'); 47 | 48 | % Calculate inner train-test (for hyperparameter optimization) 49 | calc_splits(res, 'in'); 50 | 51 | %----- 3. Run models 52 | 53 | % Calculate grid search over hyper-parameters 54 | run_model(res, 'gridsearch'); 55 | 56 | % Run main model 57 | run_model(res, 'main'); 58 | 59 | % Initialize permutations 60 | calc_permid(res, 'perm'); 61 | 62 | % Run permutation tests 63 | run_model(res, 'permutation'); 64 | 65 | %----- 4. Calculate stats and save results 66 | 67 | % Calculate statistical inference 68 | res = stat_inference(res); 69 | 70 | % Save results 71 | res = save_results(res); 72 | 73 | %----- 5. Run analysis on next level 74 | 75 | if res.frwork.level == res.frwork.nlevel 76 | % Terminate analysis 77 | return 78 | 79 | elseif res.stat.nperm == 0 || res.stat.sig 80 | % Run analysis iteratively 81 | res.frwork.level = res.frwork.level + 1; 82 | main(res); 83 | end 84 | -------------------------------------------------------------------------------- /misc/permute_data.m: -------------------------------------------------------------------------------- 1 | function [trdata, tedata] = permute_data(res, trdata, tedata, osplit, iperm) 2 | % permute_data 3 | % 4 | % # Syntax 5 | % [trdata, tedata] = permute_data(res, trdata, tedata, osplit, iperm) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load cfg 29 | cfg = loadmat(res, fullfile(res.dir.frwork, 'cfg.mat'), 'cfg'); 30 | 31 | % Load training and test indexes 32 | [otrid, oteid] = loadmat(res, fullfile(res.dir.frwork, 'outmat.mat'), 'otrid', 'oteid'); 33 | trid = otrid(:,osplit); 34 | teid = oteid(:,osplit); 35 | 36 | % Subjects permutations index 37 | permid = loadmat(res, fullfile(res.dir.frwork, 'perm', sprintf('permmat_%d.mat', ... 38 | res.stat.nperm)), 'permid'); 39 | sid = permid{res.frwork.split.all==osplit}(:,iperm); 40 | 41 | if strfind(cfg.stat.perm, 'train') 42 | % Subject orders within training set 43 | if strcmp(cfg.stat.perm, 'train+test') 44 | [~, trsid] = sort(sid(trid)); 45 | [~, trsid] = sort(trsid); 46 | else 47 | trsid = sid; 48 | end 49 | 50 | % Permute training subjects 51 | switch cfg.machine.name 52 | case {'pls' 'spls'} 53 | trdata.Y = trdata.Y(trsid,:); 54 | 55 | case {'cca' 'rcca'} 56 | trdata.RY = trdata.RY(trsid,:); 57 | end 58 | end 59 | 60 | if strfind(cfg.stat.perm, 'test') 61 | % Subject orders within test set 62 | [~, tesid] = sort(sid(teid)); 63 | [~, tesid] = sort(tesid); 64 | 65 | % Permute test subjects 66 | switch cfg.machine.name 67 | case {'pls' 'spls'} 68 | tedata.Y = tedata.Y(tesid,:); 69 | 70 | case {'cca' 'rcca'} 71 | tedata.RY = tedata.RY(tesid,:); 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /misc/process_metric.m: -------------------------------------------------------------------------------- 1 | function S = process_metric(cfg, S, runtype) 2 | % process_metric 3 | % 4 | % Processes outputs of machines. 5 | % 6 | % # Syntax 7 | % S = process_metric(cfg, S, runtype) 8 | % 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2022 University College London 11 | 12 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 13 | % $Id$ 14 | 15 | % This file is part of CCA/PLS Toolkit. 16 | % 17 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with CCA/PLS Toolkit. If not, see . 29 | 30 | % 11/10/2022 Modified by Agoston Mihalik (am3022@cam.ac.uk) 31 | % Add nsplits to calc_stability input and reshaping output 32 | 33 | % Number of inner/outer splits 34 | if strcmp(runtype, 'gridsearch') 35 | nsplits = cfg.frwork.split.nin; 36 | else 37 | nsplits = cfg.frwork.split.nout; 38 | end 39 | 40 | for i=1:numel(cfg.data.mod) 41 | m = cfg.data.mod{i}; % shorthand variable 42 | 43 | % Calculate similarity of weights 44 | if ismember(['simw' lower(m)], cfg.machine.metric) 45 | type = strsplit(cfg.machine.simw, '-'); % type of similarity measure 46 | [~, sim_all] = calc_stability({S.(['w' m])}, nsplits, type{:}); 47 | if nsplits > 1 48 | sim_all = reshape(sim_all(~eye(nsplits)), nsplits-1, nsplits); % remove diagonal entries 49 | end 50 | sim_all = num2cell(permute(sim_all, [3 2 1]), 3); 51 | [S(:).(['simw' lower(m)])] = deal(sim_all{:}); 52 | end 53 | 54 | % Transpose weights for main models 55 | if strcmp(runtype, 'main') 56 | for j=1:size(S) 57 | S(j).(['w' m]) = S(j).(['w' m])'; 58 | if ismember(['simw' lower(m)], cfg.machine.metric) 59 | S(j).(['simw' lower(m)]) = permute(S(j).(['simw' lower(m)]), [1 3 2]); 60 | end 61 | end 62 | end 63 | end 64 | 65 | % Remove weights from output for memory efficiency 66 | if ~strcmp(runtype, 'main') 67 | S = rmfield(S, {'wX' 'wY'}); 68 | end -------------------------------------------------------------------------------- /misc/qc_data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/misc/qc_data.m -------------------------------------------------------------------------------- /misc/run_machine.m: -------------------------------------------------------------------------------- 1 | function S = run_machine(cfg, trdata, tedata, featid, param) 2 | % run_machine 3 | % 4 | % # Syntax 5 | % S = run_machine(cfg, trdata, tedata, featid, param) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | %----- Model training 29 | 30 | % Run machine 31 | switch cfg.machine.name 32 | case {'pls' 'spls'} 33 | % PLS/SPLS solved by power method 34 | [S.wX, S.wY] = spls(cfg, trdata, param); 35 | 36 | case {'cca' 'rcca'} 37 | % CCA/RCCA/PLS/PCA-CCA solved by standard eigenvalue problem 38 | [S.wX, S.wY] = rcca(trdata, featid, param); 39 | end 40 | 41 | %---- Model diagnostics 42 | 43 | % Compute projections for training data 44 | if ismember(cfg.machine.name, {'pls' 'spls'}) 45 | trdata.PX = calc_proj(trdata.X, S.wX); 46 | trdata.PY = calc_proj(trdata.Y, S.wY); 47 | else 48 | trdata.PY = calc_proj(trdata.RY(:,featid.y), S.wY); 49 | trdata.PX = calc_proj(trdata.RX(:,featid.x), S.wX); 50 | end 51 | 52 | % Compute training metrics 53 | if ismember('trcorrel', cfg.machine.metric) 54 | % Correlation 55 | S.trcorrel = corr(trdata.PX, trdata.PY); 56 | end 57 | if ismember('trcovar', cfg.machine.metric) 58 | % Covariance 59 | S.trcovar = cov2(trdata.PX, trdata.PY); 60 | end 61 | isexvar = contains(cfg.machine.metric, 'trex'); 62 | if any(isexvar) 63 | % Explained variance 64 | if strcmp(cfg.defl.name, 'generalized') 65 | S = calc_exvar(cfg, trdata, [], S, cfg.machine.metric(isexvar), param, featid); 66 | else 67 | S = calc_exvar(cfg, trdata, [], S, cfg.machine.metric(isexvar)); 68 | end 69 | end 70 | cfg.machine.metric(isexvar) = []; 71 | 72 | %---- Model evaluation 73 | 74 | if ismember(cfg.machine.name, {'pls' 'spls'}) 75 | tedata.PX = calc_proj(tedata.X, S.wX); 76 | tedata.PY = calc_proj(tedata.Y, S.wY); 77 | else 78 | tedata.PX = calc_proj(tedata.RX(:,featid.x), S.wX); 79 | tedata.PY = calc_proj(tedata.RY(:,featid.y), S.wY); 80 | end 81 | 82 | % Compute test metrics 83 | if ismember('correl', cfg.machine.metric) 84 | % Correlation 85 | S.correl = corr(tedata.PX, tedata.PY); % , 'Type', 'Spearman' 86 | end 87 | if ismember('covar', cfg.machine.metric) 88 | % Covariance 89 | S.covar = cov2(tedata.PX, tedata.PY); 90 | end 91 | isexvar = contains(cfg.machine.metric, 'ex'); 92 | if any(isexvar) 93 | % Explained variance 94 | if strcmp(cfg.defl.name, 'generalized') 95 | S = calc_exvar(cfg, trdata, tedata, S, cfg.machine.metric(isexvar), param, featid); 96 | else 97 | S = calc_exvar(cfg, trdata, tedata, S, cfg.machine.metric(isexvar)); 98 | end 99 | end 100 | 101 | %---- Auxiliary steps 102 | 103 | % Calculate primal weights 104 | if ismember(cfg.machine.name, {'cca' 'rcca'}) 105 | S.wX = trdata.VX(:,featid.x) * S.wX; 106 | S.wY = trdata.VY(:,featid.y) * S.wY; 107 | end 108 | 109 | % Record unsuccessful convergence for SPLS 110 | if ismember('unsuc', cfg.machine.metric) 111 | S.unsuc = isnan(S.correl); 112 | end -------------------------------------------------------------------------------- /misc/stat_inference.m: -------------------------------------------------------------------------------- 1 | function [res, metric, permdist] = stat_inference(res) 2 | % stat_inference 3 | % 4 | % # Syntax 5 | % [res, metric, permdist] = stat_inference(res) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Quit if no permutations needed 29 | if res.stat.nperm == 0 30 | res.stat.sig = 0; 31 | return 32 | end 33 | 34 | %----- Loading 35 | 36 | % Load cfg 37 | cfg = loadmat(res, fullfile(res.dir.frwork, 'cfg.mat'), 'cfg'); 38 | 39 | % Load permuted metrics 40 | if strcmp(cfg.frwork.name, 'permutation') % first effect for maximum statistics 41 | S_perm = loadmat_struct(res, fullfile(res.dir.frwork, 'perm', 'level1', 'allperm.mat')); 42 | 43 | else % current effect 44 | S_perm = loadmat_struct(res, fullfile(res.dir.perm, 'allperm.mat')); 45 | end 46 | 47 | % Load true metrics 48 | S = loadmat_struct(res, fullfile(res.dir.res, 'model.mat')); 49 | 50 | % Calculate p-value within each data split 51 | res.stat.pval = zeros(res.frwork.split.nall, 1); 52 | for i=1:res.frwork.split.nall 53 | res.stat.pval(i) = calc_pval(S_perm.(cfg.stat.crit)(i,:), ... 54 | S.(cfg.stat.crit)(i), 'max'); 55 | end 56 | metric = S.(cfg.stat.crit); 57 | permdist = S_perm.(cfg.stat.crit); 58 | 59 | % Bonferroni correction across data splits 60 | res.stat.sig = any(res.stat.pval < (cfg.stat.alpha / res.frwork.split.nall)); 61 | 62 | 63 | % --------------------------- Private functions --------------------------- 64 | 65 | function pval = calc_pval(perm_dist, true_val, flag) 66 | 67 | if strcmp(flag, 'max') 68 | pval = (1 + nansum(perm_dist >= true_val)) / (numel(perm_dist) - ... 69 | numel(find(isnan(perm_dist))) + 1); 70 | 71 | elseif strcmp(flag, 'min') 72 | pval = (1 + nansum(perm_dist <= true_val)) / (numel(perm_dist) - ... 73 | numel(find(isnan(perm_dist))) + 1); 74 | end -------------------------------------------------------------------------------- /plot/plot_proj_2d.m: -------------------------------------------------------------------------------- 1 | function plot_proj_2d(res, P, fname) 2 | % plot_proj_2d 3 | % 4 | % # Syntax 5 | % plot_proj_2d(res, P, fname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Create figure 29 | if ~isempty(res.gen.figure.Position) 30 | figure('Position', res.gen.figure.Position); 31 | else 32 | figure; 33 | end 34 | 35 | % Plot data 36 | s = scatter(P(:,1), P(:,2)); 37 | 38 | % Update scatter properties 39 | name_value = parse_struct(res.proj.scatter); 40 | if ~isempty(res.proj.scatter.MarkerFaceColor) && ... 41 | size(res.proj.scatter.MarkerFaceColor, 1) > 1 42 | name_value{find(ismember(name_value(1:2:end), ... 43 | 'MarkerFaceColor'))*2} = res.proj.scatter.MarkerFaceColor(1,:); 44 | end 45 | parse_input(s, name_value{:}); 46 | 47 | % Add least squares line if requested 48 | if strcmp(res.proj.lsline, 'on') && ~isempty(res.proj.scatter.MarkerFaceColor) 49 | h = lsline; 50 | set(h, 'Color', res.proj.scatter.MarkerFaceColor(1,:), 'LineWidth', 1.2); 51 | end 52 | 53 | % Plot labels 54 | xlabel(res.proj.xlabel); 55 | ylabel(res.proj.ylabel); 56 | 57 | % Update axes 58 | name_value = parse_struct(res.gen.axes); 59 | parse_input(gca, name_value{:}); 60 | 61 | % Save figure 62 | saveas(gcf, [fname res.gen.figure.ext]); -------------------------------------------------------------------------------- /plot/plot_proj_2d_cmap.m: -------------------------------------------------------------------------------- 1 | function plot_proj_2d_cmap(res, P, fname, grp, lg) 2 | % plot_proj_2d_cmap 3 | % 4 | % # Syntax 5 | % plot_proj_2d_cmap(res, P, fname, grp, lg) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Create figure 29 | if ~isempty(res.gen.figure.Position) 30 | figure('Position', res.gen.figure.Position); 31 | else 32 | figure; 33 | end 34 | 35 | % Add colormap 36 | set_path('cbrewer'); 37 | if exist('cbrewer', 'file') 38 | cmap = cbrewer('seq', 'Purples', 64); 39 | colormap(cmap); 40 | end 41 | 42 | % Plot data 43 | s = scatter(P(:,1), P(:,2), [], grp, 'filled'); 44 | 45 | % Update scatter properties 46 | name_value = parse_struct(res.proj.scatter); 47 | parse_input(s, name_value{:}); 48 | 49 | % Add colorbar 50 | pos = get(gca, 'Position'); 51 | c = colorbar; 52 | ylabel(c, lg); 53 | set(gca, 'Position', pos); % reposition axes as it has been misplaced by colorbar 54 | 55 | % Plot labels 56 | xlabel(res.proj.xlabel); 57 | ylabel(res.proj.ylabel); 58 | 59 | % Update axes 60 | name_value = parse_struct(res.gen.axes); 61 | parse_input(gca, name_value{:}); 62 | 63 | % Save figure 64 | saveas(gcf, [fname res.gen.figure.ext]); -------------------------------------------------------------------------------- /plot/plot_proj_2d_group.m: -------------------------------------------------------------------------------- 1 | function plot_proj_2d_group(res, P, fname, grp, lg) 2 | % plot_proj_2d_group 3 | % 4 | % # Syntax 5 | % plot_proj_2d_group(res, P, fname, grp, lg) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Input checks 29 | ug = unique(grp); 30 | if numel(ug) ~= numel(lg) 31 | error('Number of groups should match the number of legends.') 32 | end 33 | % if numel(ug) > size(res.proj.scatter.MarkerFaceColor, 1) 34 | % error('Number of groups should match the number of colours.') 35 | % end 36 | 37 | % Create figure 38 | if ~isempty(res.gen.figure.Position) 39 | figure('Position', res.gen.figure.Position); 40 | else 41 | figure; 42 | end 43 | hold on; 44 | 45 | % Plot data 46 | for i=1:numel(ug) 47 | % Get subset of data 48 | p = P(grp==ug(i),:); 49 | 50 | % Plot data 51 | s = scatter(p(:,1), p(:,2)); 52 | 53 | % Update scatter properties 54 | name_value = parse_struct(res.proj.scatter); 55 | if ~isempty(res.proj.scatter.MarkerFaceColor) && ... 56 | size(res.proj.scatter.MarkerFaceColor, 1) > 1 57 | name_value{find(ismember(name_value(1:2:end), ... 58 | 'MarkerFaceColor'))*2} = res.proj.scatter.MarkerFaceColor(i,:); 59 | end 60 | parse_input(s, name_value{:}); 61 | 62 | % Display message based on verbosity level 63 | switch res.env.verbose 64 | case 1 65 | fprintf('Correlation between latent variables for group %d: %.4f\n', ... 66 | i, corr(p(:,1), p(:,2))); 67 | otherwise 68 | % display nothing at the moment 69 | end 70 | end 71 | 72 | % Add least squares line if requested 73 | if strcmp(res.proj.lsline, 'on') && ~isempty(res.proj.scatter.MarkerFaceColor) 74 | h = lsline; 75 | for i=1:numel(h) 76 | set(h(numel(h)+1-i), 'Color', res.proj.scatter.MarkerFaceColor(i,:), ... 77 | 'LineWidth', 1.2); % lsline plots objects in reverse order! 78 | end 79 | end 80 | hold off; 81 | 82 | % Plot labels 83 | xlabel(res.proj.xlabel); 84 | ylabel(res.proj.ylabel); 85 | 86 | % Update legend and axes properties 87 | name_value = parse_struct(res.gen.legend); 88 | if ~isempty(lg{1}) 89 | legend(lg, name_value{:}); 90 | end 91 | name_value = parse_struct(res.gen.axes); 92 | parse_input(gca, name_value{:}); 93 | 94 | % Save figure 95 | saveas(gcf, [fname res.gen.figure.ext]); -------------------------------------------------------------------------------- /plot/plot_weight_behav_horz.m: -------------------------------------------------------------------------------- 1 | function plot_weight_behav_horz(res, weight, iweight, wfname) 2 | % plot_weight_behav_horz 3 | % 4 | % # Syntax 5 | % plot_weight_behav_horz(res, weight, iweight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load label file 29 | labelfname = select_file(res, fullfile(res.dir.project, 'data'), ... 30 | 'Select delimited label file for behaviour...', 'any', res.behav.file.label); 31 | T = readtable(labelfname); 32 | if ~ismember('Label', T.Properties.VariableNames) % check if necessary fields available 33 | error('The behavioural label file should contain the following columns: Label'); 34 | end 35 | iscategory = ismember('Category', T.Properties.VariableNames); 36 | if ~iscategory 37 | T.Category = sprintfc('%d', ones(size(T, 1), 1)); 38 | end 39 | 40 | % Open figure 41 | if ~isempty(res.gen.figure.Position) 42 | figure('Position', res.gen.figure.Position); 43 | else 44 | figure; 45 | end 46 | 47 | % Set colors for the categories 48 | categ = unique(T.Category); 49 | cmap = colormap('jet'); 50 | if size(cmap, 1) < numel(categ) 51 | error('Too many groups, not enough colors to plot them.') 52 | end 53 | cmap = cmap(round(linspace(1,size(cmap, 1),numel(categ))),:); 54 | 55 | % Normalize weight 56 | if strcmp(res.behav.weight.norm, 'minmax') 57 | minmax = max(abs(weight)); 58 | weight = weight / minmax; 59 | elseif strcmp(res.behav.weight.norm, 'std') 60 | weight = weight / std(weight); 61 | elseif strcmp(res.behav.weight.norm, 'zscore') 62 | weight = zscore(weight); 63 | end 64 | 65 | % Create weight table 66 | T.Weight = weight; 67 | T = T(iweight,:); % reorder table based on the order of the weight 68 | if ~isinf(res.behav.weight.numtop) || res.behav.weight.filtzero 69 | T(T.Weight==0,:) = []; % remove 0 weights 70 | end 71 | 72 | % Subselect category colours 73 | [C, ia, ib] = intersect(categ, unique(T.Category)); 74 | cmap = cmap(ia,:); 75 | categ = unique(T.Category); 76 | 77 | % Plot weights 78 | hold on; 79 | for i=1:numel(categ) 80 | dummy = T.Weight; 81 | dummy(~ismember(T.Category, categ{i})) = 0; 82 | barh(dummy, 'FaceColor', cmap(i,:)); 83 | end 84 | hold off; 85 | 86 | % User friendly display for long label names 87 | if ~isinf(res.behav.label.maxchar) 88 | for i=1:size(T, 1) 89 | if numel(T.Label{i}) > res.behav.label.maxchar 90 | T.Label{i} = T.Label{i}(1:res.behav.label.maxchar); 91 | end 92 | end 93 | end 94 | 95 | % Plot labels 96 | ylabel(res.behav.ylabel); 97 | xlabel(res.behav.xlabel); 98 | 99 | % Update legend and axes 100 | if iscategory 101 | name_value = parse_struct(res.gen.legend); 102 | legend(categ, name_value{:}); 103 | end 104 | name_value = parse_struct(res.gen.axes); 105 | set(gca, 'yTick', 1:numel(T.Label), 'yTickLabel', T.Label, name_value{:}); 106 | 107 | % Save figure 108 | saveas(gcf, [wfname res.gen.figure.ext]); 109 | 110 | % Save weights to csv 111 | if iscategory 112 | writetable(T(:,{'Category' 'Label' 'Weight'}), [wfname '.csv'], ... 113 | 'QuoteStrings', true); 114 | else 115 | writetable(T(:,{'Label' 'Weight'}), [wfname '.csv'], 'QuoteStrings', true); 116 | end -------------------------------------------------------------------------------- /plot/plot_weight_behav_vert.m: -------------------------------------------------------------------------------- 1 | function plot_weight_behav_vert(res, weight, iweight, wfname) 2 | % plot_weight_behav_vert 3 | % 4 | % # Syntax 5 | % plot_weight_behav_vert(res, weight, iweight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load label file 29 | labelfname = select_file(res, fullfile(res.dir.project, 'data'), ... 30 | 'Select delimited label file for behaviour...', 'any', res.behav.file.label); 31 | T = readtable(labelfname); 32 | if ~ismember('Label', T.Properties.VariableNames) % check if necessary fields available 33 | error('The behavioural label file should contain the following columns: Label'); 34 | end 35 | iscategory = ismember('Category', T.Properties.VariableNames); 36 | if ~iscategory 37 | T.Category = sprintfc('%d', ones(size(T, 1), 1)); 38 | end 39 | 40 | % Open figure 41 | if ~isempty(res.gen.figure.Position) 42 | figure('Position', res.gen.figure.Position); 43 | else 44 | figure; 45 | end 46 | 47 | % Set colors for the categories 48 | categ = unique(T.Category); 49 | cmap = colormap('jet'); 50 | if size(cmap, 1) < numel(categ) 51 | error('Too many groups, not enough colors to plot them.') 52 | end 53 | cmap = cmap(round(linspace(1,size(cmap, 1),numel(categ))),:); 54 | 55 | % Normalize weight 56 | if strcmp(res.behav.weight.norm, 'minmax') 57 | minmax = max(abs(weight)); 58 | weight = weight / minmax; 59 | elseif strcmp(res.behav.weight.norm, 'std') 60 | weight = weight / std(weight); 61 | elseif strcmp(res.behav.weight.norm, 'zscore') 62 | weight = zscore(weight); 63 | end 64 | 65 | % Create weight table 66 | T.Weight = weight; 67 | T = T(iweight,:); % reorder table based on the order of the weight 68 | if ~isinf(res.behav.weight.numtop) || res.behav.weight.filtzero 69 | T(T.Weight==0,:) = []; % remove 0 weights 70 | end 71 | 72 | % Subselect category colours 73 | [C, ia, ib] = intersect(categ, unique(T.Category)); 74 | cmap = cmap(ia,:); 75 | categ = unique(T.Category); 76 | 77 | % Plot weights 78 | hold on; 79 | for i=1:numel(categ) 80 | dummy = T.Weight; 81 | dummy(~ismember(T.Category, categ{i})) = 0; 82 | bar(dummy, 'FaceColor', cmap(i,:)); 83 | end 84 | hold off; 85 | 86 | % Plot labels 87 | ylabel(res.behav.ylabel); 88 | xlabel(res.behav.xlabel); 89 | 90 | % Update legend and axes 91 | if numel(categ) > 1 92 | name_value = parse_struct(res.gen.legend); 93 | legend(categ, name_value{:}); 94 | end 95 | name_value = parse_struct(res.gen.axes); 96 | set(gca, name_value{:}); 97 | 98 | % Save figure 99 | saveas(gcf, [wfname res.gen.figure.ext]); 100 | 101 | % Save weights to csv 102 | if iscategory 103 | writetable(T(:,{'Category' 'Label' 'Weight'}), [wfname '.csv'], ... 104 | 'QuoteStrings', true); 105 | else 106 | writetable(T(:,{'Label' 'Weight'}), [wfname '.csv'], 'QuoteStrings', true); 107 | end -------------------------------------------------------------------------------- /plot/plot_weight_brain_conn_node.m: -------------------------------------------------------------------------------- 1 | function plot_weight_brain_conn_node(res, weight, wfname) 2 | % plot_weight_brain_conn_node 3 | % 4 | % # Syntax 5 | % plot_weight_brain_conn_node(res, weight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load label file 29 | labelfname = select_file(res, fullfile(res.dir.project, 'data'), ... 30 | 'Select delimited label file for regions...', 'any', res.conn.file.label); 31 | T = readtable(labelfname); 32 | 33 | % Check if necessary fields available 34 | if ~all(ismember({'X' 'Y' 'Z' 'Label'}, T.Properties.VariableNames)) 35 | error('The connectivity label file should contain the following columns: X, Y, Z, Label'); 36 | end 37 | if ~ismember('Color', T.Properties.VariableNames) 38 | T.Color = ones(size(T, 1), 1); 39 | end 40 | 41 | % Load mask 42 | maskfname = select_file(res, fullfile(res.dir.project, 'data'), ... 43 | 'Select mask file...', 'mat', res.conn.file.mask); 44 | load(maskfname); 45 | if sum(mask(:)) ~= numel(weight) 46 | error('Mask does not match the dimensionality of weight'); 47 | end 48 | 49 | % Display message based on verbosity level 50 | switch res.env.verbose 51 | case 1 52 | fprintf('Max weight: %.4f\n', max(abs(weight(:)))); 53 | otherwise 54 | % display nothing at the moment 55 | end 56 | 57 | % Create connectivity matrix 58 | conn_weight = zeros(size(mask)); 59 | conn_weight(mask==1) = weight; % fill up using linear indexing 60 | conn_weight = conn_weight + conn_weight'; % symmetric connectivity matrix is needed for downstream calculations 61 | nparcel = length(conn_weight); 62 | if numel(T.Label) ~= nparcel 63 | error('Number of parcels does not match the dimensionality of the weight vector'); 64 | end 65 | 66 | % Weights summarized by ROI node 67 | T.Size = sum(abs(conn_weight), 2) ./ sum(conn_weight ~= 0, 2); % needed due to 0s after using top connectinons 68 | T.Size(isnan(T.Size)) = 0; 69 | 70 | % Save results to text file 71 | T = T(T.Size~=0,:); 72 | [B, I] = sort(abs(T.Size), 'descend'); % sort nodes for easier readibility 73 | T = T(I,:); 74 | writetable(table(T.Label, T.Size, 'VariableNames', {'Node' 'Weight'}), [wfname '.csv']); 75 | 76 | % Prepare BrainNet files (from scratch to avoid bad files) 77 | fname = init_brainnet(res, 'labelfname', labelfname, 'T', T); 78 | 79 | % Plot brainnet 80 | if exist(fname.options, 'file') 81 | BrainNet_MapCfg(fname.surf, fname.node, [wfname res.gen.figure.ext], fname.options); 82 | else 83 | BrainNet_MapCfg(fname.surf, fname.node, [wfname res.gen.figure.ext]); 84 | end -------------------------------------------------------------------------------- /plot/plot_weight_brain_cortex.m: -------------------------------------------------------------------------------- 1 | function plot_weight_brain_cortex(res, weight, wfname) 2 | % plot_weight_brain_cortex 3 | % 4 | % # Syntax 5 | % plot_weight_brain_cortex(res, weight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load mask 29 | maskfname = select_file(res, fullfile(res.dir.project, 'data'), 'Select mask file...', 'nii', res.vbm.file.mask); 30 | hdr_mask = spm_vol(maskfname); 31 | img_mask = spm_read_vols(hdr_mask); 32 | img_mask(isnan(img_mask)) = 0; 33 | 34 | % Create image from weight 35 | img = zeros(hdr_mask.dim); 36 | img(img_mask~=0) = weight; 37 | 38 | % Normalize weight 39 | if strcmp(res.vbm.weight.norm, 'minmax') 40 | minmax = max(abs(weight)); 41 | img = img / minmax; 42 | elseif strcmp(res.vbm.weight.norm, 'std') 43 | img = img / std(weight); 44 | end 45 | 46 | % Write weight on disc 47 | hdr = struct('dim', hdr_mask.dim, 'dt', [spm_type('float32') spm_platform('bigend')], ... 48 | 'mat', hdr_mask.mat, 'pinfo', [1 0 0]', 'n', [1 1], 'descrip', 'Image'); % header settings are important!! 49 | hdr.fname = [wfname '.nii']; 50 | spm_write_vol(hdr, img); 51 | 52 | % Normalize if weight is not in MNI space 53 | if ~isequal(res.vbm.transM, eye(4)) 54 | [pathstr, name, ext] = fileparts(wfname); 55 | normalize2MNI(res, res.vbm.file.MNI, [name '.nii'], res.vbm.transM) 56 | wfname = fullfile(pathstr, ['wr' name]); % rename file 57 | end 58 | 59 | % Plot with BrainNet 60 | fname = init_brainnet(res); 61 | if exist(fname.options, 'file') 62 | BrainNet_MapCfg(fname.surf, [wfname '.nii'], [wfname res.gen.figure.ext], fname.options); 63 | else 64 | BrainNet_MapCfg(fname.surf, [wfname '.nii'], [wfname res.gen.figure.ext]); 65 | end -------------------------------------------------------------------------------- /plot/plot_weight_brain_edge.m: -------------------------------------------------------------------------------- 1 | function plot_weight_brain_edge(res, weight, wfname) 2 | % plot_weight_brain_edge 3 | % 4 | % # Syntax 5 | % plot_weight_brain_edge(res, weight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load label file 29 | labelfname = select_file(res, fullfile(res.dir.project, 'data'), ... 30 | 'Select delimited label file for regions...', 'any', res.conn.file.label); 31 | T = readtable(labelfname); 32 | 33 | % Check if necessary fields available 34 | if ~all(ismember({'Index' 'X' 'Y' 'Z' 'Label'}, T.Properties.VariableNames)) 35 | error('The connectivity label file should contain the following columns: Index, X, Y, Z, Label'); 36 | end 37 | if ~ismember('Color', T.Properties.VariableNames) 38 | T.Color = ones(size(T, 1), 1); 39 | end 40 | if ~ismember('Size', T.Properties.VariableNames) 41 | T.Size = ones(size(T, 1), 1); 42 | end 43 | 44 | % Load mask 45 | maskfname = select_file(res, fullfile(res.dir.project, 'data'), ... 46 | 'Select mask file...', 'mat', res.conn.file.mask); 47 | load(maskfname); 48 | if sum(mask(:)) ~= numel(weight) 49 | error('Mask does not match the dimensionality of weight'); 50 | end 51 | 52 | % Display message based on verbosity level 53 | switch res.env.verbose 54 | case 1 55 | fprintf('Max weight: %.4f\n', max(abs(weight(:)))); 56 | otherwise 57 | % display nothing at the moment 58 | end 59 | 60 | % Create connectivity matrix 61 | conn_weight = zeros(size(mask)); 62 | conn_weight(mask==1) = weight; % fill up using linear indexing 63 | nparcel = length(conn_weight); 64 | if numel(T.Label) ~= nparcel 65 | error('Number of parcels does not match the dimensionality of the weight vector'); 66 | end 67 | 68 | % Save results to text file 69 | [nodeA, nodeB, idnodeA, idnodeB] = deal({}); % regionA, regionB, idA, idB, descA, descB, 70 | w = []; 71 | for i=1:nparcel 72 | for j=1:nparcel 73 | if conn_weight(i,j) ~= 0 74 | nodeA(end+1,1) = T.Label(i); 75 | idnodeA{end+1,1} = T.Index(i); 76 | nodeB(end+1,1) = T.Label(j); 77 | idnodeB{end+1,1} = T.Index(j); 78 | w(end+1,1) = conn_weight(i,j); 79 | end 80 | end 81 | end 82 | 83 | Tout = table(nodeA, idnodeA, nodeB, idnodeB, w); % regionA, idA, regionB, idB, descA, descB 84 | [B, I] = sort(Tout.w, 'descend'); 85 | Tout = Tout(I,:); 86 | writetable(Tout, [wfname '.csv']); 87 | 88 | % Prepare BrainNet files (from scratch to avoid bad files) 89 | % conn_weight = conn_weight / max(abs(conn_weight(:))); % rescale weight for better visualization 90 | conn_weight = conn_weight + conn_weight'; % make matrix symmetric for BrainNet viewer 91 | fname = init_brainnet(res, 'labelfname', labelfname, 'T', T, 'wfname', wfname, 'weight', conn_weight); 92 | 93 | % Plot brainnet 94 | if exist(fname.options, 'file') 95 | BrainNet_MapCfg(fname.surf, fname.node, fname.edge, [wfname res.gen.figure.ext], fname.options); 96 | else 97 | BrainNet_MapCfg(fname.surf, fname.node, fname.edge, [wfname res.gen.figure.ext]); 98 | end -------------------------------------------------------------------------------- /plot/plot_weight_brain_node.m: -------------------------------------------------------------------------------- 1 | function plot_weight_brain_node(res, weight, wfname) 2 | % plot_weight_brain_node 3 | % 4 | % # Syntax 5 | % plot_weight_brain_node(res, weight, wfname) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load label file 29 | labelfname = select_file(res, fullfile(res.dir.project, 'data'), ... 30 | 'Select delimited label file for regions...', 'any', res.roi.file.label); 31 | T = readtable(labelfname); 32 | 33 | % Check if necessary fields available 34 | if ~all(ismember({'X' 'Y' 'Z' 'Label'}, T.Properties.VariableNames)) 35 | error(sprintf(['The ROI label file should contain the following columns: X, Y, Z, Label', ... 36 | '\n\nConsider BrainNet_GenCoord to generate X, Y, Z coordinates from volumetric atlas file'])); 37 | end 38 | if ~ismember('Color', T.Properties.VariableNames) 39 | T.Color = ones(size(T, 1), 1); 40 | end 41 | 42 | % Weights 43 | T.Size = weight; 44 | 45 | % Remove regions we don't want to visualize 46 | if ~isempty(res.roi.out) 47 | T(ismember(T.Index, res.roi.out),:) = []; 48 | end 49 | 50 | % Save results to text file 51 | T = T(T.Size~=0,:); 52 | [B, I] = sort(abs(T.Size), 'descend'); % sort nodes for easier readibility 53 | T = T(I,:); 54 | writetable(table(T.Label, T.Size, T.Color, 'VariableNames', {'Node' 'Weight' 'Color'}), [wfname '.csv']); 55 | 56 | % Prepare BrainNet files (from scratch to avoid bad files) 57 | T.Size = abs(T.Size / max(abs(T.Size)) * 2 * pi); % rescale to improve visualization 58 | fname = init_brainnet(res, 'labelfname', labelfname, 'T', T); 59 | 60 | % Plot brainnet 61 | if exist(fname.options, 'file') 62 | BrainNet_MapCfg(fname.surf, fname.node, [wfname res.gen.figure.ext], fname.options); 63 | else 64 | BrainNet_MapCfg(fname.surf, fname.node, [wfname res.gen.figure.ext]); 65 | end -------------------------------------------------------------------------------- /plot/plot_weight_stem.m: -------------------------------------------------------------------------------- 1 | function plot_weight_stem(res, weight, iweight, wfname, mod) 2 | % plot_weight_stem 3 | % 4 | % # Syntax 5 | % plot_weight_stem(res, weight, iweight, wfname, mod) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Open figure 29 | if ~isempty(res.gen.figure.Position) 30 | figure('Position', res.gen.figure.Position); 31 | else 32 | figure; 33 | end 34 | 35 | idout = false(numel(weight), 1); 36 | 37 | % Load true weight if exists 38 | if exist(res.simul.weight.file.(mod), 'file') 39 | % Load true weight 40 | data = load(res.simul.weight.file.(mod)); 41 | field = fieldnames(data); 42 | weight_true = reshape(data.(field{1}), [], 1); 43 | 44 | % Sort weight 45 | [weight_true, iweight] = sort(weight_true, 'descend'); 46 | 47 | if numel(weight_true) > 100 48 | idout = randperm(numel(weight_true))' < numel(weight_true)-99; 49 | weight_true(idout) = []; 50 | end 51 | end 52 | 53 | % Update weight 54 | weight = weight(iweight); 55 | if ~isinf(res.simul.weight.numtop) || res.simul.weight.filtzero 56 | idout = weight==0; 57 | end 58 | weight(idout) = []; 59 | 60 | % Normalize weight 61 | if strcmp(res.simul.weight.norm, 'minmax') 62 | minmax = max(abs(weight)); 63 | weight = weight / minmax; 64 | elseif strcmp(res.simul.weight.norm, 'std') 65 | weight = weight / std(weight); 66 | end 67 | 68 | % Plot weight 69 | stem(find(~idout), weight); 70 | lg = {'weight'}; 71 | 72 | % Plot labels 73 | xlabel(res.simul.xlabel); 74 | ylabel(res.simul.ylabel); 75 | 76 | if exist(res.simul.weight.file.(mod), 'file') 77 | % Normalize true weight to match scale 78 | % weight_true = weight_true / norm(weight_true) * norm(weight); 79 | % Normalize weight 80 | if strcmp(res.simul.weight.norm, 'minmax') 81 | minmax = max(abs(weight_true)); 82 | weight_true = weight_true / minmax; 83 | elseif strcmp(res.simul.weight.norm, 'std') 84 | weight_true = weight_true / std(weight_true); 85 | end 86 | 87 | % Plot true weight 88 | hold on; 89 | stem(find(~idout), weight_true); 90 | lg = [lg {'true weight'}]; 91 | end 92 | 93 | % Update legend and axes 94 | name_value = parse_struct(res.gen.legend); 95 | legend(lg, name_value{:}); 96 | name_value = parse_struct(res.gen.axes); 97 | parse_input(gca, name_value{:}); 98 | 99 | saveas(gcf, [wfname res.gen.figure.ext]); -------------------------------------------------------------------------------- /set_path.m: -------------------------------------------------------------------------------- 1 | function dir_toolkit = set_path(varargin) 2 | % set_path 3 | % 4 | % Adds essential folders to the path to initialize the toolkit for an 5 | % analysis. For visualization, it needs to be called with specific folders 6 | % to add plotting and other toolbox folders to the path. 7 | % 8 | % # Syntax 9 | % dir_toolkit = set_path(varargin) 10 | % 11 | % # Inputs 12 | % varargin:: char 13 | % folders passed as arguments will be added to the path 14 | % 15 | % `set_path` looks for folders under the toolkit folder and under the 16 | % `external` folder. In the latter case it is sufficient to use the 17 | % first few characters of the toolbox, e.g., `spm` instead of `spm12`. 18 | % 19 | % # Outputs 20 | % dir_toolkit:: char 21 | % full path to the toolkit folder 22 | % 23 | % # Examples 24 | % % Example 1 25 | % set_path; 26 | % 27 | % % Example 2 28 | % set_path('plot'); 29 | % 30 | % % Example 3 31 | % set_path('plot', 'spm', 'brainnet'); 32 | % 33 | % --- 34 | % 35 | %_______________________________________________________________________ 36 | % Copyright (C) 2022 University College London 37 | 38 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 39 | % $Id$ 40 | 41 | % This file is part of CCA/PLS Toolkit. 42 | % 43 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 44 | % it under the terms of the GNU General Public License as published by 45 | % the Free Software Foundation, either version 3 of the License, or 46 | % (at your option) any later version. 47 | % 48 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 49 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 50 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 51 | % GNU General Public License for more details. 52 | % 53 | % You should have received a copy of the GNU General Public License 54 | % along with CCA/PLS Toolkit. If not, see . 55 | 56 | dir_toolkit = fileparts(mfilename('fullpath')); 57 | addpath(dir_toolkit); 58 | 59 | % Add primary paths - essential for the basic functionality of the toolkit 60 | addpath(fullfile(dir_toolkit, 'fileio')); 61 | addpath(fullfile(dir_toolkit, 'misc')); 62 | addpath(fullfile(dir_toolkit, 'machines')); 63 | addpath(fullfile(dir_toolkit, 'util')); 64 | addpath(fullfile(dir_toolkit, 'demo')); 65 | 66 | % Add secondary paths - needed for particular behaviours (e.g. plotting certain figures) 67 | external = getfname(fullfile(dir_toolkit, 'external'), '.*'); % all available external folders 68 | for i=1:numel(varargin) 69 | idfolder = find(cellfun(@(x) ~isempty(regexpi(x, varargin{i})), external), 1, 'last'); % take the last if multiple result! 70 | if ~isempty(idfolder) 71 | addpath(genpath(fullfile(dir_toolkit, 'external', external{idfolder})), '-end'); 72 | else 73 | if ~ismember(varargin{i}, getfname(dir_toolkit, '.*')) 74 | warning('%s not found in the external folder.', varargin{i}) 75 | else 76 | addpath(fullfile(dir_toolkit, varargin{i}), '-end') 77 | end 78 | end 79 | end 80 | 81 | % Check SPM and BrainNet interference 82 | allpath = strsplit(path, ':'); 83 | idbrainnet = find(cellfun(@(x) ~isempty(regexpi(x, 'BrainNet')), allpath)); 84 | idpalm = find(cellfun(@(x) ~isempty(regexpi(x, 'PALM')), allpath)); 85 | if exist('spm', 'file') 86 | idspm = find(cellfun(@(x) ~isempty(regexpi(x, spm('Ver'))), allpath)); 87 | if ~isempty(idbrainnet) 88 | if max(idspm) > min(idbrainnet) % SPM should be higher in MATLAB search path than BrainNet 89 | rmpath(strjoin(allpath(idbrainnet), ':')); 90 | addpath(strjoin(allpath(idbrainnet), ':'), '-end'); 91 | 92 | end 93 | end 94 | if ~isempty(idpalm) 95 | if max(idspm) > min(idpalm) % SPM should be higher in MATLAB search path than BrainNet 96 | rmpath(strjoin(allpath(idpalm), ':')); 97 | addpath(strjoin(allpath(idpalm), ':'), '-end'); 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /test/data/X.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/data/X.mat -------------------------------------------------------------------------------- /test/data/Y.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/data/Y.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/cfg_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/cfg_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/grid/level1/allgrid_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/grid/level1/allgrid_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/grid/level2/allgrid_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/grid/level2/allgrid_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/inmat_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/inmat_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_1_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_1_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_2_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_2_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_3_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_3_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_4_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_4_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_5_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocx_split_1_subsample_5_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_1_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_1_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_2_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_2_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_3_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_3_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_4_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_4_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_5_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/load/preproc/preprocy_split_1_subsample_5_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/outmat_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/outmat_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/level1/allperm_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/level1/allperm_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/level2/allperm_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/level2/allperm_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/permmat_100_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/perm/permmat_100_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/model_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/model_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/param_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/param_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/res_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/res_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level1/results_table.txt: -------------------------------------------------------------------------------- 1 | split correl pval nfeatx nfeaty 2 | 1 0.9101 0.0099 5 15 3 | -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/model_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/model_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/param_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/param_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/res_1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anaston/cca_pls_toolkit/6e1ef1e04c58984b1e9e8aa22dd5aabe490fb4de/test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/res_1.mat -------------------------------------------------------------------------------- /test/framework/spls_holdout1-0.20_subsamp5-0.20_REF/res/level2/results_table.txt: -------------------------------------------------------------------------------- 1 | split correl pval nfeatx nfeaty 2 | 1 0.4750 0.1584 1 80 3 | -------------------------------------------------------------------------------- /test/get_data.m: -------------------------------------------------------------------------------- 1 | function [Xtr, Ytr, Xte, Yte] = get_data(fullrank) 2 | % get_data 3 | % 4 | % # Syntax 5 | % [Xtr, Ytr, Xte, Yte] = get_data(fullrank) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Load data 29 | load(fullfile('test', 'data', 'X.mat')); 30 | load(fullfile('test', 'data', 'Y.mat')); 31 | 32 | % Split data to training and test 33 | Xtr = X(1:40,:); 34 | Xte = X(41:50,:); 35 | Ytr = Y(1:40,:); 36 | Yte = Y(41:50,:); 37 | 38 | % Mean center data 39 | [Xtr, mnx] = mean_center_features(Xtr); 40 | Xte = mean_center_features(Xte, mnx); 41 | [Ytr, mny] = mean_center_features(Ytr); 42 | Yte = mean_center_features(Yte, mny); 43 | 44 | % Normalize data 45 | [Xtr, scx] = norm_features(Xtr, [], 'std'); 46 | Xte = norm_features(Xte, scx, 'std'); 47 | [Ytr, scx] = norm_features(Ytr, [], 'std'); 48 | Yte = norm_features(Yte, scx, 'std'); 49 | 50 | % Reduce to full rank if requested 51 | if fullrank 52 | Xtr = Xtr(:,1:10); 53 | Xte = Xte(:,1:10); 54 | Ytr = Ytr(:,1:10); 55 | Yte = Yte(:,1:10); 56 | end -------------------------------------------------------------------------------- /test/test_pipeline.m: -------------------------------------------------------------------------------- 1 | function test_pipeline 2 | % test_pipeline 3 | % 4 | % # Syntax 5 | % test_pipeline 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Set path for analysis 29 | set_path; 30 | 31 | % Project folder 32 | cfg.dir.project = 'test'; 33 | 34 | % Machine settings 35 | cfg.machine.name = 'spls'; 36 | cfg.machine.metric = {'correl'}; 37 | cfg.machine.param.nL1x = 5; 38 | cfg.machine.param.nL1y = 5; 39 | 40 | % Framework settings 41 | cfg.frwork.name = 'holdout'; 42 | cfg.frwork.split.nout = 1; 43 | cfg.frwork.flag = ''; 44 | 45 | % Deflation settings 46 | cfg.defl.name = 'pls-modeA'; 47 | 48 | % Environment settings 49 | cfg.env.comp = 'local'; 50 | 51 | % % Number of permutations 52 | cfg.stat.nperm = 100; 53 | 54 | % Update cfg with defaults 55 | cfg = cfg_defaults(cfg); 56 | 57 | % Run analysis 58 | main(cfg); 59 | 60 | % Clean up analysis files to save disc space 61 | cleanup_files(cfg); 62 | 63 | % Compare results with reference 64 | tol = 1e-10; 65 | check = false(3, 2); 66 | for i=1:2 67 | % Grid search 68 | S_ref = load(fullfile(cfg.dir.frwork, 'grid', ['level' num2str(i)], 'allgrid_1.mat')); 69 | S = load(fullfile('test', 'framework', 'spls_holdout1-0.20_subsamp5-0.20_REF', ... 70 | 'grid', ['level' num2str(i)], 'allgrid_1.mat')); 71 | if norm(S_ref.correl - S.correl) < tol 72 | check(1,i) = true; 73 | end 74 | 75 | % Permutations 76 | S_ref = load(fullfile(cfg.dir.frwork, 'perm', ['level' num2str(i)], 'allperm_1.mat')); 77 | S = load(fullfile('test', 'framework', 'spls_holdout1-0.20_subsamp5-0.20_REF', ... 78 | 'perm', ['level' num2str(i)], 'allperm_1.mat')); 79 | if norm(S_ref.correl - S.correl) < tol 80 | check(2,i) = true; 81 | end 82 | 83 | % Main results 84 | S_ref = load(fullfile(cfg.dir.frwork, 'res', ['level' num2str(i)], 'model_1.mat')); 85 | S = load(fullfile('test', 'framework', 'spls_holdout1-0.20_subsamp5-0.20_REF', ... 86 | 'res', ['level' num2str(i)], 'model_1.mat')); 87 | if norm(S_ref.correl - S.correl) < tol && ... 88 | norm(S_ref.wX - S.wX) < tol && norm(S_ref.wY - S.wY) < tol 89 | check(3,i) = true; 90 | end 91 | end 92 | if all(check(:)) 93 | fprintf('\nBasic analysis pipeline ok\n'); 94 | else 95 | fprintf('\nPotential bug in basic analysis pipeline!\n') 96 | end -------------------------------------------------------------------------------- /util/assign_defaults.m: -------------------------------------------------------------------------------- 1 | function S = assign_defaults(S, default) 2 | % assign_defaults 3 | % 4 | % It goes through all fields and subfields of S iteratively and sets them 5 | % if not existing. 6 | % 7 | % Syntax: 8 | % S = assign_defaults(S, default) 9 | % 10 | %_______________________________________________________________________ 11 | % Copyright (C) 2022 University College London 12 | 13 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 14 | % $Id$ 15 | 16 | % This file is part of CCA/PLS Toolkit. 17 | % 18 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with CCA/PLS Toolkit. If not, see . 30 | 31 | dfields = fieldnames(default); 32 | 33 | for i=1:numel(dfields) 34 | % Assign field from default if it does not exist in cfg 35 | if ~isfield(S, dfields{i}) 36 | S.(dfields{i}) = default.(dfields{i}); 37 | 38 | % Loop through subfields iteratively 39 | elseif isstruct(default.(dfields{i})) 40 | S.(dfields{i}) = assign_defaults(S.(dfields{i}), default.(dfields{i})); 41 | end 42 | end -------------------------------------------------------------------------------- /util/calc_distance.m: -------------------------------------------------------------------------------- 1 | function d = calc_distance(varargin) 2 | % calc_distance 3 | % 4 | % Syntax: 5 | % d = calc_distance(varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | d = NaN(size(varargin{1})); 29 | for i=1:numel(varargin{1}) 30 | d(i) = pdist([cellfun(@(x) x(i), varargin); ones(1, numel(varargin))]); 31 | end 32 | 33 | -------------------------------------------------------------------------------- /util/calc_exvar.m: -------------------------------------------------------------------------------- 1 | function S = calc_exvar(cfg, trdata, tedata, S, metric, varargin) 2 | % calc_exvar 3 | % 4 | % Syntax: 5 | % S = calc_exvar(cfg, trdata, tedata, S, metric, varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | if isempty(tedata) 29 | data = trdata; 30 | else 31 | data = tedata; 32 | end 33 | 34 | for i=1:numel(metric) 35 | if any(isnan(S.wX)) || any(isnan(S.wY)) 36 | S.(metric{i}) = NaN; 37 | continue 38 | end 39 | 40 | if strfind(metric{i}, 'covar') 41 | mod = metric{i}(end-1:end); 42 | else 43 | mod = metric{i}(end); 44 | end 45 | 46 | if strcmp(cfg.defl.name, 'generalized') 47 | [param, featid] = deal(varargin{:}); 48 | 49 | for m=mod 50 | M = upper(m); 51 | 52 | % Deflation 53 | B = (1-param.(['L2' m])) * trdata.(['L' M])(featid.(m)) + repmat(param.(['L2' m]), sum(featid.(m)), 1); 54 | data2 = deflation('generalized', data, ['R' M], S.(['w' M]), B, featid.(m)); 55 | 56 | % Explained variance before/after deflation 57 | L.(M) = trace(data.(['R' M])' * data.(['R' M])); 58 | L2.(M) = trace(data2.(['R' M])' * data2.(['R' M])); 59 | end 60 | 61 | if strfind(metric{i}, 'covar') 62 | % Explained covariance before/after deflation 63 | L.XY = trace(data.RX(:,featid.x)' * data.RY(:,featid.y) * data.RY(:,featid.y)' * data.RX(:,featid.x)); 64 | L2.XY = trace(data2.RX(:,featid.x)' * data2.RY(:,featid.y) * data2.RY(:,featid.y)' * data2.RX(:,featid.x)); 65 | end 66 | 67 | else 68 | for m=mod 69 | M = upper(m); 70 | 71 | switch cfg.defl.name 72 | case 'pls-projection' 73 | % Deflation 74 | data2 = deflation('pls-projection', data, M, S.(['w' M])); 75 | 76 | case 'pls-modeA' 77 | % Loading based on input training data 78 | p = trdata.(M)' * (trdata.(M) * S.(['w' M])) / ... 79 | ((trdata.(M) * S.(['w' M]))' * (trdata.(M) * S.(['w' M]))); 80 | 81 | % Deflation 82 | data2 = deflation('pls-modeA', data, M, S.(['w' M]), p); 83 | 84 | case 'pls-regression' 85 | % Loading based on input training data 86 | p = trdata.(M)' * (trdata.X * S.wX) / ... 87 | ((trdata.X * S.wX)' * (trdata.X * S.wX)); 88 | 89 | % Deflation 90 | data2 = deflation('pls-regression', data, M, S.wX, p); 91 | end 92 | 93 | % Explained variance before/after deflation 94 | [data.(['R' M]), L.(M)] = fastsvd(data.(M), 0, 0, 1, 'R', 'L'); 95 | [data2.(['R' M]), L2.(M)] = fastsvd(data2.(M), 0, 0, 1, 'R', 'L'); 96 | L.(M) = sum(L.(M)); 97 | L2.(M) = sum(L2.(M)); 98 | end 99 | 100 | if strfind(metric{i}, 'covar') 101 | % Explained covariance before/after deflation 102 | L.XY = trace(data.RX' * data.RY * data.RY' * data.RX); 103 | L2.XY = trace(data2.RX' * data2.RY * data2.RY' * data2.RX); 104 | end 105 | end 106 | 107 | % Explained variance/covariance 108 | if strfind(metric{i}, 'covar') 109 | S.(metric{i}) = (1 - L2.XY / L.XY) * 100; 110 | else 111 | S.(metric{i}) = (1 - L2.(M) / L.(M)) * 100; 112 | end 113 | end -------------------------------------------------------------------------------- /util/calc_stability.m: -------------------------------------------------------------------------------- 1 | function [S_avg, S_square, S] = calc_stability(W, nsplits, type, subtype) 2 | % calc_stability 3 | % 4 | % Calculates the stability/similarity across weights (see Baldassare et al. 5 | % 2017). 6 | % 7 | % Syntax: 8 | % [S_avg, S_square, S] = calc_stability(W, nsplits, type, subtype) 9 | % 10 | %_______________________________________________________________________ 11 | % Copyright (C) 2022 University College London 12 | 13 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 14 | % $Id$ 15 | 16 | % This file is part of CCA/PLS Toolkit. 17 | % 18 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with CCA/PLS Toolkit. If not, see . 30 | 31 | % 11/10/2022 Modified by Agoston Mihalik (am3022@cam.ac.uk) 32 | % Bug fix: output NaN in correct shape if all (or all but one) splits 33 | % have NaN weights (e.g. due to SPLS not converging) 34 | 35 | if strcmp(type, 'overlap') && ~exist('subtype', 'var') 36 | subtype = 'corrected'; % default option 37 | end 38 | 39 | % Handle NaN and/or single-column input 40 | if iscell(W) 41 | idnan = cellfun(@(x) any(isnan(x)), W); 42 | W(idnan) = []; % remove NaN 43 | W = cat(2, W{:}); 44 | else 45 | idnan = any(isnan(W), 1); 46 | W(:,idnan) = []; % remove NaN 47 | end 48 | nw = size(W, 2); 49 | if nw < 2 50 | % Create NaN in correct shape 51 | S_avg = NaN(1, nsplits); 52 | S_square = NaN(nsplits, nsplits); 53 | if nsplits < 3 54 | S = NaN; 55 | else 56 | S = NaN(1, nsplits*(nsplits-1)/2); 57 | end 58 | return 59 | end 60 | 61 | % Calculate expected ranking if requested 62 | if strcmp(type, 'expected-ranking') 63 | R = zeros(size(W)); 64 | for i=1:nw 65 | [~, R(W(:,i)~=0,i)] = sort(W(W(:,i)~=0,i), 'ascend'); 66 | end 67 | ER = mean(R, 2); 68 | S_avg = NaN(1, nw); 69 | for i=1:nw 70 | S_avg(i) = ranking_pairwise(R(:,i), ER); 71 | end 72 | return 73 | end 74 | 75 | % Get indexes of pairwise comparisons 76 | [I, J] = find(tril(ones(nw), -1)); 77 | 78 | % Calcalute all pairwise stabilities/similarities 79 | S = zeros(1, numel(J)); 80 | for el=1:numel(J) 81 | switch type 82 | case 'correlation' 83 | S(el) = abs(correlation_pairwise(W(:,I(el)), W(:,J(el)), subtype)); 84 | 85 | case 'overlap' 86 | S(el) = overlap_pairwise(W(:,I(el)), W(:,J(el)), subtype); 87 | end 88 | end 89 | 90 | % Average overlap 91 | S_square = NaN(length(idnan)); 92 | S_square(~idnan,~idnan) = squareform(S); 93 | S_avg = nanmean(S_square) * nw / (nw-1); % correction for diagonal 94 | S_square = S_square + eye(length(idnan)); % max similarity in diagonal!! 95 | 96 | 97 | % --------------------------- Private functions --------------------------- 98 | 99 | function S = ranking_pairwise(w1, w2) 100 | 101 | S = w1' * w2 / (norm(w1) * norm(w2)); 102 | 103 | 104 | function S = correlation_pairwise(w1, w2, type) 105 | 106 | S = corr(w1, w2, 'Type', type); 107 | 108 | 109 | function S = overlap_pairwise(w1, w2, type) 110 | 111 | % Expected overlap 112 | E = 0; 113 | if strcmp(type, 'corrected') 114 | E = size(w1, 1) * sparsity(w1, 'relative') * sparsity(w2, 'relative'); 115 | end 116 | 117 | % Overlap 118 | S = (sparsity(all([w1 w2], 2)) - E) / max([sparsity(w1) sparsity(w2)]); 119 | 120 | 121 | function sp = sparsity(vec, type) 122 | 123 | % Sparsity 124 | sp = sum(vec ~= 0); 125 | 126 | % Relative sparsity 127 | if exist('type', 'var') && strcmp(type, 'relative') 128 | sp = sp / numel(vec); 129 | end 130 | 131 | -------------------------------------------------------------------------------- /util/cov2.m: -------------------------------------------------------------------------------- 1 | function c = cov2(A, B) 2 | % cov2 3 | % 4 | % Custom function for computing covariance to replace MATLAB's built-in cov 5 | % function. It supports only same number of columns. 6 | % 7 | % Syntax: 8 | % c = cov2(A, B) 9 | % 10 | %_______________________________________________________________________ 11 | % Copyright (C) 2022 University College London 12 | 13 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 14 | % $Id$ 15 | 16 | % This file is part of CCA/PLS Toolkit. 17 | % 18 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with CCA/PLS Toolkit. If not, see . 30 | 31 | % Check input dimensions 32 | if size(A, 1) ~= size(B, 1) 33 | error('Size of matrices should match for covariance calculation'); 34 | end 35 | 36 | % Compute covariance 37 | c = bsxfun(@minus, A, mean(A))' * bsxfun(@minus, B, mean(B)) / (size(A, 1) - 1); -------------------------------------------------------------------------------- /util/ffd_val_str.m: -------------------------------------------------------------------------------- 1 | function str = ffd_val_str(varargin) 2 | % ffd_val_str 3 | % 4 | % # Syntax 5 | % str = ffd_val_str(varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Parse input into field-value pairs 29 | S = parse_input([], varargin{:}); 30 | 31 | % Full factorial design of value combinations 32 | dFF = fullfact(structfun(@numel, S)); 33 | 34 | % Create combinations in string format 35 | str = cell(1, size(dFF, 1)); 36 | fn = fieldnames(S); 37 | for i=1:size(dFF, 1) 38 | for j=1:size(dFF, 2) 39 | if mod(S.(fn{j})(dFF(i,j)), 1) == 0 % try decimal format 40 | str{i}{j} = [fn{j} '_' sprintf('%d', S.(fn{j})(dFF(i,j)))]; 41 | 42 | elseif strfind(fn{j}, 'L2') % specific short format for L2 regularization 43 | str{i}{j} = [fn{j} '_' sprintf('%.4f', log(1-S.(fn{j})(dFF(i,j))))]; 44 | 45 | else % otherwise use short format 46 | str{i}{j} = [fn{j} '_' sprintf('%.4f', S.(fn{j})(dFF(i,j)))]; 47 | end 48 | end 49 | str{i} = strjoin(str{i}, '_'); 50 | end -------------------------------------------------------------------------------- /util/fix_fileend.m: -------------------------------------------------------------------------------- 1 | function fix_fileend(cfg) 2 | % fix_fileend 3 | % 4 | % # Syntax 5 | % fix_fileend(cfg) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | %----- Clean up data folder 29 | movefile(fullfile(cfg.dir.data, 'inmat.mat'), fullfile(cfg.dir.data, 'inmat_1.mat')); 30 | movefile(fullfile(cfg.dir.data, 'outmat.mat'), fullfile(cfg.dir.data, 'outmat_1.mat')); 31 | 32 | %----- Clean up grid folder 33 | if strcmp(cfg.frwork.name, 'holdout') 34 | movefile(fullfile(cfg.dir.grid, 'allgrid.mat'), fullfile(cfg.dir.grid, 'allgrid_1.mat')); 35 | elseif strcmp(cfg.frwork.name, 'holdout_perm') 36 | movefile(fullfile(cfg.dir.grid, 'allgrid.mat'), fullfile(cfg.dir.grid, 'allgrid_1.mat')); 37 | movefile(fullfile(cfg.dir.grid, 'distances.mat'), fullfile(cfg.dir.grid, 'distances_1.mat')); 38 | movefile(fullfile(cfg.dir.grid, 'pvals.mat'), fullfile(cfg.dir.grid, 'allgrid_1.mat')); 39 | movefile(fullfile(cfg.dir.grid, sprintf('permid_N%d.mat', cfg.frwork.split.nin)), ... 40 | fullfile(cfg.dir.grid, sprintf('permid_N%d_1.mat', cfg.frwork.split.nin))); 41 | end 42 | 43 | %----- Clean up perm folder 44 | movefile(fullfile(cfg.dir.perm, 'allperm.mat'), fullfile(cfg.dir.perm, 'allperm_1.mat')); 45 | movefile(fullfile(cfg.dir.perm, sprintf('permid_N%d.mat', cfg.nperm)), fullfile(cfg.dir.perm, sprintf('permid_N%d_1.mat', cfg.nperm))); 46 | 47 | %----- Clean up res folder 48 | movefile(fullfile(cfg.dir.res, 'model.mat'), fullfile(cfg.dir.res, 'model_1.mat')); 49 | movefile(fullfile(cfg.dir.res, 'param.mat'), fullfile(cfg.dir.res, 'param_1.mat')); 50 | try 51 | movefile(fullfile(cfg.dir.res, 'results.mat'), fullfile(cfg.dir.res, 'results_1.mat')); 52 | catch 53 | end 54 | movefile(fullfile(cfg.dir.res, 'cfg.mat'), fullfile(cfg.dir.res, 'cfg_1.mat')); 55 | 56 | %----- Empty fileend field 57 | cfg.env.fileend = '_1'; 58 | save(fullfile(cfg.dir.res, 'cfg_1.mat'), 'cfg') -------------------------------------------------------------------------------- /util/init_brainnet.m: -------------------------------------------------------------------------------- 1 | function fname = init_brainnet(res, varargin) 2 | % init_brainnet 3 | % 4 | % # Syntax 5 | % fname = init_brainnet(res, varargin) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Parse inputs 29 | S = parse_input([], varargin{:}); 30 | 31 | % Set path for Brainnet 32 | set_path('brainnet'); 33 | 34 | % Set defaults for Brainnet 35 | res = res_defaults(res, 'brainnet'); 36 | 37 | % Make custom Brainnet folder 38 | dir_brainnet = fullfile(res.dir.project, 'data', 'BrainNet'); 39 | if ~isdir(dir_brainnet) 40 | mkdir(dir_brainnet); 41 | end 42 | 43 | % Brainnet mesh/surface file 44 | fname.surf = select_file(res, pwd, 'Select brain mesh file...', '\.nv$', which(res.brainnet.file.surf)); 45 | 46 | % Brainnet options file 47 | fname.options = select_file(res, dir_brainnet, 'Select options file...', 'mat', res.brainnet.file.options); 48 | 49 | % Brainnet edge file 50 | if isfield(S, 'wfname') && isfield(S, 'weight') 51 | [pathstr, fname.edge, ext] = fileparts(S.wfname); 52 | fname.edge = fullfile(dir_brainnet, [fname.edge, '.edge']); 53 | dlmwrite(fname.edge, S.weight, 'Delimiter', '\t'); % edge file weight*2*pi 54 | end 55 | 56 | % Brainnet node file 57 | if isfield(S, 'labelfname') && isfield(S, 'T') 58 | [pathstr, fname.node, ext] = fileparts(S.labelfname); 59 | fname.node = fullfile(dir_brainnet, [fname.node, '.node']); 60 | % Check fields (color, size, MNI space) >> to be implemented 61 | writetable(S.T(:,{'X' 'Y' 'Z' 'Color' 'Size'}), 'tmp.txt', 'delimiter', '\t', 'WriteVariableNames', 0); 62 | movefile('tmp.txt', fname.node); % node file 63 | end -------------------------------------------------------------------------------- /util/mean_center_features.m: -------------------------------------------------------------------------------- 1 | function [mat, varargout] = mean_center_features(mat, mu) 2 | % mean_center_features 3 | % 4 | % Mean centers features. 5 | % 6 | % # Syntax 7 | % [mat, varargout] = mean_center_features(mat, mu) 8 | % 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2022 University College London 11 | 12 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 13 | % $Id$ 14 | 15 | % This file is part of CCA/PLS Toolkit. 16 | % 17 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with CCA/PLS Toolkit. If not, see . 29 | 30 | if ~exist('mu', 'var') 31 | mu = nanmean(mat, 1); 32 | varargout{1} = mu; 33 | end 34 | 35 | mat = bsxfun(@minus, mat, mu); 36 | 37 | -------------------------------------------------------------------------------- /util/norm_features.m: -------------------------------------------------------------------------------- 1 | function [mat, varargout] = norm_features(mat, scaling, norm_fun) 2 | % norm_features 3 | % 4 | % Normalizes features. 5 | % 6 | % # Syntax 7 | % [mat, varargout] = norm_features(mat, scaling, norm_fun) 8 | % 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2022 University College London 11 | 12 | % Written by Joao Monteiro, Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 13 | % $Id$ 14 | 15 | % This file is part of CCA/PLS Toolkit. 16 | % 17 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 18 | % it under the terms of the GNU General Public License as published by 19 | % the Free Software Foundation, either version 3 of the License, or 20 | % (at your option) any later version. 21 | % 22 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | % GNU General Public License for more details. 26 | % 27 | % You should have received a copy of the GNU General Public License 28 | % along with CCA/PLS Toolkit. If not, see . 29 | 30 | % Calculate scaling 31 | if ~exist('scaling', 'var') || isempty(scaling) 32 | scaling = zeros(1, size(mat, 2)); % preallocation 33 | 34 | for i=1:size(mat, 2) % we loop through for memory efficiency and due to NaNs 35 | id = ~isnan(mat(:,i)); 36 | if nargin < 2 || strcmp(norm_fun, 'norm') 37 | % The norm function behaves in a different way 38 | scaling(i) = sqrt(sum(mat(id,i).^2)); 39 | elseif strcmp(norm_fun, 'norm1') 40 | scaling(i) = sum(abs(mat(id,i))); 41 | else 42 | % General case for functions that perform operations column-wise (e.g. 43 | % 'std' or 'sum') 44 | fun_handle = str2func(norm_fun); 45 | scaling(i) = fun_handle(mat(id,i)); 46 | end 47 | end 48 | 49 | % Replace badly scaled features with 0 50 | scaling(scaling < 1e-5) = 0; 51 | 52 | varargout{1} = scaling; 53 | end 54 | 55 | % Perform scaling 56 | mat = bsxfun(@rdivide, mat, scaling); 57 | 58 | % When using 'std' (e.g), a matrix can have a column with std = 0, 59 | % which results in NaN. Change all NaN to zero 60 | if any(scaling == 0) 61 | mat(:,scaling == 0) = 0; 62 | end -------------------------------------------------------------------------------- /util/normalize2MNI.m: -------------------------------------------------------------------------------- 1 | function normalize2MNI(res, template, weight, transM) 2 | % normalize2MNI 3 | % 4 | % # Syntax 5 | % normalize2MNI(res, template, weight, transM) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Handle path to template 29 | [template_path, name, ext] = fileparts(template); 30 | template = [name ext]; 31 | 32 | % Initialize matlab batch jobs 33 | matlabbatch = {struct()}; 34 | 35 | % Reorient image 36 | matlabbatch{end}.spm.util.reorient.srcfiles = {fullfile(template_path, template); ... 37 | fullfile(res.dir.res, weight)}; 38 | matlabbatch{end}.spm.util.reorient.transform.transM = transM; 39 | matlabbatch{end}.spm.util.reorient.prefix = 'r'; 40 | 41 | % Estimate normalization to MNI space using segmentation 42 | if ~exist(fullfile(template_path, ['y_r' template]), 'file') 43 | matlabbatch{end+1}.spm.spatial.preproc.channel.vols(1) = {fullfile(template_path, ['r' template])}; 44 | matlabbatch{end}.spm.spatial.preproc.channel.biasreg = 0.001; 45 | matlabbatch{end}.spm.spatial.preproc.channel.biasfwhm = 60; 46 | matlabbatch{end}.spm.spatial.preproc.channel.write = [0 0]; 47 | ngaus = [1 1 2 3 4 2]; 48 | for i=1:numel(ngaus) 49 | matlabbatch{end}.spm.spatial.preproc.tissue(i).tpm = {fullfile(fileparts(which('spm')), ... 50 | 'tpm', ['TPM.nii,' num2str(i)])}; 51 | matlabbatch{end}.spm.spatial.preproc.tissue(i).ngaus = ngaus(i); 52 | matlabbatch{end}.spm.spatial.preproc.tissue(i).native = [0 0]; 53 | matlabbatch{end}.spm.spatial.preproc.tissue(i).warped = [0 0]; 54 | end 55 | matlabbatch{end}.spm.spatial.preproc.warp.mrf = 1; 56 | matlabbatch{end}.spm.spatial.preproc.warp.cleanup = 1; 57 | matlabbatch{end}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2]; 58 | matlabbatch{end}.spm.spatial.preproc.warp.affreg = 'mni'; 59 | matlabbatch{end}.spm.spatial.preproc.warp.fwhm = 0; 60 | matlabbatch{end}.spm.spatial.preproc.warp.samp = 3; 61 | matlabbatch{end}.spm.spatial.preproc.warp.write = [0 1]; 62 | else 63 | fprintf('Segmentation skipped as normalization file already exists.\n\n'); 64 | end 65 | 66 | % Apply normalization to MNI space 67 | matlabbatch{end+1}.spm.spatial.normalise.write.subj.def(1) = {fullfile(template_path, ['y_r' template])}; 68 | matlabbatch{end}.spm.spatial.normalise.write.subj.resample(1) = {fullfile(res.dir.res, ['r' weight])}; 69 | matlabbatch{end}.spm.spatial.normalise.write.woptions.bb = [-78 -112 -70 70 | 78 76 85]; 71 | matlabbatch{end}.spm.spatial.normalise.write.woptions.vox = [2 2 2]; 72 | matlabbatch{end}.spm.spatial.normalise.write.woptions.interp = 4; 73 | matlabbatch{end}.spm.spatial.normalise.write.woptions.prefix = 'w'; 74 | 75 | % Run spm job 76 | spm('defaults', 'fMRI'); 77 | spm_jobman('run', matlabbatch); -------------------------------------------------------------------------------- /util/postproc_weight.m: -------------------------------------------------------------------------------- 1 | function [weight, iweight] = postproc_weight(res, weight, modtype) 2 | % postproc_weight 3 | % 4 | % # Syntax 5 | % [weight, iweight] = postproc_weight(res, weight, modtype) 6 | % 7 | %_______________________________________________________________________ 8 | % Copyright (C) 2022 University College London 9 | 10 | % Written by Agoston Mihalik (cca-pls-toolkit@cs.ucl.ac.uk) 11 | % $Id$ 12 | 13 | % This file is part of CCA/PLS Toolkit. 14 | % 15 | % CCA/PLS Toolkit is free software: you can redistribute it and/or modify 16 | % it under the terms of the GNU General Public License as published by 17 | % the Free Software Foundation, either version 3 of the License, or 18 | % (at your option) any later version. 19 | % 20 | % CCA/PLS Toolkit is distributed in the hope that it will be useful, 21 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | % GNU General Public License for more details. 24 | % 25 | % You should have received a copy of the GNU General Public License 26 | % along with CCA/PLS Toolkit. If not, see . 27 | 28 | % Sort weights if requested 29 | if strcmp(res.(modtype).weight.sorttype, '') 30 | iweight = 1:numel(weight); % we keep original order 31 | elseif strcmp(res.(modtype).weight.sorttype, 'abs') 32 | [~, iweight] = sort(abs(weight), 'descend'); 33 | elseif strcmp(res.(modtype).weight.sorttype, 'sign') 34 | [~, iweight] = sort(weight, 'descend'); 35 | end 36 | 37 | % Keep only top weights if requested 38 | if ~isinf(res.(modtype).weight.numtop) 39 | if strcmp(res.(modtype).weight.sorttype, 'abs') && sum(weight~=0) >= res.(modtype).weight.numtop 40 | weight(iweight(res.(modtype).weight.numtop+1:end)) = 0; 41 | elseif strcmp(res.(modtype).weight.sorttype, 'sign') 42 | numnonneg = [sum(weight>0) sum(weight<0)]; 43 | if any(numnonneg >= res.(modtype).weight.numtop) 44 | numnonneg(numnonneg>=res.(modtype).weight.numtop) = res.(modtype).weight.numtop; 45 | weight(iweight(numnonneg(1)+1:end-numnonneg(2))) = 0; 46 | end 47 | end 48 | end 49 | 50 | % Keep only positive/negative weights if requested 51 | if isfield(res.(modtype).weight, 'sign') 52 | if strcmp(res.(modtype).weight.sign, 'positive') 53 | weight(weight<0) = 0; 54 | elseif strcmp(res.(modtype).weight.sign, 'negative') 55 | weight(weight>0) = 0; 56 | end 57 | end --------------------------------------------------------------------------------