tw[i] /= swk tw = tw[tw <= 100.0] # only times in the first 100 weeks tw = tw % 1 tw = tw * 7 nc = len(tw) # Now get Fourier curve nw = 336 nb = 84 t = np.linspace(0.0, 1.0, nw) MyF = Fourier(645.0, 16, 52.1775, 12, 1.0, 6, 1.0/7.0, 8, df, t0) MyF.compute() fv = np.empty(nw) #fv.fill(2700.0) for i in range(0, nw): fv[i] = 0.0 for j in range(0, 50): fv[i] += MyF.f(t[i] + j * 2.0, 'DRUNKENNESS') fv[i] *= nc + 0.0 # nc - number of crimes fv[i] /= 50.0 * nb # nb - number of histogram bins # Got Fourier curve t = t * 7 plt.hist(tw, bins=nb) # 645 weeks but we only have alternating weeks plt.plot(t, fv, linewidth=2.5) plt.title("Drunkenness") plt.xlabel("Days") plt.ylabel("50 times average Drunkenness arrests per 2 hours") plt.savefig('time-5.png') plt.show()
nd = len(mydate) print "%d crimes in total" % nd tw = np.zeros(nd) # array of times in weeks ni = np.linspace(0, nd-1, nd, dtype=np.int) mydate.index = ni for i in range (0, nd): tw[i] = (mydate[i]-t0).total_seconds() tw[i] /= swk # Now get Fourier curve nw = 323 t = np.linspace(0.5, 644.5, nw) #MyF = Fourier(645.0, 20, 52.1775, 12, 1.0, 6, 1.0/7.0, 6, df) MyF = Fourier(645.0, 16, 52.1775, 12, 1.0, 0, 1.0/7.0, 0, df, t0) MyF.compute() fv = np.empty(nw) #fv.fill(2700.0) for i in range(0, nw): fv[i] = MyF.f(t[i], 'VEHICLE THEFT') fv[i] *= nd + 0.0 fv[i] /= 322.0 # Got Fourier curve plt.hist(tw, bins=322) # 645 weeks but we only have alternating weeks plt.plot(t, fv, linewidth=2.5) plt.title("Vehicle Theft History") plt.xlabel("Weeks") plt.ylabel("Thefts per week") plt.savefig('time-3.png') plt.show()
mydate = vt['Dates'] nd = len(mydate) print "%d crimes in total" % nd tw = np.zeros(nd) # array of times in weeks ni = np.linspace(0, nd - 1, nd, dtype=np.int) mydate.index = ni for i in range(0, nd): tw[i] = (mydate[i] - t0).total_seconds() tw[i] /= swk # Now get Fourier curve nw = 323 t = np.linspace(0.5, 644.5, nw) #MyF = Fourier(645.0, 20, 52.1775, 12, 1.0, 6, 1.0/7.0, 6, df) MyF = Fourier(645.0, 16, 52.1775, 12, 1.0, 0, 1.0 / 7.0, 0, df, t0) MyF.compute() fv = np.empty(nw) #fv.fill(2700.0) for i in range(0, nw): fv[i] = MyF.f(t[i], 'VEHICLE THEFT') fv[i] *= nd + 0.0 fv[i] /= 322.0 # Got Fourier curve plt.hist(tw, bins=322) # 645 weeks but we only have alternating weeks plt.plot(t, fv, linewidth=2.5) plt.title("Vehicle Theft History") plt.xlabel("Weeks") plt.ylabel("Thefts per week") plt.savefig('time-3.png') plt.show()
tw = tw[tw <= 100.0] # only times in the first 100 weeks tw = tw % 1 tw = tw * 7 nc = len(tw) # Now get Fourier curve nw = 336 nb = 84 t = np.linspace(0.0, 1.0, nw) MyF = Fourier(645.0, 16, 52.1775, 12, 1.0, 6, 1.0/7.0, 8, df, t0) MyF.compute() fv = np.empty(nw) #fv.fill(2700.0) for i in range(0, nw): fv[i] = 0.0 for j in range(0, 50): #fv[i] = MyF.f(t[i], 'DRUNKENNESS') fv[i] += MyF.f(t[i] + j * 2.0, 'LARCENY/THEFT') fv[i] *= nc + 0.0 # nc - number of crimes fv[i] /= 50.0 * nb # nb - number of histogram bins # Got Fourier curve t = t * 7 plt.hist(tw, bins=nb) # 645 weeks but we only have alternating weeks plt.plot(t, fv, linewidth=2.5) plt.title("Larceny/Theft") plt.xlabel("Days") plt.ylabel("50 times average Larceny/Theft arrests per 2 hours") plt.savefig('time-4.png') plt.show()
tw[i] = (mydate[i] - t0).total_seconds() tw[i] /= swk tw = tw[tw <= 100.0] # only times in the first 100 weeks tw = tw % 1 tw = tw * 7 nc = len(tw) # Now get Fourier curve nw = 336 nb = 84 t = np.linspace(0.0, 1.0, nw) MyF = Fourier(645.0, 16, 52.1775, 12, 1.0, 6, 1.0 / 7.0, 8, df, t0) MyF.compute() fv = np.empty(nw) #fv.fill(2700.0) for i in range(0, nw): fv[i] = 0.0 for j in range(0, 50): fv[i] += MyF.f(t[i] + j * 2.0, 'DRUNKENNESS') fv[i] *= nc + 0.0 # nc - number of crimes fv[i] /= 50.0 * nb # nb - number of histogram bins # Got Fourier curve t = t * 7 plt.hist(tw, bins=nb) # 645 weeks but we only have alternating weeks plt.plot(t, fv, linewidth=2.5) plt.title("Drunkenness") plt.xlabel("Days") plt.ylabel("50 times average Drunkenness arrests per 2 hours") plt.savefig('time-5.png') plt.show()