|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Data Streaming Algorithms |
| 4 | +published: true |
| 5 | +--- |
| 6 | + |
| 7 | +I hope to add details as I understand this field better. |
| 8 | +I may also use multiple languages to code parts of algorithms. |
| 9 | + |
| 10 | +# Sketching |
| 11 | + |
| 12 | + |
| 13 | +# Hadamard Transform |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +{% highlight python %} |
| 18 | +import tensorflow as tf |
| 19 | + |
| 20 | +def hademard(M): |
| 21 | + i = tf.constant(1) |
| 22 | + loop_var = int(tf.math.log(tf.cast(tf.shape(M)[0],tf.float32))/tf.math.log(2.0)) |
| 23 | + c = lambda i, d: tf.less_equal(i, tf.cond(loop_var < 1 , lambda: 1, lambda : loop_var)) |
| 24 | + T = tf.constant([[1,1],[1,-1]],dtype=tf.float32) |
| 25 | + |
| 26 | + def logic(i, H1): |
| 27 | + operator_1 = tf.linalg.LinearOperatorFullMatrix(H1) |
| 28 | + operator_2 = tf.linalg.LinearOperatorFullMatrix(T/2) |
| 29 | + operator = tf.linalg.LinearOperatorKronecker([operator_1, operator_2]) |
| 30 | + |
| 31 | + H1 = operator.to_dense() |
| 32 | + return tf.add(i, 1),H1 |
| 33 | + |
| 34 | + H0 = tf.ones((1,1)) |
| 35 | + i,H2 = tf.while_loop( c,logic,[i, H0 ]) |
| 36 | + H2 = tf.matmul(tf.matmul(H2, M), H2) |
| 37 | + |
| 38 | + return H2 |
| 39 | + |
| 40 | + |
| 41 | +#M = tf.ones((4,4),tf.float32) |
| 42 | +#M = tf.constant([[2, 3], [2, 5]], dtype=tf.float32) |
| 43 | +M = tf.linalg.band_part(tf.ones((4,4)), -1, 0) |
| 44 | +print(f'Hademard {hademard(M)}') |
| 45 | + |
| 46 | +{% endhighlight %} |
0 commit comments