def test_F2_F1(self): '''<d_id_j ψ|H|ψ>, <d_iψ|H|d_jψ>''' Sx1, Sy1, Sz1 = N_body_spins(0.5, 1, 6) Sx2, Sy2, Sz2 = N_body_spins(0.5, 2, 6) Sx3, Sy3, Sz3 = N_body_spins(0.5, 3, 6) Sx4, Sy4, Sz4 = N_body_spins(0.5, 4, 6) Sx5, Sy5, Sz5 = N_body_spins(0.5, 5, 6) Sx6, Sy6, Sz6 = N_body_spins(0.5, 6, 6) Sx12, Sy12, Sz12 = N_body_spins(0.5, 1, 2) Sx22, Sy22, Sz22 = N_body_spins(0.5, 2, 2) mps = self.mps_0_6.left_canonicalise() listH = [Sz12@Sz22+Sx12, Sz12@Sz22+Sx12+Sx22, Sz12@Sz22+Sx22+Sx12+Sx22, Sz12@Sz22+Sz12+Sx22, Sz12@Sz22+Sx22] eyeH = [(1/(mps.L-1))*eye(4) for _ in range(5)] fullH = Sz1@Sz2+Sz2@Sz3+Sz3@Sz4+Sz4@Sz5+Sz5@Sz6+Sx1+Sx2+Sx3+Sx4+Sx5+Sx6 for i, j in product(range(mps.L), range(mps.L)): ## F2 = <d_id_j ψ|H|ψ> # zero for H = I self.assertTrue(allclose(mps.F2(i, j, eyeH, testing=True), 0)) # Test gauge projectors are in the right place mps.right_canonicalise() l, r = mps.get_envs() z1 = ncon([mps.F2(i, j, listH, testing=True), l(i-1)@c(mps[i])], [[1, 2, 3, -1, -2, -3], [1, 2, 3]]) z2 = ncon([mps.F2(i, j, listH, testing=True), l(j-1)@c(mps[j])], [[-1, -2, -3, 1, 2, 3], [1, 2, 3]]) self.assertTrue(allclose(z1, 0)) self.assertTrue(allclose(z2, 0)) mps.left_canonicalise() l, r = mps.get_envs() z1 = ncon([mps.F2(i, j, listH, testing=True), l(i-1)@c(mps[i])], [[1, 2, 3, -1, -2, -3], [1, 2, 3]]) z2 = ncon([mps.F2(i, j, listH, testing=True), l(j-1)@c(mps[j])], [[-1, -2, -3, 1, 2, 3], [1, 2, 3]]) self.assertTrue(allclose(z1, 0)) self.assertTrue(allclose(z2, 0)) ## F1 = <d_iψ|H|d_jψ> # For H = I: should be equal to δ_{ij} pr(i) if i!=j: self.assertTrue(allclose(mps.F1(i, j, eyeH, testing=True), 0)) if i==j: b = mps.F1(i, j, eyeH, testing=True) a = ncon([mps.left_null_projector(i), inv(r(i))], [[-1, -2, -4, -5], [-3, -6]]) self.assertTrue(allclose(a, b)) # Test gauge projectors are in the right place mps.left_canonicalise() l, r = mps.get_envs() z1 = td(mps.F1(i, j, listH, testing=True), l(i-1)@c(mps[i]), [[0, 1, 2], [0, 1, 2]]) z1 = td(mps.F1(i, j, listH, testing=True), l(j-1)@mps[j], [[3, 4, 5], [0, 1, 2]]) self.assertTrue(allclose(z1, 0)) self.assertTrue(allclose(z2, 0)) mps.right_canonicalise() l, r = mps.get_envs() z1 = td(mps.F1(i, j, listH, testing=True), l(i-1)@c(mps[i]), [[0, 1, 2], [0, 1, 2]]) z1 = td(mps.F1(i, j, listH, testing=True), l(j-1)@mps[j], [[3, 4, 5], [0, 1, 2]]) self.assertTrue(allclose(z1, 0)) self.assertTrue(allclose(z2, 0))
def EJ(self): ee = 2 * self.eeMatrix() td = np.tensordot mo = self.mo_vectors out = td(mo, ee, axes=(1, 0)) out = td(mo, out, axes=(1, 1)) out = td(mo, out, axes=(1, 2)) out = td(mo, out, axes=(1, 3)) occ = int(np.sum(self.occupation) / 2.) EJ = [out[a, a, b, b] for a in range(occ) for b in range(occ)] return sum(EJ)
def EX(self): ex = -np.swapaxes(self.eeMatrix(), 1, 2) td = np.tensordot mo = self.mo_vectors out = td(mo, ex, axes=(1, 0)) out = td(mo, out, axes=(1, 1)) out = td(mo, out, axes=(1, 2)) out = td(mo, out, axes=(1, 3)) occ = int(np.sum(self.occupation) / 2.) EX = [out[a, a, b, b] for a in range(occ) for b in range(occ)] return sum(EX)
def EX(self): ex = -np.swapaxes(self.eeMatrix(), 1,2) td = np.tensordot mo = self.mo_vectors out = td(mo, ex, axes=(1, 0)) out = td(mo, out, axes=(1, 1)) out = td(mo, out, axes=(1, 2)) out = td(mo, out, axes=(1, 3)) occ = int(np.sum(self.occupation) / 2.) EX = [out[a,a,b,b] for a in range(occ) for b in range(occ)] return sum(EX)
def EJ(self): ee = 2*self.eeMatrix() td = np.tensordot mo = self.mo_vectors out = td(mo, ee, axes=(1, 0)) out = td(mo, out, axes=(1, 1)) out = td(mo, out, axes=(1, 2)) out = td(mo, out, axes=(1, 3)) occ = int(np.sum(self.occupation) / 2.) EJ = [out[a,a,b,b] for a in range(occ) for b in range(occ)] return sum(EJ)
def _dividing_total_data(self): """ 分组函数,仅限内部一次使用 :return: 分组列表 """ tmp1 = tmp2 = self.total_normal_data.index[0] time_parts = [] part_series = [] self.text_out("正在生成处理数列") # 将全部数据中分组为连续生产(生产间隔不大于DIVIDE_TIME)的若干大组 for date in self.total_normal_data.index: if date - tmp1 > td(cf.divide_time, 'm'): time_parts.append(self.total_normal_data[tmp2:date]) tmp2 = date tmp1 = date # 将每一大组中每SERIES_NUM的数据分为小组,将所有大组的每一小组添加到返回列表之中 for data_series in time_parts: start_num, end_num = 0, cf.series_num while end_num < len(data_series): part_series.append(Series(data_series[start_num:end_num])) start_num = end_num end_num += cf.series_num return part_series
def densityFitting(qmout, rho_basis=None): psi_basis = qmout.basis occ = [i for i in range(qmout.n_ao) if qmout.occupation[i] == 2][-1] + 1 D_matrix = densityMatrix(qmout) if rho_basis is None: rho_basis = psi_basis psi_basis_data, psi_center, psi_lm = basisData(psi_basis) rho_basis_data, rho_center, rho_lm = \ basisData(rho_basis, density=True) NN = nnMatrix(rho_basis) NE = neMatrix(psi_basis, rho_basis) G = td(D_matrix, NE, axes=([0, 1], [1, 2])) return np.linalg.solve(NN, G)
def densityFitting(qmout, rho_basis=None): psi_basis = qmout.basis occ = [i for i in range(qmout.n_ao) if qmout.occupation[i]==2][-1] + 1 D_matrix = densityMatrix(qmout) if rho_basis is None: rho_basis = psi_basis psi_basis_data, psi_center, psi_lm = basisData(psi_basis) rho_basis_data, rho_center, rho_lm = \ basisData(rho_basis, density=True) NN = nnMatrix(rho_basis) NE = neMatrix(psi_basis, rho_basis) G = td(D_matrix, NE, axes=([0,1], [1,2])) return np.linalg.solve(NN, G)
last_day = pd.Timestamp('2017-06-05') days = pd.date_range(first_day, last_day) number_of_days = len(days) sessions_list = [] columns = [ 'date', 'session_start', 'session_end', 'session_length', 'longest_length', 'mode_changes_per_second', 'mode0', 'mode1', 'mode2', 'mode3', 'mode4', 'mode5', 'mode6', 'mode7', 'mode8' ] for day in days: date = day.date() print('Preparing day', date) start = day + td(9, 'h') end = day + td(18, 'h') points_filename = 'original data\%s.%s\max_values_%s-%s.txt' % ( day.day, day.month, day.day, day.month) points = pd.read_csv(points_filename, header=None, names=['overpoints', 'timestamp'], parse_dates=[1]) if points.empty: continue points['time'] = points.timestamp.apply(pd.Timestamp.time) points = points[(points.time >= start.time()) & (points.time <= end.time())] points['previous_timestamp'] = points.timestamp.shift() points['difference'] = (points.timestamp -
mode_ids = { '': 0, 'Lava': 1, 'Krajina': 2, 'VrstevniceFill': 3, 'Spad': 4, 'Voda': 5, 'Psychedelicky': 6, 'Vrstevnice': 7, 'Vyukovy': 8 } for day in days: print('Preparing day', day.date()) start = day + td(9, 'h') end = day + td(18, 'h') seconds = pd.date_range(start, end, freq='S') mode_filename = '%s.%s\mode_change_%s-%s.txt' % (day.day, day.month, day.day, day.month) modes = pd.read_csv(mode_filename, header=None, names=['playmode', 'timestamp'], parse_dates=[1]) modes['time'] = modes.timestamp.apply(pd.Timestamp.time) modes['previous_timestamp'] = modes.timestamp.shift() modes['previous_length'] = modes.timestamp - modes.previous_timestamp modes['event'] = 'automatic' modes.loc[modes.previous_length < td(1, 'm'), 'event'] = 'click'
import pandas as pd from numpy import timedelta64 as td import matplotlib.pyplot as plt import numpy as np from sklearn.linear_model import LogisticRegression, LinearRegression import mord minute = td(1, 'm') video_end = pd.Timestamp('26-04-2017T16:00:00') end = pd.Timestamp('26-04-2017T18:00:00') modes = pd.read_csv('original data/26.4/mode_change_26-4.txt', header=None, names=['playmode', 'timestamp'], parse_dates=[1]) modes['previous_timestamp'] = modes.timestamp.shift() modes['previous_length'] = modes.timestamp - modes.previous_timestamp modes['length'] = modes.timestamp.shift(-1) - modes.timestamp modes['to_video_end'] = end - modes.timestamp modes['event'] = 'automatic' modes.loc[modes.previous_length < minute, 'event'] = 'click' # print(modes[modes.to_video_end > td(0)].loc[:, ['playmode', 'previous_length', 'length']]) points = pd.read_csv('original data/26.4/max_values_26-4.txt', header=None, names=['overpoints', 'timestamp'], parse_dates=[1]) points['previous_timestamp'] = points.timestamp.shift() points['to_end'] = end - points.timestamp