Skip to content

Instantly share code, notes, and snippets.

@Shoeboxam
Last active February 7, 2017 20:32
Show Gist options
  • Save Shoeboxam/66f00cfbc809b453ea1c41d8b85ed207 to your computer and use it in GitHub Desktop.
Save Shoeboxam/66f00cfbc809b453ea1c41d8b85ed207 to your computer and use it in GitHub Desktop.
Functional erf minimization with scalar theta
environment = [4, 5, 7, 8];
expectation = 23;
% Initial weight
theta = 0.5;
theta_old = theta - 0.25;
while abs(theta - theta_old) > 1e-12
% Derivative of squared error: ln = (expectation - reinforcement)^2
dln_dr = -2 * (expectation - theta * environment);
% By chain rule: r = theta * environment
dr_dw = transpose(environment); % env is a column vector
dln_dw = dln_dr * dr_dw;
% Save old theta so one can check for difference
theta_old = theta;
% Substitute derivatives into theta update
theta = theta - 0.001 * (dln_dw); % 1xn * nx1
end
@hyper-mage
Copy link

I'm commenting so I can check it on my computer lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment