コード例 #1
0
def run_testset(kernel_type='cosine',
                log_2gs=-12,
                log_2gt=-12,
                log_2w=-2,
                log_2p=-1,
                complete_flag=1,
                zero_diag_flag=True):
    dc = DataClass(valid_flag=False)
    dc.kernel_type = kernel_type
    dc.source_gamma = 2**log_2gs
    dc.target_gamma = 2**log_2gt
    dc.zero_diag_flag = zero_diag_flag
    y, I, K, offset = dc.get_TL_Kernel()

    w_2 = 2**log_2w
    p = 2**log_2p

    if complete_flag == 1:
        K = DataClass.complete_TL_Kernel(K, offset)

    # log_2p == -1 means that using full kernel w/o sparsify
    if log_2p != -1:
        K = DataClass.sym_sparsify_K(K, p)

    auc, ap, rl = solve_and_eval(y, I, K, offset, w_2)
    print('tst test: auc %6f ap %6f rl %6f' % (auc, ap, rl))
コード例 #2
0
def run_testset(kernel_type='cosine',
                zero_diag_flag=True,
                kernel_normal=False,
                log2_b=None,
                log2_w=None,
                log2_p=None):
    dc = DataClass(valid_flag=False, kernel_normal=kernel_normal)
    dc.kernel_type = kernel_type
    dc.zero_diag_flag = zero_diag_flag
    # dc.source_data_type = 'parallel' # CorrNet test
    y, I, K, offset = dc.get_TL_Kernel()

    # run eigen decomposition on K
    v_s, Q_s, v_t, Q_t = eigen_decompose(K, offset, max_k=128)
    # v_s, Q_s, v_t, Q_t = eigen_decompose(K, offset, max_k=5)

    beta = 2**log2_b
    K_exp = K.copy()
    K_exp = get_K_exp(K_exp, offset, v_s, Q_s, v_t, Q_t, beta, kernel_normal)

    if log2_p == -1:
        K_sp = K_exp
    else:
        K_sp = DataClass.sym_sparsify_K(K_exp, 2**log2_p)

    auc, ap, rl = solve_and_eval(y, I, K_sp, offset, 2**log2_w)
    print('test set: auc %6f ap %6f rl %6f' % (auc, ap, rl))
コード例 #3
0
def run_testset(kernel_type='cosine',
                zero_diag_flag=False,
                kernel_normal=False,
                alpha=None,
                log2_w=None,
                log2_p=None):
    dc = DataClass(valid_flag=False, kernel_normal=kernel_normal)
    dc.kernel_type = kernel_type
    dc.zero_diag_flag = zero_diag_flag
    y, I, K, offset = dc.get_TL_Kernel()

    K_rw = K.copy()
    K_rw = get_K_rw(K_rw, offset, alpha=alpha)
    if log2_p == -1:
        K_sp = K_rw
    else:
        K_sp = DataClass.sym_sparsify_K(K_rw, 2**log2_p)
    auc, ap, rl = solve_and_eval(y, I, K_sp, offset, 2**log2_w)
    print('test set: auc %8f ap %6f rl %6f' % (auc, ap, rl))
コード例 #4
0
def grid(kernel_type='cosine',
         zero_diag_flag=True,
         kernel_normal=False,
         bList=None,
         wList=None,
         pList=None):
    dc = DataClass(valid_flag=True, kernel_normal=kernel_normal)
    dc.kernel_type = kernel_type
    dc.zero_diag_flag = zero_diag_flag
    y, I, K, offset = dc.get_TL_Kernel()

    # run eigen decomposition on K
    v_s, Q_s, v_t, Q_t = eigen_decompose(K, offset, max_k=128)

    best_b = -1
    best_w = -1
    best_p = -1
    best_auc = -1
    for log2_b in bList:
        beta = 2**log2_b
        K_exp = K.copy()
        K_exp = get_K_exp(K_exp, offset, v_s, Q_s, v_t, Q_t, beta,
                          kernel_normal)
        for log2_w in wList:
            for log2_p in pList:
                if log2_p == -1:
                    K_sp = K_exp
                else:
                    K_sp = DataClass.sym_sparsify_K(K_exp, 2**log2_p)
                auc, ap, rl = solve_and_eval(y, I, K_sp, offset, 2**log2_w)
                print(
                    'log2_b %3d log2_w %3d log2_p %3d auc %8f ap %6f rl %6f' %
                    (log2_b, log2_w, log2_p, auc, ap, rl))
                if best_auc < auc:
                    best_b = log2_b
                    best_w = log2_w
                    best_p = log2_p
                return
    print('best parameters: log2_b %3d log2_w %3d log2_p %3d auc %6f' \
            % (best_b, best_w, best_p, best_auc))
コード例 #5
0
def grid(kernel_type='cosine',
         zero_diag_flag=False,
         kernel_normal=False,
         aList=None,
         wList=None,
         pList=None):
    dc = DataClass(valid_flag=True, kernel_normal=kernel_normal)
    dc.kernel_type = kernel_type
    dc.zero_diag_flag = zero_diag_flag
    y, I, K, offset = dc.get_TL_Kernel()

    best_a = -1
    best_w = -1
    best_p = -1
    best_auc = -1
    for alpha in aList:
        K_rw = K.copy()
        K_rw = get_K_rw(K_rw, offset, alpha=alpha)

        for log2_w in wList:
            for log2_p in pList:
                if log2_p == -1:
                    K_sp = K_rw
                else:
                    K_sp = DataClass.sym_sparsify_K(K_rw, 2**log2_p)
                #print DataClass.sparse_K_stat(K_sp, offset)
                auc, ap, rl = solve_and_eval(y, I, K_sp, offset, 2**log2_w)
                print('alpha %3d log2_w %3d log2_p %3d auc %8f ap %6f rl %6f' %
                      (alpha, log2_w, log2_p, auc, ap, rl))
                if best_auc < auc:
                    best_a = alpha
                    best_w = log2_w
                    best_p = log2_p
                    best_auc = auc

    print('best parameters: alpha %3d log2_w %3d log2_p %3d auc %6f' \
            % (best_a, best_w, best_p, best_auc))