Skip to content

Commit

Permalink
First Testing Completed, mark version, further tests pending.
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahkhilji committed Apr 5, 2019
1 parent 81206b6 commit 38fd4af
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def custom_ops(n):
required_lower_triangle = tf.reverse(transposed_lower_triangle, [0])
reverse_of_mat_minus_required = tf.subtract(reverse_of_mat, lower_triangular_without_diagonal)
mat_minus_required = tf.reverse(reverse_of_mat_minus_required, [1])

step_1 = tf.add(required_lower_triangle, mat_minus_required)

# Step 2: Take the maximum value along the columns of A to get a vector m
Expand All @@ -41,34 +42,37 @@ def custom_ops(n):

with_nan = lower_triangular_without_diagonal_inf_m = tf.subtract(inf_m, right_lower_triangular_inf_m)
replaced_zero = tf.where(tf.is_nan(with_nan), tf.zeros([n, n]), with_nan)

to_softmax = tf.subtract(reverse_upper_triangular_reverse_m, replaced_zero)

step_3 = tf.nn.softmax(to_softmax)
step_3 = B = tf.nn.softmax(to_softmax)

# Step 4: Sum along the rows of B to obtain vector v1

step_4 = tf.reduce_sum(step_3, 1)
step_4 = v1 = tf.reduce_sum(B, 1)

# Step 5: Sum along the columns of B to get another vector v2

step_5 = tf.reduce_sum(step_3, 0)
step_5 = v2 = tf.reduce_sum(B, 0)

# Step 6: Concatenate the two vectors and take a softmax of this vector

concat = tf.concat([step_4, step_5], 0)
concat = tf.concat([v1, v2], 0)

step_6 = v = tf.nn.softmax(concat)

# Step 7: Get the index number in vector v with maximum value

step_7 = tf.to_float(tf.argmax(step_6))
step_7 = index_number = tf.to_float(tf.argmax(v))

# Step 8: If the index number is greater than n/3 store:
# finalVal = ||v1 − v2||2
# Otherwise, store:
# finalVal = ||v1 + v2||2

n_by_3 = tf.constant(n/3)
finalVal = tf.cond(step_7 > n_by_3, lambda: tf.norm(step_4 - step_5), lambda: tf.norm(step_4 + step_5))

finalVal = tf.cond(index_number > n_by_3, lambda: tf.norm(v1 - v2), lambda: tf.norm(v1 + v2))

# Step 9: Return the variable finalVal

Expand Down

0 comments on commit 38fd4af

Please sign in to comment.