



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
梯度下降与最小二乘法 include stdafx h include cv h include cxcore h include highgui h include include include include pragma comment lib cv lib pragma comment lib cxcore lib pragma comment lib highgui lib using namespace std double ComputeGradient vector pts double theta0 double theta 1 int index double retVal 0 if index 0 for int i 0 i pts size i retVal theta0 theta1 pts i x pts i y 1 else for int i 0 i pts size i retVal theta0 theta1 pts i x pts i y pts i x return retVal int tmain int argc TCHAR argv IplImage img cvCreateImage cvSize 800 600 8 3 cvZero img create data vector pts srand time NULL for int x 0 x width 4 x 3 double y 2 x rand 50 CvPoint2D32f pt cvPoint2D32f x y pts push back pt gradient descent method double theta0 0 0 theta1 0 0 double alpha 0 000001 cvNamedWindow disp 1 for int l 0 l 100 l cout theta0 theta1 theta0 theta1 endl double tempTheta0 theta0 alpha ComputeGradient pts theta0 thet a1 0 double tempTheta1 theta1 alpha ComputeGradient pts theta0 thet a1 1 double eps sqrt tempTheta0 theta0 tempTheta0 theta0 tempTh eta1 theta1 tempTheta1 theta1 if eps 0 001 break else theta0 tempTheta0 theta1 tempTheta1 update result cvZero img for int i 0 i pts size i cvDrawCircle img cvPoint pts i x pts i y 2 CV RGB 250 0 0 2 CV AA cvDrawLine img cvPoint 0 theta0 cvPoint 200 theta0 200 theta1 CV RGB 0 250 0 2 CV AA cvShowImage disp img cvWaitKey 1000 least square method CvMat XT cvCreateMat 2 pts size CV 32FC1 CvMat X cvCreateMat pts size 2 CV 32FC1 CvMat Y cvCreateMat pts size 1 CV 32FC1 CvMat XTX cvCreateMat 2 2 CV 32FC1 CvMat THETA cvCreateMat 2 1 CV 32FC1 for int i 0 i pts size i cvSet2D XT 0 i cvScalarAll 1 cvSet2D XT 1 i cvScalarAll pts i x cvSet2D Y i 0 cvScalarAll pts i y core of method THETA invert Xt X Xt Y cvTranspose XT X cvMatMul XT X XTX cvInvert XTX XTX cvMatMul XTX XT XT cvMatMul XT Y THETA theta0 cvGet2D THETA 0 0 val 0 theta1 cvGet2D THETA 1 0 val 0 cvDrawLine img cvPoint 0 theta0 cvPoint 200 theta0 200 theta1 CV RGB 250 250 0 2 CV AA cv
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年地勤机务考试题及答案
- 2025年下半年无人机装调检修工考试试题及答案
- 2025年机务勤务试题及答案
- 2025年东航飞行测试题及答案
- 2025年航空服务员技能认定考试试题及答案解析
- 高校合同模板(3篇)
- 安全用药护理考试题及答案
- 高速公路挡墙施工合同(3篇)
- 电子商务合同法律风险防控与合同签订流程优化
- 专业人士个人房贷转按揭服务合同
- 《中兽药生产技术》课件-14.中药炮制方法-火制
- 人力资源招聘与甄选工作标准化手册
- 民俗学课件山大
- 2025-2026秋季学年第一学期学生国旗下演讲稿(20周):第五周 76载荣光里我们茁壮成长-喜迎国庆
- 办公楼供电线路改造方案
- 《无人机操控技术》高职无人机全套教学课件
- 12YJ11 卫生、洗涤设施设计图集
- 心内科STEMI再灌注治疗率提升
- 装载机司机安全考试模拟试题(含答案)
- 安全生产法2025全文
- 中储粮薪酬管理办法
评论
0/150
提交评论