An AGI-spurting work (experimental stage now) based on local similarity comparison for feature extraction – biologically inspired, zero‑training edge / pattern detection.
Project description
Cos Comparison
Local similarity comparison for feature extraction – biologically inspired, zero‑training edge / pattern detection.
Core Idea
Information is produced by local comparison in raw data.
This module implements the centre‑surround antagonism mechanism from neuroscience, extracting edges, textures, and keypoints using only sliding window similarity.
The main formula (cosine‑modulated similarity):
$$ \text{cosmod} = \frac{2,(A\cdot B)}{|A|^2 + |B|^2} $$
- Spurt for real AGI
- No training, no labels, no backpropagation
- Works on 1D, 2D, 3D, 4D data (audio, images, video, volumes)
- Supports passive (reflex) and active (template matching) modes
- Pure Python core + optional NumPy / C acceleration
Core Principles
- Information is generated by local comparison – edges, textures, patterns arise from comparing neighbouring regions.
- Centre‑surround antagonism – two sliding windows compared with a fixed displacement vector
d, mimicking retinal ganglion cells. - Three complementary similarity measures –
cos(angular),mod(magnitude),cosmod(recommended combination). - Dual operational modes – passive (detects boundaries without templates) and active (template matching with user‑supplied kernel).
- Multi‑scale and multi‑directionality – vary window size for scale, change
dfor orientation selectivity (vertical, horizontal, diagonal). - Dimension‑agnostic – same algorithm works on 1D, 2D, 3D, 4D and beyond.
- Zero training, zero labels – deterministic computation, ready to use.
- Full determinism and interpretability – every output has a clear geometric meaning.
- Modular, pluggable architecture – pure Python reference, NumPy vectorised, C high‑performance backends with automatic fallback.
See core_base.txt for the complete design philosophy.
⚠️ Warning
This is an experimental version!
- Do not use it in a productive environment.
- All interfaces may change during the experimental stage, although I will try to keep it as stable as possible.
- Do not share this software with others without including this warning.
Roadmap & How to Contribute
This is still an early‑stage project. You can:
- Fix bugs and report issues.
- Compare with other algorithms (deep learning, classical filters) on standard benchmarks.
- Test on diverse datasets – time series, medical images, audio, video.
- Develop the core ideas – propose new similarity metrics, add GPU backends, or integrate into larger pipelines.
If you encounter import errors after installation, try modifying the package's __init__.py:
from cos_comparison import *
Installation
pip install cos-comparison
Quick Start
import cos_comparison as cc
# 1D passive: find similar segments
data = [1.0, 2.0, 3.0, 4.0, 5.0]
result = cc.cos_comparison_passive_1d(data, window_size=(2,), step=(1,), d=(1,))
print(result)
# 2D passive: edge detection
image = [[1,1,0,0], [1,1,0,0], [0,0,1,1], [0,0,1,1]]
edges = cc.cos_comparison_passive_2d(image, window_size=(2,2), step=(1,1), d=(1,0))
print(edges)
# Active mode – template matching
kernel = [1.0, 0.0]
result_active = cc.cos_comparison_active_1d(data, kernel=kernel, step=(1,))
print(result_active)
# Whole‑tensor cosine
a, b = [1,2,3], [2,3,4]
sim = cc.cos_1d(a, b)
print(sim)
Optional Backends
The package automatically selects the fastest available backend:
| Priority | Backend | Requirement |
|---|---|---|
| 1 | C | Compile cos_comparison_c/include/core.c |
| 2 | NumPy | pip install numpy |
| 3 | Pure Python | Works out of the box |
Force a specific backend via environment variable:
export COS_BACKEND=cos_comparison,cos_comparison_numpy
API Overview
Passive mode (self‑similarity)
cos_comparison_passive_1d / _2d / _3d / _4d + generic N‑dim
Active mode (template matching)
cos_comparison_active_1d / _2d / _3d / _4d + generic N‑dim
Whole‑tensor cosine
cos_1d / _2d / _3d / _4d
Statistics
mean_local_* / local_variance_* – sliding window mean and variance
Command line
python -m cos_comparison passive --data input.json --window 3 3 --output out.json
License
MIT © 2025 Li Jinxin. See LICENSE for details.
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 cos_comparison-0.1.4.tar.gz.
File metadata
- Download URL: cos_comparison-0.1.4.tar.gz
- Upload date:
- Size: 29.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b2f7217d5cd66a30fc5bbb67901e7961af150a39280b85aed439d6bfff93e92
|
|
| MD5 |
74b9e6bc2e51cd00b51859ee4c358c06
|
|
| BLAKE2b-256 |
58f0906311ab4cd81bc815c77ecd39485fd47aed21283287d05d9e302a0dcf66
|
File details
Details for the file cos_comparison-0.1.4-py3-none-any.whl.
File metadata
- Download URL: cos_comparison-0.1.4-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36b1ab8201af6a9e4c223aef49971e007bbc06eabcc3347863c28ff2960ce8b
|
|
| MD5 |
ef5f06e593ce3d162f71c0bceb91be1b
|
|
| BLAKE2b-256 |
f6de741f098b62bb4eaec23bd035f8687ffebb68c6da150df86ccca126924c23
|