#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Aug 21 14:59:22 2023 @author: timofej """ 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)) phase = np.vectorize(lambda x,y: (m.atan2(y,x)+m.pi)%(2*m.pi)-m.pi) diff = np.vectorize(lambda x,y: (y-x+m.pi)%(2*m.pi)-m.pi) H2 = lambda x: -x*m.log2(x)-(1-x)*m.log2(1-x) extremes = None maxdt = 300 for dim in [9]: for eps in eps_space: path=f'/cloud/Public/_data/neuropercolation/4lay/steps=100100/dim=09/' 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_abs = np.array([[np.arctan2(*act[::-1]) for act in osc[i]] for i in range(2)]) phase_diff = diff(phase_abs[0],phase_abs[1]) 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)) av_diff = np.arccos(all_res) try: with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'r', encoding='utf-8') as f: ei = 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:] ei = [np.sum(cha)*(1-H2(eps)) for cha in channels] with open(path+f"eps={round(eps,3):.3f}_ei.txt", 'w', encoding='utf-8') as f: json.dump(ei, f, indent=1) pha_center = av_diff pha_dev = m.pi/32 from_sync = lambda i: True if abs(phase_diff[i])<0.08*m.pi else False if 0.42*m.pi0 else None to_sync = lambda i: True if abs(phase_diff[i])<0.08*m.pi else False if 0.42*m.pi