Esempio n. 1
0
def immeuble(x, y_sol):
    '''
    Paramètres
        x : abscisse du centre de l'étage
        y_sol : ordonnée du sol du la rue
    Cette fonction dessine un immeuble Le nombre d'étage est compris aléatoirement entre 0 et 4
    La couleur de la façade et la couleur de la porte sont tirées au hasard
    '''
    turtle.colormode(255)
    # Nombre d'étage (aléatoire)

    nombre_etages=randint(0,4)

    #Couleurs des éléments (aléatoire)

    couleur_facade = couleur_aleatoire()
    couleur_porte = couleur_aleatoire()

    # Dessin du RDC

    rdc(x,y_sol,couleur_facade,couleur_porte)

    # Dessin des étages
    for i in range (nombre_etages):
        etage(x, y_sol, couleur_facade, i+1)

    # Dessin du toit

    toit(x, y_sol, nombre_etages)
Esempio n. 2
0
def linear_mixture(image1,
                   image2,
                   mixing_matrix=[[1, 0.5], [0.5, 1]],
                   show_images=True):
    """
    Function that mixes to images linearly
    
    Parameters
    ----------
    image1: the first image to be mixed
    image2: the second image to be mixed
    mixing_matrix: the matrix to which the images will be multiplied
    show_images: boolean, True by default, plots the mixed images if True

    Return
    -----------
    S: the input images, flattened and stacked 
    X: the mixed signals, flattened and stacked
    """
    assert np.shape(mixing_matrix) == (2, 2)

    n = image1.shape

    source1 = image1.flatten('F')  #column wise
    source2 = image2.flatten('F')  #column wise

    source1 = source1 - np.mean(source1)
    source2 = source2 - np.mean(source2)

    source1 = source1 / np.linalg.norm(source1)
    source2 = source2 / np.linalg.norm(source2)

    S = np.stack((source1, source2))

    X = np.matmul(mixing_matrix, S)

    X1 = X[0, :]
    X2 = X[1, :]

    rdc_images = rdc(X1, X2)
    print("RDC =", rdc_images)

    if show_images == True:
        X1 = np.reshape(X1, n)
        X2 = np.reshape(X2, n)

        plt.figure()
        plt.imshow(X1.T, cmap='gray')
        plt.title("Mixed image 1")
        plt.show

        plt.figure()
        plt.imshow(X2.T, cmap='gray')
        plt.title("Mixed image 2")
        plt.show()
    return S.T, X
Esempio n. 3
0
def nonlinear_mixture(image1, image2, q1, q2, show_images=True):
    """
    Function that mixes to images nonlinearly
    
    Parameters
    ----------
    image1: the first image to be mixed
    image2: the second image to be mixed
    q1: float, interference level of the first image
    q2: float, interference level of the second image
    show_images: boolean, True by default, plots the mixed images if True

    Return
    -----------
    S: the input images, flattened and stacked 
    X: the mixed signals, flattened and stacked
    """

    # mixing the images
    source1 = np.matrix(image1)
    source1 = source1.flatten('F')  #column wise

    source2 = np.matrix(image2)
    source2 = source2.flatten('F')  #column wise

    S = np.stack((source1, source2))

    rdc_images = rdc(source1.T, source2.T)
    print("RDC =", rdc_images)

    #X1 = np.multiply(source1, np.power((source2/255),q2))
    #X2 = np.multiply(source2, np.power((source1/255),q1))

    X1 = np.multiply(source1, (np.exp(
        -q2 * (1 - source2))))  # if 0<intensities<255 then divide by 255
    X2 = np.multiply(source2, (np.exp(-q1 * (1 - source1))))

    X = np.stack((X1, X2))

    # Show mixed images
    if (show_images == True):
        X1 = np.reshape(X1, (n, n))
        X2 = np.reshape(X2, (n, n))

        plt.figure()
        plt.imshow(X1.T, cmap='gray')
        plt.title("Mixed image 1")
        plt.show

        plt.figure()
        plt.imshow(X2.T, cmap='gray')
        plt.title("Mixed image 2")
        plt.show()
    return S, X
def main(datafile, outputfile):
    X, features = read_sah_h5(datafile, just_good=False)

    result = []
    progress = ProgressBar(widgets=['Computing dependencies: ', Bar('='), ETA()])
    for f1, f2 in progress(list(combinations(features, 2))):
        x = X[:, features.index(f1)]
        y = X[:, features.index(f2)]
        result.append('%s,%s,%f' % (f1, f2, rdc(x, y, n=5)))

    with open(outputfile, 'w+') as f:
        f.write('\n'.join(result))
Esempio n. 5
0
def main(datafile, outputfile):
    X, features = read_sah_h5(datafile, just_good=False)

    result = []
    progress = ProgressBar(
        widgets=['Computing dependencies: ',
                 Bar('='), ETA()])
    for f1, f2 in progress(list(combinations(features, 2))):
        x = X[:, features.index(f1)]
        y = X[:, features.index(f2)]
        result.append('%s,%s,%f' % (f1, f2, rdc(x, y, n=5)))

    with open(outputfile, 'w+') as f:
        f.write('\n'.join(result))
def randomized_dependence_coefficient(series1, series2):
    """
    Compute the randomized dependence coefficient between two series

    Measure of nonlinear dependence between random variables based on the
    Hirschfeld-Gebelein-Renyi Maximum Correlation Coefficient

    Args:
        series1 (numpy.ndarray): First series
        series2 (numpy.ndarray): Second series

    Returns:
        Randomized dependence coefficient between the two series
    """
    return rdc(np.array(series1), np.array(series2))
Esempio n. 7
0
# Mixing process here
img2_gray_re = np.fliplr(img2_gray)

source1 = np.matrix(img1_gray)
source1 = source1.flatten('F') #column wise

source2 = np.matrix(img2_gray)
source2 = source2.flatten('F') #column wise

source1 = source1 - np.mean(source1)
source2 = source2 - np.mean(source2)

#source1 = source1/np.linalg.norm(source1)
#source2 = source2/np.linalg.norm(source2)

print("rdc = ", rdc(source1.T,source2.T))
source = np.stack((source1, source2))

print('Covariance matrix is: ')
print(np.matmul(source,source.T))

# randomly generated mixing matrix
#np.random.seed(0)
#mixing_matrix = np.random.randn(2,2)
#mixing_matrix = np.array([[0.36, 0.66], [0.03, 0.95]])
mixing_matrix = np.array([[1, 0.5], [0.5, 1]])
print('Mixing matrix is: ')
print(mixing_matrix)


# X = source * mixing_matrix - The mixed images
SDR_ica_imp = np.zeros((1, N_sources))
SDR_sp_imp = np.zeros((1, N_sources))

for pic_set in np.arange(N_sources):
    # load images and convert them
    print(pic_set)
    #mixing_matrix = np.array([[0.36, 0.66], [0.03, 0.95]])
    mixing_matrix = np.array([[1, 0.7], [0.02, 1]])
    # mixing_matrix = np.array([[1, 0.3], [0.5, 1]])
    # mixing_matrix = np.array([[0.8488177, 0.17889592], [0.05436321, 0.36153845]])
    X, source = three_projection_method.import_image(pic_set, mixing_matrix)
    # calculate kurtosis, if it's Gaussian distribution, then it's close to zero
    k1 = kurtosis(np.squeeze(source[0, :]))
    k2 = kurtosis(np.squeeze(source[1, :]))
    Kur_it[0, pic_set] = np.abs(k1) + np.abs(k2)
    rdc_it[0, pic_set] = rdc(source[0, :], source[1, :])

    # whitening processing. It's important
    X_nonwhiten = np.copy(X)
    X, W = whiten_projection(np.asarray(X))

    (sdr_ref, sir_ref, sar,
     perm) = mmetrics.bss_eval_sources(np.asarray(source), np.asarray(X))
    print(sdr_ref)

    new_mix = np.dot(W, mixing_matrix)
    #####################################
    # Using the three projection method with different non linearity
    print('Here is the first algorithm')
    separation_method = 'TV'
    sigma = 1e-3
Esempio n. 9
0
from rdc import rdc

# the signals
t = np.linspace(-np.pi, np.pi, 1000)
sine = np.sin(4 * t)  #for np.sin(3*t), rdc is higher => bad performance of ICA
sawtooth = signal.sawtooth(2 * np.pi * t)

#plotting
plt.figure()
plt.plot(t, sawtooth, label='sawtooth')
plt.plot(t, sine, label='sine')
plt.legend()
plt.show

#test the independence
print("rdc = ", rdc(sine, sawtooth))

# mixing the reference sources
mixing_matrix = [[1, 0.5], [0.5, 1]]
reference_sources = np.c_[sawtooth, sine]
#sources /= sources.std(axis = 0) #standardize it
M = np.dot(reference_sources, np.transpose(mixing_matrix))

#plotting the mixtures
plt.figure()
plt.plot(t, M[:, 0], label='mixed signal1')
plt.plot(t, M[:, 1], label='mixed signal2')
plt.legend()
plt.show

# Compute ICA
Esempio n. 10
0
    # We mix them here

    source1 = np.matrix(img1_gray_re)
    source1 = source1.flatten('F')  #column wise

    source2 = np.matrix(img2_gray_re)
    source2 = source2.flatten('F')  #column wise

    source1 = source1 - np.mean(source1)
    source2 = source2 - np.mean(source2)

    source1 = source1 / np.linalg.norm(source1)
    source2 = source2 / np.linalg.norm(source2)

    rdr_this = rdc(source1.T, source2.T)
    source = np.stack((source1, source2))

    # randomly generated mixing matrix
    np.random.seed(0)
    #mixing_matrix = np.random.rand(2,2)
    mixing_matrix = np.array([[1, 0.5], [0.5, 1]])

    X = np.matmul(source.T, mixing_matrix)

    X1 = X[:, 0]
    mx1 = np.mean(X1)
    X1 = np.reshape(X1, (n, n))

    #print(X1.min(), X1.max(), X1.mean())
Esempio n. 11
0
# Mixing process here
img2_gray_re = np.fliplr(img2_gray)

source1 = np.matrix(img1_gray)
source1 = source1.flatten('F')  #column wise

source2 = np.matrix(img2_gray)
source2 = source2.flatten('F')  #column wise

source1 = source1 - np.mean(source1)
source2 = source2 - np.mean(source2)

#source1 = source1/np.linalg.norm(source1)
#source2 = source2/np.linalg.norm(source2)

print("rdc = ", rdc(source1.T, source2.T))
source = np.stack((source1, source2))

print('Covariance matrix is: ')
print(np.matmul(source, source.T))

# randomly generated mixing matrix
#np.random.seed(0)
#mixing_matrix = np.random.rand(2,2)
#mixing_matrix = np.array([[0.36, 0.66], [0.03, 0.95]])
mixing_matrix = np.array([[1, 0.5], [0.5, 1]])
print('Mixing matrix is: ')
print(mixing_matrix)

# X = source * mixing_matrix - The mixed images
    source1, source2 = load_images('./images/set' + str(i + 1) + '_pic1.png',
                                   './images/set' + str(i + 1) + '_pic2.png',
                                   n,
                                   show_images=False)
    S, X = linear_mixture(source1,
                          source2,
                          mixing_matrix=mixing_matrix,
                          show_images=False)

    #Reference SDR
    (sdr_ref, sir_ref, sar,
     perm) = mmetrics.bss_eval_sources(np.asarray(S), np.asarray(X))
    print('The mean value of the reference SDR is: ', np.mean(sdr_ref))

    #RDC of sources
    rdc_i = rdc(S[0, :], S[1, :])
    all_rdc.append(rdc_i)
    print("rdc of sources = ", rdc_i)

    #Kurtosis of sources
    kurtosis_i = mean_kurtosis(S)
    all_kurtosis_sources.append(kurtosis_i)
    print("mean kurtosis of sources = ", kurtosis_i)
    print("kurtosis of sources  = ", kurtosis(S[0, :]), kurtosis(S[1, :]))

    #Skewness of sources
    skewness_i = mean_skewness(S)
    all_skewness_sources.append(skewness_i)
    print("mean skewness of sources = ", skewness_i)
    print("skewness of sources = ", skew(S[0, :]), skew(S[1, :]))