[PR & ML 2] [Introduction] Example: Polynomial Curve Fitting
啊啊啊,竟然不支持latex,竟然HTML代码不能包含javascript,代码编辑器也不支持Matlab!!!我要吐槽博客的编辑器。。。T_T只能贴图凑合看了,代码不是图,但这次为了省脑细胞,写的不简洁,凑合看吧。。。




numPoints = ;
lnlambda = [-Inf - ];
M = ; % [, , , ];
x = linspace(,);
% gt data for plotting
t = sin(*pi*x);
ttest = t + normrnd(,0.2, size(x)); % generate observed data
if exist('C0_Curve_Fitting_data.mat', 'file')
load('C0_Curve_Fitting_data.mat');
else
xob = :/(numPoints-):;
tob = sin(*pi*xob) + normrnd(,0.2, size(xob));
save('C0_Curve_Fitting_data.mat', 'xob', 'tob');
end ERMStest = zeros(size(M));
ERMStrain = zeros(size(M));
figCount = ;
% for i = :length(M)
i = ;
for l = :length(lnlambda)
Aob = [];
A = [];
for j = :M(i)
Aob = [Aob (xob.^j)']; %#ok<AGROW>
A = [A (x.^j)']; %#ok<AGROW>
end w = (Aob'*Aob+eye(M(i)+1)*exp(lnlambda(l)))\(Aob'*tob');
tpred = A*w; ERMStest(i) = sqrt(2*0.5*sum((tpred' - ttest).^)/length(x));
ERMStrain(i) = sqrt(*0.5*sum((Aob*w - tob').^2)/length(x));
figure(3);
if M(i)==0 || M(i)==1 || M(i)==3 || M(i)==9
disp('w=')
disp(w);
figCount = figCount + 1;
subplot(1, 3, figCount);
plot(xob,tob,'or');
hold on;
plot(x,t,'b');
plot(x,tpred, 'g')
hold off;
text(0.6,1,['M = ' num2str(M(i))],'FontSize',14);
text(0.6,1.3,['ln\lambda = ' num2str(lnlambda(l))], 'FontSize',14);
xlabel('x');
ylabel('t');
set(gca,'FontSize',14)
end
end % figure(2)
% h1 = plot(M,ERMStest,'go-', 'LineWidth', 2);
% hold on;
% h2 = plot(M,ERMStrain,'bo-', 'LineWidth', 2);
% hold off;
% legend([h1, h2], 'Test', 'Training')
% set(gca,'FontSize',14)
[PR & ML 2] [Introduction] Example: Polynomial Curve Fitting的更多相关文章
- 一起啃PRML - 1.1 Example: Polynomial Curve Fitting 多项式曲线拟合
一起啃PRML - 1.1 Example: Polynomial Curve Fitting @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ 前言: ...
- 数据拟合:多项式拟合polynomial curve fitting
http://blog.csdn.net/pipisorry/article/details/49804441 常见的曲线拟合方法 1.使偏差绝对值之和最小 2.使偏差绝对值最大的最小 3 ...
- [PR & ML 1] [Introduction] Informal Basic Concepts
最近还没更完OpenCV又开了新坑,谁教machine learning处在紧急又重要的地位呢.更新的内容总结自Pattern Recognition and Machine Learning by ...
- 【PRML读书笔记-Chapter1-Introduction】1.1 Example:Polynomial Curve Fitting
书中给出了一个典型的曲线拟合的例子,给定一定量的x以及对应的t值,要你判断新的x对应的t值多少. 任务就是要我们去发现潜在的曲线方程:sin(2πx) 这时就需要概率论的帮忙,对于这种不确定给t赋何值 ...
- [PR & ML 6] [Introduction] Information Theory
- [PR & ML 5] [Introduction] Decision Theory
- [PR & ML 4] [Introduction] Model Selection & The Curse of Dimension
这两部分内容比较少,都是直觉上的例子和非正式的定义,当然这本书中绝大多数定义都是非正式的,但方便理解.后面深入之后会对这两个章节有详细的阐述.
- [PR & ML 3] [Introduction] Probability Theory
虽然学过Machine Learning和Probability今天看着一part的时候还是感觉挺有趣,听惊呆的,尤其是Bayesian Approach.奇怪发中文的笔记就很多人看,英文就没有了,其 ...
- [matlab工具箱] 曲线拟合Curve Fitting
——转载网络 我的matlab版本是 2016a 首先,工具箱如何打开呢? 在 apps 这个菜单项中,可以找到很多很多的应用,点击就可以打开具体的工具窗口 本文介绍的工具有以下这些: curve F ...
随机推荐
- matlab inpolygon 判断点在多边形内
如何判断一个点在多边形内部? xv= [0 3 3 0 0]; %x坐标 yv= [0 0 3 3 0];%y坐标 x=1.5; y=1.5; in=inpolygon(x,y,xv,yv) plot ...
- windows消息钩子
1.消息钩子的概念: Windows应用程序是基于消息驱动的,不论什么线程仅仅要注冊窗体类都会有一个消息队列用于接收用户输入的消息和系统消息.为了拦截消息,Windows提出了钩子的概念.钩子(Hoo ...
- Sublime Text 3 安装插件管理 Package Control
自动安装: 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴对应版本的代码后回车安装 适用于 Sublime Text 3: import ...
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和
B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...
- hdu 5445 Food Problem 多重背包
Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- Effective C++ 条款45
本节条款的题目是运用成员模板接受全部兼容类型 作者阐述自己的观点是通过智能指针的样例. 在学习本节条款之前我们要先明确关于隐式转化的问题 例如以下代码: #include<iostream> ...
- 文件TEXTBOX
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Android设计模式(1)----单例模式
在非常多设计模式中.我相信大多数程序员最早接触的设计模式就是单例模式啦,当然了我也不例外. 单例模式应用起来应该是全部设计模式中最简单的.单例模式尽管简单,可是假设你去深深探究单例模式,会涉及到非常多 ...
- android133 360 06 一键锁频,清楚数据
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- javascript调试 console
Console命令详解,让调试js代码变得更简单 Firebug是网页开发的利器,能够极大地提升工作效率. 但是,它不太容易上手.我曾经翻译过一篇<Firebug入门指南>,介绍了一些 ...