-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathea_init.py
More file actions
37 lines (34 loc) · 905 Bytes
/
ea_init.py
File metadata and controls
37 lines (34 loc) · 905 Bytes
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
import copy
import numpy as np
def zperm_init(z,K):
L = len(z['x'])
ens = []
for i in range(K):
x = np.random.permutation(L)
_z = copy.copy(z)
for k in z.keys():
try:
if len(z[k]) == L:
_z[k] = z[k][x]
else:
_z[k] = z[k]
except TypeError:
_z[k] = z[k]
ens.append(copy.copy(_z))
del(_z)
return ens
def zmutate(z,idx):
""" idx are indecies that should be permuted
IMPORTAT: THIS WILL MODIFY THE INPUT!!!!!
"""
L = len(z['x'])
for i in idx:
j = np.random.randint(0,L)
for k in z.keys():
try:
if len(z[k]) == L:
_tmp = z[k][i]
z[k][i] = z[k][j]
z[k][j] = _tmp
except TypeError:
pass