OSCR

Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity.

Code ↔ Paper

1 match between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 1 match
  1. [1] § Methods › Representational similarity analysis ↔ RDM.py, lines 81–125 · score 0.55 · Pearson correlation, model features, flattened, square, matrix

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 126 lines · 5.2 KB · no license · 1 match

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from sklearn.covariance import MinCovDet
  4. from scipy.spatial.distance import pdist, squareform
  5. def normalize_rdm(rdm):
  6. """
  7. Normalizes the representational dissimilarity matrix (RDM).
  8. Args:
  9. rdm (np.ndarray): The representational dissimilarity matrix to normalize.
  10. Returns:
  11. np.ndarray: The normalized RDM if possible, otherwise returns the original RDM.
  12. """
  13. try:
  14. # Ensure the RDM is not empty and contains non-zero elements
  15. if rdm.size == 0 or np.all(rdm == 0):
  16. raise ValueError("RDM is empty or contains only zeros.")
  17. # Create a mask to extract only the lower triangular values (excluding diagonal)
  18. lower_mask = np.tril(np.ones_like(rdm), -1).astype(bool)
  19. # Find the maximum and minimum non-diagonal values
  20. max_val = np.max(rdm[lower_mask])
  21. min_val = np.min(rdm[lower_mask])
  22. # Check for the case where all non-zero elements are the same
  23. if max_val == min_val:
  24. raise ValueError("All non-zero elements in RDM are the same.")
  25. # Normalize the RDM using min-max scaling
  26. normalized_rdm = (rdm - min_val) / (max_val - min_val)
  27. return normalized_rdm
  28. except ValueError as e:
  29. # Log the error and return the original RDM in case of failure
  30. print(f"Error in RDM normalization: {e}")
  31. return rdm
  32. def calculate_mahalanobis_distance(model_features):
  33. """
  34. Calculate the Mahalanobis distances of given observations.
  35. The Mahalanobis distance is a measure of the distance between a point and a distribution.
  36. It is an effective way to determine similarity between an unknown sample and a known one.
  37. This function calculates these distances using the Minimum Covariance Determinant (MCD)
  38. estimator for robustness against outliers.
  39. Args:
  40. model_features (numpy.array): A 2D numpy array of shape [images x features]
  41. Returns:
  42. numpy.array: A 1D array of Mahalanobis distances between stimuli (images).
  43. Raises:
  44. ValueError: If the input is not a 2D numpy array or has less than 2 columns.
  45. RuntimeError: If an error occurs during the distance calculation process.
  46. """
  47. # Validate input to ensure it is a 2D numpy array with at least 2 columns
  48. if not isinstance(model_features, np.ndarray) or len(model_features.shape) != 2 or model_features.shape[1] < 2:
  49. raise ValueError("Input must be a 2D numpy array with at least 2 variables (columns).")
  50. try:
  51. # Fit the Minimum Covariance Determinant estimator to the input data for robust covariance estimation
  52. cov = MinCovDet().fit(model_features)
  53. # Calculate the Mahalanobis distance using the robust covariance matrix
  54. # pdist computes pairwise distances, and we specify the Mahalanobis metric with the inverse covariance matrix
  55. distances = pdist(model_features, metric="mahalanobis", VI=cov.covariance_)
  56. except Exception as e:
  57. # Catch any errors that occur during the distance calculation and raise a RuntimeError
  58. raise RuntimeError(f"An error occurred while calculating distances: {e}")
  59. # Return the computed Mahalanobis distances
  60. return distances
  61. def compute_rdm(model_features, distance_metric="euclidean", rescale=False):
  62. """
  63. Compute the Representational Dissimilarity Matrix (RDM) for model features.
  64. The RDM is computed based on a specified distance metric, and optionally rescaled.
  65. The diagonal of the RDM is set to zero, and the RDM can be rescaled to the 0-1 range (excluding the diagonal).
  66. Args:
  67. model_features (np.array): Features extracted from the models in the shape [images x features].
  68. distance_metric (str): Distance metric to use for computing dissimilarity.
  69. Options are 'euclidean', 'mahalanobis', or 'pearson'.
  70. rescale (bool): If True, rescale the RDM to the 0-1 range, excluding the diagonal.
  71. Returns:
  72. np.array: The computed RDM as a 2D numpy array.
  73. """
  74. # Flatten the features so that each stimulus is represented as a 1D vector
  75. model_features = model_features.reshape(model_features.shape[0], -1)
  76. # Compute pairwise distances between stimuli using the specified distance metric
  77. if model_features.shape[1] == 1 or distance_metric == "euclidean":
  78. distances = pdist(model_features, metric="euclidean") # Euclidean distance
  79. elif distance_metric == "mahalanobis":
  80. distances = calculate_mahalanobis_distance(model_features) # Mahalanobis distance
  81. elif distance_metric == "pearson":
  82. distances = pdist(model_features, metric="correlation") # Pearson correlation (distance)
  83. else:
  84. # Raise an error if an invalid distance metric is specified
  85. raise ValueError("Invalid distance metric specified.")
  86. # Convert the pairwise distances into a square matrix (RDM)
  87. rdm = squareform(distances)
  88. # Rescale the RDM to the 0-1 range, excluding the diagonal if specified
  89. if rescale:
  90. rdm = normalize_rdm(rdm) # Normalizing RDM
  91. # Set the diagonal of the RDM to zero (diagonal represents self-similarity)
  92. np.fill_diagonal(rdm, 0)
  93. # Return the RDM
  94. return rdm

RDM.py at commit 8d928d6, no license · at the source

Overview

Authors: Maren Wehrheim1, Shirin Taghian Alamooti1, Hamidreza Ramezanpour1, Kohitij Kar1
  1. York University, Department of Biology and Centre for Vision Research, Centre for Integrative and Applied Neuroscience,Toronto, ON Canada
Institutions: York University (Canada)
Journal: Nature communications, volume 17, issue 1, article 9135
Dates: received 8 September 2025; accepted 20 July 2026; published online 28 July 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-76106-1 · PMID 42649167 · PMCID PMC13518822 · OpenAlex W7171487503
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: human (organism), non-human primate (organism), systems (subfield)
Methods: Spectral & time-frequency, Machine learning, Connectivity, Single-unit activity, calcium imaging
Keywords: Social behaviour, Sensory processing
MeSH: Discrimination, Psychological*, Facial Expression*, Facial Recognition*, Visual Cortex*, Animals, Female, Humans, Macaca mulatta, Male, Models, Neurological, Neural Networks, Computer, Neurons, Pattern Recognition, Visual, Photic Stimulation (* major topic)
Topic: Face Recognition and Perception (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Citations: not cited yet (Europe PMC); 72 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repositories

Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.

vital-kolab/facial-exp-nhp

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 8d928d6a4b55ab1e14b622100a663be90c46b538, 19 September 2025
Languages: Python (5), Jupyter (1)
Size: 14 files, 6 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, environment (requirements.txt), 1 notebook
Not found: license file, CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (6 files), SciPy (3 files), Matplotlib (2 files), pandas (2 files), scikit-learn (2 files), h5py (1 file), seaborn (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
7 files

Zenodo 20544792

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (6 files), SciPy (3 files), Matplotlib (2 files), pandas (2 files), scikit-learn (2 files), h5py (1 file), seaborn (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)
7 files
At the source:

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-76106-1.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 12 scripts, each with its path and the digest of its content;
  • 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-76106-1.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 2 keywords, 14 MeSH terms, 4 funders, 62 references.

Cite

This paper

Wehrheim, M., Alamooti, S. T., Ramezanpour, H., & Kar, K. (2026). Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity. Nature communications, 17(1), 9135. https://doi.org/10.1038/s41467-026-76106-1

BibTeX

@article{wehrheim2026facial,
author = {Wehrheim, Maren and Alamooti, Shirin Taghian and Ramezanpour, Hamidreza and Kar, Kohitij},
title = {{Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity}},
journal = {Nature communications},
year = {2026},
month = jul,
volume = {17},
number = {1},
pages = {9135},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-76106-1},
url = {https://doi.org/10.1038/s41467-026-76106-1},
pmid = {42649167},
pmcid = {PMC13518822}
}

RIS

TY - JOUR
AU - Wehrheim, Maren
AU - Alamooti, Shirin Taghian
AU - Ramezanpour, Hamidreza
AU - Kar, Kohitij
TI - Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/07/28
VL - 17
IS - 1
SP - 9135
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-76106-1
UR - https://doi.org/10.1038/s41467-026-76106-1
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-76106-1",
"type": "article-journal",
"title": "Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity",
"container-title": "Nature communications",
"author": [
{
"family": "Wehrheim",
"given": "Maren"
},
{
"family": "Alamooti",
"given": "Shirin Taghian"
},
{
"family": "Ramezanpour",
"given": "Hamidreza"
},
{
"family": "Kar",
"given": "Kohitij"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "9135",
"DOI": "10.1038/s41467-026-76106-1",
"PMID": "42649167",
"PMCID": "PMC13518822",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-76106-1",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
28
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-74816-0 [code]
Hierarchical optimization predicts plasticity in the macaque inferior temporal cortex following object training.
Journal: Nature communications
In common: h5py, seaborn, scikit-learn, 4 other tools, non-human primate, 12 references, author Kohitij Kar
[2] doi:10.1038/s41593-026-02207-1 [code]
Neuronal tuning aligns dynamically with object and texture manifolds across the visual hierarchy.
Journal: Nature neuroscience
In common: seaborn, scikit-learn, pandas, 3 other tools, non-human primate, systems, 9 references
[3] doi:10.1038/s41467-026-76098-y [code]
A single computational objective can produce specialization of streams in visual cortex.
Journal: Nature communications
In common: h5py, seaborn, scikit-learn, 4 other tools, 4 references
[4] doi:10.3389/fncir.2026.1783892 [code]
Representations of facial features and surface quality in monkey area TE compared to neural network models.
Journal: Frontiers in neural circuits
In common: NumPy, non-human primate, 7 references
[5] doi:10.1523/jneurosci.0038-26.2026 [code]
Multidimensional Feature Tuning in Category Selective Areas of Human Visual Cortex.
Journal: The Journal of neuroscience : the official journal of the Society for Neuroscience
In common: h5py, seaborn, scikit-learn, 4 other tools, systems, 3 references
[6] doi:10.1038/s41467-026-74347-8 [code]
Compositionality of social gaze in the prefrontal-amygdala circuits.
Journal: Nature communications
In common: seaborn, scikit-learn, pandas, 3 other tools, non-human primate, systems, 3 references
[7] doi:10.1038/s42003-026-10169-0 [code]
Shared representations in brains and models reveal a two-route cortical organization during scene perception.
Journal: Communications biology
In common: h5py, seaborn, scikit-learn, 4 other tools, 3 references
[8] doi:10.1016/j.isci.2026.116780
The representational geometry of naturalistic textures in macaque V1 and V2.
Journal: iScience
In common: non-human primate, systems, 6 references
[9] doi:10.1162/imag.a.1286 [code]
Behavioral imitation with artificial neural networks leads to personalized models of brain dynamics during videogame play.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: h5py, seaborn, scikit-learn, 4 other tools, 2 references
[10] doi:10.7554/elife.105953 [code]
Top-down feedback in deep neural networks leads to functional differences during audiovisual integration.
Journal: eLife
In common: h5py, seaborn, scikit-learn, 4 other tools, 2 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.