Skip to main content

A path-oriented database for storing and analyzing sequential decision paths

Project description

FiberTree 决策路径存储与分析库

FiberTree 是一个专注于存储和分析顺序决策路径的数据库系统。它能高效地记录、存储和分析决策路径,并提供丰富的统计功能和可视化工具,帮助您优化决策过程。

特点

  • 灵活的路径存储 - 支持任何序列化决策路径的存储和检索
  • 统计分析 - 自动计算节点访问频率、胜率等统计数据
  • 路径学习 - 基于现有数据优化决策路径
  • 可视化功能 - 提供多种方式可视化决策树(文本、图形)
  • 高性能 - 优化的存储引擎,支持内存和SQLite后端
  • 易扩展 - 清晰的API设计,便于集成和扩展功能
  • 路径分析 - 提供对决策路径的深度分析功能
  • 多种可视化方案 - 支持文本、Graphviz和D3.js等多种可视化格式

应用场景

  • 棋类游戏的走法分析和学习
  • 推荐系统决策路径优化
  • 用户行为路径分析
  • 自动化测试场景覆盖分析
  • 决策支持系统
  • 强化学习的路径记录与分析

安装

使用pip安装

pip install fbtree

从源码安装

git clone https://github.com/yourusername/fbtree.git
cd fbtree
pip install -e .

基本用法

from fbtree import create_tree, Move

# 创建一个树
tree = create_tree()

# 开始构建路径
tree.start_path()

# 添加移动到路径
tree.add_move(Move("A1"))
tree.add_move(Move("B2"))
tree.add_move(Move("C3"))

# 记录结果
tree.record_outcome(win=1, score=10)

# 获取统计信息
stats = tree.get_statistics()
print(stats)

分析功能

from fbtree import create_tree, Move, analyze_path_frequency, find_winning_paths, calculate_move_impact

# 创建并填充决策树
tree = create_tree()
# ... 添加一些路径和结果 ...

# 分析不同深度的移动频率
freq_data = analyze_path_frequency(tree.get_all_fibers())
print("移动频率分析:", freq_data)

# 查找高胜率路径
winning_paths = find_winning_paths(tree.get_all_fibers(), min_visits=5, min_win_rate=0.6)
print("高胜率路径:", winning_paths)

# 计算各移动对胜率的影响
impact_data = calculate_move_impact(tree.get_all_fibers())
print("移动影响分析:", impact_data)

可视化功能

from fbtree import create_tree, Move, visualize_tree_text, generate_path_summary
from fbtree import generate_graphviz, generate_d3_json

# 创建并填充决策树
tree = create_tree()
# ... 添加一些路径和结果 ...

# 文本可视化
text_tree = visualize_tree_text(tree.get_all_fibers())
print(text_tree)

# 路径摘要
path_summary = generate_path_summary(tree.get_all_fibers(), min_visits=3)
print(path_summary)

# Graphviz可视化
dot_graph = generate_graphviz(tree.get_all_fibers(), max_depth=3, theme='light')
with open('tree_visualization.dot', 'w') as f:
    f.write(dot_graph)
    
# D3.js数据生成
d3_data = generate_d3_json(tree.get_all_fibers())
with open('tree_data.json', 'w') as f:
    f.write(d3_data)

核心概念

  • Fiber (纤维) - 表示一条完整的决策路径,由一系列的Move组成
  • Move (移动) - 决策路径中的单一步骤或决策
  • Tree (树) - 所有相关决策路径的集合
  • Storage (存储) - 负责持久化存储决策路径数据

文档

详细的API参考和使用指南请查看文档

贡献

欢迎贡献代码、报告问题或提出新的功能建议。请参阅贡献指南

许可

本项目基于MIT许可证 - 详情请参阅 LICENSE 文件

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

fbtree-1.2.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

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

fbtree-1.2.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file fbtree-1.2.0.tar.gz.

File metadata

  • Download URL: fbtree-1.2.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fbtree-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7939e9f9ed12f4361dcbb1f91a46588ecc051dfaee70560f5a14eaadc9b9c3f3
MD5 ade694f90919e5f5d1838ced29bd752c
BLAKE2b-256 bbc1742611eb718ee73029b2d525d17b228b4c4596345873668436c5a37ccac3

See more details on using hashes here.

File details

Details for the file fbtree-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: fbtree-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fbtree-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa6738c986a131d9ecbaa7de519ee9912ea9ade1b173bd46fc03a8bb7cd950a3
MD5 cb8fbc9acfaae4bb67c6850e897898d3
BLAKE2b-256 e73d8d8c2bd719156c9401f2b8e581eed3890fe4153fa88255754881e7a9c81e

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