traj-dist 项目使用指南
1. 项目的目录结构及介绍
traj-dist 项目的目录结构如下:
traj-dist/
├── data/
├── traj_dist/
│ ├── distances/
│ ├── extra/
│ ├── __init__.py
│ ├── example.py
│ ├── benchmark.py
│ ├── setup.py
│ ├── pyproject.toml
│ └── setup.cfg
├── README.md
└── LICENSE
目录介绍
- data/: 包含用于测试和基准的数据文件。
- traj_dist/: 项目的主要代码目录。
- distances/: 包含各种距离计算的实现。
- extra/: 包含额外的辅助函数和工具。
- init.py: 模块初始化文件。
- example.py: 示例脚本,展示如何使用 traj-dist 计算距离。
- benchmark.py: 基准测试脚本,用于性能测试。
- setup.py: 安装脚本,用于构建和安装项目。
- pyproject.toml: 项目配置文件,用于构建工具的配置。
- setup.cfg: 项目配置文件,包含构建和安装的详细配置。
- README.md: 项目说明文档。
- LICENSE: 项目许可证文件。
2. 项目的启动文件介绍
项目的启动文件是 example.py
,它位于 traj_dist/
目录下。该文件展示了如何使用 traj-dist 计算两个二维轨迹之间的距离。
example.py 内容概述
import numpy as np
from traj_dist.distance import eucl_dist, dtw, lcss,hausdorff
# 示例轨迹数据
traj1 = np.array([[0, 0], [1, 1], [2, 2]])
traj2 = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
# 计算欧氏距离
dist_eucl = eucl_dist(traj1, traj2)
print(f"欧氏距离: {dist_eucl}")
# 计算动态时间规整(DTW)距离
dist_dtw = dtw(traj1, traj2)
print(f"DTW距离: {dist_dtw}")
# 计算最长公共子序列(LCSS)距离
dist_lcss = lcss(traj1, traj2)
print(f"LCSS距离: {dist_lcss}")
# 计算豪斯多夫(Hausdorff)距离
dist_hausdorff = hausdorff(traj1, traj2)
print(f"Hausdorff距离: {dist_hausdorff}")
3. 项目的配置文件介绍
项目的配置文件主要包括 pyproject.toml
和 setup.cfg
。
pyproject.toml
pyproject.toml
文件用于配置构建工具,如 Poetry 或 setuptools。以下是示例内容:
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "traj-dist"
version = "1.0.0"
description = "A python package for computing distance between 2D trajectories"
authors = [
{ name="Brendan Guillouet" }
]
license = { file="LICENSE" }
readme = "README.md"
requires-python = ">=3.6"
dependencies = [
"numpy",
"cython"
]
setup.cfg
setup.cfg
文件包含项目的详细配置信息,如包的元数据、构建选项等。以下是示例内容:
[metadata]
name = traj-dist
version = 1.0.0
description = A python package for computing distance between 2D trajectories
long_description = file: README.md
long_description_content_type = text/markdown
author = Brendan Guillouet
license = MIT
[options]
packages = find:
include_package_data = True
install_requires =
numpy
cy