Facial expression discrimination emerges from partially overlapping neural subspaces of detection and identity.
The 1 match
- [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
- import numpy as np
- import matplotlib.pyplot as plt
- from sklearn.covariance import MinCovDet
- from scipy.spatial.distance import pdist, squareform
- def normalize_rdm(rdm):
- """
- Normalizes the representational dissimilarity matrix (RDM).
- Args:
- rdm (np.ndarray): The representational dissimilarity matrix to normalize.
- Returns:
- np.ndarray: The normalized RDM if possible, otherwise returns the original RDM.
- """
- try:
- # Ensure the RDM is not empty and contains non-zero elements
- if rdm.size == 0 or np.all(rdm == 0):
- raise ValueError("RDM is empty or contains only zeros.")
- # Create a mask to extract only the lower triangular values (excluding diagonal)
- lower_mask = np.tril(np.ones_like(rdm), -1).astype(bool)
- # Find the maximum and minimum non-diagonal values
- max_val = np.max(rdm[lower_mask])
- min_val = np.min(rdm[lower_mask])
- # Check for the case where all non-zero elements are the same
- if max_val == min_val:
- raise ValueError("All non-zero elements in RDM are the same.")
- # Normalize the RDM using min-max scaling
- normalized_rdm = (rdm - min_val) / (max_val - min_val)
- return normalized_rdm
- except ValueError as e:
- # Log the error and return the original RDM in case of failure
- print(f"Error in RDM normalization: {e}")
- return rdm
- def calculate_mahalanobis_distance(model_features):
- """
- Calculate the Mahalanobis distances of given observations.
- The Mahalanobis distance is a measure of the distance between a point and a distribution.
- It is an effective way to determine similarity between an unknown sample and a known one.
- This function calculates these distances using the Minimum Covariance Determinant (MCD)
- estimator for robustness against outliers.
- Args:
- model_features (numpy.array): A 2D numpy array of shape [images x features]
- Returns:
- numpy.array: A 1D array of Mahalanobis distances between stimuli (images).
- Raises:
- ValueError: If the input is not a 2D numpy array or has less than 2 columns.
- RuntimeError: If an error occurs during the distance calculation process.
- """
- # Validate input to ensure it is a 2D numpy array with at least 2 columns
- if not isinstance(model_features, np.ndarray) or len(model_features.shape) != 2 or model_features.shape[1] < 2:
- raise ValueError("Input must be a 2D numpy array with at least 2 variables (columns).")
- try:
- # Fit the Minimum Covariance Determinant estimator to the input data for robust covariance estimation
- cov = MinCovDet().fit(model_features)
- # Calculate the Mahalanobis distance using the robust covariance matrix
- # pdist computes pairwise distances, and we specify the Mahalanobis metric with the inverse covariance matrix
- distances = pdist(model_features, metric="mahalanobis", VI=cov.covariance_)
- except Exception as e:
- # Catch any errors that occur during the distance calculation and raise a RuntimeError
- raise RuntimeError(f"An error occurred while calculating distances: {e}")
- # Return the computed Mahalanobis distances
- return distances
- def compute_rdm(model_features, distance_metric="euclidean", rescale=False):
- """
- Compute the Representational Dissimilarity Matrix (RDM) for model features.
- The RDM is computed based on a specified distance metric, and optionally rescaled.
- The diagonal of the RDM is set to zero, and the RDM can be rescaled to the 0-1 range (excluding the diagonal).
- Args:
- model_features (np.array): Features extracted from the models in the shape [images x features].
- distance_metric (str): Distance metric to use for computing dissimilarity.
- Options are 'euclidean', 'mahalanobis', or 'pearson'.
- rescale (bool): If True, rescale the RDM to the 0-1 range, excluding the diagonal.
- Returns:
- np.array: The computed RDM as a 2D numpy array.
- """
- # Flatten the features so that each stimulus is represented as a 1D vector
- model_features = model_features.reshape(model_features.shape[0], -1)
- # Compute pairwise distances between stimuli using the specified distance metric
- if model_features.shape[1] == 1 or distance_metric == "euclidean":
- distances = pdist(model_features, metric="euclidean") # Euclidean distance
- elif distance_metric == "mahalanobis":
- distances = calculate_mahalanobis_distance(model_features) # Mahalanobis distance
- elif distance_metric == "pearson":
- distances = pdist(model_features, metric="correlation") # Pearson correlation (distance)
- else:
- # Raise an error if an invalid distance metric is specified
- raise ValueError("Invalid distance metric specified.")
- # Convert the pairwise distances into a square matrix (RDM)
- rdm = squareform(distances)
- # Rescale the RDM to the 0-1 range, excluding the diagonal if specified
- if rescale:
- rdm = normalize_rdm(rdm) # Normalizing RDM
- # Set the diagonal of the RDM to zero (diagonal represents self-similarity)
- np.fill_diagonal(rdm, 0)
- # Return the RDM
- return rdm
RDM.py at commit 8d928d6, no license · at the source
Overview
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
8d928d6a4b55ab1e14b622100a663be90c46b538, 19 September 2025Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
7 files
- RDM.py, Python, 126 lines, 1 match
- data_preprocessing.py, Python, 82 lines
- example_nb.ipynb, Jupyter, 92 lines
- main.py, Python, 31 lines
- predict.py, Python, 139 lines
- utils.py, Python, 105 lines
- Readme.md, Text, 57 lines
Zenodo 20544792
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
7 files
- RDM.py, Python, 126 lines
- data_preprocessing.py, Python, 82 lines
- example_nb.ipynb, Jupyter, 92 lines
- main.py, Python, 31 lines
- predict.py, Python, 139 lines
- utils.py, Python, 105 lines
- Readme.md, Text, 57 lines
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:
- it points to the authors' code: vital-kolab/
facial-exp-nhp , Zenodo 20544792
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:
- it points to a dataset: OSF v46jr
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://
BibTeX
@article{wehrheim2026fac
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/
url = {https://
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/
VL - 17
IS - 1
SP - 9135
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"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":
"volume": "17",
"issue": "1",
"page": "9135",
"DOI": "10.1038/
"PMID": "42649167",
"PMCID": "PMC13518822",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://
"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 communicationsIn 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 neuroscienceIn 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 communicationsIn 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 circuitsIn 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 NeuroscienceIn 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 communicationsIn 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 biologyIn 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: iScienceIn 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: eLifeIn 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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 12 scripts, and 1 match between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:529f8d9f560d610a…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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.
