This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#comparing two weights | |
weight = tf.constant(1.) | |
x_entropy_weighted_vals = tf.nn.weighted_cross_entropy_with_logits(targets=Y_labels, logits=Y_pred, pos_weight=weight) | |
x_entropy_weighted_out = sess.run(x_entropy_weighted_vals) | |
weight2 = tf.constant(0.5) | |
x_entropy_weighted_val_2 = tf.nn.weighted_cross_entropy_with_logits(targets=Y_labels, logits=Y_pred, pos_weight=weight2) | |
x_entropy_weighted_out_2 = sess.run(x_entropy_weighted_val_2) | |
#ploting the predicted values against the Sigmoid cross entropy loss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Calculating the L2 loss | |
val = tf.square(Y_truth - Y_pred) | |
L2_val = sess.run(val) | |
#ploting the predicted values against the L2 loss | |
Y_array = sess.run(Y_pred) | |
plt.plot(Y_array, L2_val, 'b-', label='L2 loss' ) | |
plt.title('L2 loss') | |
plt.xlabel('$Y_{pred}$', fontsize=15) | |
plt.ylabel('$Y_{true}$', fontsize=15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import libraries | |
import matplotlib.pyplot as plt | |
import tensorflow as tf | |
#Start a tensorflow session | |
sess = tf.Session() | |
# Create our sample data from a line space | |
Y_pred = tf.linspace(-1., 1., 500) | |
#Create our target as a zero constant tensor | |
Y_truth = tf.constant(0.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Computing L1 loss with the same values | |
temp = tf.abs(Y_truth - Y_pred) | |
L1_val = sess.run(temp) | |
#ploting the predicted values against the L2 loss | |
Y_array = sess.run(Y_pred) | |
plt.plot(Y_array, L1_val, 'r-' ) | |
plt.title('L1 loss') | |
plt.xlabel('$Y_{pred}$', fontsize=15) | |
plt.ylabel('$Y_{true}$', fontsize=15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Plot of the Pseudo-Huber loss | |
delta = tf.constant(0.24) | |
temp_ph = tf.multiply(tf.square(delta),tf.sqrt(1. + tf.square((Y_truth - Y_pred) / delta)) - 1. ) | |
pseudo_h_vals = sess.run(temp_ph) | |
#ploting the predicted values against the L2 loss | |
Y_array = sess.run(Y_pred) | |
plt.plot(Y_array, pseudo_h_vals, 'g-' ) | |
plt.title('Pseudo Huber loss') | |
plt.xlabel('$Y_{pred}$', fontsize=15) | |
plt.ylabel('$Y_{true}$', fontsize=15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Redefining our data | |
Y_pred = tf.linspace(-4., 6., 500) | |
Y_label = tf.constant(1.) | |
Y_labels = tf.fill([500,], 1.) | |
#applying sigmoid | |
x_entropy_vals = - tf.multiply(Y_label, tf.log(Y_pred)) - tf.multiply((1. - Y_label), tf.log(1. - Y_pred)) | |
x_entropy_loss = sess.run(x_entropy_vals) | |
#ploting the predicted values against the cross entropy loss | |
Y_array = sess.run(Y_pred) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x_entropy_sigmoid_vals = tf.nn.sigmoid_cross_entropy_with_logits(labels= Y_labels, logits=Y_pred) | |
x_entropy_sigmoid_out = sess.run(x_entropy_sigmoid_vals) | |
#ploting the predicted values against the Sigmoid cross entropy loss | |
Y_array = sess.run(Y_pred) | |
plt.plot(Y_array, x_entropy_sigmoid_out, 'y-' ) | |
plt.title('Sigmoid cross entropy loss') | |
plt.xlabel('$Y_{pred}$', fontsize=15) | |
plt.ylabel('$Y_{label}$', fontsize=15) | |
plt.ylim(-2, 5) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y_pred_dist = tf.constant([[1., -3., 10.]]) | |
target_dist = tf.constant([[0.1, 0.02, 0.88]]) | |
softmax_xentropy = tf.nn.softmax_cross_entropy_with_logits(labels=target_dist, logits=y_pred_dist) | |
print(sess.run(softmax_xentropy)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y_pred = tf.constant([[1., -3., 10.]]) | |
sparse_target_dist = tf.constant([2]) #true value is in the second position of the sparse tensor | |
sparse_x_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels= sparse_target_dist, logits=y_pred) | |
print(sess.run(sparse_x_entropy)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Load our libraries | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import tensorflow as tf | |
sess = tf.Session() | |
# We create our data, placeholders and variables | |
x_val = np.random.normal(1, 0.1, 100) #input values | |
y_val = np.repeat(10., 100) #target values |
OlderNewer