docstr: Function test computing min eigen value using matrix vector products.
docstr_tok: ["Function","test","computing","min","eigen","value","using","matrix","vector","products","."]
code: def test_get_min_eig_vec_proxy(self):
      """Function test computing min eigen value using matrix vector products."""
      sess, dual_formulation_object = self.prepare_dual_object()
      _, matrix_m = dual_formulation_object.get_full_psd_matrix()
      optimization_params = {
          "init_learning_rate": 0.1,
          "learning_rate_decay": 0.9,
          "eig_num_iter": 2000,
          "eig_learning_rate": 0.01,
          "init_smooth": 0.0,
          "smooth_decay": 0.9,
          "inner_num_steps": 10,
          "optimizer": "adam",
          "momentum_parameter": 0.9,
          "eig_type": "TF",
      }
      sess.run(tf.global_variables_initializer())
      optimization_object = optimization.Optimization(
          dual_formulation_object, sess, optimization_params
      )
      eig_vec = optimization_object.get_min_eig_vec_proxy()
      tf_eig_vec = optimization_object.get_min_eig_vec_proxy(
          use_tf_eig=True
      )
      self.assertIsNotNone(eig_vec)
  
      # Running the graphs and checking that minimum eigen value is correct
      # ** No smoothing
      tf_eig_vec_val, eig_vec_val, matrix_m_val = sess.run(
          [tf_eig_vec, eig_vec, matrix_m],
          feed_dict={
              optimization_object.eig_init_vec_placeholder: np.random.rand(
                  6, 1
              ),
              optimization_object.eig_num_iter_placeholder: 2000,
              optimization_object.smooth_placeholder: 0.0,
          },
      )
  
      # Eigen value corresponding to v is v^\top M v
      eig_val = np.matmul(
          np.transpose(eig_vec_val),
          np.matmul(matrix_m_val, eig_vec_val),
      )
      tf_eig_val = np.matmul(
          np.transpose(tf_eig_vec_val),
          np.matmul(matrix_m_val, tf_eig_vec_val),
      )
      [np_eig_values, _] = np.linalg.eig(matrix_m_val)
      self.assertLess(np.abs(np.min(np_eig_values) - eig_val), 1e-5)
      self.assertLess(np.abs(np.min(np_eig_values) - tf_eig_val), 1e-5)
  
      # Running the graphs and checking that minimum eigen value is correct
      # **Smoothing
      optimization_params["init_smooth"] = 0.0001
      optimization_object = optimization.Optimization(
          dual_formulation_object, sess, optimization_params
      )
      eig_vec = optimization_object.get_min_eig_vec_proxy()
      tf_eig_vec = optimization_object.get_min_eig_vec_proxy(
          use_tf_eig=True
      )
  
      tf_eig_vec_val, eig_vec_val, matrix_m_val = sess.run(
          [tf_eig_vec, eig_vec, matrix_m],
          feed_dict={
              optimization_object.eig_init_vec_placeholder: np.random.rand(
                  6, 1
              ),
              optimization_object.smooth_placeholder: 0.1,
              optimization_object.eig_num_iter_placeholder: 2000,
          },
      )
  
      # Eigen value corresponding to v is v^\top M v
      eig_val = np.matmul(
          np.transpose(eig_vec_val),
          np.matmul(matrix_m_val, eig_vec_val),
      )
      tf_eig_val = np.matmul(
          np.transpose(tf_eig_vec_val),
          np.matmul(matrix_m_val, tf_eig_vec_val),
      )
      [np_eig_values, _] = np.linalg.eig(matrix_m_val)
      self.assertLess(np.abs(np.min(np_eig_values) - eig_val), 1e-5)
      # In general, smoothed version can be far off
      self.assertLess(np.abs(np.min(np_eig_values) - tf_eig_val), 1e-1)
  
file_path: cleverhans/cleverhans/experimental/certification/tests/optimization_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow
  from cleverhans.experimental.certification import dual_formulation
  from cleverhans.experimental.certification import nn
  from cleverhans.experimental.certification import optimization
label_desc: Use image node_id 3 for calling the OptimizationTest obj's underlying member method code with example usage: obj.test_get_min_eig_vec_proxy() without return types