U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough...

43
APPROVED FOR PUBLIC RELEASE APPROVED FOR PUBLIC RELEASE U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – ARMY RESEARCH LABORATORY 16/07/2020 ARL Spectral Fitting Application Overview Will Roberts Undergraduate Student (Rising Junior) State University of New York at Buffalo

Transcript of U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough...

Page 1: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND –ARMY RESEARCH LABORATORY

16/07/2020

ARL Spectral Fitting Application Overview

Will Roberts

Undergraduate Student (Rising Junior)

State University of New York at Buffalo

Page 2: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

2

1. Theory background– E0, Δ!v½, ℏω, S

2. Use walkthrough

3. App features

4. Optimization code walkthrough

PRESENTATION OVERVIEW

This application (written in MATLAB) provides a free, publicly-accessible, and fully transparent method for performing Franck-Condon Lineshape Analysis on spectral data.

Page 3: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

3

Franck-Condon BackgroundFranck-Condon Principle and Franck-Condon Lineshape Analysis

Page 4: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

4

• Electronic movements occur about a fixed nuclear coordinate

• Vertical transition

• Franck-Condon State

FRANCK-CONDON PRINCIPLE

gaussian.com New Chemistry with Gaussian 16 & GaussView 6. https://gaussian.com/g16new/(accessed July 17, 2020).

Page 5: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

5

FRANCK-CONDON LINESHAPE ANALYSIS

Murtaza, Z.; Graff, D. K.; Zipp, A. P.; Worl, L. A.; Jones, W. E., Jr.; Bates, W. D.; Meyer, T. J., Energy Transfer in the Inverted Region: Calculation of Relative Rate Constants by Emission Spectral Fitting. The Journal of Physical Chemistry 1994, 98 (41), 10504-10513.

• Parameters– E0 – Energy quantity, or 0-0

energy gap – Δ!v½ – Full width at half-maximum– ℏω – Quantum spacing– S – Electron-vibrational coupling

constant, or Huang-Rhys factor

E0

Δ!v½

ℏω

Page 6: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

6

FRANCK-CONDON LINESHAPE ANALYSIS (CONT’D)

Balzani, V.; Ceroni, P.; Juris, A., Photochemistry and Photophysics: Concepts, Research, Applications. Wiley: 2014; p 504.

• Parameters– E0, Δ!v½, ℏω, S

Page 7: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

7

• Single mode

– I(!v) = ∑v = 05 E0 − vℏω

E0

3Svv! × exp −4 ln 2

E − E0 + vℏω∆!v!,#/%

2

• Double mode

– I(!v) = ∑vM = 05 ∑vL = 0

5 $

%

E0 − vMℏωM − vLℏωLE0

3SvMvM!

SvLvL! × exp&

'

−4 ln 2

!v − E0 + vMℏωM + vLℏωL∆!v 1/2

2

• Parameters– E0 – Energy quantity, or 0-0 energy gap – Δ!v½ – Full width at half-maximum– ℏω – Quantum spacing– S – Electron-vibrational coupling constant, or Huang-Rhys factor

FRANCK-CONDON LINESHAPE ANALYSIS (CONT’D)

Page 8: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

8

ARL Spectral Fitting App WalkthroughImporting data, by-hand fitting, optimizing fit, and exporting data

Page 9: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

9

9,10-DIPHENYLANTHRACENE

9,10-diphenylanthracene(77 K, Toluene)

Page 10: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

10

WALKTHROUGH: IMPORT

Page 11: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

11

WALKTHROUGH: DATA LOADING

Page 12: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

12

WALKTHROUGH: FITTING

Page 13: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

13

WALKTHROUGH: OPTIMIZATION

Page 14: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

14

WALKTHROUGH: CALCULATIONS

Page 15: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

15

WALKTHROUGH: EXPORT

Page 16: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

16

ARL SPECTRAL FITTING EXPORTED DATA

9,10-diphenylanthracene (77K) ParametersE₀₀ (cm-1) 24762 Energy quantity, or 0-0 energy gapΔv1/2 (cm-1) 760 Full width at half-maximumhw1 (cm-1) 1384 Quantum spacing (1)S1 1.11 Electron-vibrational coupling constant, or Huang-Rhys factor (1)hw2 (cm-1) 681 Quantum spacing (2)S2 0.31 Electron-vibrational coupling constant, or Huang-Rhys factor (2)ΔG(ES) (eV) 3.19 Free energy content of the excited stateCIE Coordinate [0.15819, 0.03349] CIE Chromaticity Coordinate

Page 17: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

17

ARL SPECTRAL FITTING EXPORTED DATA

0

0.2

0.4

0.6

0.8

1

1.2

15000170001900021000230002500027000

Inte

nsity

Wavenumber (cm⁻¹)

9,10-diphenylanthracene (77K) Fit

0

0.2

0.4

0.6

0.8

1

1.2

350 400 450 500 550 600

Inte

nsity

Wavelength (nm)

9,10-diphenylanthracene (77K) (Wavelength)

0

0.2

0.4

0.6

0.8

1

1.2

15000170001900021000230002500027000

Inte

nsity

Wavenumber (cm⁻¹)

9,10-diphenylanthracene (77K) (Wavenumber)

Page 18: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

18

ARL SPECTRAL FITTING EXPORTED DATA

1.61.822.22.42.62.8104

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Re

lative

Inte

nsity

452 nm

427 nm 404 nm

400 450 500 550 600Wavelength (nm)

9,10-diphenylanthracene (77K) Fit

Page 19: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

19

ARL Spectral Fitting App FeaturesData import, fitting, and export

Page 20: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

20

FEATURE LIST

Easy import

Export anything

Pop-out

Seamlessly switch

Simple controlsSample data

Optimize in seconds

Painless calculations

Automatically normalized

Select a peak

Adjustable axes

Advanced statistics

Publishable figures

Customize your fit

Compute E0

Fix parameters

Page 21: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

21

Optimization Code WalkthroughSingle and Double Functions, Optimization function

Page 22: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

22

SINGLE AND DOUBLE FUNCTIONS

NEW

function I = singlelineshape(x, E, hw, S, v05)I = 0;for n=0:5

I = I + (((E - n .* hw) ./ E) .^ 3) .* ...((S .^ n) ./ factorial(n)) .* exp(-4 ....* log(2) .* ((x - E + n .* hw) ./ v05) .^2);

endend

OLD

function I = singlelineshape(x, E, hw, S, v05)syms nI = symsum(I + (((E - n .* hw) ./ E) .^ 3) .* ...

((S .^ n) ./ factorial(n)) .* exp(-4 ....* log(2) .* ((x - E + n .* hw) ./ v05) .^2), n, 0, 5);

end

Problem: Optimization took upwards of 10 minutes to 1 hour to run.

Solution:

Page 23: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

23

1. Set coefficients, lb, ub based on single/double mode2. Override them if the user constrained some parameters to be fixed3. Reweight data points4. Do the fit5. Assign newly optimized parameter values6. Plot the results (fit and GoF stats)

OPTIMIZATION CODE OUTLINE

123456

Optimization

Page 24: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

24

1, 2: INITIALIZE VARIABLES, APPLY CONSTRAINTS

lb = [0, 0, 0, 0];ub = [40000, 4000, 3, 5000];

Problem: Nonsensical/irrelevant values were returned by optimization.

Solution:

problem = app.fixed;probval = cell(1,length(problem));for i=1:length(problem)

probvar = problem{i};if isequal(probvar, 'E’)

probval{i} = app.E_value;lb(b==app.E_value) = [];ub(b==app.E_value) = [];b(b==app.E_value) = [];coefficients(ismember(coefficients,'E')) = [];

% [...]

Problem: Only one parameter can be fixed at a time.

Solution:

Page 25: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

25

3: REASSIGN WEIGHTS (IF SELECTED)

xdata = app.xToFit_number;ydata = app.yToFit_number;w = ones(length(ydata), 1);if app.useweights

multiplier = app.weightmultiplier;threshold = app.weightthreshold;for l=1:length(ydata)

if ydata(l)>thresholdw(l) = multiplier;

endend

end

Problem: Noise at the spectrum’s tails affected optimization too much.

Solution:

Page 26: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

26

4, 5: DO THE FIT AND REASSIGN VALUES

OLD

x = nlinfit(xdata, ydata, 'singlelineshape(x,E,hw,S,v05)’, b)

Problem: Optimization function cannot take both bounds and weights.

Solution:

NEW

% [Initialize differently for double case]modelfun = fittype('singlelineshape(x,E,hw,S,v05)’, ...

'coefficients', coefficients, 'problem', problem);

[mdl, gof] = fit(xdata, ydata, modelfun, 'StartPoint’, ...b, 'Weights', w, 'Lower', lb, 'Upper', ub, 'problem', ... probval, 'Display', 'iter', 'MaxIter', app.maxIter, ... 'TolFun', app.TolFun, 'TolX’, app.TolX, 'Robust’, app.robust);

Page 27: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

27

OPTIMIZATION IN THE COMMAND WINDOW

Page 28: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

28

• Conclusions– Collaborative efforts and processing of photophysical data could be enhanced

through use of this application.

• Future work– Production and publication of a technical report.– Publication of the code for this project to ARL GitHub.

CONCLUSIONS AND FUTURE WORK

Page 29: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

29

• Thanks to:– Dr. Ryan O’Donnell, Army Research Laboratory– Dr. Thomas (TJ) Rohrabaugh, Army Research Laboratory– Dr. Timothy Cook, State University of New York at Buffalo

• Research was sponsored by the Army Research Laboratory and was accomplished under Cooperative Agreement Number W911NF-20-2-0154. The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of the Army Research Laboratory or the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints for Government purposes notwithstanding any copyright notation herein.

ACKNOWLEDGMENTS

Page 30: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

30

Backup SlidesFeature list, formulae, biographical information, optimization code

Page 31: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

31

• We’ve removed obstacles to data import. Now, your data loads with half the job already done. – Import both excitation and emission spectra. Supported file types include txt, csv,

and Excel workbooks. x-axis settings (wavenumber or wavelength) are detected automatically.

– Intensity data is automatically normalized on import based on the highest peak. Once a file is loaded, you have the option to manually select a peak to serve as a basis for normalization.

– The application automatically calculates E0-0 and ℏω on import based on detected data peaks. Choose your preferred method with options for how to compute E0-0(automatic peak detection, excitation/emission intersection, 1/10% rule).

FEATURE LIST — IMPORT

Page 32: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

32

• Simple controls let you focus on what’s important.– Easily tune parameters by hand with the auto-plot functionality. Then, with a single

click, optimize the fit in seconds. Optimization utilizes a nonlinear least-squares fit method, powered by the Levenberg–Marquardt algorithm. Customize your fit with optimization settings and easily fix parameters during optimization.

– Seamlessly switch between single and double mode for the fit function, as well as wavelength and wavenumber for the x-axis.

– Calculations are just a click away. We’ll calculate free energy of the excited state from parameter values, and calculate and plot your data’s CIE coordinate on a chromaticity diagram.

FEATURE LIST — FITTING

Page 33: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

33

• Data export made easy.– Export the full figure already formatted for publication as a vector-graphics object,

jpeg, pdf, or png file. – Export parameters and calculated values as a text file, csv, or Excel workbook.– You can even export your processed data and fit as a text file, csv, or Excel

workbook.

• And so much more.– Pop out the figure for easier viewing, load pre-packaged sample data, display

goodness-of-fit statistics for optimized fits

FEATURE LIST — EXPORT

Page 34: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

34

• SM = ½(MωM/ħ)(ΔQe2)

– M = reduced mass– ω = angular frequency– ΔQe = equilibrium displacement between excited and ground states

HUANG-RHYS FACTOR CALCULATION

Page 35: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

35

• ∆GES = E0 + λ0,L = E0 +∆!v#/% 2

16kBT ln 2– ∆GES = Free energy of the excited state– E0 = energy quantity– Δ!v½ – Full width at half-maximum– kB = Boltzmann constant, in cm-1

– T = temperature, in K

FREE ENERGY OF THE EXCITED STATE

Page 36: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

36

• James Franck (1882-1964, Germany)– Report in Transaction of the Faraday Society (1926)– Basic principle applied only to photoreactions

• Edward Condon (1902-1974, America)– Article in Physical Review (1926)– Expanded on Franck’s idea, to include all emission/excitation processes

FRANCK AND CONDON BACKGROUND

Page 37: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

37

• Kenneth Levenberg (1916-1973, America)– Published algorithm in 1944, while working at Frankford Army Arsenal

• Donald Marquadt (1929-1997, America)– Rediscovered Levenberg’s algorithm in 1963, for use in fitting nonlinear chemical

models

• Damped least-squares (DLS)

• Uses a combination of Gauss-Newton algorithm (GNA) and gradient descent

• Finds local not necessarily global minima

LEVENBERG–MARQUARDT ALGORITHM

Page 38: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

38

• First proposed in 1965– John Nelder (1924-2010, Britain)– Roger Mead (1938-2015, England)

• Direct search method (derivative-free)

• Minimizes a function (in this case, an approximation cost function)

• Constructs a simplex with n+1 vertices in n dimensions (n = number of variables)

• Heuristic method used to find global minimum

NELDER-MEAD ALGORITHM

Wikipedia Community Nelder-Mead method. https://en.wikipedia.org/wiki/Nelder–Mead_method (accessed July 23, 2020).

Page 39: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

39

SINGLE AND DOUBLE FUNCTIONS

function I = singlelineshape(x, E, hw, S, v05)I = 0;for n=0:5

I = I + (((E - n .* hw) ./ E) .^ 3) .* ((S .^ n) ... ./ factorial(n)) .* exp(-4 .* log(2) .* ... ((x - E + n .* hw) ./ v05) .^2);

endend

function I = doublelineshape(x, E, hw, S, v05, hw2, S2)I = 0;for two=0:5

for one=0:5I = I + (((E - one .* hw - two .* hw2) ./ E) ...

.^ 4) .* ((S .^ one) ./ factorial(one)) ...

.* ((S2 .^ two) ./ factorial(two)) .* ...exp(-4 .* log(2) .* ((x - E + one .* ...hw + two .* hw2) ./ v05) .^2);

endend

end

Page 40: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

40

1, 2: INITIALIZE VARIABLES, APPLY CONSTRAINTS

function optimize(app)% [Initialize differently for double case]

b = [app.E_value, app.hw_value, app.S_value, app.v05_value];coefficients = {'E', 'hw', 'S', 'v05’};lb = [0, 0, 0, 0];ub = [40000, 4000, 3, 5000];

problem = app.fixed;probval = cell(1,length(problem));for i=1:length(problem)

probvar = problem{i};if isequal(probvar, 'E’)

probval{i} = app.E_value;lb(b==app.E_value) = [];ub(b==app.E_value) = [];b(b==app.E_value) = [];coefficients(ismember(coefficients,'E')) = [];

% [...]

Page 41: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

41

3: REASSIGN WEIGHTS (IF SELECTED)

xdata = app.xToFit_number;ydata = app.yToFit_number;w = ones(length(ydata), 1);if app.useweights

multiplier = app.weightmultiplier;threshold = app.weightthreshold;for l=1:length(ydata)

if ydata(l)>thresholdw(l) = multiplier;

endend

end

Page 42: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

42

4, 5: DO THE FIT AND REASSIGN VALUES

% [Initialize differently for double case]modelfun = fittype('singlelineshape(x,E,hw,S,v05)’, ...

'coefficients', coefficients, 'problem', problem);

[mdl, gof] = fit(xdata, ydata, modelfun, 'StartPoint’, ...b, 'Weights', w, 'Lower', lb, 'Upper', ub, ... 'problem', probval, 'Display', 'iter', 'MaxIter', ... app.maxIter, 'TolFun', app.TolFun, 'TolX', app.TolX, ... 'Robust', app.robust);

x = coeffvalues(mdl);places = coeffnames(mdl);

for l=1:length(places)ind = places{l};if isequal(ind, 'E’)

app.E_value = round(x(l));app.E_editField.Value = round(x(l));app.E_slider.Value = round(x(l));

% [...]

Page 43: U.S. ARMY COMBAT CAPABILITIES DEVELOPMENT COMMAND – … · 4.Optimization code walkthrough PRESENTATION OVERVIEW This application (written in MATLAB) provides a free, publicly-accessible,

APPROVED FOR PUBLIC RELEASE

APPROVED FOR PUBLIC RELEASE

43

6: PLOT THE RESULT

plotfit(app);drawnow;

ar2 = num2str(gof.adjrsquare, 4);sse = num2str(gof.sse, 4);dfe = num2str(gof.dfe, 4);rmse = num2str(gof.rmse, 4);app.GoFLabel.Text = ['adj. R² = ', ar2, newline, ...

' SSE = ', sse, newline, ' DFE = ', dfe, newline, ... ' RMSE = ', rmse];

if app.showgofapp.GoFLabel.Visible = 'on’;if app.ShowTips.Value

app.Whatsthis_GoFButton.Visible = 'on’;end

elseapp.GoFLabel.Visible = 'off’;app.Whatsthis_GoFButton.Visible = 'off’;

endend