Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a set of runnable examples (scripts, configs, and Jupyter notebooks) demonstrating domain adaptation workflows and related utilities, and wires up example dependencies in setup.py so users can install the extra packages needed to run tutorials.
Changes:
- Add new example packages for toy domain adaptation, multi-site neuroimaging adaptation, cardiac MRI MPCA, and brain lateralization (with supporting utilities/configs/notebooks).
- Add
pykaleto the example extras insetup.pyto support example imports from thekalenamespace. - Introduce compatibility wrapper modules in
examples/brain_lateralization/utils/(e.g.,io_.py,plot.py) to consolidate imports.
Reviewed changes
Copilot reviewed 31 out of 36 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.py | Adds pykale to example extras (but example deps still missing items needed by new examples). |
| examples/toy_domain_adaptation/tutorial.ipynb | New notebook tutorial for toy domain adaptation. |
| examples/toy_domain_adaptation/README.md | New README describing the toy domain adaptation example. |
| examples/toy_domain_adaptation/main.py | New runnable script version of the toy domain adaptation demo. |
| examples/toy_domain_adaptation/init.py | Package marker for the toy domain adaptation example. |
| examples/multisite_neuroimg_adapt/tutorial.ipynb | New notebook tutorial for multi-site neuroimaging domain adaptation. |
| examples/multisite_neuroimg_adapt/README.md | New README describing the multi-site neuroimaging example. |
| examples/multisite_neuroimg_adapt/main.py | New runnable script for the multi-site neuroimaging workflow. |
| examples/multisite_neuroimg_adapt/configs/tutorial.yaml | New YAML config for the multi-site neuroimaging tutorial. |
| examples/multisite_neuroimg_adapt/configs/README.md | README for the multi-site example configuration folder. |
| examples/multisite_neuroimg_adapt/config.py | Default YACS config for the multi-site neuroimaging example. |
| examples/multisite_neuroimg_adapt/init.py | Package marker for the multi-site neuroimaging example. |
| examples/cmri_mpca/tutorial.ipynb | New notebook tutorial for cardiac MRI MPCA pipeline. |
| examples/cmri_mpca/README.md | New README describing the cardiac MRI MPCA example. |
| examples/cmri_mpca/main.py | New runnable script for the cardiac MRI MPCA pipeline. |
| examples/cmri_mpca/configs/tutorial_svc.yaml | New tutorial config for SVC classifier. |
| examples/cmri_mpca/configs/tutorial_lr.yaml | New tutorial config for logistic regression classifier. |
| examples/cmri_mpca/configs/README.md | README for the cardiac MRI example configuration folder. |
| examples/cmri_mpca/config.py | Default YACS config for the cardiac MRI example. |
| examples/cmri_mpca/init.py | Package marker for the cardiac MRI example. |
| examples/brain_lateralization/utils/stats.py | New stats helpers (including compatibility wrappers). |
| examples/brain_lateralization/utils/results.py | New result loading/saving helpers for the brain lateralization example. |
| examples/brain_lateralization/utils/plotting.py | New plotting utilities for the brain lateralization example. |
| examples/brain_lateralization/utils/plot.py | Compatibility wrapper for plotting utilities. |
| examples/brain_lateralization/utils/neuro_io.py | Neuroimaging I/O helpers (gifti/nifti). |
| examples/brain_lateralization/utils/io_.py | Compatibility import aggregator for brain lateralization utilities. |
| examples/brain_lateralization/utils/half_brain.py | Data download/loading + half-brain splitting utilities. |
| examples/brain_lateralization/utils/experiment.py | Main experiment runner for GSDA lateralization. |
| examples/brain_lateralization/utils/data_io.py | General data I/O helpers used by the brain lateralization pipeline. |
| examples/brain_lateralization/utils/init.py | Package marker for brain lateralization utils. |
| examples/brain_lateralization/tutorial.ipynb | New notebook demo for brain lateralization GSDA workflow. |
| examples/brain_lateralization/configs/test.yaml | New test config for brain lateralization. |
| examples/brain_lateralization/configs/demo-hcp.yaml | Demo config for HCP dataset. |
| examples/brain_lateralization/configs/demo-gsp.yaml | Demo config for GSP dataset. |
| examples/brain_lateralization/configs/default_cfg.py | Default config for brain lateralization example. |
| examples/brain_lateralization/configs/init.py | Package marker for brain lateralization configs. |
| examples/brain_lateralization/utils/init.py | Package marker for brain lateralization utilities (duplicate entry). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "metadata": {}, | ||
| "source": [ | ||
| "estimator = CoIRLS(kernel=cfg.MODEL.KERNEL, lambda_=cfg.MODEL.LAMBDA_, alpha=cfg.MODEL.ALPHA)\n", |
Comment on lines
+45
to
+52
| "#@title Import required modules\n", | ||
| "import os\n", | ||
| "from configs.default_cfg import get_cfg_defaults\n", | ||
| "from utils.experiment import run_experiment\n", | ||
| "\n", | ||
| "from utils.io_ import load_result, reformat_results\n", | ||
| "from utils import plot" | ||
| ], |
| "source": [ | ||
| "### Configurations\n", | ||
| "\n", | ||
| "The customized configuration used in this demo is stored in `configs/demoh-cp.yaml`, this file overwrites defaults in `default_cfg.py` where a value is specified. Change the configuration file path to `cfg_path = \"configs/demo-gsp.yaml\"` for running the demo with GSP data." |
Comment on lines
+1
to
+7
| DATASET: | ||
| ROOT: "D:/ShareFolder/BNA/Proc" | ||
| NUM_REPEAT: 5 | ||
| SOLVER: | ||
| SEED: 2022 | ||
| OUTPUT: | ||
| ROOT: 'D:/ShareFolder/BNA/Result' |
Comment on lines
+20
to
+22
| _C.DATASET.BASE_DIR = "SA_64x64_v2.0" | ||
| _C.DATASET.FILE_FORAMT = "zip" | ||
| _C.DATASET.LANDMARK_FILE = "landmarks.csv" |
Comment on lines
+34
to
+42
| "if 'google.colab' in str(get_ipython()):\n", | ||
| " print('Running on CoLab')\n", | ||
| " !pip uninstall --yes imgaug && pip uninstall --yes albumentations && pip install git+https://github.com/aleju/imgaug.git\n", | ||
| " !pip install numpy>=2.0.0\n", | ||
| " !pip install git+https://github.com/pykale/pykale.git\n", | ||
| " !git clone https://github.com/pykale/pykale.git\n", | ||
| " %cd pykale/examples/toy_domain_adaptation\n", | ||
| "else:\n", | ||
| " print('Not running on CoLab')" |
Comment on lines
+48
to
+56
| "if 'google.colab' in str(get_ipython()):\n", | ||
| " print('Running on CoLab')\n", | ||
| " !pip uninstall --yes imgaug && pip uninstall --yes albumentations && pip install git+https://github.com/aleju/imgaug.git\n", | ||
| " !git clone https://github.com/pykale/pykale.git\n", | ||
| " %cd pykale\n", | ||
| " !pip install .[image,example]\n", | ||
| " %cd examples/multisite_neuroimg_adapt\n", | ||
| "else:\n", | ||
| " print('Not running on CoLab')" |
Comment on lines
+45
to
+53
| "if 'google.colab' in str(get_ipython()):\n", | ||
| " print('Running on CoLab')\n", | ||
| " !pip uninstall --yes imgaug && pip uninstall --yes albumentations && pip install git+https://github.com/aleju/imgaug.git\n", | ||
| " !git clone https://github.com/pykale/pykale.git\n", | ||
| " %cd pykale\n", | ||
| " !pip install .[image,example] \n", | ||
| " %cd examples/cmri_mpca\n", | ||
| "else:\n", | ||
| " print('Not running on CoLab')" |
Comment on lines
+9
to
+11
| "# Group-Specific Discriminant Analysis for sex-specific lateralization Running Demo\n", | ||
| "\n", | ||
| "[Open in Colab](https://colab.research.google.com/github/shuo-zhou/GSDA-Lateralization/blob/main/gsda_demo.ipynb) (click `Runtime`\u2006\u2192\u2006`Run all (Ctrl+F9)`)" |
Comment on lines
+39
to
+42
| " !pip install git+https://github.com/pykale/kale-linear.git\n", | ||
| " !git clone https://github.com/pykale/kale-linear.git\n", | ||
| " %cd kalelinear/examples/toy_domain_adaptation\n", | ||
| "else:\n", |
| "source": [ | ||
| "# Group-Specific Discriminant Analysis for sex-specific lateralization Running Demo\n", | ||
| "\n", | ||
| "[Open in Colab](https://colab.research.google.com/github/pykale/kale-linear/blob/main/examples/brain_lateralization/gsda_demo.ipynb) (click `Runtime`\u2006\u2192\u2006`Run all (Ctrl+F9)`)" |
Comment on lines
+21
to
+24
| " - [Construct brain networks](#Extracting-Brain-Networks-Features)\n", | ||
| "- Machine learning pipeline:\n", | ||
| " - [Baseline: Ridge classifier](#Baseline-Model)\n", | ||
| " - [Domain adaptation](#Domain-Adaptation)\n", |
Comment on lines
+22
to
+25
| def load_weight_plot_corr(dataset, base_dir, sessions, seed_start, fontsize=14): | ||
| control_weights = fetch_weights(base_dir, "mix", "0_group_mix", dataset, sessions=sessions, seed_=seed_start) | ||
| n_control_weights = control_weights.shape[0] | ||
|
|
Comment on lines
+31
to
+41
| weights = fetch_weights( | ||
| base_dir, | ||
| group, | ||
| int(lambda_), | ||
| dataset, | ||
| sessions=sessions, | ||
| seed_=seed_start, | ||
| ) | ||
| corr_matrix = np.corrcoef(control_weights, weights)[n_control_weights:, :n_control_weights] | ||
| corrs["mean"].append(np.mean(corr_matrix)) | ||
| corrs["sd"].append(np.std(corr_matrix)) |
| return df.loc[index1, df_column_name].to_numpy() | ||
|
|
||
|
|
||
| def load_result(dataset, root_dir, lambdas, seed_start, test_size=0.0): |
Comment on lines
+101
to
+106
| res_fname = "results_%s_L%s_test_size0%s_Fisherz_%s.csv" % ( | ||
| dataset, | ||
| lambda_str, | ||
| test_size_str, | ||
| random_state, | ||
| ) |
Comment on lines
+114
to
+120
| for lambda_ in lambdas: | ||
| res_dict[lambda_] = pd.concat(res_dict[lambda_]) | ||
|
|
||
| res_df_all = pd.concat(res_list) | ||
| res_df_all = res_df_all.reset_index(drop=True) | ||
|
|
||
| return res_df_all |
| plt.xlabel(r"$\lambda$", fontsize=fontsize) | ||
| plt.rcParams["text.usetex"] = False | ||
|
|
||
| plt.savefig("figures/%s_corr.svg" % dataset, format="svg", bbox_inches="tight") |
Comment on lines
+118
to
+122
| plt.savefig( | ||
| "figures/corr_annot_%s_%s.svg" % (dataset, group_dict[group_label]), | ||
| format="svg", | ||
| bbox_inches="tight", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.