Skip to main content

Quantum-enhanced Local Outlier Factor algorithm

Project description

QuantumLOFClassifier (Quantum Local Outlier Factor Classifier)

This package provides a quantum-enhanced version of the Local Outlier Factor (LOF) anomaly detection model, utilizing quantum computing tools such as Qiskit.

📘 Overview

QuantumLOFClassifier is an estimator based on the classical Local Outlier Factor (LOF) method, enhanced with quantum-based k-distance estimation using backends such as simulators or real quantum devices.

Note: Real quantum hardware execution is not yet tested.

  • Quantum circuit execution via Qiskit AerSimulator or IBM Quantum Runtime
  • Classical LOF concepts: k-distance, local reachability density (LRD), and LOF scores
  • Anomaly detection based on a user-defined delta threshold
  • Dual-model architecture: separate classifiers for clean and noisy data

🔍 References

This implementation is inspired by the following paper:

  • Ming-Chao Guo et al., Quantum Algorithm for Unsupervised Anomaly Detection
    • Section II.A: LOF definitions and thresholding (LOF(x) ≥ δ → anomaly)
    • Sections III.A–C: Quantum distance estimation, k-distance, LRD, and LOF calculations

🚀 Example Usage

from quantum_lof import QuantumLOFClassifier

clf = QuantumLOFClassifier(
    n_neighbors=20,
    delta=1.5,
    quantum_backend='qiskit_simulator',  # or 'ibm_cairo', etc.
    shots=512,
    random_state=42
)

clf.fit(X_train, y_train)
anomalies = clf.get_anomaly_indices()
y_pred = clf.predict(X_test)
acc_clean, f1_clean, n_clean = clf.score_clean_only(X_test, y_test)


# QuantumLOFClassifier – Compliance & Gap Report (vs. Guo 2023)

*Last updated: 20250604*

---

## 1  Executive summary *(English)*

The current `QuantumLOFClassifier` implementation **partially follows** the pipeline proposed in *Guo etal., Quantum Algorithm for Unsupervised Anomaly Detection (arXiv 2304.08710, 2023).*

* **What is really quantum?**  Only the **pairwise distance estimation** is executed on a quantum backend via a Hadamardtest circuit.
* **Where does it comply?**  It respects Sec.IIIA Eq.(1317) for turning an inner product into an Euclidean distance, and keeps the LOF formula (Sec.IIIB/C).
* **Where does it diverge?**  Every block that yields exponentialspeedup in the paper (QRAM, Quantum Minimum Search, Quantum MultiplyAdder, amplitude estimationbased LOF, Groverstyle anomaly extraction) is replaced by classical code.

Overall, the code is a **hybrid proofofconcept** rather than a strict endtoend quantum algorithm.

---

## 2  Quantum sub‑modules & level of compliance

| Paper section      | Purpose                                | Implemented? | Comment                                                                  |
| ------------------ | -------------------------------------- | ------------ | ------------------------------------------------------------------------ |
| IIIA Eq.(1314)   | Amplitude embedding of input vector    | *Partial*    | Uses `StatePreparation`; cost becomes exponential instead of O(d).      |
| IIIA Fig. 3       | Hadamard test for x\|y               | **Yes**      | Circuit generated with ancillacontrolled **U<sub>y</sub><sup></sup>**. |
| IIIA Eq.(1517)   | d(x,y)=(22x\|y)                    | **Yes**      | Exact formula applied.                                                   |
| IIIA Step 1.61.7 | **Quantum Minimum Search** (Grover)    | **No**       | Replaced by Python sort.                                                 |
| IIIB              | Quantum multiplyadder & average (LRD) | **No**       | Classical loops.                                                         |
| IIIC Eq.(18)      | Quantum LOF computation                | **No**       | Classical ratio/mean.                                                    |
| Eq.(2) & (28)      | Grover anomaly extraction              | **No**       | Classical thresholding.                                                  |

---

## 3  Major divergences & limitations

1. **Absence of QRAM**  The paper assumes a QRAM oracle O<sub>X</sub>; Qiskit/NISQ hardware do not provide this.
2. **Quantum Minimum Search skipped**  Sorting is done on CPU, losing the m quantum speedup.
3. **Quantum average / inverse missing**  LRD & LOF are computed classically.
4. **High circuit cost for StatePreparation**  `StatePreparation` scales as O(2^n) gates, conflicting with the papers lowdepth assumption.
5. **No amplitudeestimation error control**  Theoretical bounds (ε,ε,ε) are not implemented.
6. **Fallback to classical path for n>100**  The paper does not define such fallback; added for practicality.

---

## 4  Practical recommendations

* Keep the current design for real datasets; full quantum blocks are unrealistic on todays hardware.
* For small toy examples (<4 samples, <4 features) a pedagogical prototype of Quantum Minimum Search could be coded, but will not scale.
* Document clearly that the library is **quantuminspired** with a single quantum subroutine.

---

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

quantlof-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

quantlof-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantlof-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for quantlof-0.1.1.tar.gz
Algorithm Hash digest
SHA256 80bb6b4b1b774c0121c06ea8c01fa78871eb1d74c4931b88b419a30e996b9dda
MD5 c39a7fe8b6fa0b1617b395eafa20f564
BLAKE2b-256 d544668cba6c05a627aca467da2d06502b436671dd3e0729c94e3aa30dcd6060

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantlof-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for quantlof-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e528c7676723c9681b3c8918f4fd016473069a174d5a35e1283b590bb4b293
MD5 0e2dcda98a778d130d8eab2e153b2c7e
BLAKE2b-256 b898e80a4daddf374135f52ef99763b10b4fc475d70e290ad15faefa93af8c5b

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