You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
matching_dependency/tfile.py

127 lines
3.4 KiB

import json
import multiprocessing
import os
import time
import ConfigSpace
import numpy as np
import pandas as pd
import torch
from tqdm import tqdm
from ConfigSpace.read_and_write import json as csj
from md_discovery import tmp_discover
from settings import er_output_dir, similarity_threshold, target_attr, hpo_output_dir
def fuck(i):
i = i * i + 1
def test1():
li = [[[6, 6, 2],
[2, 4, 6],
[2, 4, 7],
[3, 6, 4]],
[[6, 2, 7],
[3, 2, 4],
[5, 3, 5],
[6, 2, 4]],
[[7, 2, 2],
[6, 3, 2],
[6, 4, 3],
[6, 5, 6]]]
tensor = torch.Tensor(li)
norm_tensor = torch.nn.functional.normalize(tensor, dim=2)
print(norm_tensor, '\n')
sim_ten = torch.matmul(norm_tensor, norm_tensor.transpose(1, 2))
print(sim_ten / 2 + 0.5, '\n')
print(sim_ten.size())
def test2():
multiprocessing.set_start_method("spawn")
manager = multiprocessing.Manager()
lock = manager.Lock()
pool = multiprocessing.Pool(16)
with manager:
for _ in tqdm(range(0, 1000)):
result = pool.apply_async(fuck, args=(_,))
print(result)
def test3():
dic = {'description': 0, 'id': 1, 'manufacturer': 0, 'name': 0.9309734582901001, 'price': 0.912541675567627}
ll = list(dic.values())
ten = torch.Tensor(ll)
t = ten.unsqueeze(1)
t = t.unsqueeze(2)
y = t.repeat(1, 742, 742)
print(ten)
print(y)
print(torch.isfinite(ten))
print(torch.count_nonzero(y).item())
def test4():
one_bool_tensor = torch.ones((3, 3, 3), dtype=torch.bool)
print(torch.count_nonzero(one_bool_tensor).item())
def test5():
ten1 = torch.tensor([[1, 2, 3],
[7, 8, 9]])
ten2 = torch.tensor([[4, 5, 6],
[11, 12, 15]])
result = ten1 * ten2
r = torch.sum(result, 1)
print('\n')
print(result)
print(r)
def test6():
table_tensor = torch.tensor([[[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]],
[[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]]])
t = torch.tensor([[1., 2., 3.],
[4., 5., 6.]])
norm1 = torch.nn.functional.normalize(table_tensor, dim=1)
norm2 = torch.nn.functional.normalize(table_tensor, dim=2)
print('\n')
print(norm1)
print(norm2)
print(t.shape)
def test7():
iterations = 1
filename_list = os.listdir(er_output_dir)
if len(filename_list) > 0:
for _ in filename_list:
if _.startswith('eval_result'):
iterations = int(_[12:13]) + 1
print(iterations)
def test8():
cum = np.load(hpo_output_dir + 'incumbent.npy')
with open(hpo_output_dir + "configspace.json", 'r') as load_f:
dict_configspace = json.load(load_f)
str_configspace = json.dumps(dict_configspace)
configspace = csj.read(str_configspace)
config = ConfigSpace.Configuration(configspace, vector=cum)
print(cum)
if __name__ == '__main__':
start = time.time()
t_single_tuple_path = er_output_dir + "t_single_tuple.csv"
# tp_mds, tp_vio = inference_from_record_pairs(tp_single_tuple_path, similarity_threshold, target_attr)
tp_mds, tp_vio = tmp_discover.pairs_inference(t_single_tuple_path, similarity_threshold, target_attr)
print(time.time() - start)