模拟MCP
AI系统的现实引擎
  ](https://pypi.org/project/simulacrum-mcp/)    
拟像 是一个全面的工具包,可以将人工智能系统转换为复杂的现实模拟器。通过提供先进的数学建模、系统动力学模拟和混沌分析,它使人工智能能够通过严格的计算方法理解和预测复杂的现实世界现象。
🌟 主要特点
岩心模拟工具
- 系统动力学仿真 -用微分方程和反馈回路对复杂系统进行建模
- 场景比较 -使用复杂的相似性度量进行A/B现实测试
- 反馈回路分析 -识别强化/平衡循环及其系统影响
- 信念动力学 -用于社会和认知建模的心理理论模拟
- 博弈分析 -战略均衡分析与学习动态
- 贝叶斯推理 -用概率证据分析代替“我认为”
- 混沌检测 -识别黑天鹅事件和预警信号
- 概念向量分析 -分析多维空间中的复杂关系和冲突
高级分析工具
- 蒙特卡洛模拟 -具有不确定性量化和风险分析的随机建模
- 数学优化 -具有约束支持的线性/非线性规划
- 因果图分析 -基于Pearl do算子和d-分离的反事实推理
- 网络分析 -具有中心性度量的图论与社区检测
- 敏感性分析 -基于Sobol指数和Morris筛选的参数重要性排序
技术卓越
- 100%测试覆盖率 -pytest和假设的综合检验
- MCP集成 -通过模型上下文协议无缝集成光标AI
🚀 快速开始
先决条件
- Python 3.8或更高版本
- pip包管理器
安装
- 克隆存储库:
git clone https://github.com/codesmirnov/simulacrum-mcp.git
cd simulacrum-mcp- 安装依赖项:
pip install -r requirements.txt- 安装软件包:
pip install -e .Cursor AI集成
- 在游标中配置MCP:
添加到光标设置(.cursorrules 或全局设置):
{
"mcp": {
"servers": {
"simulacrum": {
"command": "python",
"args": ["-m", "simulacrum.server"],
"env": {}
}
}
}
}- 验证安装:
simulacrum-server --help📖 使用示例
系统动力学仿真
from simulacrum import DynamicsSimulator
# Define a predator-prey model
scenario = {
"name": "Lotka-Volterra Predator-Prey",
"variables": [
{"name": "prey", "initial_value": 10.0, "min_value": 0},
{"name": "predator", "initial_value": 5.0, "min_value": 0}
],
"equations": [
{
"target_variable": "prey",
"expression": "prey * (2.0 - 0.01 * predator)"
},
{
"target_variable": "predator",
"expression": "predator * (-1.0 + 0.01 * prey)"
}
],
"config": {
"time_config": {
"end_time": 50.0,
"time_step": 0.1
}
}
}
simulator = DynamicsSimulator()
result = simulator.simulate_dynamics(scenario)
print(f"Simulation completed: {result['status']}")贝叶斯信念更新
from simulacrum import ProbabilityAnalyzer
analyzer = ProbabilityAnalyzer()
# Update beliefs with evidence
analysis = {
"analysis_type": "bayesian_update",
"prior": {"rain": 0.3, "no_rain": 0.7},
"likelihood": {
"cloudy": {"rain": 0.8, "no_rain": 0.4}
},
"evidence": [
{"hypothesis": "rain", "observation": "cloudy", "strength": 1.0}
]
}
result = analyzer.analyze_probability(analysis)
print(f"Updated belief in rain: {result['final_posterior']['rain']:.2%}")混沌分析
from simulacrum import ChaosAnalyzer
analyzer = ChaosAnalyzer()
# Analyze time series for chaotic behavior
time_series_data = {
"time_series": [0.1, 0.15, 0.08, 0.12, 0.18, 0.14, 0.09, 0.16, ...]
}
result = analyzer.analyze_chaos(time_series_data)
print(f"System state: {result['overall_assessment']['system_state']}")
print(f"Risk level: {result['overall_assessment']['risk_level']}")概念向量分析
from simulacrum import VectorAnalyzer
analyzer = VectorAnalyzer()
# Analyze strategic alignment between different entities
vectors = [
{
"name": "Innovation_Focus",
"components": {"growth": 0.8, "stability": -0.2, "innovation": 0.9}
},
{
"name": "Market_Reality",
"components": {"growth": 0.3, "stability": 0.7, "innovation": 0.1}
}
]
strengths = [
{"name": "Innovation_Focus", "value": 1.5},
{"name": "Market_Reality", "value": 1.0}
]
result = analyzer.multidimensional_vector_analysis(vectors, strengths)
print(f"Total system magnitude: {result['total_magnitude']:.4f}")
print(f"Top dimensions: {', '.join([d['dimension'] for d in result['top_dimensions']])}")蒙特卡洛模拟
from simulacrum import MonteCarloSimulator
simulator = MonteCarloSimulator()
# Model with uncertainty
def profit_model(price, cost, demand):
return (price - cost) * demand
simulation = {
"model": profit_model,
"parameter_distributions": {
"price": {"type": "normal", "params": {"mean": 100, "std": 10}},
"cost": {"type": "uniform", "params": {"low": 60, "high": 80}},
"demand": {"type": "triangular", "params": {"low": 50, "mode": 100, "high": 200}}
},
"n_iterations": 5000,
"confidence_levels": [0.95, 0.99]
}
result = simulator.simulate_monte_carlo(simulation)
print(f"Expected profit: ${result['statistics']['output']['mean']:.0f}")
print(f"95% VaR: ${result['statistics']['output']['risk_metrics']['var_95']:.0f}")因果分析
from simulacrum import CausalAnalyzer
analyzer = CausalAnalyzer()
# Define causal graph
causal_graph = {
"nodes": ["Smoking", "Cancer", "Age"],
"edges": [("Smoking", "Cancer"), ("Age", "Cancer"), ("Age", "Smoking")],
"queries": [{
"type": "causal_effect",
"cause": "Smoking",
"effect": "Cancer"
}]
}
result = analyzer.analyze_causal_graph(causal_graph)
effect = result["queries"][0]
print(f"Causal effect identifiable: {effect['identifiable']}")🧪 测试
运行综合测试套件:
# Install test dependencies
pip install -e ".[dev]"
# Run all tests with coverage
pytest --cov=simulacrum --cov-report=html
# Run specific test categories
pytest tests/test_dynamics.py
pytest tests/test_probability.py
pytest tests/test_chaos.py
pytest tests/test_vector_analysis.py🏗️ 建筑
核心原则
- 单一责任 -每门课都有一个明确的目的
- 打开/关闭 -无需修改现有代码即可扩展
- 里氏替换 -子类型可以替代基类型
- 接口隔离 -客户端仅依赖于它们使用的方法
- 依赖倒置 -依赖抽象,而非具体
包结构
simulacrum/
├── core/ # Core engine and interfaces
├── tools/ # Analysis tools and simulators
├── validation/ # Data validation and type safety
└── server.py # MCP server implementation🤝 贡献
我们欢迎捐款!请查看我们的 贡献指南 了解详情。
行为准则
请注意,此项目随附 贡献者行为准则参与此项目即表示您同意遵守其条款。
安全
有关安全相关问题,请参阅我们的 安全策略.
开发设置
# Clone and setup
git clone https://github.com/codesmirnov/simulacrum-mcp.git
cd simulacrum-mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
black simulacrum/
isort simulacrum/
mypy simulacrum/📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 专为人工智能安全和对齐研究社区打造
- 受系统动力学、混沌理论和贝叶斯认识论的启发
- 专为人工智能辅助系统的实际部署而设计
📞 联系
codesmirnov
- github: @codesmirnov
- 电子邮件:hello@codesmirnov.ru
______________________________________________________________________
将人工智能从模式识别转变为现实模拟。
