PDA

View Full Version : درخواست کمک برای تبدیل یک الگوریتم به برنامه متلب



msabori
چهارشنبه 03 مهر 1392, 18:34 عصر
سلام یک الگوریتم موازی دارم ( الگوریتم merge sort به صورت موازی) که می خواستم به زبان متلب تبدیل کنم
ولی متلب کار نکردم کسی می تونه کمک کنه الگوریتم رو هم در ضمیمه می زارم. لطفا هر کی می تونه کمک کنه

rahnema1
جمعه 12 مهر 1392, 21:14 عصر
حتما باید تحت matlab باشه؟ برنامه ای که گذاشتید شبیه زبان برنامه نویسی cilk است یک کد رای پدازش موازی که تحت لینوکس کامپایل و اجرا میشه به سایت زیر مراجعه کنید
http://supertech.csail.mit.edu/cilk

mehrnaz64
چهارشنبه 24 مهر 1392, 18:02 عصر
سلام دوستان
وقت به خیر
منم به طور مشابه برای تبدیل این الگوریتم به متلب مشکل دارم
ممنون میشم راهنمایی بفرمایید
سپاس فراوان
در پناه خدا باشید

input:
data - a set of observations
model - a model that can be fitted to data
n - the minimum number of data required to fit the model
k - the number of iterations performed by the algorithm
t - a threshold value for determining when a datum fits a model
d - the number of close data values required to assert that a model fits well to data
output:
best_model - model parameters which best fit the data (or nil if no good model is found)
best_consensus_set - data points from which this model has been estimated
best_error - the error of this model relative to the data

iterations := 0
best_model := nil
best_consensus_set := nil
best_error := infinity
while iterations < k
maybe_inliers := n randomly selected values from data
maybe_model := model parameters fitted to maybe_inliers
consensus_set := maybe_inliers

for every point in data not in maybe_inliers
if point fits maybe_model with an error smaller than t
add point to consensus_set

if the number of elements in consensus_set is > d
(this implies that we may have found a good model;
now test how good it is)
this_model := model parameters fitted to all points in consensus_set
this_error := a measure of how well this_model fits these points
% The line above contains the bug. This_error should be replaced by a score that is either the size of the consensus set, or the robust error norm computed on ALL samples (not just the consensus set).
if this_error < best_error
(we have found a model which is better than any of the previous ones;
keep it until a better one is found)
best_model := this_model
best_consensus_set := consensus_set
best_error := this_error

increment iterations

return best_model, best_consensus_set, best_error

rahnema1
چهارشنبه 24 مهر 1392, 22:19 عصر
سلام، توی کد زیر یک مدل رگرسیون ساده y به x قرار داره بنام fitt که نقادیر برگردونده شده اون یکی beta که پارامتر مدله و دیگری R2 را بر می گردونه که شاخص برازش یا fit مدله




x=1:100;
y=2*(x+randn(1,100))+1;
data=[x;y]';
function [beta,R2]= fitt(data)
n = size(data)(1);
X = [ones(n,1) data(:,1)];
Y=data(:,2);
beta = inv(X'*X)*X'*Y;
resids = Y - X*beta; % resids = e = y - Xa
RSS = resids' * resids; % residual sum of squares
TSS = sum((Y - mean(Y)).^2); % total sum of squares
R2 = 1 - RSS/TSS;
end
plot(x,y,'*')
iterations=0;
n=50;
K=100;
t=.01;
d=20;
besterror=Inf
while (iterations<K)
ind=randperm(size(data)(1),n);
maybeinliers=data(ind,:);
[beta,R2]=fitt(maybeinliers);
maybemodelparam1=beta;
consensusset = maybeinliers;
everypointindatanotinmaybeinliers =data;
everypointindatanotinmaybeinliers(ind,:)=[];
fitted=maybemodelparam1(1)+maybemodelparam1(2)*eve rypointindatanotinmaybeinliers(:,1);%X*beta
consensusset=[consensusset; everypointindatanotinmaybeinliers(abs(fitted-everypointindatanotinmaybeinliers(:,2))<t,:)];
if (size(consensusset)(1)>d)
[beta,R2]=fitt(consensusset);
thismodel=beta;
thiserror=R2;
%thiserror=size(consensusset)(1)
%[beta,R2]=fitt(data);thiserror=R2
if (thiserror <besterror)
bestmodel=thismodel;
bestconsensusset=consensusset;
besterror=thiserror;
end
end
iterations=iterations+1;
end

heliye_87
شنبه 27 مهر 1392, 21:13 عصر
سلام به همه
من دانشجوی کارشناسی هستم و در ابتدای مطالعه راجع به پردازش تصویر برای همین عذر میخوام اگر سئوالم خیلی پایه و مبتدی هست
میشه من رو راهنمایی کنید این الگوریتم هایی که در اینترنت موجودند را چطوری به متلب تبدیل میکنید
یعنی باید برنامه نویسی متلب رو مسلط باشیم تا بتونیم همچین کاری رو انجام بدیم؟
با تشکر فراوان

rahnema1
شنبه 27 مهر 1392, 22:56 عصر
سلام به همه
من دانشجوی کارشناسی هستم و در ابتدای مطالعه راجع به پردازش تصویر برای همین عذر میخوام اگر سئوالم خیلی پایه و مبتدی هست
میشه من رو راهنمایی کنید این الگوریتم هایی که در اینترنت موجودند را چطوری به متلب تبدیل میکنید
یعنی باید برنامه نویسی متلب رو مسلط باشیم تا بتونیم همچین کاری رو انجام بدیم؟
با تشکر فراوان

خب معلومه تا بلد نباشیم که نمی تونیم تبدیل کنیم مثل اینکه بخواهیم از زبون فارسی به زبون انگلیسی حرف بزنیم اگه زبان بلد نباشیم، مفهوم رو می فهمیم ولی نمی تونیم انتقال بدیم