time | calls | line |
---|
| | 1 | function [p1_a,p1_b,p1_c, p2_a,p2_b,p2_c, skew_factor] = fit_Gaussian_model_monosomy_2(workingDir, saveName, data,locations,init_width,func_type)
|
| | 2 | % attempt to fit a 2-gaussian model to data.
|
| | 3 |
|
| 1 | 4 | show = false;
|
| 1 | 5 | p1_a = nan; p1_b = nan; p1_c = nan;
|
| 1 | 6 | p2_a = nan; p2_b = nan; p2_c = nan;
|
| 1 | 7 | skew_factor = 1;
|
| | 8 |
|
| 1 | 9 | if isnan(data)
|
| | 10 | % fitting variables
|
| | 11 | return
|
| | 12 | end
|
| | 13 |
|
| | 14 | % find max height in data.
|
| 1 | 15 | datamax = max(data);
|
| | 16 | %datamax(data ~= max(datamax)) = [];
|
| | 17 |
|
| | 18 | % if maxdata is final bin, then find next highest p
|
| 1 | 19 | if (find(data == datamax) == length(data))
|
| | 20 | data(data == datamax) = 0;
|
| | 21 | datamax = data;
|
| | 22 | datamax(data ~= max(datamax)) = [];
|
| | 23 | end;
|
| | 24 |
|
| | 25 | % a = height; b = location; c = width.
|
| 1 | 26 | p1_ai = datamax; p1_bi = locations(1); p1_ci = init_width;
|
| 1 | 27 | p2_ai = datamax; p2_bi = locations(2); p2_ci = init_width;
|
| | 28 |
|
| 1 | 29 | initial = [p1_ai,p1_ci,p2_ai,p2_ci,skew_factor,skew_factor];
|
| 1 | 30 | options = optimset('Display','off','FunValCheck','on','MaxFunEvals',100000);
|
| 1 | 31 | time= 1:length(data);
|
| | 32 |
|
0.06 | 1 | 33 | [Estimates,~,exitflag] = fminsearch(@fiterror, ... % function to be fitted.
|
| | 34 | initial, ... % initial values.
|
| | 35 | options, ... % options for fitting algorithm.
|
| | 36 | time, ... % problem-specific parameter 1.
|
| | 37 | data, ... % problem-specific parameter 2.
|
| | 38 | func_type, ... % problem-specific parameter 3.
|
| | 39 | locations, ... % problem-specific parameter 4.
|
| | 40 | show ... % problem-specific parameter 5.
|
| | 41 | );
|
| 1 | 42 | if (exitflag > 0)
|
| | 43 | % > 0 : converged to a solution.
|
| | 44 | else
|
| | 45 | % = 0 : exceeded maximum iterations allowed.
|
| | 46 | % < 0 : did not converge to a solution.
|
| | 47 | % return last best estimate anyhow.
|
| | 48 | end;
|
| 1 | 49 | p1_a = abs(Estimates(1));
|
| 1 | 50 | p1_b = locations(1);
|
| 1 | 51 | p1_c = abs(Estimates(2));
|
| 1 | 52 | p2_a = abs(Estimates(3));
|
| 1 | 53 | p2_b = locations(2);
|
| 1 | 54 | p2_c = abs(Estimates(4));
|
| 1 | 55 | skew_factor1 = abs(Estimates(5));
|
| 1 | 56 | skew_factor2 = abs(Estimates(6));
|
| 1 | 57 | if (skew_factor < 0); skew_factor = 0; end; if (skew_factor > 2); skew_factor = 2; end;
|
| | 58 |
|
| 1 | 59 | c1_ = p1_c/2 + p1_c*skew_factor1/(100.5-abs(100.5-p1_b))/2;
|
| 1 | 60 | p1_c = p1_c*p1_c/c1_;
|
| 1 | 61 | c2_ = p2_c/2 + p2_c*skew_factor2/(100.5-abs(100.5-p2_b))/2;
|
| 1 | 62 | p2_c = p2_c*p2_c/c2_;
|
| 1 | 63 | end
|
Other subfunctions in this file are not included in this listing.