Method for structural preservation via Attractiveness-based Pairwise Embedding
Project description
README.md
# MAPE: Method for structural preservation via Attractiveness-based Pairwise Embedding
MAPE is a custom embedding tool designed to preserve structural relationships through pairwise attractiveness modeling.
It uses mutual pair extraction and repel-enhanced loss to generate interpretable low-dimensional representations.
Ideal for educational, linguistic, and visualization tasks.
---
## Dependencies
MAPE requires the following Python libraries with specific version constraints to ensure compatibility and reproducibility:
| Library | Required Version Range |
|----------------|----------------------------|
| `numpy` | >=1.26, <2.0 |
| `pandas` | >=2.2, <2.3 |
| `scipy` | >=1.11, <1.12 |
| `scikit-learn` | >=1.4, <1.5 |
| `matplotlib` | >=3.8, <3.9 |
| `torch` | >=2.4, <2.5 |
> Please ensure these versions are installed before running MAPE.
> Using other versions may result in unexpected behavior or compatibility issues.
To install the required dependencies manually:
```bash
pip install numpy>=1.26,<2.0 pandas>=2.2,<2.3 scipy>=1.11,<1.12 scikit-learn>=1.4,<1.5 matplotlib>=3.8,<3.9 torch>=2.4,<2.5
---
## Installation
To install locally from source:
```bash
pip install .
To install from TestPyPI:
pip install -i https://test.pypi.org/simple/ mape
CLI Usage
To reduce the dimensionality of a dataset containing a label column, use the following command:
mape data.csv --n_components 2 --output_csv result.csv --plot_file result.png
Key Options
-
--output_csv result.csv
Saves the low-dimensional coordinates toresult.csv. -
--n_components 2
Specifies that the data should be reduced to 2 dimensions. -
--plot_file result.png
Generates a scatter plot (result.png) with points color-coded by their label values.
The tool automatically extracts numeric columns for embedding and uses the
labelcolumn (if present) for visualization.
To see all available options:
sppa --help
Python API Usage
To generate low-dimensional coordinates and a 2D scatter plot from your dataset, run the following script.
Make sure that data.csv is placed in the same directory.
# test.py
from mape import run_embedding
from mape.mape import DEFAULT_PARAMS
run_embedding("data.csv", output_csv="result.csv", plot_file="result.png", **DEFAULT_PARAMS)
This will produce:
result.csv: a file containing the embedded coordinatesresult.png: a scatter plot where points are color-coded by their label (if present)
Input Format
The input CSV should contain:
- One or more numeric columns (used for embedding)
- An optional
labelcolumn (used for coloring the scatter plot)
Example:
label,value1,value2,value3
A,1.0,2.0,3.0
B,2.5,3.1,1.2
A,0.9,1.8,2.5
C,3.0,2.9,0.5
Parameters
You can customize the embedding behavior using the following parameters:
| Parameter | Description | Default |
|---|---|---|
n_components |
Target dimensionality | 2 |
steps |
Optimization steps | 300 |
k |
Number of neighbors for mutual pair extraction | 5 |
alpha1 |
Weight for cosine similarity | 5.0 |
alpha2 |
Weight for Euclidean distance | 1.0 |
a, b |
Kernel shape parameters | 1.0 |
alpha_mix |
Mixing ratio between standard and Gaussian kernel | 0.5 |
tau, gamma |
Repel threshold and sharpness | 0.5, 30.0 |
lambda_repel |
Weight of repel loss | 5.0 |
init_mode |
Initialization method (random, pca, spectral) |
spectral |
device |
Computation device (cpu or cuda) |
cpu |
Output
embedding.csv: Contains the embedded coordinates and labelsembedding_result.png: 2D scatter plot (ifn_components == 2)
License
This project is licensed under the MIT License.
See the LICENSE file for details.
Author
Takeshi Matsuda
Hannan University – Information Science
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mape-0.1.2.tar.gz.
File metadata
- Download URL: mape-0.1.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4d04d5335002a8d7119b59cac05b951043688a97ba334ffca3b9fde7683b554
|
|
| MD5 |
92333a4c67de5d60b64e7e7a1780557a
|
|
| BLAKE2b-256 |
8e04e4282602d1f818bcb8c5103d0e4bdb82166821f8f4c18329249782147fc0
|
File details
Details for the file mape-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mape-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
691db11c92c3a11136a63fea7f4270121f2301b18f704ba43e8c4def5801359e
|
|
| MD5 |
248e2b0bd56a6b35d5f7c72cb933ed86
|
|
| BLAKE2b-256 |
f949ad31805555b6d4ced848815d8fcd61d92a3e8d40b4d5cc3c79a02c3f1470
|