Files
bo-ptycho/notebooks/convergence.ipynb
T
2026-08-12 22:08:17 +09:00

3.6 KiB

In [ ]:
import os
import numpy as np
import matplotlib.pyplot as plt
In [ ]:
result_dir = "../results/260812-Si/Si2V1_2"
train_x = np.load(os.path.join(result_dir, 'train_x.npy')).T
train_y = np.load(os.path.join(result_dir, 'train_y.npy')).T
In [ ]:
train_x.shape
In [ ]:
xparams = [
    'defocus [A]',
    'layers',
    'thickness [A]'
]

sort_index = np.argsort(train_y)

x = train_x[:,sort_index]
y = train_y[sort_index]

EPSILON = 1e-3 # choose best according to plot

train_y_scaled = np.log(-train_y + y[-1] + EPSILON)
y_scaled = np.log(-y + y[-1] + EPSILON)

fig, ax = plt.subplots(1, 2, figsize=(7,3))
ax[0].plot(y, 'k')
ax[1].plot(y_scaled, 'k')
plt.show()

fig, ax = plt.subplots(1, 2, figsize=(7,3))
ax[0].plot(train_y, 'k')
ax[1].plot(train_y_scaled, 'k')
plt.show()
In [ ]:
cut = 0 # set to -1 to get all points

fig, axs = plt.subplots(1, len(x), figsize=(3*len(x)+0.5, 3.5), sharey=True)

for i, axi in enumerate(axs):
    axi.scatter(x[i][cut:], y_scaled[cut:], c=y_scaled[cut:], cmap='coolwarm')
    axi.set_xlabel(xparams[i])

axs[0].set_ylabel('$- \\log (\ \\mathtt{fourier\_error}\ )$')

plt.tight_layout()
plt.show()
In [ ]:

fig, axs = plt.subplots(len(x), len(x), figsize=(3*len(x)+0.5, 3*len(x)+0.5))

for i, axi in enumerate(axs):
    for j, axij in enumerate(axi):
        axij.scatter(
            x[j], x[i],
            c = y_scaled, # color
            cmap = 'coolwarm',
            s = 20, # size
            alpha = 0 if i == j else 1 # make diagonal transparent
            )
        if i == len(x)-1:
            axij.set_xlabel(xparams[j])
        else:
            axij.set_xticks([])
        if j == 0:
            axij.set_ylabel(xparams[i])
        else:
            axij.set_yticks([])

plt.tight_layout()
plt.show()
In [ ]: