You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
Hi, thanks for the great project! I noticed that if we were using float element in the observation vector, we should use custom objects.
A snippet of cpp end likes this:
char* EncodeObservation(pyhanabi_observation_encoder_t* encoder,
pyhanabi_observation_t* observation) {
REQUIRE(encoder != nullptr);
REQUIRE(encoder->encoder != nullptr);
REQUIRE(observation != nullptr);
REQUIRE(observation->observation != nullptr);
auto obs_enc = reinterpret_cast<hanabi_learning_env::ObservationEncoder*>(
encoder->encoder);
auto obs = reinterpret_cast<hanabi_learning_env::HanabiObservation*>(
observation->observation);
std::vector<int> encoding = obs_enc->Encode(*obs);
std::string obs_str = "";
for (int i = 0; i < encoding.size(); i++) {
obs_str += (encoding[i] ? "1" : "0");
if (i != encoding.size() - 1) {
obs_str += ",";
}
}
return strdup(obs_str.c_str());
}
And the python-end likes this:
def encode(self, observation):
"""Encode the observation as a sequence of bits."""
c_encoding_str = lib.EncodeObservation(self._encoder,
observation.observation())
encoding_string = encode_ffi_string(c_encoding_str)
lib.DeleteString(c_encoding_str)
# Canonical observations are bit strings, so it is ok to encode using a
# string. For float or double observations, make a custom object
encoding = [int(x) for x in encoding_string.split(",")]
return encoding
I understand the current implementation only deals with int observation elements. They are first convert to "01"strings and then decoded in python with cffi. As for ``float, I tried to replace obs_str += (encoding[i] ? "1" : "0");` with `obs_str += std::to_string(encoding[i] )` (assuming the contents of `encoding` are floats). But what python-end decoded are not floats. I wonder if there are any examples demonstrating how to deal with float observations?
The text was updated successfully, but these errors were encountered:
0xJchen
changed the title
Defining Non-canonical Observations
Defining Non-canonical (Float) Observations
Feb 25, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi, thanks for the great project! I noticed that if we were using float element in the observation vector, we should use custom objects.
A snippet of cpp end likes this:
And the python-end likes this:
I understand the current implementation only deals with
int
observation elements. They are first convert to "01"strings and then decoded in python withcffi
. As for ``float, I tried to replace
obs_str += (encoding[i] ? "1" : "0");` with `obs_str += std::to_string(encoding[i] )` (assuming the contents of `encoding` are floats). But what python-end decoded are not floats. I wonder if there are any examples demonstrating how to deal with float observations?The text was updated successfully, but these errors were encountered: