-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_data.py
39 lines (33 loc) · 1.26 KB
/
analyze_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Analyze logs:
import re
import sys
from pathlib import Path
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
data = []
for logfile in Path(f"{sys.path[0]}/data").glob('simulation_hc_*.csv'):
d = pd.read_csv(logfile,
skiprows=1,
index_col=0,
names=['Year', 'Herbivores', 'Carnivores'])
d['Seed'] = int(re.match(r'.*_(\d+)\.csv', str(logfile))[1])
data.append(d)
hc = pd.concat(data).pivot(columns='Seed')
print(hc.tail())
plt.plot(hc.Herbivores, 'b', alpha=0.4)
plt.plot(hc.Carnivores, 'r', alpha=0.4)
plt.show()
print(sum(hc.loc[299, 'Carnivores'] == 0))
print(sum(hc.loc[299, 'Herbivores'] == 0))
with_c = (hc.loc[299, 'Herbivores'] > 0) & (hc.loc[299, 'Carnivores'] > 0)
hc_eq = hc.loc[hc.index >= 175, np.hstack((with_c.values, with_c.values))]
print(hc_eq.Herbivores.unstack().mean(), hc_eq.Herbivores.unstack().std())
print(hc_eq.Carnivores.unstack().mean(), hc_eq.Carnivores.unstack().std())
bins = np.arange(0, 140, 2)
plt.hist(hc_eq.Herbivores.unstack(), bins=bins, fc='b', histtype='step', alpha=1, lw=3,
label='Herbivores')
plt.hist(hc_eq.Carnivores.unstack(), bins=bins, fc='r', histtype='step', alpha=1, lw=3,
label='Carnivores')
plt.legend()
plt.show()