當前位置: 首頁>>代碼示例>>Python>>正文


Python tensorflow.matrix_determinant方法代碼示例

本文整理匯總了Python中tensorflow.matrix_determinant方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.matrix_determinant方法的具體用法?Python tensorflow.matrix_determinant怎麽用?Python tensorflow.matrix_determinant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.matrix_determinant方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: internal_novelty_loss

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def internal_novelty_loss(grams, mul=1.0):
    gram = keras.layers.Concatenate(axis=0)(grams)
    # gram will be something like (5, 64, 64)
    flat = keras.layers.Flatten()(gram)
    flat = PrintLayerShape("flat shape")(flat)

    # ~ (5, 4096)
    covar = Lambda(lambda x: K.dot(x,K.transpose(x)),
            output_shape = lambda input_shape: [input_shape[0], input_shape[0]])(flat)
    covar = PrintLayer("covar")(covar)

    # ~ (5, 5)
    #det = Lambda(lambda x: -tf.matrix_determinant(x),
            #output_shape = lambda input_shape: [1])(covar)
    #det = Lambda(lambda x: -2*tf.reduce_sum(tf.log(tf.diag(tf.cholesky(x)))),
           #output_shape = lambda input_shape: [1])(covar)
    
    def eye_diff(x):
        shape = K.shape(x)
        return x - mul * tf.eye(shape[0], shape[1])

    det = Lambda(lambda x: K.sum(K.square(eye_diff(x))),
            output_shape = lambda input_shape: [1])(covar)
    det = PrintLayer("det")(det)
    return det 
開發者ID:wxs,項目名稱:subjective-functions,代碼行數:27,代碼來源:gram.py

示例2: dpp_style

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def dpp_style(self, submethod):
        """Computes the DPP of a matrix."""
        det_entries = []
        if submethod == "inverse_dist":
            for i in range(self.total_CFs):
                for j in range(self.total_CFs):
                    det_temp_entry = tf.divide(1.0, tf.add(
                        1.0, self.compute_dist(self.cfs_frozen[i], self.cfs_frozen[j])))
                    if i == j:
                        det_temp_entry = tf.add(det_temp_entry, 0.0001)
                    det_entries.append(det_temp_entry)

        elif submethod == "exponential_dist":
            for i in range(self.total_CFs):
                for j in range(self.total_CFs):
                    det_temp_entry = tf.divide(1.0, tf.exp(
                        self.compute_dist(self.cfs_frozen[i], self.cfs_frozen[j])))
                    det_entries.append(det_temp_entry)

        det_entries = tf.reshape(det_entries, [self.total_CFs, self.total_CFs])
        diversity_loss = tf.matrix_determinant(det_entries)
        return diversity_loss 
開發者ID:interpretml,項目名稱:DiCE,代碼行數:24,代碼來源:dice_tensorflow1.py

示例3: test_MatrixDeterminant

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def test_MatrixDeterminant(self):
        t = tf.matrix_determinant(self.random(2, 3, 4, 3, 3))
        self.check(t) 
開發者ID:riga,項目名稱:tfdeploy,代碼行數:5,代碼來源:ops.py

示例4: get_log_det_jacobian

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def get_log_det_jacobian(self, o):
        J = self.compute_jacobian(o)
        def step(J_i):
            return tf.log(tf.abs(tf.matrix_determinant(J_i)))
        return tf.map_fn(step, J) 
開發者ID:pbrakel,項目名稱:anica,代碼行數:7,代碼來源:models.py

示例5: testBatchGradientUnknownSize

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def testBatchGradientUnknownSize(self):
    with self.test_session():
      batch_size = tf.constant(3)
      matrix_size = tf.constant(4)
      batch_identity = tf.tile(
          tf.expand_dims(
              tf.diag(tf.ones([matrix_size])), 0), [batch_size, 1, 1])
      determinants = tf.matrix_determinant(batch_identity)
      reduced = tf.reduce_sum(determinants)
      sum_grad = tf.gradients(reduced, batch_identity)[0]
      self.assertAllClose(batch_identity.eval(), sum_grad.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:linalg_grad_test.py

示例6: _compareDeterminant

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def _compareDeterminant(self, matrix_x):
    with self.test_session():
      self._compareDeterminantBase(matrix_x, tf.matrix_determinant(matrix_x)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:5,代碼來源:determinant_op_test.py

示例7: testNonSquareMatrix

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def testNonSquareMatrix(self):
    # When the determinant of a non-square matrix is attempted we should return
    # an error
    with self.assertRaises(ValueError):
      tf.matrix_determinant(
          np.array([[1., 2., 3.], [3., 5., 4.]]).astype(np.float32)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:8,代碼來源:determinant_op_test.py

示例8: testWrongDimensions

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def testWrongDimensions(self):
    # The input to the determinant should be a 2-dimensional tensor.
    tensor1 = tf.constant([1., 2.])
    with self.assertRaises(ValueError):
      tf.matrix_determinant(tensor1) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:7,代碼來源:determinant_op_test.py

示例9: testDeterminants

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def testDeterminants(self):
    with self.test_session():
      for batch_shape in [(), (2, 3,)]:
        for k in [1, 4]:
          operator, mat = self._build_operator_and_mat(batch_shape, k)
          expected_det = tf.matrix_determinant(mat).eval()

          self._compare_results(expected_det, operator.det())
          self._compare_results(np.log(expected_det), operator.log_det()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:11,代碼來源:operator_test_util.py

示例10: novelty_loss

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def novelty_loss(grams, mul=1.0):
    dets = []
    for gram in grams:
        # gram will be something like (5, 64, 64)
        flat = keras.layers.Flatten()(gram)

        # ~ (5, 4096)
        covar = Lambda(lambda x: K.dot(x,K.transpose(x)),
                output_shape = lambda input_shape: [input_shape[0], input_shape[0]])(flat)
        covar = PrintLayer("covar")(covar)

        # ~ (5, 5)
        #det = Lambda(lambda x: -tf.matrix_determinant(x),
                #output_shape = lambda input_shape: [1])(covar)
        #det = Lambda(lambda x: -2*tf.reduce_sum(tf.log(tf.diag(tf.cholesky(x)))),
               #output_shape = lambda input_shape: [1])(covar)
        
        def eye_diff(x):
            shape = K.shape(x)
            return x - mul * tf.eye(shape[0], shape[1])

        det = Lambda(lambda x: K.sum(K.square(eye_diff(x))),
                output_shape = lambda input_shape: [1])(covar)
        det = PrintLayer("det")(det)
        dets.append(det)

    if len(dets) > 1:
        return keras.layers.add(dets)
    else:
        return dets[0] 
開發者ID:wxs,項目名稱:subjective-functions,代碼行數:32,代碼來源:gram.py

示例11: _calc_component_density

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def _calc_component_density(z, phi, mu, sigma):
        sig_inv = tf.matrix_inverse(sigma)
        sig_sqrt_det = K.sqrt(tf.matrix_determinant(2 * np.pi * sigma) + K.epsilon())
        density = phi * (K.exp(-0.5 * K.sum(K.dot(z - mu, sig_inv) * (z - mu),
                                            axis=-1,
                                            keepdims=True)) / sig_sqrt_det) + K.epsilon()

        return density 
開發者ID:izikgo,項目名稱:AnomalyDetectionTransformations,代碼行數:10,代碼來源:dagmm.py

示例12: estimate_rotation

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import matrix_determinant [as 別名]
def estimate_rotation(xyz0, xyz1, pconf, noise):
  """Estimates the rotation between two sets of keypoints.

  The rotation is estimated by first subtracting mean from each set of keypoints
  and computing SVD of the covariance matrix.

  Args:
    xyz0: [batch, num_kp, 3] The first set of keypoints.
    xyz1: [batch, num_kp, 3] The second set of keypoints.
    pconf: [batch, num_kp] The weights used to compute the rotation estimate.
    noise: A number indicating the noise added to the keypoints.

  Returns:
    [batch, 3, 3] A batch of transposed 3 x 3 rotation matrices.
  """

  xyz0 += tf.random_normal(tf.shape(xyz0), mean=0, stddev=noise)
  xyz1 += tf.random_normal(tf.shape(xyz1), mean=0, stddev=noise)

  pconf2 = tf.expand_dims(pconf, 2)
  cen0 = tf.reduce_sum(xyz0 * pconf2, 1, keepdims=True)
  cen1 = tf.reduce_sum(xyz1 * pconf2, 1, keepdims=True)

  x = xyz0 - cen0
  y = xyz1 - cen1

  cov = tf.matmul(tf.matmul(x, tf.matrix_diag(pconf), transpose_a=True), y)
  _, u, v = tf.svd(cov, full_matrices=True)

  d = tf.matrix_determinant(tf.matmul(v, u, transpose_b=True))
  ud = tf.concat(
      [u[:, :, :-1], u[:, :, -1:] * tf.expand_dims(tf.expand_dims(d, 1), 1)],
      axis=2)
  return tf.matmul(ud, v, transpose_b=True) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:36,代碼來源:main.py


注:本文中的tensorflow.matrix_determinant方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。