Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor get model dimensions from labels #126

Conversation

Arun-Niranjan
Copy link
Contributor

@Arun-Niranjan Arun-Niranjan commented Dec 30, 2023

Currently when setting up a model using labels, it is not possible to set up both A and B matrix stubs from the same labels dictionary, due to the implied absence/presence of the actions key.

This isn't a great user experience - ideally someone should be able to specify all the labels in a single variable, and then generate all constituent parts of the model from that.

E.g. the following label spec:

model_labels = {
    "observations": {
        "species_observation": [
            "absent",
            "present",
        ],
        "budget_observation": [
            "high",
            "medium",
            "low",
        ],
    },
    "states": {
        "species_state": [
            "extant",
            "extinct",
        ],
    },
    "actions": {
        "conservation_action": [
            "manage",
            "survey",
            "stop",
        ],
    },
}

raises the following error from create_A_matrix_stub():

  File "/home/arunn/repos/pymdp-cookbook/venv/lib/python3.11/site-packages/pymdp/utils.py", line 457, in create_A_matrix_stub
    num_obs, _, num_states, _= get_model_dimensions_from_labels(model_labels)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 4)

This change:

  • adds a Dimensions object to be returned when getting dimensions from labels. as 6 return values is a bit messy
  • ignores dimensions related to actions when creating an A matrix
  • adds a new unit test for Dimensions and updates the existing one for the create_A_matrix_stub()

@Arun-Niranjan Arun-Niranjan marked this pull request as ready for review December 30, 2023 17:12
@conorheins
Copy link
Collaborator

Looks great -- thanks @Arun-Niranjan !

@conorheins conorheins merged commit 9aa1e2c into infer-actively:master Feb 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants