neuropercolation/evaluation/4Layer Res+EI.py

60 lines
1.7 KiB
Python
Raw Normal View History

2023-08-23 14:25:27 +00:00
#!/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 datetime import datetime
from plot import qtplot
eps_space = list(np.linspace(0.005,0.5,100))
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)
for dim in [7]:
diff_res = [0]
av_ei = [0]
for eps in eps_space:
path=f'/cloud/Public/_data/neuropercolation/4lay/steps=100000/dim={dim:02}/'
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
res = np.linalg.norm(resultant(phase_diff))
diff_res.append(res)
with open(path+f"eps={round(eps,3):.3f}_channels.txt", 'r', encoding='utf-8') as f:
channels = json.load(f)[100:]
ei = [np.sum(cha)*(1-H2(eps)) for cha in channels]
av_ei.append(np.average(ei))
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,
[diff_res, av_ei],
['Resultant', 'avEI'],
export=True,
path=path,
filename=f'Resultant and EI for dim={dim}.png',
close=True)