Skip to main content

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

PyPI version Python 3.8+ License: MIT

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

  1. Information is generated by local comparison – edges, textures, patterns arise from comparing neighbouring regions.
  2. Centre‑surround antagonism – two sliding windows compared with a fixed displacement vector d, mimicking retinal ganglion cells.
  3. Three complementary similarity measurescos (angular), mod (magnitude), cosmod (recommended combination).
  4. Dual operational modespassive (detects boundaries without templates) and active (template matching with user‑supplied kernel).
  5. Multi‑scale and multi‑directionality – vary window size for scale, change d for orientation selectivity (vertical, horizontal, diagonal).
  6. Dimension‑agnostic – same algorithm works on 1D, 2D, 3D, 4D and beyond.
  7. Zero training, zero labels – deterministic computation, ready to use.
  8. Full determinism and interpretability – every output has a clear geometric meaning.
  9. 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.

##Imcompatible Warning I will make imcompatible changes in version 0.2 to adjust development in future. you can code it to adjust it:

import cos_comparison as core

you can change in version 0.2 as:

form cos_comparison import core

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

cos_comparison-0.1.5.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

cos_comparison-0.1.5-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file cos_comparison-0.1.5.tar.gz.

File metadata

  • Download URL: cos_comparison-0.1.5.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cos_comparison-0.1.5.tar.gz
Algorithm Hash digest
SHA256 07c190583a1bbe5bd5723581542b4aece04af8245f0f2d72d2904826d03b6516
MD5 bda050a4a309c02c36e596e4575599d7
BLAKE2b-256 77cf63f7d0e72f906d462edfb86b7fd40f1dc22a6e223f1986dfb0612c51d2e2

See more details on using hashes here.

File details

Details for the file cos_comparison-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: cos_comparison-0.1.5-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

Hashes for cos_comparison-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 90fabce1e03ca3af17d195ba51dadb70db83ad7919c7714ddc32eb07ee7a8c33
MD5 9d18e8b0c43c105e6729c8a9d2ff93ed
BLAKE2b-256 4b9165f4c7865c6caa588166b2bd08173d32e0cc3279c55d151d18dc33a8221f

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