模式识别作业汇总

鼠标滚动缩放   ——此部分转载:http://www.ilovematlab.cn/thread-35476-2-1.html

function test
t=linspace(0,2*pi,7).'; r=1:10;
plot(cos(t)*r,sin(t)*r,'LineWidth',3)


% ---------------- 用鼠标滚轮缩放图像 ----------------
set(gcf,'WindowScrollWheelFcn',@wswf)
    function wswf(src,cbd)
        cp=get(gca,'CurrentPoint'); % 当前点
        if cbd.VerticalScrollCount > 0
            k=1.25; % 缩小图像(放大范围)
        else
            k=0.75; % 放大图像(缩小范围)
        end
        % 以当前点为缩放中心,缩放图像(改变范围)
        axis(k*axis+(1-k)*cp([1,1,3,3]))
    end
% ------------------ 用鼠标移动数据范围 -----------------
set(gcf,'WindowButtonDownFcn',@wbdf)
    function wbdf(src,cbd) % 鼠标按下响应
        cp=get(gca,'CurrentPoint'); % 初始位置
        set(src,'Pointer','crosshair') % 指针样式
        
        set(gcf,'WindowButtonUpFcn',@wbuf)
        function wbuf(src,cbd) % 鼠标放开响应
            cp=cp-get(gca,'CurrentPoint'); % -位移
            xlim(xlim+cp(1));
            ylim(ylim+cp(3));
            set(gcf,'WindowButtonUpFcn','')
            set(src,'Pointer','arrow')
        end
    end
end

等价于:

function test
t=linspace(0,2*pi,7).'; r=1:10;
plot(cos(t)*r,sin(t)*r,'LineWidth',3)
% ---------------- 用鼠标滚轮缩放图像 ----------------
set(gcf,'WindowScrollWheelFcn',@wswf)
% ------------------ 用鼠标移动数据范围 -----------------
set(gcf,'WindowButtonDownFcn',@wbdf)
end

 function wswf(src,cbd)
        cp=get(gca,'CurrentPoint'); % 当前点
        if cbd.VerticalScrollCount > 0
            k=1.25; % 缩小图像(放大范围)
        else
            k=0.75; % 放大图像(缩小范围)
        end
        % 以当前点为缩放中心,缩放图像(改变范围)
        axis(k*axis+(1-k)*cp([1,1,3,3]))
end

function wbdf(src,cbd) % 鼠标按下响应
        cp=get(gca,'CurrentPoint'); % 初始位置
        set(src,'Pointer','crosshair') % 指针样式
        set(gcf,'WindowButtonUpFcn',@wbuf)

end

 function wbuf(src,cbd) % 鼠标放开响应
            cp=cp-get(gca,'CurrentPoint'); % -位移
            xlim(xlim+cp(1));
            ylim(ylim+cp(3));
            set(gcf,'WindowButtonUpFcn','')
            set(src,'Pointer','arrow')
end


设置subplot子图间距

h1=subplot(*,*,1);

p=get(h1,'pos');   %1x4维

p(3)=P(3)+0.05;   %右竖线

p(4)=p(4)+0.05;   %上横线

set(h1,'pos',p);


按钮组的单选按钮值

要在按钮组的控件下写SelectionChangedFcn函数

得到此控件的tag值:

str=get(hObject,'tag')

switch str

case '单选按钮1tag'

case '单选按钮2tag'

end


进度条

h=waitbar(0,'wait...');

set(h,'doublebuffer','on');

.....

waitbar(m*n/(M-4)/(N-4),h);

...

close(h);


弹框输入值:

prompt={'聚类数'};    %—————输入需要决策的类别数,默认二类
titlee='输入期望聚类数:';
def={'2'};
answer=inputdlg(prompt,titlee,[1 40],def);

C=str2num(answer{1});   %如果有n个框输入值,则每个值用answer{n}取


常用句式:

打开文件:[a,b]=uigetfile('*','标题');path=[b a];load(path)   or   imrean(path);

指定显示:axes(handles.tag),若在同一坐标多次画图,可在前面加一句:cla(handles.tag);

得到任意控件的“值”:get(handles.tag,'方式')—————得到编辑框“dx'的输入值:get(handles.dx,'String')

连接多个字符为一个字符:[ ]————figure('NumberTitle','off','Name',['距离:',d,'角度:',a]);

xlabel字符大小设置:xlabel('...','FontSize',10)






模式识别第一章作业题,中科院刘成林,Question 1 (Pattern Classification, Chapter 2, Problem 12) Let ωmax(x) be the state of nature for which P(ωmax|x) ≥ P(ωi|x) for all i, i = 1,...,c. (a) Show that P(ωmax|x) ≥ 1/c (b) Show that for the minimum-error-rate decision rule the average probability of error is given by P(error) = 1−RP(ωmax|x)p(x)dx (c) Use these two results to show that P(error) ≤ (c−1)/c (d) Describe a situation for which P(error) = (c−1)/c Question 2 (Pattern Classification, Chapter 2, Problem 13) In many pattern classification problems one has the option either to assign the pattern to one of c classes, or to reject it as being unrecognizable. If the cost for rejects is not too high, rejection may be a desirable action. Let λ(αi|ωi) =     0 i = j i,j = 1,...,c λr i = c + 1 λs otherwise where λr is the loss incurred for choosing the (c + 1)th action, rejection, and λs is the loss incurred for making a substitution error. Show that the minimum risk is obtained if we decide ωi if P(ωi|x) ≥ P(ωi|x) for all j and if P(ωi|x) ≥ 1− λr λs , and reject otherwise. What happens if λr = 0? What happens if λr > λs? Question 3 Now we have N samples, and each sample xi, i = 1,...,N has d-dimensions. Please provide us the proofs and the pseudo-codes of PCA algorithm Question 4 (Pattern Classification, Chapter 2, Problem 10) Consider the following decision rule for a two-category one-dimensional problem: Decide ω1 if x > θ; otherwise decide ω2. (a)Showtheprobabilityoferrorforthisruleisgivenby P(error) = P(ω1)Rθ−∞p(x|ω1)dx+P(ω2)R∞ θ p(x|ω2)dx (b) By differentiating, show that a necessary condition to minimize P(error) is that θ satisfy p(θ|ω1)P(ω1) = p(θ|ω2)P(ω2) (c) Does this equation define θ uniquely? (d) Give an example where a value of θ satisfying the equation actually maximizes the probability of error. Question 5 (Pattern Classification, Chapter 2, Problem 24) Consider the multivariate normal density for which σij = 0 and σii = σ2 i , i.e., Σ = diag(σ2 1,σ2 2,...,σ2 d). (a) Show that
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值