0
$\begingroup$

I am trying to build fit the best fit for my random distribution. I have done exactly by the formulas in the book shown bellow. I get divergence in the error function. Where did I go wrong? my Matlab code is attached.

L=0.00001 %learning rate 

itter=1000000; %number of itterations
n=800;


sigma_R = 1.281*0.01;
min_value_R = 1.281-sigma_R;
max_value_R = 1.281+sigma_R;
%R_rnd = min_value_R + (max_value_R - min_value_R) * rand(n,1);

t0=0;
t1=0;%initial guess

x_data=[1:n]'; %NX1
onss=ones(1,n)';
pred_m=[onss,x_data];%NX2
real_data=min_value_R + (max_value_R - min_value_R) * rand(n,1);%our data which we try to aproximate NX1
for k=1:itter
B=[t0,t1]';% coefficient for prediction matrices 2X1
h_pred=pred_m*B; %2NX2 X 2X1= 2NX1 hipothesys  vector prediction
Dm=(2/(2*n))*sum((h_pred-real_data).*x_data);
Dc=(2/(2*n))*sum((h_pred-real_data));
t0=t0-L*Dm;
t1=t1-L*Dc;
E=(1/n)*sum((real_data-h_pred).^2); %error function

end


enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.