def correlation_experiment(file, lan, embf, name): data, cencoder, tencoder, embchars = readdata(file, lan) cdecoder = {v: k for k, v in cencoder.items()} tdecoder = {v: k for k, v in tencoder.items()} features = getphonfeatures() lanfeatures = [ np.array(features[cdecoder[f]]) if cdecoder[f] in features else None for f in range(len(cencoder)) ] featsim = getsimmatrix(lanfeatures, len(cencoder), embchars) embeddings = embf(data, cencoder, embchars, tencoder, cdecoder, tdecoder, lan) sims = [getsimmatrix(m, len(cencoder), embchars) for m in embeddings] rs = [correlation(featsim, sims[i])[0] for i in [0, 1, 2]] print("%s %s:" % (lan, name)) print(" PEARSON R FOR EMBEDDING AND FEATURE REPR. SIMILARITIES:") print(" %s,DIM=5" % lan, rs[0]) print(" %s,DIM=15" % lan, rs[1]) print(" %s,DIM=30" % lan, rs[2]) randrs = [[], [], []] for i in range(N): ranembeddings = [matshuf(m) for m in embeddings] ransims = [ getsimmatrix(m, len(cencoder), embchars) for m in ranembeddings ] randrs[0].append(correlation(featsim, ransims[0])[0]) randrs[1].append(correlation(featsim, ransims[1])[0]) randrs[2].append(correlation(featsim, ransims[2])[0]) print((" P=%.2f CONF. INTERVALS FOR PEARSON R OF RANDOM ASSIGNMENT OF\n" % P) + " EMBEDDINGS TO PHONEMES AND PHONETIC FEATURE DESCRIPTIONS:") civals = [confidenceival(randrs[i]) for i in [0, 1, 2]] print(" %s,DIM=5" % lan, confidenceival(randrs[0]), checkr(civals[0], rs[0]), rs[0]) print(" %s,DIM=15" % lan, confidenceival(randrs[1]), checkr(civals[1], rs[1]), rs[1]) print(" %s,DIM=30" % lan, confidenceival(randrs[2]), checkr(civals[2], rs[2]), rs[2]) print()
# print() # print(mod.status,"\t",mod.objVal,"\t",ct) return mod # %% # Number of instances Is = 10 # Number of models, where model 0 is the non altered basic order model M = 1 # Combinations Combs = order_pot(poten(list(range(1, M)))) parN,parP,parC,parD=readdata() Ic = 0 h=0 # For instance ii in set of instances Is for ii in range(Is): # For model set mn in set of models: for mn in Combs: Ic = Ic + 1 h = h + 1 MathModel(parC[ii], parD[ii], parN[ii], parP[ii], mn, ii, Ic) print(h,"\t",ii,"\t",mn) print("")
#closeddf = data.collect("Close") #highdf = data.collect("High") #lowdf = data.collect("Low") #pre-saved data in pickle, open it for quicker run. pickle_in = open("Close.pickle", "rb") closeddf = pickle.load(pickle_in) pickle_in = open("Low.pickle", "rb") lowdf = pickle.load(pickle_in) pickle_in = open("High.pickle", "rb") highdf = pickle.load(pickle_in) #different indicators is calculated by calling back to data.py and save it as the particular #pandas database #normalizing the closeddf by using the first day closing price normalizedCloseddf = data.normalizeData(closeddf) volumeDF = data.readdata("Volume") SMAdf = data.SMA(closeddf, 20) EMAdf = data.EMA(closeddf, 5) RSIdf = data.RSI(closeddf, 14) KSTdf = data.KST(closeddf, 10, 15, 20, 30, 10, 10, 10, 15) TRIXdf = data.TRIX(closeddf, 15) IXIC = pd.DataFrame(index=normalizedCloseddf.index) IXIC = normalizedCloseddf[['IXIC Close']] highbbdf, lowbbdf = data.BollingerBand(closeddf) MassIdf = data.MassI(highdf, lowdf) MOMdf = data.MOM(closeddf, 10) ROCdf = data.ROC(closeddf, 10) dailyReturnDF = data.dailyReturn(normalizedCloseddf) MACDdf, MACDsigndf, MACDDiffdf = data.MACD(closeddf) STOKdf = data.STOK(closeddf, lowdf, highdf) STOdf = data.STO(closeddf, lowdf, highdf, 14)
checkr(civals[0], rs[0]), rs[0]) print(" %s,DIM=15" % lan, confidenceival(randrs[1]), checkr(civals[1], rs[1]), rs[1]) print(" %s,DIM=30" % lan, confidenceival(randrs[2]), checkr(civals[2], rs[2]), rs[2]) print() if __name__ == "__main__": print("1. CORRELATION EXPERIMENTS") print("--------------------------") print() # correlation_experiment("../data/finnish","FI",getsvdembs,"SVD") # correlation_experiment("../data/turkish","TUR",getsvdembs,"SVD") # correlation_experiment("../data/spanish","ES",getsvdembs,"SVD") # correlation_experiment("../data/finnish","FI",getw2vembs,"W2V") # correlation_experiment("../data/turkish","TUR",getw2vembs,"W2V") # correlation_experiment("../data/spanish","ES",getw2vembs,"W2V") # correlation_experiment("../data/finnish","FI",getrnnembs,"RNN") # correlation_experiment("../data/turkish","TUR",getrnnembs,"RNN") # correlation_experiment("../data/spanish","ES",getrnnembs,"RNN") data, cencoder, tencoder, embchars = readdata('../data/finnish', "FI") modeld = initmodel(cencoder, tencoder, 15) encoded = encode(data[0][1], data[0][2], modeld) train(data, modeld) # for i in range(100): # print(update(data[0][1],data[0][2],data[0][0],modeld))