Skip to content

Commit becb133

Browse files
Initial commit: Range–CoMine impl + baselines + experiments + lattice export + tests + CI + packaging + docker
0 parents  commit becb133

42 files changed

Lines changed: 7712 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
name: CI
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
jobs:
9+
test-and-plots:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.11'
16+
- name: Install deps
17+
run: python -m pip install -U pip pytest matplotlib
18+
- name: Run tests
19+
run: pytest -q
20+
- name: Generate example plots
21+
run: |
22+
python experiments.py --mode min_prev --mins 0.3,0.5 --d1 8 --d2 25 --features 3 --instances 4 --seed 5 --algos range,naive --export_svg
23+
python experiments.py --mode range --min_prev 0.5 --d1s 3 --d2s 6,8 --csv examples/toy.csv --algos range,naive --export_svg
24+
python lattice_export.py --outfile lattice_demo --d1 8 --d2 30 --min_prev 0.5 --features 4 --instances 5 --seed 7 --cross_level --png
25+
- name: Upload plots
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: plots
29+
path: plots/**

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# Simple reproducible container for Range–CoMine
3+
FROM python:3.11-slim
4+
5+
# System deps for matplotlib (headless)
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
build-essential \
8+
libfreetype6-dev \
9+
libpng-dev \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /app
13+
COPY . /app
14+
15+
# Install package + deps
16+
RUN python -m pip install -U pip && \
17+
pip install -r requirements.txt && \
18+
pip install -e .
19+
20+
# Default command runs tests; override with `docker run ... <cmd>`
21+
CMD ["pytest", "-q"]

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.PHONY: install test plots lattice all
2+
3+
install:
4+
python -m pip install -U pip pytest matplotlib
5+
6+
test:
7+
pytest -q
8+
9+
plots:
10+
python experiments.py --mode min_prev --mins 0.3,0.5 --d1 8 --d2 25 --features 3 --instances 4 --seed 5 --algos range,naive --export_svg
11+
python experiments.py --mode range --min_prev 0.5 --d1s 3 --d2s 6,8 --csv examples/toy.csv --algos range,naive --export_svg
12+
13+
lattice:
14+
python lattice_export.py --outfile lattice_demo --d1 8 --d2 30 --min_prev 0.5 --features 4 --instances 5 --seed 7 --cross_level --png
15+
16+
all: install test plots lattice
17+
18+
19+
lock:
20+
pip install -r requirements.txt && pip freeze > requirements.lock
21+
22+
docker-build:
23+
docker build -t range-comine:latest .
24+
25+
docker-test:
26+
docker run --rm -v $(PWD)/plots:/app/plots range-comine:latest
27+
28+
docker-minprev:
29+
docker run --rm -v $(PWD)/plots:/app/plots range-comine:latest \
30+
python experiments.py --mode min_prev --mins 0.3,0.5 --d1 8 --d2 25 --features 3 --instances 4 --seed 5 --algos range,naive --export_svg
31+
32+
docker-range:
33+
docker run --rm -v $(PWD)/plots:/app/plots range-comine:latest \
34+
python experiments.py --mode range --min_prev 0.5 --d1s 3 --d2s 6,8 --csv examples/toy.csv --algos range,naive --export_svg
35+
36+
docker-lattice:
37+
docker run --rm -v $(PWD)/plots:/app/plots range-comine:latest \
38+
python lattice_export.py --outfile lattice_demo --d1 8 --d2 30 --min_prev 0.5 --features 4 --instances 5 --seed 7 --cross_level --png

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Range–CoMine (demo implementation)
2+
3+
This repository contains a **reference implementation** of *Range–CoMine* (single‑pass colocation mining for a **distance range**) and two baselines (Naive and RangeInc‑Mining). It is designed for clarity and correctness on small–medium datasets.
4+
5+
## Quick start
6+
7+
```bash
8+
# (In this folder)
9+
python -m range_comine.cli --synthetic --features 4 --instances 6 --d1 10 --d2 35 --min_prev 0.5 --algo range_comine
10+
```
11+
12+
Use the baselines:
13+
```bash
14+
python -m range_comine.cli --synthetic --features 4 --instances 6 --d1 10 --d2 35 --min_prev 0.5 --algo naive
15+
python -m range_comine.cli --synthetic --features 4 --instances 6 --d1 10 --d2 35 --min_prev 0.5 --algo range_inc
16+
```
17+
18+
## Data format
19+
20+
If using real data, prepare a CSV with header:
21+
```
22+
id,feature,x,y
23+
A.1,A,12.3,45.6
24+
...
25+
```
26+
27+
## Notes
28+
29+
- This demo uses an O(n^2) star‑neighborhood build and a naive clique enumeration for k≥3. It is faithful to the paper’s logic but not tuned for very large datasets.
30+
- For production scale, replace the neighbor construction with an **R‑tree/IR‑tree** and use a **join‑less** clique enumeration with star instances as in the paper.
31+
- The **critical distance** computation follows the 3‑step procedure (map → cumulative union → PI sweep) and **CDMP** pruning.
32+
33+
## Citation
34+
35+
Please cite the original paper when using this code.
36+
37+
38+
## Credits
39+
40+
This reference implementation follows the ideas presented in:
41+
42+
> **Srikanth Baride, Anuj S. Saxena, Vikram Goyal.** *Efficiently Mining Colocation Patterns for Range Query.* **Big Data Research**, 31:100369, 2023.
43+
44+
If you use this repository in academic work, please cite the above paper. (BibTeX sketch)
45+
46+
```bibtex
47+
@article{Baride2023RangeCoMine,
48+
title = {Efficiently Mining Colocation Patterns for Range Query},
49+
author = {Baride, Srikanth and Saxena, Anuj S. and Goyal, Vikram},
50+
journal = {Big Data Research},
51+
volume = {31},
52+
pages = {100369},
53+
year = {2023},
54+
issn = {2214-5796}
55+
}
56+
```
57+
58+
59+
## Experiments (CLI + SVG export)
60+
61+
Synthetic:
62+
```bash
63+
python experiments.py --mode min_prev --mins 0.2,0.4,0.6 --d1 10 --d2 35 --features 4 --instances 8 --seed 13 --algos range,naive,range_inc --export_svg
64+
```
65+
66+
CSV dataset:
67+
```bash
68+
python experiments.py --mode range --min_prev 0.5 --d1s 5,10 --d2s 20,30 --csv examples/toy.csv --algos range,naive --export_svg
69+
```
70+
71+
## Lattice export (PDF/SVG)
72+
```bash
73+
python lattice_export.py --outfile lattice_demo --d1 8 --d2 30 --min_prev 0.5 --features 4 --instances 5 --seed 7
74+
# outputs plots/lattice_demo.pdf and plots/lattice_demo.svg
75+
```
76+
77+
## Tests
78+
```bash
79+
pytest -q
80+
```
81+
82+
83+
## Makefile shortcuts
84+
```bash
85+
make install # deps
86+
make test # run pytest
87+
make plots # quick sweeps + SVG
88+
make lattice # lattice export (PDF/SVG/PNG, cross-level edges)
89+
make all # install + test + plots + lattice
90+
```
91+
92+
## CI (GitHub Actions)
93+
A workflow at `.github/workflows/ci.yml` runs:
94+
- `pytest`
95+
- sample experiments (min_prev/range) with SVG export
96+
- lattice export with cross-level edges and PNG
97+
- uploads `plots/` as build artifacts
98+
99+
100+
## Packaging
101+
Install in editable/development mode:
102+
```bash
103+
./dev_install.sh
104+
# or
105+
pip install -e .
106+
```
107+
108+
109+
## Console scripts
110+
After `pip install -e .`, you can run:
111+
```bash
112+
range-comine-cli --synthetic --features 4 --instances 6 --d1 10 --d2 35 --min_prev 0.5 --algo range_comine
113+
range-comine-exp --mode min_prev --mins 0.2,0.4,0.6 --d1 10 --d2 35 --features 4 --instances 8 --seed 13 --algos range,naive,range_inc --export_svg
114+
range-comine-lattice --outfile lattice_demo --d1 8 --d2 30 --min_prev 0.5 --features 4 --instances 5 --seed 7 --cross_level --png
115+
```
116+
117+
## Lockfiles
118+
- Classic pip:
119+
```bash
120+
make lock # creates requirements.lock via pip freeze
121+
```
122+
- Using **uv**:
123+
```bash
124+
uv venv && uv pip install -e .
125+
uv lock # creates uv.lock
126+
```
127+
128+
## Docker
129+
```bash
130+
make docker-build # build image
131+
make docker-test # run tests in container
132+
make docker-minprev # min_prev sweep (plots mounted to ./plots)
133+
make docker-range # range sweep (plots mounted to ./plots)
134+
make docker-lattice # lattice export (PDF/SVG/PNG)
135+
```

dev_install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#!/usr/bin/env bash
3+
set -euo pipefail
4+
python -m pip install -U pip
5+
pip install -e .
6+
echo "Installed range-comine in editable mode."

examples/toy.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
id,feature,x,y
2+
A.1,A,0,0
3+
A.2,A,10,0
4+
A.3,A,20,0
5+
B.1,B,0,8
6+
B.2,B,12,1
7+
B.3,B,22,2
8+
C.1,C,1,20
9+
C.2,C,13,19
10+
C.3,C,25,18
11+
D.1,D,2,28
12+
D.2,D,14,27
13+
D.3,D,26,26

0 commit comments

Comments
 (0)