import tensorflow as tf

y = tf.constant([1, 2, 3, 0, 2])
y = tf.one_hot(y, depth=4) # max_label=3种
y = tf.cast(y, dtype=tf.float32) out = tf.random.normal([5, 4])
out
loss1 = tf.reduce_mean(tf.square(y - out))
loss1
loss2 = tf.square(tf.norm(y - out)) / (5 * 4)
loss2
loss3 = tf.reduce_mean(tf.losses.MSE(y, out))
loss3

a = tf.fill([4], 0.25)
a * tf.math.log(a) / tf.math.log(2.)
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))
a = tf.constant([0.1, 0.1, 0.1, 0.7])
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))
a = tf.constant([0.01, 0.01, 0.01, 0.97])
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))

tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.25, 0.25, 0.25, 0.25])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.1, 0.1, 0.8, 0.1])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.1, 0.7, 0.1, 0.1])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.01, 0.97, 0.01, 0.01])
tf.losses.BinaryCrossentropy()([1],[0.1])
tf.losses.binary_crossentropy([1],[0.1])

吴裕雄--天生自然TensorFlow2教程:误差计算的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:前向传播(张量)- 实战

    手写数字识别流程 MNIST手写数字集7000*10张图片 60k张图片训练,10k张图片测试 每张图片是28*28,如果是彩色图片是28*28*3-255表示图片的灰度值,0表示纯白,255表示纯黑 ...

  2. 吴裕雄--天生自然TensorFlow2教程:创建Tensor

    import numpy as np import tensorflow as tf tf.convert_to_tensor(np.ones([2, 3])) tf.convert_to_tenso ...

  3. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  4. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  5. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

  6. 吴裕雄--天生自然TensorFlow2教程:链式法则

    import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...

  7. 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  8. 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

  9. 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

随机推荐

  1. yum grouplist 安装gnome桌面环境

      经常,我们如果需要安装一些比较复杂的软件时,都会在安装操作系统的时候直接勾选,然后进行安装.但是,有的时候,等操作系统安装完了才发现有遗漏的软件没有安装. 这个时候,yum就要出来救场了.使用yu ...

  2. boolean类型set、get方法

    今天在了解lombok的时候偶然看到一个问题,在bean中存在boolean类型的数据的时候,用eclipse工具自动生成的set.get方法存在的问题. 不管变量为isXXX还是XXX时,set.g ...

  3. Django Web接口开发

    什么是接口 接口一般来讲分为两种: (1)程序内部的接口:方法与方法.模块与模块之间的交互,程序内部抛出的接口,如登录发帖,发帖就必须要登录,如果不登录不能发帖,发帖和登录这两个模块之间就要有交互,就 ...

  4. HGAME 2020 week1 web

    1.Cosmos 的博客 知识点:git source code leak 2.接 头 霸 王 Description HGAME Re:Dive 开服啦~ 打开题目,提示了"头" ...

  5. HBase 2.1.3 集群 web 报错InvalidProtocolBufferException 解决方法

    搭建好HBase 集群后,各种后台进程都正常,搭建手册参考: Hbase 2.1.3 集群搭建手册https://www.cndba.cn/dave/article/3322 但是通过web访问,却报 ...

  6. 读书小记--<态度>

    前言 前段时间再读了吴军老师的<态度>,分享的是和女儿的日常书信.觉得收获很多,同时推荐他的<浪潮之巅><数学之美><大学之路>系列书籍. 下面是个人的 ...

  7. The Preliminary Contest for ICPC Asia Xuzhou 2019 B. so easy (unordered_map+并查集)

    这题单用map过不了,太慢了,所以改用unordered_map,对于前面删除的点,把它的父亲改成,后面一位数的父亲,初始化的时候,map里是零,说明它的父亲就是它本身,最后输出答案的时候,输出每一位 ...

  8. layui数据表格固定头部和第一列、colspan合并列

    刚看到原型图的时候,纳尼?不是跟我开玩笑吧,小女子资历尚浅,还真没做过像这样的功能,然后就是各种找度娘,可是都没有找到合适的,很多都是行合并,真的是头疼呀!再纠结是用VUE实现还是用layui实现好, ...

  9. 吴裕雄 python 机器学习——模型选择参数优化随机搜索寻优RandomizedSearchCV模型

    import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...

  10. 使用session在jsp页面之间传递多维数组,用于实现全局变量的效果

    使用session在jsp页面之间传递多维数组:发送数据的jsp页面:int [][] form_number=new int[4][4]; session.setAttribute("se ...