def get_alpha_b(model):
    """
    Get the ``(alpha, b)`` parameters from a model
    """
    y = model.prob.y_array
    len_y = model.prob.size
    y_0 = svmc.double_getitem(y,0)
    coefs, perm, rho = get_model_params(model)
    minp = min(perm)
    alpha = zeros(len_y)
    alpha[perm-minp] = coefs
    return (alpha, -rho)
def get_model_params(model):
    """
    Extract the alpha and b parameters from the SVM model.
    returns (alpha, b)
    """
    rho = svmc.svm_get_model_rho(model.model)
    n = svmc.svm_get_model_num_coefs(model.model)
    coefs_dblarr = svmc.new_double(n)
    perm_intarr = svmc.new_int(n)
    try:
        svmc.svm_get_model_coefs(model.model,coefs_dblarr)
        svmc.svm_get_model_perm(model.model,perm_intarr)
        coefs = np.zeros(n,dtype=float)
        perm = np.zeros(n,dtype=int)
        for i in range(n):
            coefs[i] = svmc.double_getitem(coefs_dblarr,i)
            perm[i] = svmc.int_getitem(perm_intarr,i)
    finally:
        svmc.delete_double(coefs_dblarr)
        svmc.delete_int(perm_intarr)
    return (coefs, perm, rho)
예제 #3
0
def get_model_params(model):
    """
    Extract the alpha and b parameters from the SVM model.
    returns (alpha, b)
    """
    rho = svmc.svm_get_model_rho(model.model)
    n = svmc.svm_get_model_num_coefs(model.model)
    coefs_dblarr = svmc.new_double(n)
    perm_intarr = svmc.new_int(n)
    try:
        svmc.svm_get_model_coefs(model.model,coefs_dblarr)
        svmc.svm_get_model_perm(model.model,perm_intarr)
        coefs = np.zeros(n,dtype=float)
        perm = np.zeros(n,dtype=int)
        for i in range(n):
            coefs[i] = svmc.double_getitem(coefs_dblarr,i)
            perm[i] = svmc.int_getitem(perm_intarr,i)
    finally:
        svmc.delete_double(coefs_dblarr)
        svmc.delete_int(perm_intarr)
    return (coefs, perm, rho)