@@ -36,105 +36,110 @@ export function optimizePeaks(
3636 groupingFactor : 10 ,
3737 stages : [
3838 {
39+ // Stage 1: local stabilization
40+ factorLimits : 2 ,
41+ maxNumberOfPeaks : 40 ,
3942 optimization : {
4043 kind : 'lm' ,
4144 options : { maxIterations : 20 , errorTolerance : 1e-3 } ,
4245 } ,
4346 parameters : {
4447 fwhm : {
4548 optimize : true ,
46- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 2 ,
49+ min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 0.5 ,
4750 max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
4851 } ,
4952 mu : { optimize : false } ,
5053 x : { optimize : false } ,
5154 y : {
5255 optimize : true ,
53- init : ( peak : any ) => peak . y * 0.8 ,
56+ init : ( peak : any ) => peak . y ,
5457 } ,
5558 } ,
5659 } ,
5760 {
61+ factorLimits : 2 ,
62+ maxNumberOfPeaks : 40 ,
5863 optimization : {
5964 kind : 'lm' ,
60- options : { maxIterations : 20 , errorTolerance : 5e-4 } ,
65+ options : { maxIterations : 20 , errorTolerance : 1e-3 } ,
6166 } ,
6267 parameters : {
6368 fwhm : {
6469 optimize : true ,
65- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 2 ,
70+ min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 0.5 ,
6671 max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
6772 } ,
6873 mu : { optimize : false } ,
6974 x : { optimize : false } ,
7075 y : {
7176 optimize : true ,
77+ init : ( peak : any ) => peak . y ,
7278 } ,
7379 } ,
7480 } ,
7581 {
82+ // Stage 2: regroup into the real overlapping cluster
83+ factorLimits : 2 ,
84+ maxNumberOfPeaks : 40 ,
7685 optimization : {
7786 kind : 'lm' ,
78- options : { maxIterations : 20 , errorTolerance : 1e-5 } ,
87+ options : { maxIterations : 25 , errorTolerance : 1e-4 } ,
7988 } ,
8089 parameters : {
8190 fwhm : {
8291 optimize : true ,
83- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 2 ,
92+ min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 0.5 ,
8493 max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
8594 } ,
8695 mu : { optimize : true } ,
8796 x : { optimize : false } ,
88- y : {
89- optimize : true ,
90- } ,
97+ y : { optimize : true } ,
9198 } ,
9299 } ,
93100 {
101+ // Stage 3: final polish
102+ factorLimits : 2 ,
103+ maxNumberOfPeaks : 40 ,
94104 optimization : {
95105 kind : 'lm' ,
96- options : { maxIterations : 20 , errorTolerance : 5e-4 } ,
106+ options : { maxIterations : 30 , errorTolerance : 1e-5 } ,
97107 } ,
98108 parameters : {
99109 fwhm : {
100110 optimize : true ,
101- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 3 ,
102- max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 3 ,
111+ min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 0.5 ,
112+ max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
103113 } ,
104114 mu : { optimize : true } ,
105- x : { optimize : true } ,
106- y : { optimize : true } ,
107- } ,
108- } ,
109- {
110- optimization : {
111- kind : 'lm' ,
112- options : { maxIterations : 20 , errorTolerance : 1e-4 } ,
113- } ,
114- parameters : {
115- fwhm : {
115+ x : {
116116 optimize : true ,
117- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 2 ,
118- max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
117+ min : ( peak : any ) => peak . x - ( peak . shape ?. fwhm ?? 0 ) / 4 ,
118+ max : ( peak : any ) => peak . x + ( peak . shape ?. fwhm ?? 0 ) / 4 ,
119119 } ,
120- mu : { optimize : false } ,
121- x : { optimize : true } ,
122120 y : { optimize : true } ,
123121 } ,
124122 } ,
125123 {
124+ // Stage 3: final polish
125+ factorLimits : 2 ,
126+ maxNumberOfPeaks : 40 ,
126127 optimization : {
127128 kind : 'lm' ,
128- options : { maxIterations : 20 , errorTolerance : 1e-8 } ,
129+ options : { maxIterations : 30 , errorTolerance : 1e-5 } ,
129130 } ,
130131 parameters : {
131132 fwhm : {
132133 optimize : true ,
133- min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) / 2 ,
134+ min : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 0.5 ,
134135 max : ( peak : any ) => ( peak . shape ?. fwhm ?? 0 ) * 2 ,
135136 } ,
136137 mu : { optimize : true } ,
137- x : { optimize : true } ,
138+ x : {
139+ optimize : true ,
140+ min : ( peak : any ) => peak . x - ( peak . shape ?. fwhm ?? 0 ) / 4 ,
141+ max : ( peak : any ) => peak . x + ( peak . shape ?. fwhm ?? 0 ) / 4 ,
142+ } ,
138143 y : { optimize : true } ,
139144 } ,
140145 } ,
0 commit comments