matlab drawnow連成曲線,precision recall曲線Matlab實現

在用哈希進行檢索時,常會用到precision recall曲線對其性能進行定量評價。precision recall的定義在信息檢索評價指標中已做了詳細說明,這里再記錄一下precision recall的具體實現。

precision recall曲線matlab一般使用的都是下面的版本:

function[recall, precision, rate] =recall_precision(Wtrue, Dhat)

%

% Input:

% Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN

% Dhat = estimated distances

%

% Output:

%

% exp. # of good pairs inside hamming ball of radius <= (n-1)

% precision(n) = --------------------------------------------------------------

% exp. # of total pairs inside hamming ball of radius <= (n-1)

%

% exp. # of good pairs inside hamming ball of radius <= (n-1)

% recall(n) = --------------------------------------------------------------

% exp. # of total good pairs

max_hamm = max(Dhat(:))

hamm_thresh = min(3,max_hamm);

[Ntest, Ntrain] = size(Wtrue);

total_good_pairs = sum(Wtrue(:));

% find pairs with similar codes

precision = zeros(max_hamm,1);

recall = zeros(max_hamm,1);

rate = zeros(max_hamm,1);

for n = 1:length(precision)

j = (Dhat<=((n-1)+0.00001));

%exp. # of good pairs that have exactly the same code

retrieved_good_pairs = sum(Wtrue(j));

% exp. # of total pairs that have exactly the same code

retrieved_pairs = sum(j(:));

precision(n) = retrieved_good_pairs/retrieved_pairs;

recall(n)= retrieved_good_pairs/total_good_pairs;

rate(n) = retrieved_pairs / (Ntest*Ntrain);

end

% The standard measures for IR are recall and precision. Assuming that:

%

% * RET is the set of all items the system has retrieved for a specific inquiry;

% * REL is the set of relevant items for a specific inquiry;

% * RETREL is the set of the retrieved relevant items

%

% then precision and recall measures are obtained as follows:

%

% precision = RETREL / RET

% recall = RETREL / REL

% if nargout == 0 || nargin > 3

% if isempty(fig);

% fig = figure;

% end

% figure(fig)

%

% subplot(311)

% plot(0:hamm_thresh-1, precision(1:hamm_thresh), varargin{:})

% hold on

% xlabel('hamming radius')

% ylabel('precision')

%

% subplot(312)

% plot(0:hamm_thresh-1, recall(1:hamm_thresh), varargin{:})

% hold on

% xlabel('hamming radius');

% ylabel('recall');

%

% subplot(313);

% plot(recall, precision, varargin{:});

% hold on;

% axis([0 1 0 1]);

% xlabel('recall');

% ylabel('precision');

%

% drawnow;

% end

function[score, recall] =evaluation(Wtrue, Dhat, fig, varargin)

%

% Input:

% Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN

% Dhat = estimated distances

% The next inputs are optional:

% fig = figure handle

% options = just like in the plot command

%

% Output:

%

% exp. # of good pairs inside hamming ball of radius <= (n-1)

% score(n) = --------------------------------------------------------------

% exp. # of total pairs inside hamming ball of radius <= (n-1)

%

% exp. # of good pairs inside hamming ball of radius <= (n-1)

% recall(n) = --------------------------------------------------------------

% exp. # of total good pairs

[Ntest, Ntrain] = size(Wtrue);

total_good_pairs = sum(Wtrue(:));

% find pairs with similar codes

score = zeros(20,1);

for n = 1:length(score)

j = find(Dhat<=((n-1)+0.00001));

%exp. # of good pairs that have exactly the same code

retrieved_good_pairs = sum(Wtrue(j));

% exp. # of total pairs that have exactly the same code

retrieved_pairs = length(j);

score(n) = retrieved_good_pairs/retrieved_pairs;

recall(n)= retrieved_good_pairs/total_good_pairs;

end

% The standard measures for IR are recall and precision. Assuming that:

%

% * RET is the set of all items the system has retrieved for a specific inquiry;

% * REL is the set of relevant items for a specific inquiry;

% * RETREL is the set of the retrieved relevant items

%

% then precision and recall measures are obtained as follows:

%

% precision = RETREL / RET

% recall = RETREL / REL

if nargout == 0 || nargin > 3

if isempty(fig);

fig = figure;

end

figure(fig)

subplot(211)

plot(0:length(score)-1, score, varargin{:})

hold on

xlabel('hamming radium')

ylabel('percent correct (precision)')

title('percentage of good neighbors inside the hamm ball')

subplot(212)

plot(recall, score, varargin{:})

hold on

axis([0 1 0 1])

xlabel('recall')

ylabel('percent correct (precision)')

drawnow

end

不能看出,上面的score就是前面的precision,在追溯到08年,也就是譜哈希SH發表的那年,同樣可以在SH中有畫precision recall的曲線,跟第二個一樣。考證這些,無非就是想說在自己畫PR曲線時,就用這些牛提供的比較靠譜,自己寫出來的不一定對。

好了,再對畫precision recall輸入的參數做些梳理。畫precision recall曲線時,用到的groundtruth是原歐式空間中查詢樣本的近鄰,所以在計算Wtrue時,可以采用下面的方法計算:

%center, then normalize data

X = X - ones(size(X,1),1)*mean(X);

for i = 1:size(X,1)

X(i,:) = X(i,:) / norm(X(i,:));

end

rp = randperm(size(X,1));

trIdx = rp(1:trN);

testIdx = rp(trN+1:trN+testN);

Xtr = X(trIdx,:);

Xtst = X(testIdx,:);

D_tst = distMat(Xtst,Xtr);

D_tr = distMat(Xtr);

Dball = sort(D_tr,2);

Dball = mean(Dball(:,50));

WTT = D_tst < Dball;

上面第一步先對數據進行中心化,然后進行歸一化。之后挑選出訓練樣本和測試樣本(查詢樣本),然后計算Wture。Dhat就是計算查詢樣本與database之間的漢明距離,可以通過下面方法計算:

%get Hamming distance between queries and database

B1 = compactbit(H);

B2 = compactbit(H_query);

Dhamm = hammingDist(B2,B1);

H是database中的編碼,進行壓縮以十進制數進行表示,同理H_query即為查詢樣本的編碼。將上面都計算出來后,便可以得到precision和recall,plot一下就可以了。

參考:

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/397529.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/397529.shtml
英文地址,請注明出處:http://en.pswp.cn/news/397529.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

trap

http://blog.csdn.net/elbort/article/details/8525599 http://mywiki.wooledge.org/SignalTrap轉載于:https://www.cnblogs.com/flowjacky/p/4785723.html

WinSCP實現Ubuntu與 Windows 文件共享方法

2019獨角獸企業重金招聘Python工程師標準>>> WinSCP是一個Windows環境下使用SSH的開源圖形化SFTP客戶端。同時支持SCP協議。它的主要功能就是在本地與遠程計算機間安全的復制文件。WinSCP綠色中文版 一款基于SSH安全高效的FTP上傳軟件。WinSCP 可以執行所有基本的文…

緩存機制

緩存 緩存就是數據交換的緩沖區&#xff08;稱作Cache&#xff09; 客戶端&#xff1a;緩存&#xff08;expires&#xff09;、deflate壓縮 緩存服務器&#xff1a;CDN/cache緩存靜態內容如&#xff1a;html、jpg、gif、js等 靜態web服務器&#xff1a;Apache/nginx靜態服務器提…

Shell學習總結

Shell 是什么&#xff1f; Shell 是一個用C語言編寫的程序&#xff0c;它是用戶使用Linux的橋梁。Shell既是一種命令語言&#xff0c;又是一種程序設計語言。 Shell 是指一種應用程序&#xff0c;這個應用程序提供了一個界面&#xff0c;用戶通過這個界面訪問操作系統內核的服務…

java有幾個關鍵字,Java多線程常用的幾個關鍵字

Java多線程常用的幾個關鍵字二、volatile作用&#xff1a;volatile關鍵字的作用是&#xff1a;使變量在多個線程間可見(具有可見性)&#xff0c;但是僅靠volatile是不能保證線程的安全性&#xff0c;volatile關鍵字不具備synchronized關鍵字的原子性。Demo1:package com.ietree…

PHP獲取QQ等級,php仿QQ等級太陽顯示函數

開頭先引述下QQ等級的算法&#xff1a;設當前等級為N&#xff0c;達到當前等級最少需要的活躍天數為D&#xff0c;當前活躍天數為Dc&#xff0c;升級剩余天數為Dr&#xff0c;則&#xff1a;從而推出:好了&#xff0c;引述完成&#xff0c;懶得寫字了&#xff0c;貼出代碼&…

Bugfree實用心得_轉

轉自&#xff1a;http://blog.csdn.net/benkaoya/article/details/8719257 本博下有許多實用技巧 1. 什么是問題跟蹤系統 問題跟蹤系統&#xff08;Issue Tracking System&#xff09;是專門用于記錄、跟蹤和管理各類問題的軟件。 問題跟蹤系統出現于上世紀80年代&#xff0c;…

【qxbt day1】 P2367 語文成績

今天學了 差分********* 很明白 然后 配合著luogu上的題寫一下吧 裸的差分 當時一直打暴力60分 交了十幾次 今天才知道 查詢修改什么的是差分 直接看題把 輸入輸出格式輸入格式&#xff1a; 第一行有兩個整數n&#xff0c;p&#xff0c;代表學生數與增加分數的次…

python會什么比c慢

眾所周知&#xff0c;python執行速度比c慢。原因為何&#xff1f; 先來看下面這張圖&#xff1a; python的傳統運行執行模式&#xff1a;錄入的源代碼轉換為字節碼&#xff0c;之后字節碼在python虛擬機中運行。代碼自動被編譯&#xff0c;之后再解釋成機器碼在CPU中執行。 補充…

多維動歸第一題

https://www.luogu.org/problemnew/show/P1508 好了這題就是較為簡單的坐標類DP&#xff08;感覺&#xff09;&#xff0c;總之是一個二維的區域&#xff0c;需要一步一步地向可前進方向dp&#xff0c;而倒退過來&#xff0c;就是每一個地方取之前的地方里最多的一個進行選擇&a…

Json字符串處理

2019獨角獸企業重金招聘Python工程師標準>>> pom.xml <dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.7</version> </dependency> 編寫GsonUtils類 // // Source c…

用腳本控制虛擬機

#############用腳本控制虛擬機給file.sh 一個權限chmod x file.sh轉載于:https://blog.51cto.com/forever8/1863587

HDU 5288

//枚舉因子&#xff0c;查找和i最近的左右是i因子的點即可。#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define LL long long using namespace std;const int MAX100010; const LL mod1e97; int l_next[10010];…

Git 初步學習

學習目標&#xff1a; 在linux 上安裝Git 服務器 在windows 上安裝 Git 客戶端 創建Git倉庫&#xff0c;git用戶 在windows 中獲取項目&#xff0c;對項目進行增刪改查&#xff0c;更新到服務器 創建兩個分支&#xff0c;進行分支修改和代碼合并 1. 在linux上安裝git服務器 使用…

CRTMPServer 在CentOS 64-bit下的編譯(轉)

CRTMPServer 在CentOS 64-bit下的編譯 http://blog.csdn.net/qiuchangyong/article/details/52848942 一、Centos 用 wget 下載需要的軟件 wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz 二、安裝 cmake tar zxvf cmake-2.8.4.tar.gzcd cmake-2.8.6./bootstrapgma…

HTML 學習筆記 day one

HTML學習筆記 day one Chapter one 網站開發基礎 1.2網站的基本架構 網站的基本要素&#xff1a;內容&#xff0c;頁面&#xff0c;超鏈接 動態網頁和靜態網頁的區別在于&#xff1a;動態網頁會自動更新&#xff0c;后綴名是.asp或者.aspx;而靜態網頁不會自動更新&#xff0c…

Jquery事件冒泡

事件冒泡 什么是事件冒泡 在一個對象上觸發某類事件&#xff08;比如單擊onclick事件&#xff09;&#xff0c;如果此對象定義了此事件的處理程序&#xff0c;那么此事件就會調用這個處理程序&#xff0c;如果沒有定義此事件處理程序或者事件返回true&#xff0c;那么這個事件會…

WPF對某控件添加右鍵屬性

代碼創建右鍵屬性 ContextMenu cm new ContextMenu();MenuItem mi new MenuItem();mi.Header "打開此文件所有文件夾";mi.Click mi_Click;cm.Items.Add(mi);lv.ContextMenu cm; 轉載于:https://www.cnblogs.com/lunawzh/p/5986356.html

解決虛擬機 正在決定eht0 的ip信息失敗 無鏈接-- 添加虛擬網卡

添加步驟&#xff1a;1、進入設備管理器 2、點下一步3、繼續下一步4、繼續往下走轉載于:https://www.cnblogs.com/Yongzhouunknown/p/4802530.html

jquery元素節點操作

jquery元素節點操作 創建節點 var $div $(<div>); var $div2 $(<div>這是一個div元素</div>); 插入節點 1、append()和appendTo()&#xff1a;在現存元素的內部&#xff0c;從后面插入元素 var $span $(<span>這是一個span元素</span>); $(#d…