Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow cost function sorting

I'm pretty new to tensor flow and i'm trying to make my network sort an series of 8 numbers.

the way i would like to evaluate how well it has done is by subtracting x by y, invert the negative numbers and multiply them by a weight if thats necessary. And i was wondering if this is possible in tensorflow. Or if in any case there is better way to do this.

Something that is not tensoflow would look something like:

    w = 20
    s = 0
    print prediction, y
    for i in range(len(prediction.val)):
        s+= (y[i] / prediction[i] - 1) * w
    if s < 0:
        s = s * -1
    return s

In this case, if the total is a negative it will be inverted, however i would preferably do each element individually.

I'm currently stuck after:

prediction = neural_network_model(x)
sub = tf.subtract(prediction,y)
like image 609
MickBoe1 Avatar asked Sep 16 '26 12:09

MickBoe1


1 Answers

i found a solution that works and looks like :

prediction = neural_network_model(x)
sub = tf.subtract(prediction,y)
sign = tf.sign(sub)
cost = tf.multiply(sub,sign)

this does not yet include the weight but for now its working fine

like image 125
MickBoe1 Avatar answered Sep 19 '26 02:09

MickBoe1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!