In [1]:
import os
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import tools
reload(tools)
from tools import *
In [2]:
source = "/home/walterms/mcmd/nn/data/unlbl/"
fnames = sorted([source+f for f in os.listdir(source)])
foutdir = "/home/walterms/mcmd/nn/data/pca/"
run = "lat_nbrs_e3"
newnames = []
for f in fnames:
if f.endswith(".log") or f.endswith("swp"): continue
if f.startswith(source+"edge_3"):
newnames.append(f)
fnames = newnames
# Sort based on edge size
fparams = []
for f in fnames:
edg = float(f[len(source)+len("edge_3_"):])
fparams.append([edg, 28**2])
idxs = np.argsort(fparams,axis=0)
fparams = np.array([fparams[i] for i in idxs[:,0]])
fnames = [fnames[i] for i in idxs[:,0]]
fnames, fparams = fnames[::6], fparams[::6]
edges = fparams[:,0]
nfiles = len(fnames)
In [3]:
fidx = np.array([0,3,5,6,7,8])
fnames = np.asarray([fnames[i] for i in fidx])
fparams = np.asarray([fparams[i] for i in fidx])
edges = fparams[:,0]
nrods = fparams[:,1].astype(int)
nfiles = len(fnames)
print fnames
print edges
In [4]:
# FOR APPENDING DEFECTS TO A PREEXISTING FNAMES
source = "/home/walterms/mcmd/nn/data/defects/"
# fnames = [source+f for f in os.listdir(source)]
defectnames = [source+f for f in ["minushalf_small","minusone_small","plusone_small","plushalf_small"]]
def_nrod = 6**2
tmp = np.array([[5.0, def_nrod] for _ in range(len(defectnames))])
edges = np.append(edges,tmp[:,0])
nrods = np.append(nrods,tmp[:,1].astype(int))
fnames = np.append(fnames,np.asarray(defectnames))
nfiles += len(defectnames)
print fnames
run = "lat_nbrs_e3defect"
print "Runname", run
In [5]:
singles = [0,0,0,0,0,0,1,1,1,1]
In [14]:
# FOR BIGBOX STATES
source = "/home/walterms/mcmd/nn/data/unlbl/"
fnames = [source+"bigbox1"]
foutdir = "/home/walterms/mcmd/nn/data/pca/"
run = "lat_nbrs_bigbox1"
nfiles = len(fnames)
nrod = 60**2
edges = np.array([[15.00, nrod/(15**2)]])
In [59]:
# FOR XTUD SETS
# Note, nProc = 10000, sweepEval = 100, nEquil = 0
source = "/home/walterms/mcmd/nn/data/train/"
fnames = [source+f for f in ["X","U","D","T"]]
foutdir = "/home/walterms/mcmd/nn/data/pca/"
run = "lat_nbrs_xtud"
nfiles = 4
nrod = 28**2
edges = np.array([[6.324, nrod/(6.324**2)] for _ in range(nfiles)])
In [54]:
# FOR DEFECT SETS
source = "/home/walterms/mcmd/nn/data/defects/"
# fnames = [source+f for f in os.listdir(source)]
fnames = [source+f for f in ["minushalf_small","minusone_small","plusone_small","plushalf_small"]]
foutdir = "/home/walterms/mcmd/nn/data/pca/"
run = "lat_nbrs_defects"
nfiles = len(fnames)
nrod = 10**2
edges = np.array([[5., nrod/(5**2)] for _ in range(nfiles)])
In [6]:
use_xyth = False
In [25]:
# hyperparams
# NBRS = np.array([10,20,30])
# methods = ["random", "radial", "angular", "polar"]
NBRS = np.array([36,])
methods = ["random","WD","WA"]
nmethod = len(methods)
nx_probe = 20
nprobe = nx_probe**2
nblskip = 1
sparse_bulk_factor = 1
NBL = 60
nft = 2 if use_xyth else 1
nsample = nprobe*NBL*nfiles
sample_per_file = nsample // nfiles
print nfiles, sample_per_file, nsample
In [26]:
# Designed for handling
# the unlbl nn dataset
#
#
import tools
reload(tools)
from tools import *
fRot = 0.
for n_nbr in NBRS:
for imeth, meth in enumerate(methods):
prestr = foutdir+run if not use_xyth else foutdir+run+"_xyth"
foutname = prestr+"_"+str(n_nbr)+"_"+meth
print "Preparing samples for "+foutname
# Let's add an extra dimension being the density label to X
# Easy to extract later
# Adding probe rod info
X = np.empty((nsample,n_nbr)) if not use_xyth else np.empty((nsample,nft*n_nbr))
isample = 0
for ifile,f in enumerate(fnames):
fin = open(f,'r')
edge = edges[ifile]
nrod = nrods[ifile]
rho = nrod/(edge*edge)
print f
nbl = 0
rods = np.zeros((nrod,3))
irod = 0
isample_per_f = 0
probes = gen_probes(nx_probe,edge)
if singles[ifile]:
probes = probes[190].reshape(1,2)
for line in fin.readlines():
if nbl < nblskip:
if line == "\n": nbl+=1
continue
if line == "\n":
# Done a block
samples = get_lat_nbrs(rods,n_nbr,edge,nx_probe,probes,method=meth,use_xyth=use_xyth)
if not singles[ifile]:
if isample_per_f + len(samples) > sample_per_file:
samples = samples[:sample_per_file]
if isample+len(samples) > nsample:
samples = samples[:nsample-isample]
len_samples = len(samples)
else:
len_samples = 1
# rh = np.ones((len_samples,1)) * params["ReducedRho"]
# samples = np.append(rh,samples,axis=1)
X[isample:isample+len_samples] = samples
isample += len_samples
isample_per_f += len_samples
nbl+=1
if isample >= nsample:
break
if isample_per_f >= sample_per_file:
break
rods = np.zeros((nrod,3))
irod = 0
continue
if line.startswith("label"):
continue
rod = [float(s) for s in line.split()]
rod[0] *= edge
rod[1] *= edge
rod[2] *= twopi
rod[2] = myrotate(rod[2])
rods[irod] = rod
irod+=1
fin.close()
print nbl
if isample >= nsample:
break
fout = open(foutname,'w')
print "Writing to "+foutname
for samp in X:
s = ""
for th in samp:
s += "%0.6f "%(th)
s += "\n"
fout.write(s)
fout.close()
print "Done"
In [20]:
X.shape
Out[20]:
In [19]:
nbl
Out[19]:
In [26]:
f_sample = fnames[0]
edge_sample = edges[0]
nfiles = 1
print f_sample, edge_sample
In [11]:
f_sample = "/home/walterms/mcmd/nn/data/defects/plusone"
edge_sample = 5.
# edge_sample = 6.324
nfiles = 1
In [28]:
import tools
reload(tools)
from tools import *
In [12]:
#
# This Chunk suited for looking at a single block of a single file
#
# This block is different
# It's for handling the FNN unlabeled dataset
NBL = 1
nblskip = 1
n_nbr = 36
nrod = 28**2
nx_probe = 20
nprobe = nx_probe**2
sparse_bulk_factor = 1
nsample = NBL*nprobe*nfiles
methods = ["random", "radial", "angular", "polar2"]
nmethod = len(methods)
# X = np.empty((nmethod,nsample,n_nbr))
# nbrs_full = np.empty(shape=(nmethod,nrod,n_nbr,4)) # first 4 is for each method
X = []
nbrs_full = []
alphas = []
for ifile,f in enumerate([f_sample]):
fin = open(f,'r')
print f, float(nrod)/(edge_sample*edge_sample)
nbl = 0
lambdacount = 0
rods = np.zeros((nrod,3))
irod = 0
probes = gen_probes(nx_probe,edge_sample)
for line in fin.readlines():
if nbl < nblskip:
if line == "\n": nbl+=1
continue
if line == "\n":
# Done a block
for im, meth in enumerate(methods):
x, nbs, alphs = \
get_lat_nbrs(rods,n_nbr,edge_sample,nx_probe,probes,method=meth,ret_nbrs=True,
use_xyth=use_xyth)
X.append(x)
nbrs_full.append(nbs)
alphas.append(alphs)
# for im, meth in enumerate(methods):
# X[im,ifile:(ifile+1)*NBL*nrod], nbrs_full[im] = \
# get_nbrs(rods,n_nbr,edge,use_bulk=use_bulk,method=meth,ret_nbrs=True)
X = np.asarray(X)
nbrs_full = np.asarray(nbrs_full)
alphas = np.asarray(alphas)
nbl+=1
if nbl >= NBL+nblskip:
break
rods = np.zeros((nrod,3))
irod = 0
continue
if line.startswith("label"):
continue
rod = [float(s) for s in line.split()]
rod[0] *= edge_sample
rod[1] *= edge_sample
rod[2] *= twopi
rod[2] = myrotate(rod[2])
rods[irod] = rod
irod+=1
fin.close()
# print np.mean(lambdas[ifile])
# _=plt.plot(lambdas[ifile],'k.',markersize=2)
# _=plt.axis([0,nlambda,-1,1])
# plt.show()
# lvar = np.var(lambdas,axis=1)
# _ = plt.plot(edges[:,1],lvar,'o')
# _ = plt.xlabel(r'$\rho$')
# _ = plt.ylabel(r'$\sigma^2(\lambda)$',rotation="horizontal",labelpad=20)
# plt.show()
print "Done"
In [13]:
probes = gen_probes(nx_probe,edge_sample)
In [17]:
f,ax = plt.subplots(4,2,figsize=(10,18))
iprob = 0
# probe 189 for X, nblskip 5, is a good test case
colbase = coldict[8]
for imeth, meth in enumerate(methods):
nbrs = nbrs_full[imeth,iprob]
for ni, nbr in enumerate(nbrs[:,:3]):
col = tuple([cc*(1. - 0.7*ni/float(n_nbr)) for cc in coldict[8]])
# col = (0,1-float(ni)/n_nbr,float(ni)/n_nbr)
plotrods([nbr],ax[imeth,0],col=col,lw=3.,add_crosses=True)
# plotrods(rods,ax[imeth,0])
px, py = probes[iprob,0], probes[iprob,1]
aL = 0.5
alph = alphas[3][iprob]
hx, hy = aL*cos(alph), aL*sin(alph)
ax[imeth,0].scatter(px,py,s=200,marker='o',c='k',zorder=-1)
ax[imeth,0].arrow(px,py,hx,hy, head_width=0.05, head_length=0.1, fc='k', ec='k',zorder=-1)
ax[imeth,0].set_aspect("equal")
ax[imeth,0].set_title(meth)
ax[imeth,1].set_title(meth)
ax[imeth,1].set_ylabel(r'$feature$',rotation="vertical",labelpad=0,fontsize=14)
ax[imeth,1].plot(X[imeth,iprob])
# ax[imeth,1].set_ylim(-1,1)
# break
In [43]:
test = nbrs[:,:3].copy()
test[:,0] -= np.mean(test[:,0])
test[:,1] -= np.mean(test[:,1])
kk = get_xyth_feature(test)
In [44]:
plt.plot(kk)
Out[44]:
In [31]:
import tools
reload(tools)
from tools import *
In [48]:
print alphas[3,iprob]
plt.plot(np.arctan2(test_red[:,1],test_red[:,0]))
Out[48]:
In [15]:
import seaborn as sns
import itertools
sns.set()
sns.set_style("white")
sty = sns.set_style("ticks",{"xtick.major.size":0.8,"ytick.major.size":0.8})
sns.set_style({"xtick.direction": "in","ytick.direction": "in"})
# sns.palplot(sns.color_palette("cubehelix", 8))
# sns.set_palette("cubehelix")
npal = 10
shift = 1
stride = 1
start = 2
rot = 30.0
gamma = 1.0
dark = 0.2
light = 0.8
palnamething = sns.cubehelix_palette(npal,start=start,rot=rot,light=light,dark=dark,reverse=True, gamma=gamma)
# palnamething = sns.color_palette("Paired")
# palnamething = sns.color_palette("bright")
sns.set_palette(palnamething, npal)
pal = sns.color_palette(palnamething, npal)
palette = itertools.cycle(pal)
sns.palplot(pal)
for _ in range(shift):
next(palette)
coldict = {}
for i in range(npal):
for s in range(1,stride):
next(palette)
coldict.update({i:next(palette)})
In [ ]:
In [ ]:
In [ ]: