使用Keras实现查找函数的最佳参数

2024-05-20 05:27:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否有可能建立一个基本的Keras回归神经网络,其中输入(x_数据)仅为4个双精度,是返回与测量数据(y_数据)大小相同的数组/数据帧的函数的参数输入?我目前正在使用非线性优化,但我认为如果能用神经网络解决这个问题,可能会很有趣,也很酷

重申一下,如何设置它,以便keras模型找到4个参数的最佳值,以最小化测量数据数组和函数输出数组之间的误差

例如:

y_data = np.array() # > 10,000 entries

x_data = [param1,param2,param3,param4]

但是我有一个函数,它计算一个与y_数据大小相等的输出数据帧,我想为4个参数找到一个最佳值,以最小化calc_votlage和y_数据之间的均方误差

calc_voltage = function(param1,param2,param3,param4)

我想使用如下类似的设置,最小化计算电压和y_数据之间的均方误差

model = keras.Sequential()
model.add(keras.layers.Dense(units = 1, activation = 'linear', input_shape=[4]))
model.add(keras.layers.Dense(units = 64, activation = 'relu'))
model.add(keras.layers.Dense(units = 64, activation = 'relu'))
model.add(keras.layers.Dense(units = 64, activation = 'relu'))
model.add(keras.layers.Dense(units = 1, activation = 'linear'))
model.compile(loss='mse', optimizer="adam")

model.fit(x_data, y_data, epochs=40, verbose=1) 

#not sure how to do this whether it should be something like this rather?

model.fit(function(param1,param2,param3,param4), y_data, epochs=40, verbose=1)


Tags: 数据函数adddata参数modellayers数组