Skip to content

Commit

Permalink
multilayer to multiway
Browse files Browse the repository at this point in the history
  • Loading branch information
letiziaia committed Apr 15, 2024
1 parent 65a80a1 commit 9ba9679
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: multilayer-alignment
name: multiway-alignment

on:
push:
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[![multilayer-alignment](https://github.com/letiziaia/multilayer-alignment/actions/workflows/validate.yml/badge.svg)](https://github.com/letiziaia/multilayer-alignment/actions/workflows/validate.yml)
[![multiway-alignment](https://github.com/letiziaia/multiway-alignment/actions/workflows/validate.yml/badge.svg)](https://github.com/letiziaia/multiway-alignment/actions/workflows/validate.yml)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/release/python-3100/)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/letiziaia/multilayer-alignment/blob/main/LICENSE)
[![codecov](https://codecov.io/gh/letiziaia/multilayer-alignment/graph/badge.svg?token=KSXP8K5A8S)](https://codecov.io/gh/letiziaia/multilayer-alignment)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/letiziaia/multiway-alignment/blob/main/LICENSE)
[![codecov](https://codecov.io/gh/letiziaia/multiway-alignment/graph/badge.svg?token=KSXP8K5A8S)](https://codecov.io/gh/letiziaia/multiway-alignment)

# multilayer-alignment
# multiway-alignment

This repository implements an algorithm for quantifying multilayer alignment or higher-order alignment, that is, the alignment across n different dimensions. You can refer to the [slide deck](https://docs.google.com/presentation/d/1HMEE5kOwwJPLBmAgycKIMSWRx0eCxd3RtSxVR1Jdczw/) for the original idea.
This repository implements an algorithm for quantifying multiway alignment or higher-order alignment, that is, the alignment across n different dimensions. You can refer to the [slide deck](https://docs.google.com/presentation/d/1HMEE5kOwwJPLBmAgycKIMSWRx0eCxd3RtSxVR1Jdczw/) for the original idea.

## Structure of the repo

- `\multilayer_alignment\`: source code
- `\multiway_alignment\`: source code
- `\tests\`: tests for the source code

## Installing the package
Expand All @@ -19,16 +19,16 @@ This repository implements an algorithm for quantifying multilayer alignment or
This package can be installed directly from the Python Package Index (PyPI) using `pip` from the command-line interface by executing the following command:

```shell
$ pip install multilayer-alignment
$ pip install multiway-alignment
```

### Build from source

Alternatively, the package can be installed by first cloning the repository containing the source code and then installing the package locally in a chosen directory:

```shell
$ git clone git@github.com:letiziaia/multilayer-alignment.git
$ cd multilayer-alignment
$ git clone git@github.com:letiziaia/multiway-alignment.git
$ cd multiway-alignment
$ pip install .
```

Expand Down
12 changes: 6 additions & 6 deletions RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ python -m unittest discover -v
```python
# import needed libraries
>>> import pandas as pd
>>> import multilayer_alignment.consensus as mac
>>> import multiway_alignment.consensus as mac

# load the opinion labels to a pandas DataFrame
>>> df = pd.DataFrame(
Expand Down Expand Up @@ -73,8 +73,8 @@ $ python -m unittest discover -v
```python
# import needed libraries
>>> import pandas as pd
>>> import multilayer_alignment.consensus as mac
>>> import multilayer_alignment.score as mas
>>> import multiway_alignment.consensus as mac
>>> import multiway_alignment.score as mas

# load the partitions labels to a pandas DataFrame
>>> df = pd.DataFrame(
Expand All @@ -92,21 +92,21 @@ $ python -m unittest discover -v

# compute 3-way alignment score using AMI (adjusted mutual info score)
# and adjust with the null model
>>> mas.multilayer_alignment_score(
>>> mas.multiway_alignment_score(
... df, partition_labels, which_score="ami", adjusted=True,
... )
6.40685300762983e-16

# compute 3-way alignment score using NMI (normalized mutual info score)
# and adjust with the null model
>>> mas.multilayer_alignment_score(
>>> mas.multiway_alignment_score(
... df, partition_labels, which_score="nmi", adjusted=True,
... )
0.0

# if we use NMI (normalized mutual info score) without adjusting it
# with a null model, the resulting score is inflated
>>> mas.multilayer_alignment_score(
>>> mas.multiway_alignment_score(
... df, partition_labels, which_score="nmi", adjusted=False,
... )
0.6666666666666666
Expand Down
127 changes: 0 additions & 127 deletions multilayer_alignment/null_models.py

This file was deleted.

File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions multilayer_alignment/score.py → multiway_alignment/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from multiprocessing.pool import Pool
from tqdm import tqdm

from multilayer_alignment.consensus import get_consensus_labels
from multiway_alignment.consensus import get_consensus_labels

from multilayer_alignment.utils.logging import logger
from multiway_alignment.utils.logging import logger


def _compute_layer_expectation(
Expand All @@ -37,7 +37,7 @@ def _compute_layer_expectation(
return np.array(_all_scores).mean()


def multilayer_alignment_score(
def multiway_alignment_score(
opinions: typing.Union[pd.DataFrame, pd.Series],
mutual_clusters_labels: typing.List,
which_score: str = "nmi",
Expand Down Expand Up @@ -92,10 +92,10 @@ def maximal_alignment_curve(
a tuple of two dictionaries, the first one including all the scores for all the combinations,
and the second one being the maximal alignment curve.
In the first dictionary, the key is the size of the combination (int) and
the list of layers and the value is a tuple, where the first element is the multilayer alignment score,
the list of layers and the value is a tuple, where the first element is the multiway alignment score,
and the second element is the dictionary of mutual communities for that combination;
In the second dictionary, the key is the size of the combination (int) and
the value is a list, where the first element is the highest multilayer alignment score for that size,
the value is a list, where the first element is the highest multiway alignment score for that size,
the second element is the list of layers that gives the highest alignment score,
and the last element is the dictionary of mutual communities for that combination
"""
Expand Down Expand Up @@ -125,7 +125,7 @@ def maximal_alignment_curve(
labels_list = get_consensus_labels(opinions=l_comb_df)

# CRITERIA
nmi = multilayer_alignment_score(
nmi = multiway_alignment_score(
l_comb_df, labels_list, which_score=which_score, adjusted=adjusted
)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import seaborn as sns # type: ignore
import typing

from multilayer_alignment.score import maximal_alignment_curve # type: ignore
from multilayer_alignment.null_models import expected_curve_equal_sized_clusters
from multilayer_alignment.utils.logging import logger
from multiway_alignment.score import maximal_alignment_curve # type: ignore
from multiway_alignment.null_models import expected_curve_equal_sized_clusters
from multiway_alignment.utils.logging import logger


def plot_maximal_alignment_curve(
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from setuptools import setup, find_packages # type: ignore

setup(
name="multilayer_alignment",
name="multiway_alignment",
version="0.1.0",
packages=find_packages(),
author="Letizia Iannucci",
author_email="letizia.iannucci@aalto.fi",
description="Quantifying multiway (higher-order) alignment with mutual information",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/letiziaia/multilayer-alignment",
url="https://github.com/letiziaia/multiway-alignment",
license="Apache 2.0",
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compute_maximal_alignment_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from multilayer_alignment.score import maximal_alignment_curve
from multiway_alignment.score import maximal_alignment_curve


class TestComputeMaximalAlignmentCurve(unittest.TestCase):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_compute_multilayer_alignment_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

import pandas as pd

from multilayer_alignment.score import multilayer_alignment_score
from multiway_alignment.score import multiway_alignment_score


class TestComputeMultilayerAlignmentScore(unittest.TestCase):
class TestComputeMultiwayAlignmentScore(unittest.TestCase):
"""
Test functionality of mutual_clusters.compute_multilayer_alignment_score()
Test functionality of mutual_clusters.compute_multiway_alignment_score()
------------
Example
------------
>>> python3 -m unittest -v tests.test_compute_multilayer_alignment_score
>>> python3 -m unittest -v tests.test_compute_multiway_alignment_score
"""

def test_on_empty(self):
"""
compute_multilayer_alignment_score returns a float
compute_multiway_alignment_score returns a float
"""
_a = pd.DataFrame({"A": [0, 1, 2]})
_labels = ["a", "b", "c"]
_res0 = multilayer_alignment_score(_a, _labels)
_res0 = multiway_alignment_score(_a, _labels)
self.assertIsInstance(
_res0,
float,
f"""compute_multilayer_alignment_score should return a float, but returned {type(_res0)}""",
f"""compute_multiway_alignment_score should return a float, but returned {type(_res0)}""",
)
self.assertGreaterEqual(
_res0,
0.0,
"""compute_multilayer_alignment_score should return the correct value of avg NMI""",
"""compute_multiway_alignment_score should return the correct value of avg NMI""",
)
self.assertLessEqual(
_res0,
1.0,
"""compute_multilayer_alignment_score should return the correct value of avg NMI""",
"""compute_multiway_alignment_score should return the correct value of avg NMI""",
)
self.assertEqual(
_res0,
1.0,
"""compute_multilayer_alignment_score should return the correct value of avg NMI""",
"""compute_multiway_alignment_score should return the correct value of avg NMI""",
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_consensus_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from multilayer_alignment.consensus import get_consensus_labels
from multiway_alignment.consensus import get_consensus_labels


class TestGetConsensusLabels(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_consensus_labels_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from multilayer_alignment.consensus import _get_consensus_labels_df
from multiway_alignment.consensus import _get_consensus_labels_df


class TestGetConsensusLabels(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_consensus_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from multilayer_alignment.consensus import get_consensus_partition
from multiway_alignment.consensus import get_consensus_partition


class TestGetConsensusPartition(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_consensus_partition_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from multilayer_alignment.consensus import get_consensus_partition_recursive
from multiway_alignment.consensus import get_consensus_partition_recursive


class TestGetConsensusPartitionRecursive(unittest.TestCase):
Expand Down

0 comments on commit 9ba9679

Please sign in to comment.