import tensorflow as tf
from tensorflow import keras

import numpy as np

import os
import sys


from data import data

fns=[f"runs/{zw}" for zw in os.listdir("runs")]


fs=[np.load(fn) for fn in fns if os.path.isfile(fn)]

x=fs[0]["x"]
ds=[f["d"] for f in fs]
ps=[f["p"][:,0] for f in fs]


ds=np.array(ds)
ps=np.array(ps)

d=np.sqrt(np.mean(np.square(ds),axis=0))

np.savez_compressed("merged",x=x,ds=ds,ps=ps,d=d)


print(np.corrcoef(ps))



sx=[(xx,dd) for xx,dd in zip(x,d)]
sx.sort(key=lambda x:x[1])

sx=[xx for xx,dd in sx]
sx=np.array(sx)

from plt import plt


col1=[1.0,0.0,0.0]
col2=[0.0,1.0,0.0]

col1,col2=np.array(col1),np.array(col2)

ln=len(sx)

cols=[col1*(i/ln)+col2*(1-i/ln) for i in range(ln)]



plt.scatter(sx[:,0],sx[:,1],c=cols)

plt.savefig(f"imgs/recombine.png")

#plt.plot(sx[:,0],sx[:,1],'.')

plt.how()

















