code: def test_handles_reducing_perplexity_value(self):
      perplexity = 20  # initial perplexity values
      k_neighbors = perplexity * 3
      aff = PerplexityBasedNN(self.x, perplexity=perplexity)
  
      self.assertEqual(aff.perplexity, perplexity)
      self.assertEqual(aff.effective_perplexity_, perplexity)
  
      # Check that the initial `P` matrix is allright
      n_samples = self.x.shape[0]
      original_P = aff.P.copy()
      # Can't check for equality because the matrix is symmetrized therefore
      # each point may have non-zero values in more than just the k neighbors
      self.assertTrue(original_P.nnz >= n_samples * k_neighbors)
  
      # Check that lowering the perplexity properly changes affinity matrix
      perplexity = 10  # lower the perplexity value
      k_neighbors = perplexity * 3
  
      aff.set_perplexity(perplexity)
      self.assertEqual(aff.perplexity, perplexity)
      self.assertEqual(aff.effective_perplexity_, perplexity)
  
      reduced_P = aff.P.copy()
      self.assertTrue(reduced_P.nnz >= n_samples * k_neighbors)
      self.assertTrue(
          reduced_P.nnz < original_P.nnz,
          "Lower perplexities should consider less neighbors, "
          "resulting in a sparser affinity matrix",
      )
  
      # Check that increasing the perplexity works (with a warning)
      # Larger than the original perplexity, but still less than the number of
      # nearest neighbors
      perplexity = 40
      with self.assertLogs(affinity.log, level="WARNING"):
          aff.set_perplexity(perplexity)
          self.assertEqual(aff.perplexity, perplexity)
          self.assertEqual(aff.effective_perplexity_, perplexity)
  
      # Raising the perplexity above the number of neighbors in the kNN graph
      # would need to recompute the nearest neighbors, so it should raise an error
      with self.assertRaises(RuntimeError):
          aff.set_perplexity(70)
  
imports: import logging
  import unittest
  from functools import partial
  import numpy
  from scipy.spatial.distance import squareform, pdist
  from sklearn import datasets
  from sklearn.model_selection import train_test_split
  from openTSNE import affinity, nearest_neighbors
label_desc: Use image node_id 3 for calling the TestPerplexityBased obj's underlying member method code with example usage: obj.test_handles_reducing_perplexity_value() without return types