免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Web开发工程师项目进度报告
- 交易员托管行业研究报告
- 产康技术在产妇恢复中的应用案例分析
- 伐木场工作计划与森林资源管理方案
- SAP高级顾问团队管理方案与案例分析
- 业务拓展经理业务拓展经理培训讲义
- 2024年广东深圳实验学校招聘教师考试真题
- QA检验员新员工入职培训手册
- ESG专员团队建设方案
- 产品创新设计与市场需求分析报告
- 2025衢州市市级机关事业单位第三期编外招聘39人笔试考试参考试题及答案解析
- 人教版八年级上册生物第五单元第一章综合实践项目 设计并制作生态瓶
- 2025全国医疗应急能力培训系列课程参考答案
- GB/T 15843.4-2024信息技术安全技术实体鉴别第4部分:采用密码校验函数的机制
- 风电场反违章培训课件
- OLP-网管系统用户手册(武汉光迅)
- 敦煌的艺术智慧树知到答案章节测试2023年
- 病人心理与心理护理课件
- 传输专业常用仪表
- 自然地理学-第五章-地貌精课件
- 楚航无人船水域测量机器人系统介绍课件
评论
0/150
提交评论