def check_multinomial_samples(value, expected_shape, expected_mean, tol):
 assert (value.shape == expected_shape)
 assert is_binary(value)
 assert np.all((value.sum(axis=1) == 1))
 mean = value.mean(axis=0)
 max_error = np.abs((mean - expected_mean)).max()
 if (max_error > tol):
  print('Actual mean:')
  print(mean)
  print('Expected mean:')
  print(expected_mean)
  print('Maximal error:', max_error)
  raise ValueError("Samples don't seem to have the right mean.")

def check_multinomial_samples ( value , expected_shape , expected_mean , tol ) : assert ( value . shape == expected_shape ) assert is_binary ( value ) assert np . all ( ( value . sum ( axis = 1 ) == 1 ) ) mean = value . mean ( axis = 0 ) max_error = np . abs ( ( mean - expected_mean ) ) . max ( ) if ( max_error > tol ) : print ( 'Actual mean:' ) print ( mean ) print ( 'Expected mean:' ) print ( expected_mean ) print ( 'Maximal error:' , max_error ) raise ValueError ( "Samples don't seem to have the right mean." )
tests that a matrix of multinomial samples 1) has the right shape 2) is binary 3) has one 1 per row 4) converges to the right mean .