简体   繁体   English

当 tensorflow Model.fit 没有在深度对冲示例代码中传递的参数 y 的情况下工作?

[英]When the tensorflow Model.fit works without argument y passed in the Deep Hedging sample code?

I am studying the Deep Hedging code and I am very puzzled why the model.fit is called but only x is passed in?我正在研究深度套期保值代码,我很困惑为什么调用了 model.fit 但只传入了 x? model_simple.fit(x=xtrain, batch_size=batch_size, epochs=epochs, validation_data=xtest, verbose=1) ? model_simple.fit(x=xtrain, batch_size=batch_size, epochs=epochs, validation_data=xtest, verbose=1) xtrain is of type list but not tf.data Dataset type . xtrain是 list 类型,但不是tf.data 数据集类型

Without y how can this model be trained?没有 y 如何训练这个 model?

The code of class Deep_Hedging_Model is here class Deep_Hedging_Model的代码在这里

#@title <font color='Blue'>**Run the Deep Hedging Algorithm (Simple Network)!**</font>
%autoreload 2

optimizer = Adam(learning_rate=lr)

# Setup and compile the model
model_simple = Deep_Hedging_Model(N=N, d=d+2, m=m, risk_free=risk_free, \
          dt = dt, strategy_type="simple", epsilon = epsilon, \
          use_batch_norm = use_batch_norm, kernel_initializer = kernel_initializer, \
          activation_dense = activation_dense, activation_output = activation_output, \
          final_period_cost = final_period_cost, delta_constraint = delta_constraint, \
          share_stretegy_across_time = share_stretegy_across_time, \
          cost_structure = cost_structure)
loss = Entropy(model_simple.output,None,loss_param)
model_simple.add_loss(loss)

model_simple.compile(optimizer=optimizer)

early_stopping = EarlyStopping(monitor="loss", \
          patience=10, min_delta=1e-4, restore_best_weights=True)
reduce_lr = ReduceLROnPlateau(monitor="loss", \
          factor=0.5, patience=2, min_delta=1e-3, verbose=0)

callbacks = [early_stopping, reduce_lr]

# Fit the model.
model_simple.fit(x=xtrain, batch_size=batch_size, epochs=epochs, \
          validation_data=xtest, verbose=1)

clear_output()

print("Finished running deep hedging algorithm! (Simple Network)")

It seems like this model is trained using a loss function that doesn't depend on a target y value.似乎这个 model 是使用不依赖于目标y值的损失 function 进行训练的。 Instead, it uses this Entropy loss value which was added using the add_loss API .相反,它使用使用add_loss API添加的Entropy损失值。 I can't tell you what this Entropy value means because I don't know any specific details about this model, but basically the model wasn't compiled with a loss function so model.fit() will fall back to optimizing only the losses added via add_loss() . I can't tell you what this Entropy value means because I don't know any specific details about this model, but basically the model wasn't compiled with a loss function so model.fit() will fall back to optimizing only the losses通过add_loss()添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM