sangge 5a62c6e689 Implement fully homomorphic encryption (FHE) based KNN classifier
This commit adds a complete FHE-based K-nearest neighbors implementation using TFHE:

Key Features:
- Encrypts training data and query vectors using FheInt32 and FheUint8
- Implements encrypted Euclidean distance calculation with 100x scaling for precision
- Uses bitonic sorting with encrypted conditional swaps for secure k-selection
- Includes comprehensive progress tracking and timing for long-running operations
- Memory optimizations: pre-allocated vectors and reused encrypted constants

Algorithm Implementation:
- Encrypted distance computation with homomorphic arithmetic operations
- Bitonic sort algorithm adapted for encrypted data structures
- Secure index tracking with encrypted FheUint8 values
- Select API usage for conditional swaps maintaining data privacy

Performance:
- Handles 100 training points with 10 dimensions in ~98 minutes on consumer hardware
- Includes detailed progress bars and time estimation
- Results validated against plain-text implementation (8/10 match rate)

Documentation:
- Comprehensive function documentation for all core algorithms
- Time complexity analysis and performance benchmarking notes
- Clear separation between client-side encryption/decryption and server-side computation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-07 09:16:41 +08:00

hfe_knn

全同态加密下的KNN算法实现

knn算法关键是使用一个距离函数来计算样本之间的距离常用的距离函数有欧氏距离、曼哈顿距离等。 计算距离可以在全密文下实现。 主要是寻找一个全同态加密的比较大小方案

全同态加密计划使用TFHE-rs, 简化后流程无须交互,仅在单个程序内模拟即可。 评分详情见参赛手册

评分机制

正确率计算

  • 算法需要返回10个最近邻向量的索引
  • 正确率 = 正确的索引数量 / 10
  • 例如10个结果中有9个正确正确率 = 90%

评分规则

  • 门槛要求正确率必须≥90%即10个结果中至少9个正确
  • 排名依据:达到门槛后,按总耗时排名(越快越好)
  • 淘汰机制:正确率<90%直接得0分

"正确"的定义

  • 比赛方有标准答案真实的10个最近邻
  • 算法结果与标准答案比较
  • 顺序不重要,只要索引正确即可

数据格式

  • 训练数据JSONL格式每行包含一个query向量和data数组
  • 输出格式:{"answer": [索引1, 索引2, ..., 索引10]}
  • 索引从1开始编号
Description
No description provided
Readme MIT 248 KiB
Languages
Rust 75.2%
Python 18.2%
Shell 4.6%
Dockerfile 2%