Using bootstrp with my own defined function

2 visualizzazioni (ultimi 30 giorni)
Hello
I am currently tasked with fitting 2 sets of data. I extracted 5 datapoints as a training set and I created a function that works the percentage differnce between the two sets which is as follows;
% img is a 1D normlised matrix and adam is a count of a certain feature in the images. Each image is stored in a cell array
function erfun = per_dif(img, adam, thresh, siz)
tota = 0;
totb = 0;
for i = 1:5
err = abs((round(sum(sum(img{i}.*img{i}>thresh == 1)))/siz)-adam(i));
tota = tota + err;
totb = totb + adam(i);
end
erfun = tota/totb;
end
In reality, the 'thresh' & 'siz' variables are unknown, I set a function as follows;
fun = @(x)per_dif(adam_im,adam_count,x(1),x(2))
and I used the fminsearch function on it as follows
x0 = [0.5,1];
x = fminsearch(f,x0)
I used the values of x on the test set and I got a result that makes sense.
Now, I want to increase the accuracy of my model using the bootstrp method. Instead of setting aside 5 training and 5 test data points, I want to use my whole set, and iterate through a random 5 of them to get multiple values of x (and then use mean and standard deviation).
It isjust that I cant seem to get the code working. This is what i have right now;
f = @(x)fminsearch(per_dif(adam_im, adam_count,x(1),x(2)),x0);
bootstat = bootstrp(200,@f,[adam_im,adam_count])

Risposta accettata

udi ibgui
udi ibgui il 28 Gen 2020
I have recreated a function that minimises my data
function x = per_dif_fit(img, adam)
x0 = [0.5,1];
tota = @(x)0;
totb = 0;
for i = 1:5
err = @(x)abs((round(sum(sum(img{i}.*img{i}>x(1) == 1)))/x(2))-adam(i));
tota = @(x)tota(x) + err(x);
totb = totb + adam(i);
end
a = @(x)tota(x)/totb;
x = fminsearch(a,x0)
end
and used that as an input to the bootstrp. It worked

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by