コード例 #1
0
ファイル: model.py プロジェクト: gestom/metro_models
def iter_over_coordinates(input_coordinates_part, C, COV, structure, k):
    """
    input: input_coordinates_part numpy array, coordinates for model creation
           C numpy array kxd, matrix of k d-dimensional cluster centres
           COV numpy array kxdxd, matrix of covariance matrices
           structure list(int, list(floats), list(floats)),
                      number of non-hypertime dimensions, list of hypertime
                      radii nad list of wavelengths
           k positive integer, number of clusters
    output: grid_densities_part numpy array kx1, number of part of cells
                                                 belonging to the clusters
    uses: dio.create_X(), np.shape(), gc.collect(), np.tile(),
          np.sum(), np.dot(), np.array(),
          cl.partition_matrix()
    objective: to find out the number of cells (part of them) belonging to
               the clusters
    """
    X = dio.create_X(input_coordinates_part, structure)
    n, d = np.shape(X)
    gc.collect()
    D = []
    for cluster in range(k):
        C_cluster = np.tile(C[cluster, :], (n, 1))
        XC = dio.hypertime_substraction(X, C_cluster, structure)
        #XC = X - C_cluster
        VI = COV[cluster]#COV[cluster, :, :]
        D.append(np.sum(np.dot(XC, VI) * XC, axis=1))
        gc.collect()
    D = np.array(D)
    gc.collect()
    U = cl.partition_matrix(D, version='model')
    #U = U ** 2 #!!!
    gc.collect()
    grid_densities_part = np.sum(U, axis=1, keepdims=True)
    return grid_densities_part
コード例 #2
0
ファイル: model.py プロジェクト: gestom/metro_models
def covariance_matrices(X, C, U, structure):
    """
    input: X numpy array nxd, matrix of n d-dimensional observations
           C numpy array kxd, matrix of k d-dimensional cluster centres
           U numpy array kxn, matrix of weights
           structure list(int, list(floats), list(floats)),
                      number of non-hypertime dimensions, list of hypertime
                      radii nad list of wavelengths
    output: COV numpy array kxdxd, matrix of covariance matrices
    uses: cl.distance_matrix(), cl.partition_matrix()
          np.shape(), np.tile(), np.cov(), np.linalg.inv(), np.array()
    objective: to calculate covariance matrices for model
    """
    k, n = np.shape(U)
    D = cl.distance_matrix(X, C, U, structure)
    ## not pure fuzzy W :)
    #W = cl.partition_matrix(D, version='fuzzy')
    ## W with binary memberships from U
    #W = W * U
    COV = []
    for cluster in range(k):
        C_cluster = np.tile(C[cluster, :], (n, 1))
        XC = dio.hypertime_substraction(X, C_cluster, structure)
        #XC = X - C_cluster
        #V = np.cov(XC, aweights=W[cluster, :], ddof=0, rowvar=False)
        #V = np.cov(XC, ddof=0, rowvar=False)  # puvodni, melo by byt stejne
        V = np.cov(XC, bias=True, rowvar=False)
        if len(np.shape(V)) == 2:
            Vinv = np.linalg.inv(V)
        else:
            #print('V: ' + str(V))
            Vinv = np.array([[1 / V]])
        COV.append(Vinv)
    COV = np.array(COV)
    return COV
コード例 #3
0
ファイル: model.py プロジェクト: gestom/metro_models
def one_freq(one_input_coordinate, C, COV, structure, k,
                    density_integrals):
    """
    input: one_input_coordinate numpy array, coordinates for model creation
           C numpy array kxd, matrix of k d-dimensional cluster centres
           COV numpy array kxdxd, matrix of covariance matrices
           structure list(int, list(floats), list(floats)),
                      number of non-hypertime dimensions, list of hypertime
                      radii nad list of wavelengths
           k positive integer, number of clusters
           density_integrals numpy array kx1, matrix of ratios between
                                               measurements and grid cells
                                               belonging to the clusters
    output: freq array len(input_coordinates_part)x1,
                                           frequencies(stat) obtained
                                           from model in positions of part
                                           of input_coordinates
    uses: dio.create_X(), np.shape(), gc.collect(), np.tile(),
          np.sum(), np.dot(), np.array(),
          cl.partition_matrix()
    objective: to create grid of frequencies(stat) over a part time-space
               (histogram)
    """
    X = dio.create_X(one_input_coordinate, structure)
    n, d = np.shape(X)
    D = []
    for cluster in range(k):
        # C_cluster = np.tile(C[cluster, :], (n, 1))
        XC = dio.hypertime_substraction(X, C[cluster:cluster+1], structure)
        #XC = X - C[cluster]
        VI = COV[cluster]#COV[cluster, :, :]
        D.append(np.sum(np.dot(XC, VI) * XC, axis=1))
        # gc.collect()
    D = np.array(D)
    # gc.collect()
    U = cl.partition_matrix(D, version='model')
    #U = (U ** 2) * density_integrals
    U = U * density_integrals
    # gc.collect()
    freq = np.sum(U, axis=0)
    return freq
コード例 #4
0
def distance_matrix(X, C, U, structure):
    """
    input: X numpy array nxd, matrix of n d-dimensional observations
           C numpy array kxd, matrix of k d-dimensional cluster centres
           U numpy array kxn, matrix of weights
    output: D numpy array kxn, matrix of distances between every observation
            and every center
    uses: np.shape(), np.tile(), np.array(), np.abs()
    objective: to find difference between every observation and every
               center in every dimension
    """
    k, n = np.shape(U)
    D = []
    for cluster in range(k):
        C_cluster = np.tile(C[cluster, :], (n, 1))
        XC = dio.hypertime_substraction(X, C_cluster, structure)
        #XC = X - C_cluster
        # PROC ????
        ## L1 metrics
        #D.append(np.sum(np.abs(XC), axis=1))
        D.append(np.sqrt(np.sum(XC**2, axis=1)))
    D = np.array(D)
    return D