首页 > 解决方案 > 您如何将 2D 矩阵表示为输入状态,并让它选择它认为对该状态最佳操作的行的索引?

问题描述

我正在尝试构建一个 RL 模型,其中输入是 NxM 矩阵,N 是可选动作的数量,M 是描述动作的特征。

到目前为止,在我见过的所有 RL 问题中,状态空间要么是一个向量并传入常规神经网络,要么是一个图像并通过卷积神经网络传入。

但是假设我们有一个环境,目标是学习为固定任务选择最强的工作人员,单个状态表示如下所示:


names = ['Bob','Henry','Mike','Phil']
max_squat = [300,400,200,100]
max_bench = [200,100,225,100]
max_deadlift = [600,400,300,225]
strongest_worker_df = pd.DataFrame({'Name':names,'Max_Squat':max_squat,'Max_Bench':max_bench,'Max_Deadlift':max_deadlift})

在此处输入图像描述

我想传入这个 2D 矩阵(当然没有 Name 列)作为输入并让它返回一个行索引,然后将该行索引作为一个动作传递给环境并获得奖励。然后在关于动作选择的奖励梯度上运行强化学习算法。

关于如何解决这个问题的任何建议,特别是国家代表?

标签: reinforcement-learning

解决方案


好吧,只要您的矩阵大小固定(N 和 M 不变),您就可以对其进行矢量化(连接行),网络就会像这样工作。

这样做可能不是最理想的,因为考虑到问题设置,似乎最好将每一行通过相同的神经网络来获取特征,然后有一个对连接特征进行操作的顶级鉴别器。

可以执行此操作的示例模型(在 TensorFlow 代码中)是:

model_input = x = Input(shape=(N, M))
x = Dense(64, activation='relu')(x)
x = Dropout(0.1)(x)
x = Dense(32, activation='relu')(x)
x = Dropout(0.1)(x)
x = Dense(16, activation='relu')(x)
x = Dropout(0.1)(x)

# The layers above this line define the feature generator, at this point
# your model has 16 fetaures for every person, i.e. an Nx16 matrix.
# Each person's feature have gone through the same nodes and have received
# the same transformations from them.

x = Flatten()(x)

# The Nx16 matrix is now flattened and below define the discriminator
# which will have a softmax output of size N (the highest output identifies
# the selected index)

x = Dense(16, activation='relu')(x)
x = Dropout(0.1)(x)
x = Dense(16, activation='relu')(x)
x = Dropout(0.1)(x)
x = Dense(16, activation='relu')(x)
x = Dropout(0.1)(x)
x = Dense(N, activation='softmax')(x)


model = Model(inputs=model_input, outputs=x)

推荐阅读