untracked m-files
This commit is contained in:
6
statistics/do_regression.m
Normal file
6
statistics/do_regression.m
Normal file
@@ -0,0 +1,6 @@
|
||||
function parameter = do_regression(x, y, start_parameter)
|
||||
|
||||
options = optimoptions('fminunc','GradObj','on');
|
||||
fun = @exp_funct;
|
||||
myfunc = @ (p)(lserr(p, x, y, fun));
|
||||
parameter = fminunc(myfunc, start_parameter, options);
|
||||
3
statistics/exp_funct.m
Normal file
3
statistics/exp_funct.m
Normal file
@@ -0,0 +1,3 @@
|
||||
function y = exp_funct(A, tau, t)
|
||||
|
||||
y = A .* (1 - exp(-1 * (t./tau)));
|
||||
3
statistics/lin_funct.m
Normal file
3
statistics/lin_funct.m
Normal file
@@ -0,0 +1,3 @@
|
||||
function y = lin_funct(a, b, x)
|
||||
|
||||
y = a.*x + b;
|
||||
7
statistics/lserr.m
Normal file
7
statistics/lserr.m
Normal file
@@ -0,0 +1,7 @@
|
||||
function [err, grad] = lserr(p, x, y, fun)
|
||||
|
||||
err = sum(y - fun(p(1), p(2), x)).^2;
|
||||
|
||||
if nargout > 1
|
||||
grad = lserr_gradient(p, x, y);
|
||||
end
|
||||
10
statistics/lserr_gradient.m
Normal file
10
statistics/lserr_gradient.m
Normal file
@@ -0,0 +1,10 @@
|
||||
function grad = lserr_gradient(param, x, y)
|
||||
h = 1e-6;
|
||||
|
||||
grad = 0*param;
|
||||
for i = 1:length(param)
|
||||
paramh = param;
|
||||
paramh(i) = param(i) + h;
|
||||
grad(i) = (lserr(paramh,x,y) - lserr(param,x,y))/h;
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user