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