KZKY memo

自分用メモ.

TensorFlow: Python API: Math

基本element-wise.記事を書いている時点では,v6.0なので注意

Arithmetic Operators

  • tf.add
  • tf.sub
  • tf.mul
  • tf.div
  • tf.truediv
  • tf.floordiv
  • tf.mod

特に注意点はなし.

sample codes

Basic Math Functions

  • tf.add_n
  • tf.abs
  • tf.neg
  • tf.sign
  • tf.inv
  • tf.square
  • tf.round
  • tf.sqrt
  • tf.rsqrt
  • tf.pow
  • tf.exp
  • tf.log
  • tf.ceil
  • tf.floor
  • tf.maximum
  • tf.minimum
  • tf.cos
  • tf.sin

maxinum, minimumは,引数2つとって,element-wiseにmax/minを取る.

sample codes

Matrix Math Functions

  • tf.diag
  • tf.transpose
  • tf.matmul
  • tf.batch_matmul
  • tf.matrix_determinant
  • tf.batch_matrix_determinant
  • tf.matrix_inverse
  • tf.batch_matrix_inverse
  • tf.cholesky
  • tf.batch_cholesky
  • tf.self_adjoint_eig
  • tf.batch_self_adjoint_eig

特に気をつけるところはなし.

sample codes

Complex Number Functions

  • tf.complex
  • tf.complex_abs
  • tf.conj
  • tf.imag
  • tf.real

取りあえずスキップ

Reduction

  • tf.reduce_sum
  • tf.reduce_prod
  • tf.reduce_min
  • tf.reduce_max
  • tf.reduce_mean
  • tf.reduce_all
  • tf.reduce_any
  • tf.accumulate_n

reduce_xxxは,keep_dims=Trueとしないとtensor-rankが1つ落ちる.落ちたTensorの次元は,長さ1になる.defaultはFalse. reduction_indicesを指定できて,defaultはNoneで,scalarが返ってくる.all, anyは,"logical and", "logical or"accumulateだけは,element-wise.

sample codes

Segmentation

  • tf.segment_sum
  • tf.segment_prod
  • tf.segment_min
  • tf.segment_max
  • tf.segment_mean
  • tf.unsorted_segment_sum
  • tf.sparse_segment_sum
  • tf.sparse_segment_mean


segmentationの中であるoperationをelement-wiseで行う感じ.segmentaionはtensorにおける0次元目で 行われる.segmentation_idsはtensorの0次元目の長さと同じでなければならない.segmentation_idsの要素は,0次元目の長さを超えてはならない.segmentation_idsの要素は,連続な値を並べていく(e.g., [0, 0, 1, 2, 2]).sortされてないとイケない.

連続した値を使わなくてもいい関数もある(unsorted_segment_xxx)

選択した次元に対して,segment_xxxをする関数もある(sparse_segment_xxx)

ここの図を見るといい.

sample codes

Sequence Comparison and Indexing

  • tf.argmin
  • tf.argmax
  • tf.listdiff
  • tf.where
  • tf.unique
  • tf.edit_distance
  • tf.invert_permutation

tf.argmin, tf.argmax はreductionなんだけど,なぜかここにある.

sample codes