对于一系列(x,Q ^ 2)值,我有一些数据y(x,Q ^ 2),对于函数形式,有ansatz作为
y_ansatz(x,Q ^ 2)= L(x,Q ^ 2)(1 + c(x)/ Q ^ 2)
其中L是已知值。
我想在我输入(x,Q ^ 2,L(x,Q ^ 2))并在y(x,Q ^ 2)上训练以获得c(x)的情况下进行拟合。
我尝试使用model.fit()
,但这将为整个y(x,Q ^ 2)生成一个模型,而不仅仅是c(x),例如
inputs_train = np.stack((x_train, q2_train)).T
hist = model.fit(inputs_train,
dat_train,
batch_size= 32,
epochs=10000,
shuffle=True,
verbose=1,
callbacks=[es, mc],
validation_data=(inputs_val, dat_val))
我还想使用自定义损失函数,
损失=(1 / N_数据)*(y_ansatz-y_true)@ mat @(y_ansatz-y_true)
其中mat是一个N_data by N_data矩阵, 但是在keras中,您只能将y_pred和y_true传递给自定义损失函数。其他线程已经解决了这个问题,例如Keras Custom loss function to pass arguments other than y_true and y_pred,但我不知道如何在批处理数据时确保选择正确的mat元素。
如果有人知道怎么做会很有帮助:
为给定ansatz的一部分生成模型,而不是直接为数据生成模型
创建一个自定义损失函数,该函数需要其他输入并可以批量处理
非常感谢! :)