• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python standard_ops.reduce_sum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.ops.standard_ops.reduce_sum函数的典型用法代码示例。如果您正苦于以下问题:Python reduce_sum函数的具体用法?Python reduce_sum怎么用?Python reduce_sum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reduce_sum函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testIndexedSlicesGradientInCondInWhileLoop

  def testIndexedSlicesGradientInCondInWhileLoop(self):
    with ops.Graph().as_default():
      embedding_matrix = tf.get_variable(
          "embedding_matrix", [5, 5],
          initializer=tf.random_normal_initializer())

      def Cond(it, _):
        return it < 5
      def Body(it, cost):
        embedding = embedding_ops.embedding_lookup(embedding_matrix, [0])
        cost = tf.cond(tf.equal(it, 3),
                       lambda: tf.square(cost),
                       lambda: cost + tf.reduce_sum(embedding))
        return it + 1, cost
      _, cost = control_flow_ops.While(
          Cond, Body, [tf.constant(0), tf.constant(0.0)])

      dynamic_grads = tf.gradients(cost, [embedding_matrix])[0]
      dynamic_grads = tf.segment_sum(dynamic_grads.values,
                                     dynamic_grads.indices)

      embedding = embedding_ops.embedding_lookup(embedding_matrix, [0])
      static = tf.square(
          tf.reduce_sum(embedding) +
          tf.reduce_sum(embedding) +
          tf.reduce_sum(embedding)) + tf.reduce_sum(embedding)
      static_grads = tf.gradients(static, [embedding_matrix])[0]
      static_grads = tf.segment_sum(static_grads.values, static_grads.indices)

      with self.test_session() as sess:
        sess.run(tf.initialize_all_variables())
        self.assertAllEqual(*sess.run([static_grads, dynamic_grads]))
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:32,代码来源:control_flow_ops_test.py


示例2: li

 def li(weights, name=None):
   """Applies li regularization to weights."""
   with ops.op_scope([weights], name, 'li_regularizer') as scope:
     my_scale = ops.convert_to_tensor(scale,
                                      dtype=weights.dtype.base_dtype,
                                      name='scale')
   return standard_ops.mul(
         my_scale,
         standard_ops.reduce_sum(standard_ops.sqrt(standard_ops.reduce_sum(tf.square(weights), 1))),
         name=scope)
开发者ID:shorxp,项目名称:tensorlayer,代码行数:10,代码来源:cost.py


示例3: while_loop_body

 def while_loop_body(iteration, matrix, inactive, old_inactive):
   """Performs one iteration of the projection."""
   del old_inactive  # Needed by the condition, but not the body.
   iteration += 1
   scale = (1.0 - standard_ops.reduce_sum(
       matrix, axis=0, keepdims=True)) / standard_ops.maximum(
           1.0, standard_ops.reduce_sum(inactive, axis=0, keepdims=True))
   matrix += scale * inactive
   new_inactive = standard_ops.cast(matrix > 0, matrix.dtype)
   matrix *= new_inactive
   return (iteration, matrix, new_inactive, inactive)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:11,代码来源:swap_regret_optimizer.py


示例4: while_loop_body

 def while_loop_body(iteration, multipliers, inactive, old_inactive):
   """Performs one iteration of the projection."""
   del old_inactive  # Needed by the condition, but not the body.
   iteration += 1
   scale = standard_ops.minimum(
       0.0,
       (radius - standard_ops.reduce_sum(multipliers)) / standard_ops.maximum(
           1.0, standard_ops.reduce_sum(inactive)))
   multipliers += scale * inactive
   new_inactive = standard_ops.cast(multipliers > 0, multipliers.dtype)
   multipliers *= new_inactive
   return (iteration, multipliers, new_inactive, inactive)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:12,代码来源:external_regret_optimizer.py


示例5: lo

 def lo(weights, name='lo_regularizer'):
   """Applies group column regularization to weights."""
   with tf.name_scope(name) as scope:
       my_scale = ops.convert_to_tensor(scale,
                                      dtype=weights.dtype.base_dtype,
                                      name='scale')
       if tf.__version__ <= '0.12':
           standard_ops_fn = standard_ops.mul
       else:
           standard_ops_fn = standard_ops.multiply
       return standard_ops_fn(
         my_scale,
         standard_ops.reduce_sum(standard_ops.sqrt(standard_ops.reduce_sum(tf.square(weights), 0))),
         name=scope)
开发者ID:johndpope,项目名称:LapSRN-tensorflow,代码行数:14,代码来源:cost.py


示例6: li

 def li(weights, name=None):
   """Applies li regularization to weights."""
   with tf.name_scope('li_regularizer') as scope:
       my_scale = ops.convert_to_tensor(scale,
                                          dtype=weights.dtype.base_dtype,
                                          name='scale')
       # if tf.__version__ <= '0.12':
       #     standard_ops_fn = standard_ops.mul
       # else:
       standard_ops_fn = standard_ops.multiply
       return standard_ops_fn(
         my_scale,
         standard_ops.reduce_sum(standard_ops.sqrt(standard_ops.reduce_sum(tf.square(weights), 1))),
         name=scope)
开发者ID:DKfromsd,项目名称:seq2seq-chatbot,代码行数:14,代码来源:cost.py


示例7: lo

 def lo(weights, name=None):
   """Applies group column regularization to weights."""
   with ops.op_scope([weights], name, 'lo_regularizer') as scope:
     my_scale = ops.convert_to_tensor(scale,
                                      dtype=weights.dtype.base_dtype,
                                      name='scale')
   #   return standard_ops.mul(
   #       my_scale,
   #       standard_ops.reduce_sum(standard_ops.sqrt(standard_ops.reduce_sum(weights**2, 0))),
   #       name=scope)
     return standard_ops.mul(
         my_scale,
         standard_ops.reduce_sum(standard_ops.sqrt(standard_ops.reduce_sum(tf.square(weights), 0))),
       #   standard_ops.reduce_mean(standard_ops.sqrt(standard_ops.reduce_mean(tf.square(weights), 0))),
         name=scope)
开发者ID:zhangzongliang,项目名称:tensorlayer,代码行数:15,代码来源:cost.py


示例8: mn_i

 def mn_i(weights, name=None):
   """Applies max-norm regularization to weights."""
   with ops.op_scope([weights], name, 'maxnorm_o_regularizer') as scope:
     my_scale = ops.convert_to_tensor(scale,
                                      dtype=weights.dtype.base_dtype,
                                              name='scale')
     return standard_ops.mul(my_scale, standard_ops.reduce_sum(standard_ops.reduce_max(standard_ops.abs(weights), 1)), name=scope)
开发者ID:shorxp,项目名称:tensorlayer,代码行数:7,代码来源:cost.py


示例9: testIndexedSlicesWithShapeGradientInWhileLoop

  def testIndexedSlicesWithShapeGradientInWhileLoop(self):
    with self.test_session() as sess:
      num_steps = 9

      inputs = tf.placeholder(dtype="float32", shape=[num_steps])
      initial_outputs = tf.TensorArray(dtype="float32", size=num_steps)
      initial_i = tf.constant(0, dtype="int32")

      def Cond(i, _):
        return i < num_steps

      def Body(i, outputs):
        x = tf.gather(inputs, i)
        outputs = outputs.write(i, x)
        return i + 1, outputs

      _, outputs = tf.while_loop(Cond, Body, [initial_i, initial_outputs])

      outputs = tf.reduce_sum(outputs.pack())
      r = tf.gradients([outputs], [inputs])[0]
      grad_wr_inputs = ops.convert_to_tensor(r)
      o, grad = sess.run([outputs, grad_wr_inputs],
                         feed_dict={inputs: [4, 6, 0, 7, 0, 0, 1, 2, 0]})
      self.assertEquals(o, 20)
      self.assertAllEqual(grad, [1] * num_steps)
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:25,代码来源:control_flow_ops_test.py


示例10: testIndexedSlicesWithDynamicShapeGradientInWhileLoop

  def testIndexedSlicesWithDynamicShapeGradientInWhileLoop(self):
    for dtype in [dtypes.float32, dtypes.float64]:
      with self.test_session() as sess:
        inputs = tf.placeholder(dtype=dtype)
        initial_outputs = tf.TensorArray(dtype=dtype, dynamic_size=True,
                                         size=1)
        initial_i = tf.constant(0, dtype=dtypes.int32)

        def Cond(i, _):
          return i < tf.size(inputs)  # pylint: disable=cell-var-from-loop

        def Body(i, outputs):
          x = tf.gather(inputs, i)  # pylint: disable=cell-var-from-loop
          outputs = outputs.write(i, x)
          return i + 1, outputs

        _, outputs = tf.while_loop(Cond, Body, [initial_i, initial_outputs])

        outputs = tf.reduce_sum(outputs.pack())
        r = tf.gradients([outputs], [inputs])[0]
        grad_wr_inputs = ops.convert_to_tensor(r)
        o, grad = sess.run([outputs, grad_wr_inputs],
                           feed_dict={inputs: [1, 3, 2]})
        self.assertEquals(o, 6)
        self.assertAllEqual(grad, [1] * 3)
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:25,代码来源:control_flow_ops_test.py


示例11: mn_i

 def mn_i(weights, name='maxnorm_i_regularizer'):
     """Applies max-norm regularization to weights."""
     with tf.name_scope(name) as scope:
         my_scale = ops.convert_to_tensor(scale, dtype=weights.dtype.base_dtype, name='scale')
         if tf.__version__ <= '0.12':
             standard_ops_fn = standard_ops.mul
         else:
             standard_ops_fn = standard_ops.multiply
         return standard_ops_fn(my_scale, standard_ops.reduce_sum(standard_ops.reduce_max(standard_ops.abs(weights), 1)), name=scope)
开发者ID:dccforever,项目名称:tensorlayer,代码行数:9,代码来源:cost.py


示例12: l1

 def l1(weights, name=None):
   """Applies L1 regularization to weights."""
   with ops.name_scope(scope, 'l1_regularizer', [weights]) as name:
     my_scale = ops.convert_to_tensor(scale,
                                      dtype=weights.dtype.base_dtype,
                                      name='scale')
     return standard_ops.mul(
         my_scale,
         standard_ops.reduce_sum(standard_ops.abs(weights)),
         name=name)
开发者ID:AriaAsuka,项目名称:tensorflow,代码行数:10,代码来源:regularizers.py


示例13: _project_log_stochastic_matrix_wrt_kl_divergence

def _project_log_stochastic_matrix_wrt_kl_divergence(log_matrix):
  """Projects its argument onto the set of log-left-stochastic matrices.

  Args:
    log_matrix: 2d square tensor, the element-wise logarithm of the matrix to
      project.

  Returns:
    The 2d square tensor that results from projecting exp(`matrix`) onto the set
      of left-stochastic matrices w.r.t. the KL-divergence applied column-wise.
  """

  # For numerical reasons, make sure that the largest matrix element is zero
  # before exponentiating.
  log_matrix -= standard_ops.reduce_max(log_matrix, axis=0, keepdims=True)
  log_matrix -= standard_ops.log(
      standard_ops.reduce_sum(
          standard_ops.exp(log_matrix), axis=0, keepdims=True))
  return log_matrix
开发者ID:AnishShah,项目名称:tensorflow,代码行数:19,代码来源:swap_regret_optimizer.py


示例14: l1

 def l1(weights, name=None):
     """Applies L1 regularization to weights."""
     with ops.op_scope([weights], name, "l1_regularizer") as scope:
         my_scale = ops.convert_to_tensor(scale, dtype=weights.dtype.base_dtype, name="scale")
         return standard_ops.mul(my_scale, standard_ops.reduce_sum(standard_ops.abs(weights)), name=scope)
开发者ID:hlt-mt,项目名称:tensorflow,代码行数:5,代码来源:learn.py


示例15: Body

 def Body(it, cost):
   embedding = embedding_ops.embedding_lookup(embedding_matrix, [0])
   cost = tf.cond(tf.equal(it, 3),
                  lambda: tf.square(cost),
                  lambda: cost + tf.reduce_sum(embedding))
   return it + 1, cost
开发者ID:JamesFysh,项目名称:tensorflow,代码行数:6,代码来源:control_flow_ops_test.py


示例16: _distribution

 def _distribution(self, state):
   distribution = _maximal_eigenvector_power_method(
       self._stochastic_matrix(state))
   distribution = standard_ops.abs(distribution)
   distribution /= standard_ops.reduce_sum(distribution)
   return distribution
开发者ID:AnishShah,项目名称:tensorflow,代码行数:6,代码来源:swap_regret_optimizer.py



注:本文中的tensorflow.python.ops.standard_ops.reduce_sum函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python state_ops.assign函数代码示例发布时间:2022-05-27
下一篇:
Python standard_ops.matmul函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap