24小时热门版块排行榜    

Znn3bq.jpeg
北京石油化工学院2026年研究生招生接收调剂公告
查看: 1400  |  回复: 8
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

xmcrobbie

银虫 (小有名气)

[求助] 有段程序,就5,6行,我看了N天了,请教高手

function Y = sampleWithR(weights,K)
%Y = sampleWithR(weights,K)
%Generates K samples from the discrete distribution specified by weights
%O(K)

%Need to handle border effects
cdf = cumsum(weights);
Y = histc(rand(K,1)*cdf(end),[0; cdf]);
Y = [Y(1:end-2); Y(end-1)+Y(end)];


我不知道这个函数起什么作用啊。。。。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xmcrobbie

银虫 (小有名气)

引用回帖:
7楼: Originally posted by coolslj at 2013-10-22 12:50:06
楼主没有提供该程序的背景和上下文,所以专家们有点盲人摸象。

该程序根据一个分布的直方图,产生了一个新的分布的直方图。
从这个角度看,该程序无实际意义。
我推测它主要是用于教学。...

function res = searchImCostTRandEndc (im,len,wid,MAX_NUM,thresh,currAngles)
%[res,respOut] = getSegments (im,frameNum,len,wid,thresh,currAngles)
%Searches binary im for patches of size len by wid of white
%Randomized version, thresh is the number of examples to return

SUPPRESS = 0;
SCALE = 1/3; %When we weight the background flanks by .5
%SCALE = 1/2;

%We want our final log potentials to be between 0 & 10
%FINAL_SCALE = 1/3;

[origY, origX, dummy] = size(im);


if ~exist('currAngles'),
  currAngles = 15:15:360;
  %currAngles = 15:15:180;
end
if ~exist('roi'),
  roi = [1 1;origY origX];
end

%Thresh is the number of pixels we're allowing to be misclassified
if ~exist('thresh') | isempty(thresh),
    %thresh = 1*len*wid;
    thresh = 0;
end

%Convert to a probability
%thresh = exp(-thresh/SCALE);

%Add the size of our patch to buffer our ROI
roi = round(roi + max([len wid])*[-1 -1;1 1]);

%Make sure ROI does not exceed our image dimensions
roi(1, = max([1 1],roi(1,);
roi(2, = min([origY origX],roi(2,);

%dtheta = 15;
ddir = 1; %Maybe go back to 2?
ddir = min(length(currAngles)-1,ddir);
dpos = 1; %Maybe go back to 2?

im = im(roi(1,1):roi(2,1),roi(1,2):roi(2,2),;
[imy,imx,dummy] = size(im);

%Shift our currentAngle
currAngles = -90 - currAngles;

[len,wid] = deal(round(len),round(wid));

%im = uint8(im);
%wwid = ceil(wid/8);
%wwid = 2;

%imPatch = [zeros(len,wid) ones(len,wid) zeros(len,wid)];
%Use felzenswchab style likelihood
%imPatch = [zeros(wid,wid*3); -ones(len,wid) ones(len,wid) -ones(len,wid); -ones(wid,wid*3)];

yy = [-(len-1)/2len-1)/2].^2/(.4*len.^2);
xx = [-(wid-1)/2wid-1)/2].^2/(.4*wid.^2);
[yy,xx] = ndgrid(yy,xx);
kk = exp(-(yy + xx));
kk = kk.*(len*wid/(sum(kk()));
imPatch = [zeros(wid,wid*3); -ones(len,wid) kk -ones(len,wid); -ones(wid,wid*3)];

%yind = 1:len; yind = yind - mean(yind);
%xind = 1:wid; xind = xind - mean(xind);
%[Y,X] = ndgrid(yind/(5*len),xind/(5*wid));
%imPatch = exp(-Y.^2 + -X.^2);

resp = zeros([length(currAngles) imy imx]);
for dir = 1:length(currAngles),
  currAngle = -90 - currAngles(dir);
  kernal = imrotate(imPatch,currAngle);

  %kernal = kernal./sum(kernal();  
  %kernal = kernal./sum(kernal(kernal > 0));

  [mm,nn,dummy] = size(kernal);
  
  %currResp = filter2(kernal == 1,im == 0,'valid') + .5*filter2(kernal == 0,im == 1,'valid');
  %tmp = filter2(kernal == 1,im == 0,'valid');
  tmp = filter2(kernal.*(kernal > 0),im == 0,'valid');
  currResp = tmp + .25*filter2(kernal < 0,im == 1,'valid');
  indy = ceil(mm/2):imy-floor(mm/2);
  indx = ceil(nn/2):imx-floor(nn/2);
  if ~isempty(currResp),
    %resp(dir,indy,indx) = exp(-currResp/SCALE);  
    %currResp = exp(-currResp/SCALE);
    currResp = exp(-currResp/(len*wid*SCALE));
    %currResp(tmp == sum(kernal( == 1)) = 0;
    currResp(tmp == sum(kernal(kernal > 0))) = 0;
    resp(dir,indy,indx) = currResp;
  end
end

%keyboard;
resp(resp < thresh) = 0;
%ord = find(sampleWithR(exp(-resp(/(len*wid)),thresh));

%%%%%%%%%%%%在这里调用了sampleWithR%%%%%%%
ord = find(sampleWithR(resp(,MAX_NUM));
resp = resp(ord);
[resp,I] = sort(resp);
resp = flipud(resp);
ord = ord(flipud(I));
%ord = ord(I);

res.resp = resp;
%res.resp = resp.^(1/FINAL_SCALE);

[ang i j] = ndgrid(pi/180*currAngles,roi(1,1):roi(2,1), roi(1,2):roi(2,2));

res.resp = resp;
ang = ang(ord); res.u = cos(ang); res.v = sin(ang);
res.x = j(ord);
res.y = i(ord);
res.len = len/2*ones(size(resp));
res.w = wid/2*ones(size(resp));
8楼2013-10-22 14:30:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 9 个回答

haier20022

新虫 (正式写手)

【答案】应助回帖

感谢参与,应助指数 +1
是matlab程序吧?
2楼2013-10-20 13:33:29
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

feixiaolin

荣誉版主 (文坛精英)

优秀版主

function Y = sampleWithR(weights,K)
% 依权值重采样;
cdf = cumsum(weights);
% 权值累加
Y = histc(rand(K,1)*cdf(end),[0; cdf]);
% 统计直方图
Y = [Y(1:end-2); Y(end-1)+Y(end)];
% 直方图最末一bin修正
3楼2013-10-20 14:40:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xmcrobbie

银虫 (小有名气)

引用回帖:
3楼: Originally posted by feixiaolin at 2013-10-20 14:40:26
function Y = sampleWithR(weights,K)
% 依权值重采样;
cdf = cumsum(weights);
% 权值累加
Y = histc(rand(K,1)*cdf(end),);
% 统计直方图
Y = ;
% 直方图最末一bin修正...

Y = histc(rand(K,1)*cdf(end),[0; cdf]);  这行不理解啊。rand(K,1)是随机产生K个0到1的数吧。[0; cdf] 应该是在在cdf2前加个0吧。

应该是看看产生的这K个数,落在统计直方图中各个bin的个数吧。。。

这么理解对吗?
4楼2013-10-20 16:30:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 347材料专硕求调剂 +17 zj8215216 2026-04-06 17/850 2026-04-08 15:21 by zzucheup
[考研] 一志愿哈工大,初试329,求环境科学与工程调剂! +11 余未辛 2026-04-06 11/550 2026-04-08 15:21 by screening
[考研] 324求调剂 +15 想上学求调 2026-04-03 15/750 2026-04-08 14:51 by zzucheup
[考研] 280求调剂 +9 李rien 2026-04-04 9/450 2026-04-08 13:20 by lijunpoly
[考研] 一志愿南科大生物学297分,求调剂推荐 +8 Y-yyusx 2026-04-06 9/450 2026-04-07 19:38 by biomichael
[考研] 化学调剂 +18 艾志恒 2026-04-03 19/950 2026-04-07 16:00 by 起飞的比熊1
[考研] 求调剂 +5 chenxrlkx 2026-04-05 7/350 2026-04-06 07:54 by houyaoxu
[考研] 材料专硕322分 +10 哈哈哈吼吼吼哈 2026-04-04 10/500 2026-04-05 21:22 by 学员8dgXkO
[考研] 0832食品科学与工程学硕282调剂 +6 鱼在水中游a 2026-04-02 9/450 2026-04-05 11:45 by flysky1234
[考研] 278求调剂 +14 范婷娜 2026-04-04 15/750 2026-04-04 22:15 by lqwchd
[考研] 283求调剂 +4 mcbbc 2026-04-03 5/250 2026-04-04 20:51 by imissbao
[考研] 一志愿北交大材料工程总分358 +6 cs0106 2026-04-03 6/300 2026-04-04 11:20 by w_xuqing
[考研] 一志愿双非085502,267分,过四级求调剂 +3 再忙也要吃饭啊 2026-04-03 3/150 2026-04-04 05:03 by gswylq
[考研] 081200-11408-276学硕求调剂 +5 崔wj 2026-04-03 5/250 2026-04-03 15:06 by arrow8852
[考研] 320求调剂 +5 振—TZ 2026-04-02 5/250 2026-04-03 14:42 by fxue1114
[考研] 调剂 +7 祉岷. 2026-04-02 7/350 2026-04-03 09:11 by 花呗还欠600
[考研] 295求调剂 +7 愿旅途永远坦然 2026-04-02 7/350 2026-04-03 08:22 by fangshan711
[考研] 302求调剂 +9 zyx上岸! 2026-04-02 9/450 2026-04-02 23:07 by 马儿快快地跑
[考研] 285求调剂 +8 AZMK 2026-04-02 11/550 2026-04-02 20:16 by yulian1987
[考研] 298求B区调剂 +4 zzz,,r 2026-04-02 5/250 2026-04-02 12:17 by 土木硕士招生
信息提示
请填处理意见