#joint probability for hpi and mortgage in a time window (for seasonal data?) ## calculate the string of hpi and mortgage hpi_seas_str, _ = gt.connotation([hpi_seasonal], connotation) hpi_non_seas_str, _ = gt.connotation([hpi_non_seas], connotation) mortgage_str, _ = gt.connotation([unique_mortgage], connotation) mortgage_lf_str, _ = gt.connotation([mortgage_lf], connotation) ##find matches of up in hpi intervals cfg1 = { "pre_processing": "~ 10", "connotation": "D1 0.005", "expression": "p+" } matches_hpi = gt.ssts(hpi_seasonal, cfg1, 'clean') ## determinate the frequency of each character per window data_freq_test = gt.CharFreq(hpi_seas_str, 1, 10) data_freq_test2 = gt.CharFreq(mortgage_str, 1, 10) p_joint_prob = np.multiply(data_freq_test["p"], data_freq_test2["p"]) ax1 = plt.subplot(2, 1, 1) ax2 = plt.subplot(2, 1, 2) # ax3 = plt.subplot(3,1,3) ax1.plot(time_all, hpi_values) [ ax1.axvspan(time_all[i[0]], time_all[i[1] - 1],
#SSTS------------------------ #configure for hpi series cfg1 = { "pre_processing": "RM 25", "connotation": "D1 0.05", "expression": "p+" } #configure for mortgage series (only to have derivative string) cfg2 = {"pre_processing": "", "connotation": "D1 0.01", "expression": ""} print(np.where(time_hpi == time_all[0])[0]) hpi_values = list(hpi_values)[np.where( time_hpi == time_all[0])[0][0]:np.where(time_hpi == time_all[-1])[0][0] + 1] matches = gt.ssts(hpi_values, cfg1) matches2 = gt.ssts(unique_mortgage, cfg2, report="full") fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) ax1.plot(time_all, hpi_values) [ ax1.axvspan(time_all[i[0]], time_all[i[1]], facecolor='green', alpha=0.10) for i in matches ] ax1.set_title("HPI") ax1.set_xlabel("date (by month)") ax2.plot(time_all, unique_mortgage) max_p = []
sorted(tuple_list, key=lambda i: i[1]), lambda i: i[1])] m, t = ([i[0] for i in tuple_list], [i[1] for i in tuple_list]) time = sorted(list(set(time_hpi_1).intersection(t))) hpi_values = hpi_values1[[time_hpi_1.index(x) for x in time]] cfg = {"pre_processing": "", "connotation": "D1 0.01", "expression": "p+"} cfg2 = { "pre_processing": "HP 10", "connotation": "D1 0.01", "expression": "p+" } matches = ssts.ssts(hpi_values, cfg2) matches2 = ssts.ssts(hpi_values1, cfg, report="full") fig, axs = plt.subplots(nrows=2, ncols=1, sharex=True) fig.suptitle("HPI and Mortgage") axs[0].plot(time, hpi_values) axs[1].set_xlabel("Date") axs[0].set_ylabel("House Price Index") [ axs[0].axvspan(time[i[0]], time[i[1] - 1], facecolor='green', alpha=0.10) for i in matches ] axs[1].plot(t, m) axs[1].set_ylabel("Mortgage Counts")
"expression": "[10].(1z){1000,}" } i = 0 for tag, iotip, cfg, lag in zip(["wrist", "hand", "elbow", "torso"], [iotip_wrist, iotip_hand, iotip_elbow, torso], [cfg1, cfg1, cfg2, cfg1], [1, 0, 0, 0]): acc_[tag] = load_sensor_IOTIP(iotipsPath + iotip, "Green", "Accelerometer") gyr_[tag] = load_sensor_IOTIP(iotipsPath + iotip, "Green", "Gyroscope") mag_[tag] = load_sensor_IOTIP(iotipsPath + iotip, "Green", "Magnetometer") #Align Data time[tag], acc_[tag], gyr_[tag], mag_[tag] = syncData( acc_[tag], gyr_[tag], mag_[tag]) matches = gt.ssts(acc_[tag][:10000, 0], cfg) delay = matches[lag][0] time[tag] = time[tag][delay:] acc_[tag] = acc_[tag][delay:] gyr_[tag] = gyr_[tag][delay:] mag_[tag] = mag_[tag][delay:] #sync devices time, acc_, gyr_, mag_ = syncDevicesData(acc_, gyr_, mag_) #Pre_process # acc = lowpass(acc_, f=25, fs=100) # gyr = lowpass(gyr_, f=25, fs=100) # mag = lowpass(mag_, f=25, fs=100)
} cfg3 = { "pre_processing": "", "connotation": "D1 0.1", "expression": "n[zp]" } cfg4 = {"pre_processing": "", "connotation": "D1 0.05", "expression": "z+"} print(final) # # matches1 = gt.ssts(final, cfg1) # matches2 = gt.ssts(final, cfg2) # matches3 = gt.ssts(final, cfg3) matches4 = gt.ssts(final, cfg4) plt.plot(sig) plt.plot(sig_std + 2) plt.plot(sig_sum + 4) plt.plot(sig_zcr + 6) plt.plot(sig_ad + 8) plt.plot(final + 10) # [plt.axvline(i[0] + (i[1]-i[0])//2) for i in matches1] # [plt.axvline(i[0] + (i[1]-i[0])//2) for i in matches2] # [plt.axvline(i[0] + (i[1]-i[0])//2) for i in matches3] [plt.axvline(i[0] + (i[1] - i[0]) // 2) for i in matches4] #[plt.axvspan(i[0]-2, i[1]+2, facecolor='green', alpha=1) for i in matches1]