loop causes enlargement of array
Show older comments
Hello, my theta vector 2X1 two values needs to be updated each itteration. instead i get theta to be size 1000 (as the number of the itterations)
Why my theta updating line causes theta to inflate?
Thanks
n=1000;
t=1.4;
sigma_R = t*0.001;
min_value_t = t-sigma_R;
max_value_t = t+sigma_R;
y_data = min_value_t + (max_value_t - min_value_t) * rand(n,1);
x_data=[1:1000];
L=0.0001; %learning rate
%plot(x_data,y_data);
itter=1000;
theta_0=0;
theta_1=0;
theta=[theta_0;theta_1];
itter=1000;
for i=1:itter
onss=ones(1,1000);
x_mat=[onss;x_data]';
pred=x_mat*theta;
residuals = (pred-y_data)';
theta_0=theta_0-((x_data.*residuals)*(L/n));
theta_1=theta_1-((x_data.*residuals)*(L/n));
theta=[theta_0,theta_1];
end
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!