-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute-natural-heat-capacity-generational
114 lines (85 loc) · 3.38 KB
/
compute-natural-heat-capacity-generational
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
from embodied_ising import ising
import numpy as np
from sys import argv
from os import path, makedirs
from embodied_ising import TimeEvolve2
import matplotlib.pyplot as plt
import pickle
import glob
# --- COMPUTE HEAT CAPACITY -------------------------------------------------------+
if len(argv) < 3:
print("Usage: " + argv[0] + " <sim> + <bind> + <gen>")
# loadfile = 'sim-20180131-145412'
# bind = 0
# iterNum = 0
loadfile = str(argv[1])
bind = int(argv[2])
iterNum = int(argv[3])
# --- CONSTANTS ----------------------------------------------------------------+
settings = {}
# ENVIRONMENT SETTINGS
settings['pop_size'] = 50 # number of organisms
settings['numKill'] = int(settings['pop_size'] / 1.66)
settings['food_num'] = 100 # number of food particles
settings['food_radius'] = 0.03
settings['org_radius'] = 0.05
# SIMULATION SETTINGS
settings['TimeSteps'] = 4000 # number of timesteps per iteration
# number of system-wide spin updates per unit of time (multiplies computation time)
settings['thermalTime'] = 10
# settings['evolution_toggle'] = False # only toggles for CriticalLearning
# settings['evolution_rate'] = 1 # number of iterations to skip to kill/mate (gives more time to eat before evolution)
settings['dt'] = 0.2 # kinetic time step (dt)
settings['r_max'] = 720
settings['dr_max'] = 90 # max rotational speed (degrees per second)
settings['v_max'] = 0.5 # max velocity (units per second)
settings['dv_max'] = 0.05 # max acceleration (+/-) (units per second^2)
settings['x_min'] = -4.0 # arena eastern border
settings['x_max'] = 4.0 # arena western border
settings['y_min'] = -4.0 # arena southern border
settings['y_max'] = 4.0 # arena northern border
settings['plotLive'] = True # live updates of figures
# -----------------------------------------------------------------------------
# animation settings
settings['plot'] = False
settings['diagnostics'] = False
settings['frameRate'] = 2
settings['save_data'] = False # for saving figures, keep off
savefile = True
R = 1
Nbetas = 101
betas = 10 ** np.linspace(-1, 1, Nbetas)
BetaFactor = betas[bind]
loadstr = 'save/' + loadfile + '/isings/gen[' + str(iterNum) + ']-isings.pickle'
# print(iterNum)
isings = pickle.load(open(loadstr, 'rb'))
size = isings[0].size # get size from first agent
numAgents = len(isings)
C = np.zeros((R, numAgents))
Sm = np.zeros((R, numAgents))
Sp = np.zeros((R, numAgents))
F = np.zeros((R, numAgents))
for rep in range(R):
T = 2000
isings_new = TimeEvolve2(isings, BetaFactor, settings, T)
if settings['plot'] == True:
plt.clf()
# NOTE: The thermalize time in the settings plays a role in the thermalization of the NN each time step.
for orgNum, I in enumerate(isings_new):
C[rep, orgNum] = (I.E2m - I.Em ** 2) / size
Sm[rep, orgNum] = (I.m2 - I.m ** 2) / size
#TODO: relative positions instead of absolute
Sp[rep, orgNum] = np.linalg.norm((I.p2m - np.power(I.pm, 2)))
F[rep, orgNum] = I.fitness / float(T)
# print(np.mean(C, 0))
folder = 'save/' + loadfile + '/C-S-natural_' + str(iterNum) + '/'
file = 'C-S-size_' + str(size) + '-Nbetas_' + \
str(Nbetas) + '-bind_' + str(bind)
filename = folder + file
if not path.exists(folder):
makedirs(folder)
if savefile:
np.savez(filename, C=C, Sm=Sm, Sp=Sp, F=F)
# savestr = 'Saving: ./.../' + file
# print(savestr)