当前位置: 首页 > web >正文

python神经网络学习小结2

初始神经网络

张量运算

numpy速度快原因 numpy有些内置的优化函数 当发这些优化函数进行运算时 运算会交给基础线性代数程序集(BLAS)blas是低层次 高效率的操作程序 通常用c或fortran实现

广播

tensorflow简介

tf基于py开发,主要由google开发

keras简介

线性分类器

import numpy as np
from matplotlib import pyplot
import tensorflow as tfsample_num = 1000
ne_samples = np.random.multivariate_normal(mean=[0, 3], cov=[[1, .5], [.5, 1]], size=sample_num)
po_samples = np.random.multivariate_normal(mean=[3, 0], cov=[[1, .5], [.5, 1]], size=sample_num)inputs = np.vstack((ne_samples, po_samples)).astype(np.float32)
targets = np.vstack((np.zeros((sample_num, 1), dtype='float32'), np.ones((sample_num, 1), dtype='float32')))pyplot.scatter(inputs[:, 0], inputs[:, 1], c=targets[:, 0])
# pyplot.show()input_dim = 2
output_dim = 1w = tf.Variable(initial_value=tf.random.uniform(shape=(input_dim, output_dim)))
b = tf.Variable(initial_value=tf.zeros(shape=(output_dim, )))def model(x):return tf.matmul(x, w) + bdef square_loss(outputs, predictions):sample_loss = tf.square(outputs - predictions)return tf.reduce_mean(sample_loss)learning_rate = .1def train(x, outputs):with tf.GradientTape() as tape:predictions = model(x)loss = square_loss(outputs, predictions)grad_loss_w, grad_loss_b = tape.gradient(loss, [w, b])w.assign_sub(grad_loss_w * learning_rate)b.assign_sub(grad_loss_b * learning_rate)return lossfor epoch in range(20):loss = train(inputs, targets)print(f'loss at step {epoch}: {loss:.4f}')x = np.linspace(-1, 4, 100)
y = - (w[0] / w[1] * x) + (0.5 - b) / w[1]
pyplot.plot(x, y, '-r')
predictions = model(inputs)
pyplot.scatter(inputs[:, 0], inputs[:, 1], c=predictions[:, 0] > 0.5)
pyplot.show()

http://www.xdnf.cn/news/9180.html

相关文章:

  • python时间序列处理
  • 总结:进程和线程的联系和区别
  • 快速上手SHELL脚本常用命令
  • SAP成本核算-事中控制(成本对象控制/成本归集与结算)
  • OpenGL多重渲染
  • 基于Robust Video Matting 使用Unity 实现无绿幕实时人像抠图
  • GJOI 5.24 题解
  • 时空弯曲和测地线浅谈
  • 开卡包的期望
  • 第12次03 :登录状态的保持
  • 一个简单的系统插桩实现​
  • 龙虎榜——20250526
  • C++虚函数和纯虚函数
  • 云原生技术在企业数字化转型中的战略价值与实践路径
  • MySql(三)
  • 高精度装配人形机器人|产品参数详细介绍
  • Day03
  • 架空线路智能云台监控系统介绍
  • 大数据学习(122)-分区与分桶表
  • 【前端】Proxy对象在控制台中惰性求值_vue常见开发问题
  • AI换场景工具:图生生1分钟完成电商商拍
  • Vue 样式穿透(深度选择器)::v-deep
  • 多空间投影:提示微调的革命性突破
  • 车载通信网络 --- OSI模型中物理层和数据链路层
  • 【Netty】- 聊天室1
  • sse和streamablehttp
  • 基于Windows原生工具搭建本地文件服务器 IIS(Internet Information Services)​
  • STM32G0xx基于串口(UART)Ymodem协议实现OTA升级包括Bootloader、上位机、应用程序
  • 两个Ubuntu机器(内网)免密登录设置
  • MFC: 文件加解密(单元测试模块)