MushroomRL / mushroom-rl

Python library for Reinforcement Learning.
MIT License
803 stars 145 forks source link

Multi modal state support #128

Closed angel-ayala closed 1 year ago

angel-ayala commented 1 year ago

I have an environment which delivers robot sensors through the info var and some other information as state, and the library does not allows to use an state composed of more than one dimensional data. That's was by design purpose? I was thinking in create a preprocessor which encode and the decode the given data into a state vector. However, I'm unable to get the vars given in info.

I was looking into Core class code and found that info is setted after env.step https://github.com/MushroomRL/mushroom-rl/blob/918820a3eb7373d5571aab5e25c87a595a9827e3/mushroom_rl/core/core.py#L148-L150 and then using only the last step info data on agent.fit https://github.com/MushroomRL/mushroom-rl/blob/918820a3eb7373d5571aab5e25c87a595a9827e3/mushroom_rl/core/core.py#L166-L167

I need to pass state and info data to use multi sensor type information as state to an algorithm.

Can be a solution creates a preprocessor that takes a state with two elements and then convert it in a single vector? Or a multi modal approach should considers agent.fit method adaptation to accept a tuple as state?

Thanks,

boris-il-forte commented 1 year ago

Dear @angel-ayala , By design, the policy should not have access to the env info. The policy should only act on the state. I suggest an easy solution: wrap your environment with another environment, that simply concatenates the two states.

In general, you can have an arbitrary representation of the state as numpy array in mushroom. If using a numpy array of objects is not fine, you could always create a state class that implements the copy and access methods, and you should be fine.

In general, however, we suggest avoiding using a dictionary as a state, we recommend flattening it into a single vector of concatenated info.