papilon 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- papilon-0.1.0/LICENSE +21 -0
- papilon-0.1.0/PKG-INFO +13 -0
- papilon-0.1.0/README.md +57 -0
- papilon-0.1.0/papilon/__init__.py +7 -0
- papilon-0.1.0/papilon/causal.py +25 -0
- papilon-0.1.0/papilon/energy.py +5 -0
- papilon-0.1.0/papilon/entropy.py +10 -0
- papilon-0.1.0/papilon/optimizer.py +17 -0
- papilon-0.1.0/papilon/relationships.py +32 -0
- papilon-0.1.0/papilon/simulation.py +10 -0
- papilon-0.1.0/papilon/states.py +10 -0
- papilon-0.1.0/papilon.egg-info/PKG-INFO +13 -0
- papilon-0.1.0/papilon.egg-info/SOURCES.txt +17 -0
- papilon-0.1.0/papilon.egg-info/dependency_links.txt +1 -0
- papilon-0.1.0/papilon.egg-info/requires.txt +6 -0
- papilon-0.1.0/papilon.egg-info/top_level.txt +1 -0
- papilon-0.1.0/pyproject.toml +24 -0
- papilon-0.1.0/setup.cfg +19 -0
papilon-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vector1 Research
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
papilon-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: papilon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Papilon: A Statistical Mechanics Framework for Causal Data Simulation
|
|
5
|
+
Author-email: Your Name <you@example.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: numpy
|
|
8
|
+
Requires-Dist: pandas
|
|
9
|
+
Requires-Dist: scikit-learn
|
|
10
|
+
Requires-Dist: seaborn
|
|
11
|
+
Requires-Dist: matplotlib
|
|
12
|
+
Requires-Dist: networkx
|
|
13
|
+
Dynamic: license-file
|
papilon-0.1.0/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Papilon ๐ฆ
|
|
2
|
+
|
|
3
|
+
**Papilon** is a Python library for exploring the statistical mechanics of complex systems. Inspired by the butterfly effect and chaos theory, Papilon enables researchers and data scientists to simulate, analyze, and optimize dynamic systems through entropy modeling, causal inference, and scenario generation.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## โจ Features
|
|
8
|
+
|
|
9
|
+
- ๐ **Entropy & Energy Modeling** โ quantify system uncertainty
|
|
10
|
+
- ๐ **Causal Inference** โ reveal hidden directional relationships
|
|
11
|
+
- ๐ฌ **Scenario Simulation** โ generate alternative state evolutions
|
|
12
|
+
- ๐ง **Optimization Engine** โ search for efficient configurations
|
|
13
|
+
- ๐งฉ **Relationship Discovery** โ mutual information & correlation
|
|
14
|
+
- ๐ **Optional MMM & Regression** โ model outcome influence
|
|
15
|
+
|
|
16
|
+
## ๐ฆ Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/YOUR_USERNAME/papilon.git
|
|
20
|
+
cd papilon
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> Requires: Python 3.8+, numpy, pandas, matplotlib, seaborn, scikit-learn, networkx, statsmodels
|
|
25
|
+
|
|
26
|
+
## ๐ Example Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from papilon import (
|
|
30
|
+
shannon_entropy,
|
|
31
|
+
simulate_kde_scenarios,
|
|
32
|
+
analyze_relationships,
|
|
33
|
+
infer_causal_structure,
|
|
34
|
+
grid_search_optimize
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
See [`examples/`](examples/) for a full end-to-end complex systems notebook.
|
|
39
|
+
|
|
40
|
+
## ๐ Use Cases
|
|
41
|
+
|
|
42
|
+
- Studying dynamic system behavior (ecology, traffic, climate)
|
|
43
|
+
- Testing interventions under causal feedback
|
|
44
|
+
- Finding stable/efficient parameter regimes
|
|
45
|
+
- Teaching entropy, causality, and complexity science
|
|
46
|
+
|
|
47
|
+
## ๐งช Example Output
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## ๐ License
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
_Developed with curiosity and chaos in mind._
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .entropy import shannon_entropy, joint_entropy
|
|
2
|
+
from .simulation import simulate_kde_scenarios
|
|
3
|
+
from .energy import energy_score
|
|
4
|
+
from .states import count_microstates, macrostate_entropy
|
|
5
|
+
from .relationships import analyze_relationships
|
|
6
|
+
from .causal import infer_causal_structure
|
|
7
|
+
from .optimizer import grid_search_optimize
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import networkx as nx
|
|
3
|
+
from sklearn.feature_selection import f_regression
|
|
4
|
+
|
|
5
|
+
def infer_causal_structure(df, threshold=0.01, visualize=True):
|
|
6
|
+
numeric_df = df.select_dtypes(include='number').dropna()
|
|
7
|
+
features = numeric_df.columns.tolist()
|
|
8
|
+
G = nx.DiGraph()
|
|
9
|
+
|
|
10
|
+
for target in features:
|
|
11
|
+
for predictor in [col for col in features if col != target]:
|
|
12
|
+
X = numeric_df[[predictor]]
|
|
13
|
+
y = numeric_df[target]
|
|
14
|
+
_, pval = f_regression(X, y)
|
|
15
|
+
if pval[0] < threshold:
|
|
16
|
+
G.add_edge(predictor, target, weight=1 - pval[0])
|
|
17
|
+
|
|
18
|
+
if visualize:
|
|
19
|
+
import matplotlib.pyplot as plt
|
|
20
|
+
pos = nx.spring_layout(G, seed=42)
|
|
21
|
+
nx.draw(G, pos, with_labels=True, node_size=1500, font_size=10, edge_color='gray')
|
|
22
|
+
plt.title('Inferred Causal Graph')
|
|
23
|
+
plt.show()
|
|
24
|
+
|
|
25
|
+
return G
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def shannon_entropy(data):
|
|
4
|
+
_, counts = np.unique(data, return_counts=True)
|
|
5
|
+
probabilities = counts / counts.sum()
|
|
6
|
+
return -np.sum(probabilities * np.log2(probabilities))
|
|
7
|
+
|
|
8
|
+
def joint_entropy(x, y):
|
|
9
|
+
joint = list(zip(x, y))
|
|
10
|
+
return shannon_entropy(joint)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from itertools import product
|
|
4
|
+
|
|
5
|
+
def grid_search_optimize(df, feature_ranges, objective_fn, constraints=None):
|
|
6
|
+
keys, values = zip(*feature_ranges.items())
|
|
7
|
+
all_configs = [dict(zip(keys, v)) for v in product(*values)]
|
|
8
|
+
|
|
9
|
+
if constraints:
|
|
10
|
+
all_configs = list(filter(constraints, all_configs))
|
|
11
|
+
|
|
12
|
+
results = []
|
|
13
|
+
for config in all_configs:
|
|
14
|
+
score = objective_fn(config)
|
|
15
|
+
results.append({**config, 'score': score})
|
|
16
|
+
|
|
17
|
+
return pd.DataFrame(results).sort_values('score', ascending=False)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import seaborn as sns
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from sklearn.feature_selection import mutual_info_regression
|
|
5
|
+
|
|
6
|
+
def analyze_relationships(df, target=None, visualize=True):
|
|
7
|
+
results = {}
|
|
8
|
+
numeric_df = df.select_dtypes(include=['number']).dropna()
|
|
9
|
+
|
|
10
|
+
if visualize:
|
|
11
|
+
plt.figure(figsize=(10, 8))
|
|
12
|
+
sns.heatmap(numeric_df.corr(), annot=True, cmap='coolwarm')
|
|
13
|
+
plt.title('Correlation Matrix')
|
|
14
|
+
plt.show()
|
|
15
|
+
|
|
16
|
+
results['correlation_matrix'] = numeric_df.corr()
|
|
17
|
+
|
|
18
|
+
if target and target in df.columns:
|
|
19
|
+
X = numeric_df.drop(columns=[target])
|
|
20
|
+
y = numeric_df[target]
|
|
21
|
+
mi = mutual_info_regression(X, y, random_state=42)
|
|
22
|
+
mi_series = pd.Series(mi, index=X.columns).sort_values(ascending=False)
|
|
23
|
+
results['mutual_information'] = mi_series
|
|
24
|
+
|
|
25
|
+
if visualize:
|
|
26
|
+
plt.figure(figsize=(8, 5))
|
|
27
|
+
mi_series.plot(kind='bar')
|
|
28
|
+
plt.title(f'Mutual Information with Target: {target}')
|
|
29
|
+
plt.ylabel('MI Score')
|
|
30
|
+
plt.show()
|
|
31
|
+
|
|
32
|
+
return results
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from sklearn.neighbors import KernelDensity
|
|
4
|
+
|
|
5
|
+
def simulate_kde_scenarios(df, columns, n_samples=1000, bandwidth=1.0):
|
|
6
|
+
data = df[columns].dropna().values
|
|
7
|
+
kde = KernelDensity(kernel='gaussian', bandwidth=bandwidth)
|
|
8
|
+
kde.fit(data)
|
|
9
|
+
simulated = kde.sample(n_samples)
|
|
10
|
+
return pd.DataFrame(simulated, columns=columns)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from collections import Counter
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
def count_microstates(data):
|
|
5
|
+
return dict(Counter(map(tuple, data)))
|
|
6
|
+
|
|
7
|
+
def macrostate_entropy(microstates):
|
|
8
|
+
total = sum(microstates.values())
|
|
9
|
+
probs = [v / total for v in microstates.values()]
|
|
10
|
+
return -sum(p * np.log2(p) for p in probs)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: papilon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Papilon: A Statistical Mechanics Framework for Causal Data Simulation
|
|
5
|
+
Author-email: Your Name <you@example.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: numpy
|
|
8
|
+
Requires-Dist: pandas
|
|
9
|
+
Requires-Dist: scikit-learn
|
|
10
|
+
Requires-Dist: seaborn
|
|
11
|
+
Requires-Dist: matplotlib
|
|
12
|
+
Requires-Dist: networkx
|
|
13
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
papilon/__init__.py
|
|
6
|
+
papilon/causal.py
|
|
7
|
+
papilon/energy.py
|
|
8
|
+
papilon/entropy.py
|
|
9
|
+
papilon/optimizer.py
|
|
10
|
+
papilon/relationships.py
|
|
11
|
+
papilon/simulation.py
|
|
12
|
+
papilon/states.py
|
|
13
|
+
papilon.egg-info/PKG-INFO
|
|
14
|
+
papilon.egg-info/SOURCES.txt
|
|
15
|
+
papilon.egg-info/dependency_links.txt
|
|
16
|
+
papilon.egg-info/requires.txt
|
|
17
|
+
papilon.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
papilon
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "papilon"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Papilon: A Statistical Mechanics Framework for Causal Data Simulation"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Your Name", email = "you@example.com" }
|
|
11
|
+
]
|
|
12
|
+
dependencies = [
|
|
13
|
+
"numpy",
|
|
14
|
+
"pandas",
|
|
15
|
+
"scikit-learn",
|
|
16
|
+
"seaborn",
|
|
17
|
+
"matplotlib",
|
|
18
|
+
"networkx"
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.packages.find]
|
|
22
|
+
where = ["."]
|
|
23
|
+
include = ["papilon*"]
|
|
24
|
+
exclude = ["tests*", "examples*"]
|
papilon-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = papilon
|
|
3
|
+
version = 0.1.0
|
|
4
|
+
description = Papilon: A Statistical Mechanics Framework for Causal Data Simulation
|
|
5
|
+
|
|
6
|
+
[options]
|
|
7
|
+
packages = find:
|
|
8
|
+
install_requires =
|
|
9
|
+
numpy
|
|
10
|
+
pandas
|
|
11
|
+
scikit-learn
|
|
12
|
+
seaborn
|
|
13
|
+
matplotlib
|
|
14
|
+
networkx
|
|
15
|
+
|
|
16
|
+
[egg_info]
|
|
17
|
+
tag_build =
|
|
18
|
+
tag_date = 0
|
|
19
|
+
|