docstr: Test removing hidden state factor levels and/or observation levels from the likelihood arrays 
  of a generative model, using the `_prune_A` and `_prune_B` functions of the `learning` module
docstr_tok: ["Test","removing","hidden","state","factor","levels","and\/or","observation","levels","from","the","likelihood","arrays","of","a","generative","model",",","using","the","`","_prune_A","`","and","`","_prune_B","`","functions","of","the","`","learning","`","module"]
code: def test_prune_likelihoods(self):
      """
      Test removing hidden state factor levels and/or observation levels from the likelihood arrays
      of a generative model, using the `_prune_A` and `_prune_B` functions of the `learning` module
      """
  
      """ Test 1a. Testing `_prune_A()` in case of a single hidden state factor/modality """
  
      A = utils.random_A_matrix([5], [4])[0]
  
      obs_levels_to_prune = [2, 3]
      state_levels_to_prune = [1, 3]
  
      A_pruned = learning._prune_A(
          A, obs_levels_to_prune, state_levels_to_prune
      )
  
      expected_shape = (
          A.shape[0] - len(obs_levels_to_prune),
          A.shape[1] - len(state_levels_to_prune),
      )
      self.assertTrue(A_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(A_pruned))
  
      """ Test 1b. Testing `_prune_A()` in case of a single hidden state factor/modality, where hidden state levels aren't pruned at all """
  
      A = utils.random_A_matrix([5], [4])[0]
  
      obs_levels_to_prune = [2, 3]
      state_levels_to_prune = []
  
      A_pruned = learning._prune_A(
          A, obs_levels_to_prune, state_levels_to_prune
      )
  
      expected_shape = (
          A.shape[0] - len(obs_levels_to_prune),
          A.shape[1] - len(state_levels_to_prune),
      )
      self.assertTrue(A_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(A_pruned))
  
      """ Test 1c. Testing `_prune_A()` in case of a single hidden state factor/modality, where observation levels aren't pruned at all """
  
      A = utils.random_A_matrix([5], [4])[0]
  
      obs_levels_to_prune = []
      state_levels_to_prune = [2, 3]
  
      A_pruned = learning._prune_A(
          A, obs_levels_to_prune, state_levels_to_prune
      )
  
      expected_shape = (
          A.shape[0] - len(obs_levels_to_prune),
          A.shape[1] - len(state_levels_to_prune),
      )
      self.assertTrue(A_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(A_pruned))
  
      """ Test 1d. Testing `_prune_A()` in case of a multiple hidden state factors/modalities """
  
      num_obs = [3, 4, 5]
      num_states = [2, 10, 4]
      A = utils.random_A_matrix(num_obs, num_states)
  
      obs_levels_to_prune = [[0, 2], [], [1, 2, 3]]
      state_levels_to_prune = [[], [5, 6, 7, 8], [1]]
  
      A_pruned = learning._prune_A(
          A, obs_levels_to_prune, state_levels_to_prune
      )
  
      expected_lagging_dimensions = []
      for f, ns in enumerate(num_states):
          expected_lagging_dimensions.append(
              ns - len(state_levels_to_prune[f])
          )
      for m, no in enumerate(num_obs):
          expected_shape = (no - len(obs_levels_to_prune[m]),) + tuple(
              expected_lagging_dimensions
          )
          self.assertTrue(A_pruned[m].shape == expected_shape)
          self.assertTrue(utils.is_normalized(A_pruned[m]))
  
      """ Test 2a. Testing `_prune_B()` in case of a single hidden state factor / control state factor """
  
      B = utils.random_B_matrix([4], [3])[0]
  
      state_levels_to_prune = [1, 3]
      action_levels_to_prune = [0, 1]
  
      B_pruned = learning._prune_B(
          B, state_levels_to_prune, action_levels_to_prune
      )
  
      expected_shape = (
          B.shape[0] - len(state_levels_to_prune),
          B.shape[1] - len(state_levels_to_prune),
          B.shape[2] - len(action_levels_to_prune),
      )
      self.assertTrue(B_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(B_pruned))
  
      """ Test 2b. Testing `_prune_B()` in case of a single hidden state factor, where control state levels aren't pruned at all """
  
      B = utils.random_B_matrix([4], [3])[0]
  
      state_levels_to_prune = [1, 3]
      action_levels_to_prune = []
  
      B_pruned = learning._prune_B(
          B, state_levels_to_prune, action_levels_to_prune
      )
  
      expected_shape = (
          B.shape[0] - len(state_levels_to_prune),
          B.shape[1] - len(state_levels_to_prune),
          B.shape[2] - len(action_levels_to_prune),
      )
      self.assertTrue(B_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(B_pruned))
  
      """ Test 1c. Testing `_prune_B()` in case of a single hidden state factor, where hidden state levels aren't pruned at all """
  
      B = utils.random_B_matrix([4], [3])[0]
  
      state_levels_to_prune = []
      action_levels_to_prune = [0]
  
      B_pruned = learning._prune_B(
          B, state_levels_to_prune, action_levels_to_prune
      )
  
      expected_shape = (
          B.shape[0] - len(state_levels_to_prune),
          B.shape[1] - len(state_levels_to_prune),
          B.shape[2] - len(action_levels_to_prune),
      )
      self.assertTrue(B_pruned.shape == expected_shape)
      self.assertTrue(utils.is_normalized(B_pruned))
  
      """ Test 1d. Testing `_prune_B()` in case of a multiple hidden state factors """
  
      num_states = [2, 10, 4]
      num_controls = [5, 3, 4]
      B = utils.random_B_matrix(num_states, num_controls)
  
      state_levels_to_prune = [[0, 1], [], [1, 2, 3]]
      action_levels_to_prune = [[], [0, 1], [1]]
  
      B_pruned = learning._prune_B(
          B, state_levels_to_prune, action_levels_to_prune
      )
  
      for f, ns in enumerate(num_states):
          expected_shape = (
              ns - len(state_levels_to_prune[f]),
              ns - len(state_levels_to_prune[f]),
              num_controls[f] - len(action_levels_to_prune[f]),
          )
          self.assertTrue(B_pruned[f].shape == expected_shape)
          self.assertTrue(utils.is_normalized(B_pruned[f]))
  
imports: import unittest
  import numpy
  from pymdp import utils, maths, learning
  from copy import deepcopy
label_desc: Use image node_id 19 for calling the TestLearning obj's underlying member method code with example usage: obj.test_prune_likelihoods() without return types