[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 ...
随机推荐
- 从零开始学android开发-字符如何转换整形 string 转化为int
int i = Integer.parseInt(string);
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- node.js在windows下的学习笔记(5)---用NODE.JS创建服务器和客户端
//引入http模块 var http = require('http'); //调用http的createServer的方法,这个方法有一个回调函数,这个回调数 //的作用是当有请求发送给服务器的时 ...
- 显示 png 图片
uses pngimage;{显示 png 图片}procedure TForm1.Button2Click(Sender: TObject);var png: TPngImage;begin ...
- File类的基本操作之读出所有目录路径
package org.mark.file; import java.io.File; /** * File类的基本操作之读出所有文件夹路径 * 假设给定一个文件夹,要求将此文件夹中的所有文件都列出来 ...
- iOS使用宏写单例
本文只介绍ARC情况下的单例 过去一直背不下来单例如何写,就是知道这么回事,也知道通过宏来写单例,但是一直记不住,今天就来记录一下 - (void)viewDidLoad { [super v ...
- android EditText输入变化事件详解
editText.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) { // ...
- as。 对象和数组
---恢复内容开始--- http://w3help.org/zh-cn/causes/SJ9011 ---恢复内容结束--- http://zengrong.net/post/5.htm
- 编写一个程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词
#include<iostream> #include<string> #include<vector> using namespace std; int main ...
- SQL Server 2014 AlwaysON
. 环境准备 虚拟机:ssag-bj-ad-01, ssag-bj-fc-01, ssag-bj-sql-01, ssag-bj-sql-02, ssag-sh-ad-01, ssag-sh-fc-0 ...