예제 #1
0
def getAsymmetricSigmaForScipyMatrix(raw_mean_control_profile, dev_control_matrix, config_params):
    dev_control_matrix_tall = np.zeros((0, 1))
    repeated_raw_mean_control_profile = np.zeros((0, 1))
    raw_mean_control_profile = np.matrix(raw_mean_control_profile).transpose()
    for i in range(dev_control_matrix.shape[1]):
        dev_control_matrix_tall = np.vstack((dev_control_matrix_tall, dev_control_matrix[:, [i]]))
        repeated_raw_mean_control_profile = np.vstack((repeated_raw_mean_control_profile, raw_mean_control_profile))
    dev_control_matrix_tall = np.array(dev_control_matrix_tall)
    pos = dev_control_matrix_tall >= 0
    neg = dev_control_matrix_tall < 0
    dev_control_matrix_tall_squared = dev_control_matrix_tall**2
    lowess = np.zeros(dev_control_matrix_tall.shape)
    for i in range(dev_control_matrix.shape[1]):
        if get_verbosity(config_params) >= 3:
            print dev_control_matrix_tall[pos],  dev_control_matrix_tall_squared[pos]
            print dev_control_matrix_tall.shape, dev_control_matrix_tall_squared.shape, pos.shape, scipy.nonzero(pos)[0].shape[0]
    lowess[pos] = np.array( mlab.smooth(repeated_raw_mean_control_profile[pos],  dev_control_matrix_tall_squared[pos] , 0.3, 'lowess')  ).transpose()[0]
    lowess[neg] = np.array( mlab.smooth(repeated_raw_mean_control_profile[neg],  dev_control_matrix_tall_squared[neg] , 0.3, 'lowess')  ).transpose()[0]
    lowess_pos = np.zeros(raw_mean_control_profile.shape) + np.nan
    lowess_neg = np.zeros(raw_mean_control_profile.shape) + np.nan
    for i in range(raw_mean_control_profile.shape[0]):
        for j in range(i, dev_control_matrix_tall.shape[0], raw_mean_control_profile.shape[0]):
            if pos[j]:
                lowess_pos[i] = lowess[j]
            else:
                lowess_neg[i] = lowess[j]
    lowess_symmetric = np.array( mlab.smooth(repeated_raw_mean_control_profile,  dev_control_matrix_tall, 'lowess')  ).transpose()[0]

    return np.sqrt( lowess_neg ).real , np.sqrt( lowess_pos ).real, np.sqrt(lowess_symmetric[range(raw_mean_control_profile.shape[0])]).real
예제 #2
0
def smooth(xx, yy):
    k = wellbehaved(xx) & wellbehaved(yy)
    yy_normalized = np.zeros(xx.shape) + np.nan
    if np.sum(yy[k]) == 0:
        return yy_normalized
    lowess_line = np.array( mlab.smooth(xx[k], yy[k], 0.3, 'rlowess')  ).transpose()[0]
    if np.sum(lowess_line) == 0:
        return yy_normalized
    yy_normalized[k] = xx[k] * yy[k] / lowess_line
    return yy_normalized