Assuming a relation such that $y = f(x)$, where $y$ represents a scalar and $x \in 20 \times 1$ vector consisting of zeros and ones, I want to set up a reinforcement learning model that changes the values of the elements of $x$ in order to maximize the $y$.

Let's assume that $y = f(x)$ is equal to

weights = np.random.uniform(-1, 1, 20) 
y       = np.sum(weights*x)

How do I set up such model? In my implementation, I am using keras API and I am trying to adapt the cartpole case code (https://keras.io/examples/rl/actor_critic_cartpole/). However, this code solves for a different problem since the model can perform only one action that can assume discrete values. Secondarily, is it appropriate to set as a reward function simply $y$?. The following code reports how I would structure the architectures.

num_inputs = 20
num_actions = 2
num_hidden = 128

inputs = layers.Input(shape=(num_inputs,))
common = layers.Dense(num_hidden, activation="relu")(inputs)
action = layers.Dense(num_actions, activation="softmax")(common)
critic = layers.Dense(1)(common)

model = keras.Model(inputs=inputs, outputs=[action, critic])

However, how can I control the fact that the input parameters could assume only discrete values (0 and 1)?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy