-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquareRR_AOPS_Fig_04bc.py
71 lines (63 loc) · 2.81 KB
/
SquareRR_AOPS_Fig_04bc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
The code for the research presented in the paper titled "Enabling inverse design of plasmon-based nonlinear square resonators with deep neural networks."
This code corresponds to the article's Forward Deep Neural Network (DNN) section.
This code regenerates the Fig. 4b and c of the paper.
Please cite the paper in any publication using this code.
"""
import numpy as np
import keras
import pandas as pd
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
result1 = pd.read_csv("result_V.csv", header=None)
result1 = result1.to_numpy()
result1 = result1.astype(np.float16)
x_train = result1[0:result1.shape[0],0:6]
y_train = result1[0:result1.shape[0],6]
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
# Load the saved forward model
json_file = open("SquareRR_AOPS_forward_model.json", "r")
loaded_model_json = json_file.read()
json_file.close()
loaded_model = keras.models.model_from_json(loaded_model_json)
loaded_model.load_weights("SquareRR_AOPS_forward_model_weights.h5")
loaded_model.summary()
# Lower sample
result3 = pd.read_csv("SquareRR_AOPS_Fig_04bc_Lower_sample.csv", header=None)
result3 = result3.to_numpy()
result3 = result3.astype(np.float16)
x_test3 = result3[:,0:6]
y_test3 = result3[:,6]
x_test3 = sc.transform(x_test3)
# FDTD origin
result4 = pd.read_csv("SquareRR_AOPS_Fig_04bc_FDTD_origin.csv", header=None)
result4 = result4.to_numpy()
result4 = result4.astype(np.float16)
x_test4 = result4[:,0:6]
y_test4 = result4[:,6]
x_test4 = sc.transform(x_test4)
# Higher sample
result5 = pd.read_csv("SquareRR_AOPS_Fig_04bc_Higher_sample.csv", header=None)
result5 = result5.to_numpy()
result5 = result5.astype(np.float16)
x_test5 = result5[:,0:6]
y_test5 = result5[:,6]
x_test5 = sc.transform(x_test5)
# DL prediction
Pre4 = loaded_model.predict(x_test4)
# Plot all 4 curve
X= result4[:,0]
plt.plot(X, result4[:,6], linewidth=2, linestyle='-.', color=((255/255, 127/255, 14/255))) #DFTD
plt.plot(X,Pre4[:,0], linewidth=2, linestyle='--', color=((0/255, 114/255, 189/255))) #DL
plt.plot(X,result3[:,6], linewidth=2, color=((126/255, 47/255, 142/255))) #Lower sample
plt.plot(X,result5[:,6], linewidth=2, linestyle=':', color=((119/255, 172/255, 48/255))) #Higher sample
plt.xlabel('Wavelength(nm)', fontname='Times New Roman', fontsize=18)
plt.ylabel('Transmission', fontname='Times New Roman', fontsize=18)
plt.xticks(fontfamily='Times New Roman', fontsize=14)
plt.yticks(fontfamily='Times New Roman', fontsize=14)
plt.title('Comparing DL to FDTD for through port', loc='center', fontname='Times New Roman', fontsize=18)
font_prop = FontProperties(family="Times New Roman", size=16)
plt.legend(['FDTD', 'DL', 'Low Near', 'High Near'], prop=font_prop)
plt.show()