Develop evaluation codes
This commit is contained in:
parent
7a5b7eae6e
commit
0f62707e33
@ -26,12 +26,12 @@ def resultant(sample):
|
|||||||
def H2(x):
|
def H2(x):
|
||||||
return -x*m.log2(x)-(1-x)*m.log2(1-x)
|
return -x*m.log2(x)-(1-x)*m.log2(1-x)
|
||||||
|
|
||||||
extremes = 50000
|
extremes = None
|
||||||
maxdt = 500
|
maxdt = 300
|
||||||
|
|
||||||
for dim in [7]:
|
for dim in [9]:
|
||||||
for eps in eps_space:
|
for eps in eps_space:
|
||||||
path=f'/cloud/Public/_data/neuropercolation/4lay/steps=1000100/dim={dim:02}/'
|
path=f'/cloud/Public/_data/neuropercolation/4lay/cons=27-3diag_steps=1000100/dim=09/batch=0/'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'r', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'r', encoding='utf-8') as f:
|
||||||
@ -49,6 +49,7 @@ for dim in [7]:
|
|||||||
|
|
||||||
|
|
||||||
all_res = norm(resultant(phase_diff))
|
all_res = norm(resultant(phase_diff))
|
||||||
|
av_diff = np.arccos(all_res)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'r', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'r', encoding='utf-8') as f:
|
||||||
@ -62,39 +63,75 @@ for dim in [7]:
|
|||||||
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'w', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'w', encoding='utf-8') as f:
|
||||||
json.dump(ei, f, indent=1)
|
json.dump(ei, f, indent=1)
|
||||||
|
|
||||||
bot_ei = sorted(enumerate(ei[:-maxdt]), key = lambda x: x[1])[ extremes]
|
pha_center = av_diff
|
||||||
top_ei = sorted(enumerate(ei[:-maxdt]), key = lambda x: x[1])[-extremes]
|
pha_dev = m.pi/8
|
||||||
|
orth_ind = sorted([i for i,val in enumerate(ei[:-maxdt]) if (pha_center-pha_dev)<=abs(phase_diff[i])<=(pha_center+pha_dev)], key = lambda i: ei[i])
|
||||||
|
|
||||||
bot_ei_pool = [ei for ei in enumerate(ei[:-maxdt]) if ei[1] <= bot_ei[1]]
|
if extremes is None:
|
||||||
top_ei_pool = [ei for ei in enumerate(ei[:-maxdt]) if ei[1] >= top_ei[1]]
|
extremes = len(orth_ind)//4000*1000
|
||||||
|
|
||||||
bot_eis = choose(bot_ei_pool, extremes)
|
print(len(orth_ind))
|
||||||
top_eis = choose(top_ei_pool, extremes)
|
#print(all_res, av_diff)
|
||||||
|
|
||||||
bot_ind = [enum[0] for enum in bot_eis]
|
|
||||||
top_ind = [enum[0] for enum in top_eis]
|
bot_ind = orth_ind[ :extremes]
|
||||||
|
top_ind = orth_ind[-extremes: ]
|
||||||
|
|
||||||
|
# bot_ei_pool = [ei for ei in enumerate(ei[:-maxdt]) if ei[1] <= bot_ei[1]]
|
||||||
|
# top_ei_pool = [ei for ei in enumerate(ei[:-maxdt]) if ei[1] >= top_ei[1]]
|
||||||
|
|
||||||
|
# bot_eis = choose(bot_ei_pool, extremes)
|
||||||
|
# top_eis = choose(top_ei_pool, extremes)
|
||||||
|
|
||||||
|
# bot_ind = [enum[0] for enum in bot_ei]
|
||||||
|
# top_ind = [enum[0] for enum in top_ei]
|
||||||
|
|
||||||
bot_res = []
|
bot_res = []
|
||||||
top_res = []
|
top_res = []
|
||||||
for dt in range(maxdt):
|
orth_res = []
|
||||||
bot_pha = [phase_diff[i+dt] for i in bot_ind]
|
tot_res = []
|
||||||
top_pha = [phase_diff[i+dt] for i in top_ind]
|
|
||||||
|
bot_ei = []
|
||||||
|
top_ei = []
|
||||||
|
orth_ei = []
|
||||||
|
tot_ei = []
|
||||||
|
for dt in range(maxdt):
|
||||||
|
bot_res.append( norm(resultant([phase_diff[i+dt] for i in bot_ind])) )
|
||||||
|
top_res.append( norm( resultant([phase_diff[i+dt] for i in top_ind])) )
|
||||||
|
orth_res.append( norm( resultant([phase_diff[i+dt] for i in orth_ind])) )
|
||||||
|
tot_res.append( norm( resultant(phase_diff[dt:dt-maxdt])) )
|
||||||
|
|
||||||
|
bot_ei.append( np.average([ei[i+dt] for i in bot_ind]) )
|
||||||
|
top_ei.append( np.average([ei[i+dt] for i in top_ind]) )
|
||||||
|
orth_ei.append( np.average([ei[i+dt] for i in orth_ind]) )
|
||||||
|
tot_ei.append( np.average(ei[dt:dt-maxdt]) )
|
||||||
|
|
||||||
bot_res.append( norm(resultant(bot_pha)) )
|
|
||||||
top_res.append( norm(resultant(top_pha)) )
|
|
||||||
if dt%100==99:
|
if dt%100==99:
|
||||||
print(f'Done dt={dt}')
|
print(f'Done dt={dt}')
|
||||||
|
|
||||||
|
|
||||||
qtplot(f'Diachronic resultant for dim={dim} with 4 layers',
|
qtplot(f'Diachronic resultant for dim={dim} with 4 layers',
|
||||||
[np.array(range(maxdt))]*3,
|
[np.array(range(maxdt))]*4,
|
||||||
[bot_res, top_res, [all_res]*maxdt],
|
[bot_res, top_res, orth_res, tot_res],
|
||||||
['Resultant ev of bottom 100 ei', 'Resultant ev of top 100 ei', 'Average Resultant'],
|
['Resultant ev of bottom {extremes} ei', 'Resultant ev of top {extremes} ei',
|
||||||
|
'Resultant ev of phase filtered ei', 'Average Resultant'],
|
||||||
x_tag = 'dt',
|
x_tag = 'dt',
|
||||||
y_tag = 'concentration',
|
y_tag = 'concentration',
|
||||||
export=True,
|
export=True,
|
||||||
path=path,
|
path=path,
|
||||||
filename=f'Diachronic Resultant for eps={round(eps,3)} dim={dim} extremes={extremes}.png',
|
filename=f'Diachronic Resultant for eps={round(eps,3):.3f} dim={dim} extremes={extremes} roll{pha_dev:.3f}.png',
|
||||||
|
close=True)
|
||||||
|
|
||||||
|
qtplot(f'Diachronic ei for dim={dim} with 4 layers',
|
||||||
|
[np.array(range(maxdt))]*4,
|
||||||
|
[bot_ei, top_ei, orth_ei, tot_ei],
|
||||||
|
['EI ev of bottom {extremes} ei', 'EI ev of top {extremes} ei',
|
||||||
|
'EI ev of phase filtered ei', 'Average EI'],
|
||||||
|
x_tag = 'dt',
|
||||||
|
y_tag = 'average ei',
|
||||||
|
export=True,
|
||||||
|
path=path,
|
||||||
|
filename=f'Diachronic EI for eps={round(eps,3):.3f} dim={dim} extremes={extremes} roll{pha_dev:.3f}.png',
|
||||||
close=True)
|
close=True)
|
||||||
|
|
||||||
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
||||||
|
92
evaluation/4Layer EI to Phase Survey.py
Normal file
92
evaluation/4Layer EI to Phase Survey.py
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Created on Mon Aug 21 14:59:22 2023
|
||||||
|
|
||||||
|
@author: astral
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import math as m
|
||||||
|
import numpy as np
|
||||||
|
from numpy.linalg import norm
|
||||||
|
from datetime import datetime
|
||||||
|
from random import sample as choose
|
||||||
|
|
||||||
|
from plot import qtplot
|
||||||
|
|
||||||
|
eps_space = list(np.linspace(0.01,0.2,20))
|
||||||
|
|
||||||
|
def resultant(sample):
|
||||||
|
phase_x = [m.cos(ind) for ind in sample]
|
||||||
|
phase_y = [m.sin(ind) for ind in sample]
|
||||||
|
|
||||||
|
return (np.average(phase_x), np.average(phase_y))
|
||||||
|
|
||||||
|
def H2(x):
|
||||||
|
return -x*m.log2(x)-(1-x)*m.log2(1-x)
|
||||||
|
|
||||||
|
extremes = 50000
|
||||||
|
maxdt = 500
|
||||||
|
|
||||||
|
for dim in [7]:
|
||||||
|
for eps in eps_space:
|
||||||
|
path=f'/cloud/Public/_data/neuropercolation/4lay/cons=14_steps=1000100/dim={dim:02}/batch=0/'
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'r', encoding='utf-8') as f:
|
||||||
|
phase_diff = json.load(f)
|
||||||
|
except:
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_activation.txt", 'r', encoding='utf-8') as f:
|
||||||
|
activation = json.load(f)[100:]
|
||||||
|
|
||||||
|
osc = list(zip(*activation))
|
||||||
|
phase = np.array([[np.arctan2(*act[::-1]) for act in osc[i]] for i in range(2)])
|
||||||
|
phase_diff = (phase[1]-phase[0]+m.pi)%(2*m.pi)-m.pi
|
||||||
|
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(list(phase_diff), f, indent=1)
|
||||||
|
|
||||||
|
|
||||||
|
all_res = norm(resultant(phase_diff))
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_channelsum.txt", 'r', encoding='utf-8') as f:
|
||||||
|
chasum = json.load(f)
|
||||||
|
except:
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_channels.txt", 'r', encoding='utf-8') as f:
|
||||||
|
channels = json.load(f)[100:]
|
||||||
|
|
||||||
|
chasum = [int(np.sum(cha)) for cha in channels]
|
||||||
|
|
||||||
|
with open(path+f"eps={round(eps,3):.3f}_channelsum.txt", 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(chasum, f, indent=1)
|
||||||
|
|
||||||
|
maxchas = max(chasum)
|
||||||
|
|
||||||
|
res = [norm(resultant([pha for i, pha in enumerate(phase_diff) if chasum[i]==n])) for n in range(maxchas+1) if len([pha for i, pha in enumerate(phase_diff) if chasum[i]==n])>=20]
|
||||||
|
#dist = [len([pha for i, pha in enumerate(phase_diff) if chasum[i]==n]) for n in range(maxchas+1)]
|
||||||
|
|
||||||
|
qtplot(f'Channel-Resultant for dim={dim}',
|
||||||
|
[list(range(len(res)))],
|
||||||
|
[res],
|
||||||
|
[f'Resultant against open channels'],
|
||||||
|
x_tag = 'open channels',
|
||||||
|
y_tag = 'resultant',
|
||||||
|
export=True,
|
||||||
|
path=path,
|
||||||
|
filename=f'Channel-Resultant eps={round(eps,3):.3f} dim={dim}.png',
|
||||||
|
close=True)
|
||||||
|
|
||||||
|
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
||||||
|
|
||||||
|
# qtplot(f'Resultant and EI evolution for dim={dim} with 4 layers',
|
||||||
|
# [[0]+eps_space]*2,
|
||||||
|
# [max(av_ei)*diff_res, av_ei],
|
||||||
|
# ['Resultant', 'avEI'],
|
||||||
|
# export=True,
|
||||||
|
# path=path,
|
||||||
|
# filename=f'Resultant and EI for dim={dim}.png',
|
||||||
|
# close=True)
|
||||||
|
|
||||||
|
|
@ -29,14 +29,16 @@ def H2(x):
|
|||||||
extremes = 50000
|
extremes = 50000
|
||||||
maxdt = 500
|
maxdt = 500
|
||||||
|
|
||||||
for dim in [7]:
|
for dim in [9]:
|
||||||
for eps in eps_space:
|
for eps in eps_space[:1]:
|
||||||
path=f'/cloud/Public/_data/neuropercolation/4lay/steps=1000100/dim={dim:02}/'
|
path=f'/cloud/Public/_data/neuropercolation/4lay/cons=9-3dist_steps=1000100/dim=09/batch=0/'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'r', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_phase_diff.txt", 'r', encoding='utf-8') as f:
|
||||||
phase_diff = json.load(f)
|
phase_diff = json.load(f)
|
||||||
except:
|
except:
|
||||||
|
# None
|
||||||
|
# if True:
|
||||||
with open(path+f"eps={round(eps,3):.3f}_activation.txt", 'r', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_activation.txt", 'r', encoding='utf-8') as f:
|
||||||
activation = json.load(f)[100:]
|
activation = json.load(f)[100:]
|
||||||
|
|
||||||
@ -62,22 +64,34 @@ for dim in [7]:
|
|||||||
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'w', encoding='utf-8') as f:
|
with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'w', encoding='utf-8') as f:
|
||||||
json.dump(ei, f, indent=1)
|
json.dump(ei, f, indent=1)
|
||||||
|
|
||||||
pha_divs = 8
|
pha_divs = 32
|
||||||
pha_sort = [0]*pha_divs
|
pha_sort = [0]*pha_divs
|
||||||
|
|
||||||
pha_sort = [[pha for pha in list(enumerate(phase_diff))[:-maxdt] if i*m.pi/pha_divs <= abs(pha[1]) <= (i+1)*m.pi/pha_divs] for i in range(pha_divs)]
|
pha_sort = [[pha for pha in list(enumerate(phase_diff))[:-maxdt] if i*m.pi/pha_divs <= abs(pha[1]) <= (i+1)*m.pi/pha_divs]
|
||||||
dia_ei = [[np.average([ei[pha[0]+dt] for pha in pha_div]) for dt in range(maxdt)] for pha_div in pha_sort]
|
for i in range(pha_divs)]
|
||||||
|
dia_ei = [np.average([ei[i] for i, pha in pha_div]) for pha_div in pha_sort]
|
||||||
|
phase_dist = [len(pha)/len(phase[0][:-maxdt]) for pha in pha_sort]
|
||||||
|
|
||||||
qtplot(f'Diachronic EI for dim={dim} with 4 layers',
|
qtplot(f'EI Distribution against phase diff for dim={dim}',
|
||||||
[list(range(maxdt))]*pha_divs,
|
[[(div+.5)*m.pi/pha_divs for div in range(pha_divs)]],
|
||||||
dia_ei,
|
[dia_ei],
|
||||||
[f'EI evolution for initial phase in [{div}pi,{div+1}pi]' for div in range(pha_divs)],
|
[f'EI distribution against phase diff'],
|
||||||
x_tag = 'dt',
|
x_tag = 'abs phase',
|
||||||
y_tag = 'average EI',
|
y_tag = 'average EI',
|
||||||
colors = 'rgb',
|
|
||||||
export=True,
|
export=True,
|
||||||
path=path,
|
path=path,
|
||||||
filename=f'Diachronic EI for eps={round(eps,3)} dim={dim} pha_divs={pha_divs}.png',
|
filename=f'Phase-EI eps={round(eps,3):.3f} dim={dim} pha_divs={pha_divs}.png',
|
||||||
|
close=True)
|
||||||
|
|
||||||
|
qtplot(f'Phasediff Distribution for dim={dim}',
|
||||||
|
[[(div+.5)*m.pi/pha_divs for div in range(pha_divs)]],
|
||||||
|
[phase_dist],
|
||||||
|
[f'Phase distribution'],
|
||||||
|
x_tag = 'abs phase',
|
||||||
|
y_tag = 'frequency',
|
||||||
|
export=True,
|
||||||
|
path=path,
|
||||||
|
filename=f'Phasediff dist eps={round(eps,3):.3f} dim={dim} pha_divs={pha_divs}.png',
|
||||||
close=True)
|
close=True)
|
||||||
|
|
||||||
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
@ -126,6 +126,8 @@ def qtplot(titletext, spaces, vals, names, x_tag=f'noise level {chr(949)}', y_ta
|
|||||||
# save to file
|
# save to file
|
||||||
exporter.export(path+filename)
|
exporter.export(path+filename)
|
||||||
|
|
||||||
|
print(f'Saving to {path+filename}')
|
||||||
|
|
||||||
def handleAppExit():
|
def handleAppExit():
|
||||||
# Add any cleanup tasks here
|
# Add any cleanup tasks here
|
||||||
print("closing")
|
print("closing")
|
||||||
|
@ -15,18 +15,20 @@ eps_space = np.linspace(0.005,0.5,100)
|
|||||||
|
|
||||||
stp = 1000100
|
stp = 1000100
|
||||||
|
|
||||||
for batch in range(1,5):
|
for batch in range(5):
|
||||||
for dim in [7]:
|
for dim in [8]:
|
||||||
for eps in eps_space[1:41:2]:
|
for eps in eps_space[1:41:2]:
|
||||||
eps = round(eps,3)
|
eps = round(eps,3)
|
||||||
cons = [(n,n) for n in range(dim)]+[(n,(n+3)%7) for n in range(dim)]
|
cons = [(n,(n+m)%dim) for n in range(dim) for m in [0,int(dim/2)]]
|
||||||
|
initstate = [[0,0],[0,0]]
|
||||||
sim = Simulate4Layers(dim,
|
sim = Simulate4Layers(dim,
|
||||||
eps,
|
eps,
|
||||||
coupling=cons,
|
coupling=cons,
|
||||||
|
init=initstate,
|
||||||
steps=stp,
|
steps=stp,
|
||||||
draw=None,
|
draw=None,
|
||||||
res=2,
|
res=2,
|
||||||
save='simple',
|
save='simple',
|
||||||
path=f'/cloud/Public/_data/neuropercolation/4lay/cons={len(cons)}_steps={stp}/dim={dim:02}/batch={batch}/',
|
path=f'/cloud/Public/_data/neuropercolation/4lay/cons={len(cons)}-2diag_steps={stp}/dim={dim:02}/batch={batch}/',
|
||||||
)
|
)
|
||||||
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
print(f'Done eps={eps:.3f} with dim={dim} at {datetime.now()}')
|
Loading…
Reference in New Issue
Block a user