-
Notifications
You must be signed in to change notification settings - Fork 0
/
RICE_1_0___9_18_2020.ipf
2814 lines (1859 loc) · 78.3 KB
/
RICE_1_0___9_18_2020.ipf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma TextEncoding = "Windows-1252"
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
//The functions described below comprise of the program described as the Refractive Index Confidence Explorer or RICE. RICE relies on an interative approach
//to estimate uncertainty in optical closure calculations using discrete solutions. For each RICE cycle RICE attempts to determine if a given discrete refractive index value could have provided
//the refractive index that was calculated experimentally( or test values). By doing this a large number of times for a series of near refractive index values,
// a probability distribution is created of refractive index values that could have yielded the observed value under the uncertainty conditions. All calculations operate under
// assumptions of Mie Theory.
//RICE was developed at the University of California Riverside in 2020 by Alexander Frie and Roya Bahreini. RICE was developed with support from the national science foundation (AGS 1454374).
//If you have questions feel free to contact Alex at afrie003@ucr.edu.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Menu "RICE"
"RICE 1.0", User_interface_RICE()
"Refractive Index Calcuation", RI_calculation()
"Change Confidence Interval (after running RICE)", RICE_Reanalyze()
//creates a menu item that iniates the macro
End
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function RICE_Reanalyze() //reanalyzes confidence interveral at different confidence levels using RICE outputs.
string adaptive_output="RICE_Output"
variable CI=0.95
prompt adaptive_output, "RICE_Output Matrix, should be named 'RICE_Output'", popup, WaveList("*",";","")
prompt CI, "New confidence level (0-1)"
doprompt "RICE_Reanalyze", adaptive_output, CI
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
Output_updater_k($Adaptive_output,CI)
Output_updater_n($Adaptive_output,CI)
end
function User_interface_RICE() //Creates a simple user interface for the selection of input waves
string dia_bins="dia_bins"
string Size_t_series="Size_t_series"
string n_t_series="RI_t_series"
string k_t_series="k_t_series"
prompt dia_bins, "Midpoint Diameter of Size Bins (nm)", popup, WaveList("*",";","")
prompt Size_t_series, "dN/dlog(dp) (1/cm3), Rows as dp, Columns as Time", popup, WaveList("*",";","")
prompt n_t_series,"n-Value Time Series", popup, WaveList("*",";","")
prompt k_t_series,"k-Value Time Series", popup, WaveList("*",";","")
doprompt "Input Data", dia_bins, Size_t_series, n_t_series, k_t_series // prompts for the input data
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
Adapt_RI_Interval($dia_bins,$Size_t_series,$n_t_series,$k_t_series)
end
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Adapt_RI_interval prompts for the uncertainty and run conditions for the RICE analysis. This function also repeatedly adjusts the test RI range input range in an effort to capture the probability space around the calculated refractive index.
//Adapt_RI_interval starts by inputting a small number of iterations and discrete RI values into the RI interval function. Once the output from RI interval satisfies a set of parameters, in an effort to guess the appropriate sampling space, Adapt_RI_interval
//increases the number of iterations and discrete RI values input into RI_interval for the final analysis of a given point.
function Adapt_RI_Interval(dia_bins, Size_t_series, RI_t_series, k_t_series)
wave dia_bins, Size_t_series, RI_t_series,K_t_series
variable ad, af=0, as=0, n_in,k_in, k_change, k_width1, n_change, n_width1,k_step1, n_step1, ty, tx, qi, V_mid_point, iter, spin_up_cycles=5, spin_up_matrix=64, duration=0, iq, good_count=0, spin_up_repeat=1, abs_limit=0.05,scat_limit=0.05,step_modifier, matrix_final=144, SD_Dia=0.03,SD_N=0.1,SD_Scat=0.05,SD_Abs=0.05,iter_start=10, wavelength=375, iter_final=100,k_start=0, k_end=0.1, n_start=1.0, n_end=2, n_step=0.01,k_step=0.001, indicators=0, repeat_count=0,n_width=0.05, k_width=0.002, adaptors=0, bin_counter, bin_counter2,start_time
variable idle_n, idle_k,CL=95, Calc_type=1, uncertainty_type=0
string wave_sd_scat,wave_sd_abs
duplicate /o RI_t_series, mult_SD_scat,mult_SD_abs
prompt uncertainty_type, " Do you have static relative optical uncertainties (0) or uncertainties for each measurement(1)?"
doprompt "Uncertainty Types" uncertainty_type
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
// can chose whether to use static relative values or dynamic relative values for unceretainties
if (uncertainty_type==0)
//promts for uncertainty conditions and wavelength of measurement
prompt SD_Dia, "Relative Uncertainty in Particle Size"
prompt SD_N, "Relative Uncertainty in Particle Number Concentrations"
prompt SD_Scat, "Relative Uncertainty in Scattering Coefficients"
prompt SD_abs, "Relative Uncertainty in Absorption Coefficients"
prompt wavelength, "Wavelength of Optical Measurements (nm)"
doprompt "Uncertainties" SD_Dia,SD_N,SD_Scat,SD_Abs, wavelength
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
else
prompt SD_Dia, "Relative Uncertainty in Particle Size"
prompt SD_N, "Relative Uncertainty in Particle Number Concentrations"
prompt Wave_SD_Scat, "Wave of Relative Uncertainty in Scattering Coefficients", popup, WaveList("*",";","")
prompt Wave_SD_abs, "Wave of Relative Uncertainty in Absorption Coefficients", popup, WaveList("*",";","")
prompt wavelength, "Wavelength of Optical Measurements (nm)"
doprompt "Uncertainties" SD_Dia,SD_N,wave_SD_Scat,wave_SD_Abs, wavelength
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
duplicate /o $WAVE_SD_SCAT, mult_SD_scat
duplicate /o $WAVE_SD_abs, mult_SD_abs
endif
// prompts for conditions of the analysis and output confidence interval size
prompt iter_start, "Number of iterations to perform during spin up."
prompt spin_up_matrix, "i x j value during spin up."
prompt iter_final, "Number of interations to perform when calcuating final solution."
prompt matrix_final, "i x j value when calcuating the final solution."
Prompt calc_type, "RI Calcuation Type, 0=difference based (Frie et al. 2019); 1=\"chi squared based\" (Dingle et al. 2019)."
prompt CL, "Width of the output confidence interval (between 0 and 100)."
doprompt "RICE Operational and Output Settings",iter_start, spin_up_matrix, iter_final, Matrix_final, CL, calc_type
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
CL/=100
//prompts for the name of, and creates, the output folder
killstrings /z T_name
variable run_type
string T_name="output_name"
prompt Run_type, "Do you want to keep all run files(1) or only output files(0)? RICE outputs are much smaller if only output files are kept. "
prompt T_name, "Output folder name"
doprompt "Output", T_name, run_type
if(v_flag==1) //aborts on cancel
print "canceled by user"
abort
endif
killwaves/z Adaptive_output
newdatafolder /o :$T_name
setdatafolder :$T_name
make /n=(dimsize(RI_t_series,0)), space_n, space_k, k_Upper_Bound, k_Lower_Bound, n_Upper_Bound, n_Lower_Bound, count_,n_CI_width,k_CI_width
duplicate /o RI_t_series, n_series
duplicate /o k_t_series, k_series
duplicate /o size_t_series, Size_dist_series
///Establishes a wave to save the initial conditions so they can be repeated at each point with
variable matrix_max=spin_up_matrix, iq_tracker=-1, divider=1
killwaves /z settings1
make /n=(1,16) settings1
settings1[0][0]=SD_Dia
settings1[0][1]=SD_N
settings1[0][2]=SD_scat
settings1[0][3]=SD_Abs
settings1[0][4]=iter_start
settings1[0][5]=n_width
settings1[0][6]=k_width
settings1[0][7]=k_step
settings1[0][8]=n_step
settings1[0][11]=spin_up_cycles
settings1[0][12]=spin_up_repeat
settings1[0][13]=abs_limit
settings1[0][14]=scat_limit
settings1[0][15]=Matrix_max
variable start_=0
for (iq=0;iq<numpnts(RI_t_series);iq+=1) //performs the analysis for each point within the t_series
if (uncertainty_type==1)
SD_scat=mult_sd_scat[iq]
SD_abs=mult_sd_abs[iq]
endif
print "uncertainty conditions:", " SD Diameter=",SD_Dia," SD Number concentration=",SD_N," SD Scattering=",SD_scat," SD Absorption=",SD_Abs
adaptors=0
if (RI_t_series[iq]>0) // doesn't analyze nan or negative n values
saveexperiment
//checks to see if this is the frist point being analyzed, if it is, it saves the settings in the settings1 wave
if( start_==0)
start_=1
SD_Dia=settings1[0]
SD_N=settings1[1]
SD_scat=settings1[2]
SD_Abs=settings1[3]
iter=settings1[4]
n_width=settings1[5]
k_width=settings1[6]
k_step=settings1[7]
n_step=settings1[8]
spin_up_cycles=settings1[11]
spin_up_repeat=settings1[12]
abs_limit=settings1[13]
scat_limit=settings1[14]
Matrix_max=settings1[15]
endif
//creates a folder name for the given point and places all outputs in that folder
killstrings /z folder_name
string folder_name="point_"+num2str(iq)
newdatafolder /o $folder_name
killwaves/z settings_tracker2
setdatafolder $folder_name
make /o /n=1 final_run, matrix_max1
duplicate /o settings1, settings
//sets a base value for the n and k width to explore for probable true RI values
n_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*(RI_t_series[iq]-1)
k_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*k_t_series[iq]
//explores the edges and center of the base n and k widths to examine which diameters are important: removes diameters with <1% of the total absorption and scattering in any of the cases
duplicate /o dia_bins, size_profile
killwaves/z matrix_max1
for(qi=0;qi<numpnts(dia_bins);qi+=1)
size_profile[qi]=size_t_series[qi][iq]
endfor
bin_trim(Ri_t_series[iq],K_t_series[iq],n_width,k_width, dia_bins,size_profile,wavelength)
wave size_input, bin_input
// begins the iterative loop where RI values near the input retrieved RI value are tested for the ability to produce the observed value under the uncertainty conditions.
// First, the code "spins up" and establishes a likely complete sampling space using relatively quick settings then the code runs a final run with a goal of giving a confident and reproducible answer
for (adaptors=0;adaptors<1000;adaptors+=1)
iter=iter_start
start_time=datetime
if (adaptors==0)
matrix_max=spin_up_matrix
variable RI_points=matrix_max
else
variable k_mod
if(k_t_series[iq]/0.5<1)
k_mod=k_t_series[iq]/0.5
else
k_mod=1
endif
//After one run, it checks to see if the fit parameters are satisfied, if they are, the final RI sampling space has been selected. If not, the RI sampling area is adjusted
wave gauss_out, mid_point
if (RI_points<0.5*matrix_max)
if (iq_tracker==iq)
divider*=2
else
divider=1
endif
if(k_t_series[iq]>0)
print"less 50% of n and k bins are physically meaningful, trying a smaller starting sampling space"
n_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*(RI_t_series[iq]-1)/divider
k_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*k_t_series[iq]/divider
iq_tracker=iq
endif
elseif (gauss_out[mid_point[0]][1]==-999)
print"unable to fit n result with signmoid, changing sampling space"
n_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*(RI_t_series[iq]-1)/divider
k_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*k_t_series[iq]/divider
elseif (gauss_out[mid_point[0]][10]==-999)
print"unable to fit k result with signmoid, changing sampling space"
n_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*(RI_t_series[iq]-1)/divider
k_width=((SD_Dia+SD_N+SD_Scat+SD_abs)*2)*k_t_series[iq]/divider
endif
if (k_t_series[iq]==0)
idle_k=0
endif
if (gauss_out[mid_point[0]][26]<=1)
if (gauss_out[mid_point[0]][28]<=1)
if (idle_n<=0.65)
if (idle_k<=0.65)
good_count+=1
else
good_count=0
endif
else
good_count=0
endif
else
good_count=0
endif
else
good_count=0
endif
if (good_count==1)
duplicate /o dia_bins, size_profile
killwaves/z matrix_max1
for(qi=0;qi<numpnts(dia_bins);qi+=1)
size_profile[qi]=size_t_series[qi][iq]
endfor
iter=iter_final
adaptors=120000
good_count*=0
matrix_max=matrix_final
final_run=1
bin_trim(Ri_t_series[iq],K_t_series[iq],n_width,k_width, dia_bins,size_profile,wavelength)
wave size_input, bin_input
else
final_run=0
//expands n width based on the fit of the sigmoid of the previous run results. The max exansion is capped at 20% of the orginial value
n_width1=n_width
if (gauss_out[mid_point[0]][26]>1)
n_width = n_width+(n_width*(gauss_out[mid_point[0]][3]-gauss_out[mid_point[0]][1]-1)*0.1)
n_change=n_width-n_width1
If(0.3<n_change/n_width1)
n_width=1.2*n_width1
endif
//adds an additional n_step of width if there was data in the last n bin of the previous run
if (gauss_out[mid_point[0]][33]==1)
n_width+=n_step
endif
//if no width expansion was needed, the number of idle n bins are checked and the width is reduced if too many bins are unused
elseif (idle_n>(0.65))
if (idle_n>(0.75))
n_width*=0.8
gauss_out[mid_point[0]][29]=3
else
n_width*=0.9
endif
endif
//changes the width of k exploration if many k values seem to lie within a single probability bin
k_width1 = k_width
if (gauss_out[mid_point[0]][28]>1)
k_width = k_width+(k_width*(gauss_out[mid_point[0]][12]-gauss_out[mid_point[0]][10]-1)*0.1)
k_change=k_width-k_width1
If(0.3<k_change/k_width1)
k_width=1.2*k_width1
endif
if (k_t_series[iq]-k_width>0)
elseif (gauss_out[mid_point[0]][34]==1)
k_width+=k_step
endif
//if no width expansion was needed, the number of idle n bins are checked and the width is reduced if too many bins are unused
elseif (idle_k>(0.65))
if(idle_k>(0.75))
k_width*=0.8
gauss_out[mid_point[0]][30]=3
else
k_width*=0.9
gauss_out[mid_point[0]][30]=3
endif
endif
endif
endif
//recalculates n_step and k_step based on the updates to n or k width
n_step=(n_width/(trunc(sqrt(matrix_max)/2)))
k_step=(k_width/(trunc(sqrt(matrix_max)/2)))
//calcuates the parameters for creating a range of test RI values. Then creates the aformentioned range of test RI values.
k_end=k_t_series[iq]+k_width
k_start=k_t_series[iq]-k_width
n_end=RI_t_series[iq]+n_width
n_start=RI_t_series[iq]-n_width
make /o /n=1 matrix_max1
matrix_max1[0]=matrix_max
makeRIrange(k_start,k_end,k_step,n_start,n_end,n_step)
wave n_range, k_range
duplicate /o n_range, n_input, k_input
// Trims the input n and k values to those that are above 1 and 0, respectively
bin_counter=0
bin_counter2=-1
for(qi=0;qi<numpnts(n_range);qi+=1)
if (k_range[qi]>=0)
if (n_range[qi]>=1)
bin_counter=bin_counter2+1
bin_counter2=bin_counter
n_input[bin_counter]=n_range[qi]
k_input[bin_counter]=k_range[qi]
endif
endif
endfor
redimension /N=(bin_counter+1), n_input
redimension /N=(bin_counter+1), k_input
RI_points=numpnts(n_input)
if (numpnts(k_input)<RI_points)
RI_points=numpnts(k_input)
endif
// determines the location of the midpoint value in the RI range, (the location of the input retrieved RI)
killwaves /z mid_point
make /n=1, mid_point
n_in=RI_t_series[iq]
k_in=K_t_series[iq]
for(af=0;af<RI_points;af+=1)
if (abs(n_in-n_input[af])<n_step/10)
if ((abs(k_in-k_input[af])<k_step/10))
mid_point[0]=af
V_mid_point=af
endif
endif
endfor
// print "number of iterations=",iter,"n range=",RI_t_series[iq],"±", n_width,"k range=", k_t_series[iq],"±", k_width," n values every", n_step,"k values every", k_step
print "point",iq+1,"of", numpnts(RI_t_series)
//creates a settings wave which saves the uncertainty inputs and iteration levels for a run.
if (adaptors==0)
make/o /n=(1,16), settings
endif
settings[0][0]=SD_Dia
settings[0][1]=SD_N
settings[0][2]=SD_scat
settings[0][3]=SD_Abs
settings[0][4]=iter
settings[0][5]=n_width
settings[0][6]=k_width
settings[0][7]=k_step
settings[0][8]=n_step
settings[0][10]=(n_width/n_step)*2*(k_width/k_step)*2
settings[0][11]=spin_up_cycles
settings[0][12]=spin_up_repeat
settings[0][13]=abs_limit
settings[0][14]=scat_limit
settings[0][15]=Matrix_max
////runs code that estimates the probability of the discrete RI values test of having yielded the input retrieved RI.
wave n_range, k_range
RI_Interval (bin_input,k_input,N_input,Size_input,SD_Dia,SD_N,SD_Scat,SD_Abs,iter, wavelength,CL,calc_type)
wave gauss_out
wave n_axis, k_axis
//calculates the number of idle/empty n and k bins relative to the number of bins
idle_n=gauss_out[mid_point[0]][31]/(numpnts(n_axis))
idle_k=gauss_out[mid_point[0]][32]/(numpnts(k_axis))
//prints the idle value
print "idle n ", gauss_out[mid_point[0]][31]/(numpnts(n_axis))
print "idle k ", gauss_out[mid_point[0]][32]/(numpnts(k_axis))
//measures the length of a single loop through the width adjustment and RI_interval function
duration=datetime-start_time
settings[0][9]=duration
killwaves /z adaptive_output_all
Make /n=(1,46), Adaptive_output_all
//records output from RI_interval in the adaptive_output_all matrix for each RI_interval run
for (ad=0;ad<dimsize(gauss_out,1);ad+=1)
Adaptive_output_all[0][ad]=gauss_out[mid_point[0]][ad]
endfor
if (adaptors<1)
duplicate/o adaptive_output_all, output_tracker
endif
if (adaptors>0.1)
concatenate/o/NP=0 {output_tracker,adaptive_output_all}, adaptive_output_all2
duplicate /o adaptive_output_all2, output_tracker
endif
if (adaptors<1)
duplicate/o settings, settings_tracker
endif
if (adaptors>0)
concatenate/o/NP=0 {settings_tracker,settings}, settings_tracker2
duplicate /o settings_tracker2, settings_Tracker
endif
variable tq
endfor
setdatafolder ::
//creates an output wave including only the final solutions of RICE for each point in the input time series.
if (exists("adaptive_output")==0)
Make /o /n=(dimsize(RI_t_series,0),46), Adaptive_output
endif
for (tq=0;tq<dimsize(gauss_out,1);tq+=1)
Adaptive_output[iq][tq]=gauss_out[mid_point[0]][tq]
endfor
//creates simplified output wave and flag waves
if(Adaptive_output[iq][26]<=1.05)
space_n[iq]=0
elseif (Adaptive_output[iq][26]<=1.125)
space_n[iq]=1
elseif (Adaptive_output[iq][26]<=1.2)
space_n[iq]=2
elseif (Adaptive_output[iq][26]>1.2)
space_n[iq]=3
endif
if(Adaptive_output[iq][28]<=1.05)
space_k[iq]=0
elseif (Adaptive_output[iq][28]<=1.125)
space_k[iq]=1
elseif (Adaptive_output[iq][28]<=1.2)
space_k[iq]=2
elseif (Adaptive_output[iq][28]>1.2)
space_k[iq]=3
endif
if (Adaptive_output[iq][45]<=iter/2)
count_[iq]=1
else
count_[iq]=0
endif
k_lower_bound[iq]=Adaptive_output[iq][24]
k_upper_bound[iq]=Adaptive_output[iq][23]
n_lower_bound[iq]=Adaptive_output[iq][22]
n_upper_bound[iq]=Adaptive_output[iq][21]
n_CI_width[iq]=n_upper_bound[iq]-n_lower_bound[iq]
k_CI_width[iq]=k_upper_bound[iq]-k_lower_bound[iq]
if (run_type==0)
killdatafolder/Z $folder_name
endif
endif
endfor
killwaves /z RICE_Output
duplicate /o Adaptive_output, RICE_Output
killwaves /z Adaptive_output
setdatafolder ::
end
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//creates a confidence interval based on the sigmoidal fit of a probability distrubiton
Function Sigmoid2Interval(Sig_coef,step_width, CL)
wave Sig_coef
variable step_width,CL
variable base, Max_,center,Rate
Base=Sig_coef[0]
Max_=Sig_coef[1]
Center=Sig_coef[2]
Rate=Sig_coef[3]
variable i=0, position=0, top, bottom,cuml_prob,x,y
variable non_neg_base
if (base<0)
non_neg_base=0
else
non_neg_base=base
endif
i=0
for (i=0;cuml_prob<(1-((1-CL)/2));i+=1)
x=center+i*step_width
cuml_prob= (Base+(max_/(1+exp((center-x)/rate))))
top=x
if (i>100000)
cuml_prob=999
top=-999
endif
endfor
for (i=0;cuml_prob>((1-CL)/2);i+=1)
cuml_prob=0
x=0
x=center-i*step_width
cuml_prob=(Base+(max_/(1+exp((center-x)/rate))))
bottom=x
if (i>100000)
cuml_prob=-999
bottom=-999
endif
endfor
killwaves /z cI_out
make /n=(2) cI_out
if (bottom<0)
bottom=0
endif
cI_out[0]=top
cI_out[1]=bottom
end
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Used to update the result of a previous k RICE run using a new confidence interval
Function Output_updater_k(Adaptive_output,CL)
wave adaptive_output
variable CL
make /o /n=(dimsize(adaptive_output,0)) k_lower_bound_updated
make /o /n=(dimsize(adaptive_output,0)) k_upper_bound_updated
make /o /n=(dimsize(adaptive_output,0)) k_CI_width_updated
variable i=0
make/o /n=(4,1) w_coef_1
for (i=0;i<dimsize(adaptive_output,0);i+=1)
w_coef_1[0]=adaptive_output[i][41]
w_coef_1[1]=adaptive_output[i][42]
w_coef_1[2]=adaptive_output[i][43]
w_coef_1[3]=adaptive_output[i][44]
Sigmoid2Interval(w_coef_1,(w_coef_1[2]-0)/10000,CL)
wave cI_out
k_upper_bound_updated[i]=cI_out[0]
k_lower_bound_updated[i]=cI_out[1]
k_CI_width_updated[i]=cI_out[0]-cI_out[1]
endfor
killwaves w_coef_1
end
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Used to update the result of a previous n RICE run using a new confidence interval
Function Output_updater_n(Adaptive_output, CL)
wave adaptive_output
variable CL
make /o /n=(dimsize(adaptive_output,0)) n_lower_bound_updated
make /o /n=(dimsize(adaptive_output,0)) n_upper_bound_updated
make /o /n=(dimsize(adaptive_output,0)) n_CI_width_updated
variable i=0
make /o/n=(4,1) w_coef_1
for (i=0;i<dimsize(adaptive_output,0);i+=1)
w_coef_1[0]=adaptive_output[i][37]
w_coef_1[1]=adaptive_output[i][38]
w_coef_1[2]=adaptive_output[i][39]
w_coef_1[3]=adaptive_output[i][40]
Sigmoid2Interval(w_coef_1,(w_coef_1[2]-1)/10000,CL)
wave cI_out
n_upper_bound_updated[i]=cI_out[0]
n_lower_bound_updated[i]=cI_out[1]
n_CI_width_updated[i]=cI_out[0]-cI_out[1]
endfor
killwaves w_coef_1, cI_out
end
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//makeRIrange creates an n and k input waves
function makeRIrange(k_start,k_end,k_step,n_start,n_end,n_step)
variable k_start,k_end,k_step,n_start,n_end,n_step
variable n_points, k_points
if (exists ("matrix_max1")==1)
wave matrix_max1
n_points=(trunc(sqrt(matrix_max1[0])))+1
k_points=(trunc(sqrt(matrix_max1[0])))+1
IF (K_END>0)
k_points=abs((k_end-k_start)/(k_step))+1
ELSE
K_POINTS=1
ENDIF
else
n_points=abs((n_end-n_start)/(n_step))+2 //establishes the number of points needed for n and number needed of k
IF (K_END>0)
k_points=abs((k_end-k_start)/(k_step))+1
ELSE
K_POINTS=1
ENDIF
endif
variable Rin=0, n=0,R
variable repeat=0, length=0
killwaves /z k_range, n_range
make /o/n=(n_points), k_range //creates n and k output waves
make /o /n=(n_points), n_range
duplicate/o n_range, n_holder
duplicate/o k_range, k_holder
for (r=0;r<numpnts(n_holder);r+=1)
n_holder[r]=(n_step)*r+n_start
endfor
duplicate/o n_holder, n_range1
duplicate/o k_range, K_range1
K_range1=k_start
for (repeat=0;repeat<k_points;repeat+=1)
k_holder=(k_step)*repeat+k_start
if (repeat>0)
concatenate /o/NP {n_range1,n_holder}, N_range
concatenate /o/NP {k_range1,k_holder}, k_range
duplicate/o k_range, K_range1
duplicate/o n_range, n_range1
endif
endfor