小编Art*_*tur的帖子

Keras神经网络函数逼近

我试图近似以下函数: 在此输入图像描述

但我最好的结果看起来像:

在此输入图像描述 (右侧的损失函数)我什至尝试过 50k epoch,得到类似的结果。

模型:

model = Sequential()
model.add(Dense(40, input_dim=1,kernel_initializer='he_normal', activation='relu'))
model.add(Dense(20, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(1,input_dim=1, activation=activation_fun))
model.compile(loss='mse', optimizer='adam', metrics=['mse', 'mae', 'mape', 'cosine'])
history = model.fit(x, y, batch_size=32, epochs=5000, verbose=0)

preds = model.predict(x_test)
prettyPlot(x,y,x_test,preds,history,'linear',5000)
model.summary()
Run Code Online (Sandbox Code Playgroud)

PrettyPlot函数创建绘图。

如何在不改变神经网络拓扑的情况下获得更好的结果?我不希望它太大或太宽。如果可能的话,我想使用更少的隐藏层和神经元。

我想要近似的函数:

def fun(X):
    return math.sin(1.2*X + 0.5) + math.cos(2.5*X + 0.2) + math.atan(2*X + 1) -  math.cos(2*X + 0.5) 
Run Code Online (Sandbox Code Playgroud)

样品:

range = 20
x = np.arange(0, range, 0.01).reshape(-1,1)
y = np.array(list(map(fun, x))).reshape(-1,1)

x_test = (np.random.rand(range*10)*range).reshape(-1,1)
y_test = np.array(list(map(fun, x_test))).reshape(-1,1)
Run Code Online (Sandbox Code Playgroud)

然后使用 MinMaxScaler …

neural-network keras

6
推荐指数
1
解决办法
1282
查看次数

标签 统计

keras ×1

neural-network ×1