ASP-KNN: a declarative, constraint-aware, and explainable reformulation of k-Nearest Neighbors in answer set programming

The classical k-Nearest Neighbors (KNN) algorithm provides a simple and effective non-parametric approach to classification, but its procedural formulation offers limited transparency and lacks mechanisms for incorporating domain constraints or reasoning control. This paper introduces ASP-KNN, a declarative reformulation of KNN using Answer Set Programming (ASP), where neighbor selection, ranking, and vote aggregation are expressed through logical rules. The baseline ASP-KNN program closely reproduces the predictive behavior of classical KNN while exposing intermediate reasoning structures such as selected neighbors and vote distributions. Building on this formulation, we introduce two declarative extensions. The first extension incorporates label exclusion constraints that prevent the assignment of forbidden labels directly within the classification process. The second extension introduces a soft preference mechanism that refines decisions in ambiguous neighborhoods by favoring assignments supported by closer neighbors. Experiments on five widely used public benchmark datasets (Iris, Wine, Breast Cancer, Pima Diabetes, and Sonar), together with a lightweight comparison to a standard interpretable classifier (Decision Tree), suggest that the baseline ASP formulation closely reproduces the predictive behavior of classical KNN while enabling explicit constraint enforcement and interpretable reasoning traces. The constraint-based extension guarantees zero violations of forbidden labels, while the preference mechanism refines decisions in ambiguous neighborhood configurations without significantly altering overall predictive performance. Runtime analysis further reveals a computational trade-off between reasoning flexibility and efficiency, with most overhead arising from ASP grounding. Overall, ASP-KNN suggests that instance-based classification can be reformulated as a transparent and extensible reasoning process, enabling the integration of constraints, preferences, and symbolic explanations within a unified KNN framework.

Authors

Institutions

Publication Details

Journal
Journal of King Saud University - Computer and Information Sciences
Published
2026-05-14
DOI
https://doi.org/10.1007/s44443-026-00833-0
Primary Topic
Logic, Reasoning, and Knowledge
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

ASP-KNN: a declarative, constraint-aware, and explainable reformulation of k-Nearest Neighbors in answer set programming

Xunpeng Xia, Dongjie Tang, Liu Liu
Journal of King Saud University - Computer and Information Sciences
Logic, Reasoning, and Knowledge
article

ASP-KNN: a declarative, constraint-aware, and explainable reformulation of k-Nearest Neighbors in answer set programming

Xunpeng Xia, Dongjie Tang, Liu Liu
article en

Abstract

The classical k-Nearest Neighbors (KNN) algorithm provides a simple and effective non-parametric approach to classification, but its procedural formulation offers limited transparency and lacks mechanisms for incorporating domain constraints or reasoning control. This paper introduces ASP-KNN, a declarative reformulation of KNN using Answer Set Programming (ASP), where neighbor selection, ranking, and vote aggregation are expressed through logical rules. The baseline ASP-KNN program closely reproduces the predictive behavior of classical KNN while exposing intermediate reasoning structures such as selected neighbors and vote distributions. Building on this formulation, we introduce two declarative extensions. The first extension incorporates label exclusion constraints that prevent the assignment of forbidden labels directly within the classification process. The second extension introduces a soft preference mechanism that refines decisions in ambiguous neighborhoods by favoring assignments supported by closer neighbors. Experiments on five widely used public benchmark datasets (Iris, Wine, Breast Cancer, Pima Diabetes, and Sonar), together with a lightweight comparison to a standard interpretable classifier (Decision Tree), suggest that the baseline ASP formulation closely reproduces the predictive behavior of classical KNN while enabling explicit constraint enforcement and interpretable reasoning traces. The constraint-based extension guarantees zero violations of forbidden labels, while the preference mechanism refines decisions in ambiguous neighborhood configurations without significantly altering overall predictive performance. Runtime analysis further reveals a computational trade-off between reasoning flexibility and efficiency, with most overhead arising from ASP grounding. Overall, ASP-KNN suggests that instance-based classification can be reformulated as a transparent and extensible reasoning process, enabling the integration of constraints, preferences, and symbolic explanations within a unified KNN framework.

Journal of King Saud University - Computer and Information Sciences
Shanghai Customs College (CN)
Reduced inequalities
Openalex Percentile: Top 3%
Logic, Reasoning, and Knowledge
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.