Ejemplo n.º 1
0
def windowed_data_lstm(window_size, *ts_data):
    dataset = np.ndarray((len(ts_data[0]) - window_size + 1, window_size, len(ts_data)))

    for i, ts in enumerate(ts_data):
        dataset[:, :, i] = sliding_window_view(ts, (window_size,), 1)

    return dataset
Ejemplo n.º 2
0
def peaksToFingerprints(local_peaks, fn=15, songName = "None"):
    """Welcome to peaksToFingerprints.

    Args:
        local_peaks : The list of local peaks (a boolean array)
        fn : 
    Returns:
        fingerprints : a np array with all fingerprints (size 4)
    """
    
    
    times, freqs = np.where(local_peaks.T)
    fp = []
    f = sliding_window_view(freqs, window_shape=(len(freqs)-fn,), step = 1)
    t = sliding_window_view(freqs, window_shape=(len(times)-fn,), step = 1)
    fp.extend(list(zip(np.tile(freqs[:-fn], fn), f[1:].flatten(), (t[1::]-times[np.newaxis, :-fn]).flatten(), np.tile(times[:-fn], fn))))
    return fp
Ejemplo n.º 3
0
def windowed_data(window_size, *ts_data):
    k = window_size * len(ts_data)
    dataset = np.ndarray((len(ts_data[0]) - window_size + 1, k))

    for i, ts in enumerate(ts_data):
        dataset[:, window_size * i:window_size * (i + 1)] = sliding_window_view(ts, (window_size,), 1)

    return dataset[:-1]
Ejemplo n.º 4
0
def win_ver(board):
    h = sliding_window_view(board, (1, 4), (1, 1)).reshape(
        -1, 4)  #gets size (1, 4) windows(horizontal).
    for i in h:  #compare the windows to see if they have 4 ones or 4 twos
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    v = sliding_window_view(board, (4, 1), (1, 1)).reshape(
        -1, 4)  #gets size (4, 1) windows(vertical).
    for i in v:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    d1 = np.sum(sliding_window_view(board, (4, 4),
                                    (1, 1)).reshape(-1, 4, 4) * d1_filter,
                axis=1,
                dtype=int)
    #gets size (4, 4) windows(potential diagonal win).
    #Apply identity matrix inorder to keep main diagonal.
    #then flatten into shape(1, 4) arrays.
    for i in d1:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    d2 = np.sum(sliding_window_view(board, (4, 4),
                                    (1, 1)).reshape(-1, 4, 4) * d2_filter,
                axis=1,
                dtype=int)
    #same process using the second filter.
    for i in d2:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins
Ejemplo n.º 5
0
def win_ver(board):
    h = sliding_window_view(board, (1, 4), (1, 1)).reshape(-1, 4)
    for i in h:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    v = sliding_window_view(board, (4, 1), (1, 1)).reshape(-1, 4)
    for i in v:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    d1 = np.sum(sliding_window_view(board, (4, 4),
                                    (1, 1)).reshape(-1, 4, 4) * d1_filter,
                axis=1,
                dtype=int)
    for i in d1:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins

    d2 = np.sum(sliding_window_view(board, (4, 4),
                                    (1, 1)).reshape(-1, 4, 4) * d2_filter,
                axis=1,
                dtype=int)
    for i in d2:
        c = list(i)
        if c == [1, 1, 1, 1]:
            return True  #True = player1 wins
        if c == [2, 2, 2, 2]:
            return False  #False = player2 wins