def discrete_network_embedding(A: np.ndarray, T: List[int]): S = (A + (A @ A)) / 2 W = np.random.uniform(-1, 1, (M, C)) B = np.random.uniform(-1, 1, (M, N)) # W = np.random.rand(M, C) # これは正の値しか出ない # B = np.random.rand(M, N) before_W = W before_B = B for _ in count(1, 20): for _ in count(1, 9): B = equation_11(B, S, W, T) print("updating B" + str(loss(B, S, W, T))) W = equation_13(B, T) print("updating W" + str(loss(B, S, W, T))) # x = [] # y = [] # colors = [] # fig, ax = plt.subplots() # for i in range(0, N): # b_i = B[:, i] # x.append(b_i[0]) # y.append(b_i[1]) # ax.annotate(str(i), (b_i[0], b_i[1])) # if np.argmax(W.T @ b_i) == 0: # colors.append("r") # else: # colors.append("b") # for i in range(len(x)): # ax.scatter(x[i], y[i], c=colors[i]) # plt.show() return before_B, before_W, B, W
def WO(W: np.ndarray, T: List[int]): assert W.shape == (M, C) assert len(T) == L w_mean = W.mean(axis=1) sum_mc = W.sum(axis=1) wo = [] for _i in range(0, L): ci = T[_i] woi = sum_mc - (W[:, ci] * C) wo.append(woi) for _ in count(L + 1, N): woi = sum_mc - sum_mc # 0 wo.append(woi) return np.column_stack(wo)
# Q3: How many part-time employees are there? import helper data = helper.read_salaries() employee_type = helper.get_column(data, 4) # get employee type (full or part-time) print(helper.count(employee_type, 'P')) # print full-time count
# Q5: How many detectives? import helper data = helper.read_salaries() jobs = helper.get_column(data, 2) print(helper.count(jobs, 'DETECTIVE'))
# Q2: How many full time employees are there? import helper data = helper.read_salaries() job_term = helper.get_column(data, 4) full_time_employees = helper.count(job_term, "F") print(full_time_employees) #31,090 full_time_employees
# Q3: How many part-time employees are there? import helper data = helper.read_salaries() timing = helper.get_column(data, 4) print(helper.count(timing, 'P'))
# Q4: How many employees in the police department? import helper data = helper.read_salaries() departments = helper.get_column(data, 3) print(helper.count(departments, 'POLICE'))
# Q5: How many detectives? import helper data = helper.read_salaries() detective_only = helper.get_column(data, 2) detective_count = helper.count(detective_only, "POLICE OFFICER (ASSIGNED AS DETECTIVE)") print(detective_count) #989 detectives
# Q3: How many part-time employees are there? import helper #import module data = helper.read_salaries() part_time = helper.get_column(data, 4) #assign variable name to look in position type count_parttime = helper.count(part_time, 'P') #count the specific type of part-time employees print(count_parttime)
# Q2: How many full time employees are there? import helper data = helper.read_salaries() full_time = helper.get_column(data, 4) #assign variable name to look in 'position type' column count_fulltime = helper.count(full_time, 'F') #count the specific number of full time employees print(count_fulltime)
# Q5: How many detectives? import helper data = helper.read_salaries() positions = helper.get_column(data, 2) # get positions print(helper.count( positions, 'POLICE OFFICER (ASSIGNED AS DETECTIVE)')) # print police detective count
# Q3: How many part-time employees are there? import helper data = helper.read_salaries() job_term = helper.get_column(data,4) part_time_employees = helper.count(job_term, "P") print(part_time_employees) #2,093 part_time_employees
# Q5: How many detectives? import helper data = helper.read_salaries() detectives_list = helper.get_column(data, 2) # #assign variable name to look in Job Title column detectives_count = helper.count(detectives_list, "POLICE OFFICER (ASSIGNED AS DETECTIVE)") #count the number of detectives print(detectives_count)
# Q4: How many employees in the police department? import helper data = helper.read_salaries() police_only = helper.get_column(data, 3) police_count = helper.count(police_only, "POLICE") print(police_count) #13,414 employees in the police department