Skip to main content

Embedding Method for Structural Preservation via Pairwise Attractiveness

Project description

README.md

# SPPA: Structural Preservation via Pairwise Attractiveness Algorithm

A custom embedding tool using mutual pair extraction and repel-enhanced loss.  
Designed for educational, linguistic, and visualization tasks.

---

## 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 to result.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 label column (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 coordinates
  • result.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 label column (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 labels
  • embedding_result.png: 2D scatter plot (if n_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mape-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mape-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file mape-0.1.1.tar.gz.

File metadata

  • Download URL: mape-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for mape-0.1.1.tar.gz
Algorithm Hash digest
SHA256 44773a600b671ca6e5bd23004594cc07861f8f756e5d43130e46fd2c691a07f8
MD5 398c5658bf4f7c34f5c870bc17a28e45
BLAKE2b-256 b2d259dd944912b960b2920dcb76ec6472433e4aade982315e7ebf4ebf317613

See more details on using hashes here.

File details

Details for the file mape-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mape-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for mape-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50d5cf3bb3305911746157464f20854fdebc331f29d9a4b223ef07e18dbf996c
MD5 220d012a79f2605048388479f3ef05c8
BLAKE2b-256 6125eab821f1f41e22e1eea8c9935f05c2ed5b0bbfdfb24a9ebd4e8556f1f44d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page