示例#1
0
def sentence_to_dmd_vec(to_keep, time_lags, concat_avg, vectors):
    v = numpy.asarray(vectors)
    list_of_modes = []
    for d in time_lags:
        dmd = HODMD(svd_rank=to_keep, opt=True, exact=True, d=d)
        dmd.fit(v.T)
        fmode = dmd.modes.T
        list_of_modes.append(numpy.hstack(numpy.absolute(fmode)))

    if concat_avg:
        mean_vec = p_mean_vector([1.0], v)
        list_of_modes.append(mean_vec)

    return numpy.hstack(list_of_modes)
示例#2
0
    def _get_modes_from_word_vecs(self, v, concat_avg=True):
        list_of_modes = []
        time_lags = [1, 2]
        for d in time_lags:
            dmd = HODMD(svd_rank=2, opt=True, exact=True, d=d)
            dmd.fit(v.T)
            fmode = dmd.modes.T
            list_of_modes.append(np.hstack(np.absolute(fmode)))

        if concat_avg:
            mean_vec = self._p_mean_vector([1.0], v)
            list_of_modes.append(mean_vec)

        return list_of_modes
示例#3
0
dataGridHalf2 = uGridHalf2

# Joined data
tVector = np.hstack((tVectorHalf1, tVectorHalf2))
xGrid, tGrid = np.meshgrid(xVector1, tVector)
uGrid = np.vstack((uGridHalf1, uGridHalf2))
vGrid = np.vstack((vGridHalf1, vGridHalf2))
aGrid = np.vstack((aGridHalf1, aGridHalf2))
uexGrid = np.vstack((uexGridHalf1, uexGridHalf2))
dataGrid = np.vstack((dataGridHalf1, dataGridHalf2))

# Compute DMDs
d = 5
print('Computing DMD 1...')
hodmd1 = HODMD(svd_rank=rank, opt=True, d=d)
hodmd1.fit(dataGridHalf1.T)

print('Computing DMD 2...')
hodmd2 = HODMD(svd_rank=rank, opt=True, d=d)
hodmd2.fit(dataGridHalf2.T)

print('Computing mixed DMD...')
hodmd = HODMD(svd_rank=rank, opt=True, d=d)
hodmd.fit(dataGrid.T)

# Adjust times for partials
hodmd1.original_time['dt'] = hodmd1.dmd_time[
    'dt'] = tVectorHalf1[1] - tVectorHalf1[0]
hodmd1.original_time['t0'] = hodmd1.dmd_time['t0'] = tVectorHalf1[0]
hodmd1.original_time['tend'] = hodmd1.dmd_time['tend'] = tVectorHalf1[-1]
hodmd1.dmd_time['tend'] = tVector1[-1]
示例#4
0
文件: DMD.py 项目: gocaba/TFM-MUMI
# fig = plt.figure(figsize=(17,6))
# plt.pcolor(xGrid, tGrid, uGrid)
# plt.title('Displacement')
# plt.colorbar()
# plt.show()
# # print('Done')

print('Computing DMD...')

# ----------------------------------------------------------------------------------------------------------------------

# Compute DMD on displacement
d  = 5
dmd = HODMD(svd_rank=rank, opt=True, d=d)
# dmd = MrDMD(svd_rank=rank, max_level = 3, max_cycles = 1)
dmd.fit(dataGrid.T)

# Show eigenvalues
for eig in dmd.eigs:
    print('Eigenvalue {}: distance from unit circle {}'.format(eig, np.abs(eig.imag**2+eig.real**2 - 1)))

dmd.plot_eigs(show_axes=True, show_unit_circle=True)

# Show modes
fig = plt.figure(figsize=(8,3))
fig.subplots_adjust(top=0.8, bottom=0.2)
plt.subplot(121)
for mode in dmd.modes.T:
    plt.plot(xVector, mode.real)
    plt.title('Modes')
    plt.xlabel('$x$')
示例#5
0
# fig = plt.figure(figsize=(17,6))
# plt.pcolor(xGrid, tGrid, uGrid)
# plt.title('Displacement')
# plt.colorbar()
# plt.show()
# # print('Done')

print('Computing DMD...')

# ----------------------------------------------------------------------------------------------------------------------

# Compute DMD on displacement
d = 5
dmd = HODMD(svd_rank=rank, opt=True, d=d)
# dmd = MrDMD(svd_rank=rank, max_level=2, max_cycles=2)
dmd.fit(dataGrid.T)

# Show eigenvalues
for eig in dmd.eigs:
    print('Eigenvalue {}: distance from unit circle {}'.format(
        eig, np.abs(eig.imag**2 + eig.real**2 - 1)))

dmd.plot_eigs(show_axes=True, show_unit_circle=True)

# Show modes
for mode in dmd.modes.T:
    plt.plot(xVector, mode.real)
    plt.title('Modes')
plt.show()

# Show dynamics