Exemplo n.º 1
0
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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
# 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
Exemplo n.º 4
0
# Q5: How many detectives?
import helper

data = helper.read_salaries()
jobs = helper.get_column(data, 2)
print(helper.count(jobs, 'DETECTIVE'))
Exemplo n.º 5
0
# 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
Exemplo n.º 6
0
# 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'))
Exemplo n.º 7
0
# 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'))

Exemplo n.º 8
0
# 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
Exemplo n.º 9
0
# 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)
Exemplo n.º 10
0
# 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)
Exemplo n.º 11
0
# 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
Exemplo n.º 12
0
# 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
Exemplo n.º 13
0
# 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)
Exemplo n.º 14
0
# 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