diff options
author | Matt Argao <mcargao@email.wm.edu> | 2012-10-23 15:40:28 -0400 |
---|---|---|
committer | Matt Argao <mcargao@email.wm.edu> | 2012-10-23 15:40:28 -0400 |
commit | 29f10e82fcff18e60bdb42cc824b2e18a40887bf (patch) | |
tree | 555904561cf28b736089bc088cd2a4311cb9125a /fitter_check.m | |
parent | 80b72a51a3f8f0e33bf79a20a4d5fbaca050d920 (diff) | |
download | mode_match-29f10e82fcff18e60bdb42cc824b2e18a40887bf.tar.gz mode_match-29f10e82fcff18e60bdb42cc824b2e18a40887bf.zip |
Improved optimization
Removes repeating optic sets
Stores possible solutions
Returns waist from fitness function
Solutions with same significant digits are truncated
Visualize possible solutions
Outputs solutions with a fitness threshold
Diffstat (limited to 'fitter_check.m')
-rw-r--r-- | fitter_check.m | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/fitter_check.m b/fitter_check.m index 53d3299..ff93c13 100644 --- a/fitter_check.m +++ b/fitter_check.m @@ -1,5 +1,6 @@ % ########################################## +% Sample Solution clear; lambda= 1.064E-6 ; Ltot= 1.010675025828971 ; @@ -31,38 +32,62 @@ w_final_handmade = solution_visualization(q0,x0, qf, xf, optics, lambda); title('Hand made'); % ########################################## + %Initialize sample arrays sample_energy = []; sample_x = []; +possible_soln = []; +possible_lens_pos = []; lens_size = .03; %Lens permutations lens_permutations = perms( [ focal_length1, focal_length2, focal_length3 ]); -n_perms = size(lens_permutations,1); n_shuffles=10; +%Check if permutation has duplicates +lens_permutations = unique(lens_permutations,'rows'); +n_perms = size(lens_permutations,1); + for i = 1:n_perms lenses_choice=lens_permutations(i,:) - + for iteration = 1:n_shuffles optics_x_rand = sort(lens_size+(xf-2*lens_size)*rand(1,3)); - fitness_simplified=@(x) fitness(q0, qf, Ltot, x, lenses_choice ); + fitness_simplified=@(x) fitness(q0, qf, Ltot, x, lenses_choice, lambda ); [x_sol, energy]=fminsearch(fitness_simplified, optics_x_rand, optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',2000)); sample_energy = [sample_energy; energy]; sample_x = [sample_x; x_sol]; + %Return final Waist of trial + q_f_trial = gbeam_propagation(Ltot,q0,x0,optics_placer(x_sol, lenses_choice)); + [waist, Radius] = q2wr(q_f_trial, lambda); + + %If it is a good solution, add to list of possible solutions + waist_desired = wf; + compare_waist = abs(waist - waist_desired); + tolerance = 1E-6; + + if compare_waist < tolerance + possible_soln = [possible_soln; x_sol]; + possible_lens_pos = [possible_lens_pos; lenses_choice]; + end + + %Visualize solution figure(2) solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lenses_choice), lambda); - drawnow; + title('Testing Points'); + drawnow; + end end -[energy_min, index_of_energy_min] = min(sample_energy(:)) +%Display solution with lowest energy +[energy_min, index_of_energy_min] = min(sample_energy(:)); x_sol = sample_x(index_of_energy_min,:); lenses_choice=lens_permutations(ceil(index_of_energy_min/n_shuffles),:); @@ -70,5 +95,24 @@ figure(2) w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lenses_choice), lambda); title('Optimized made'); + +%Truncate other possible solutions to an accuracy of n decimal places +n=4; +possible_soln = round(possible_soln*10^n)./10^n; +[possible_soln, index] = unique(possible_soln,'rows'); %Unique solutions only + +rounded_x_sol = round(x_sol*10^n)./10^n; +remove_index = find(ismember(possible_soln, rounded_x_sol,'rows'),1); +possible_soln(remove_index,:) = []; +index(remove_index,:) = []; + +%Visualize other solutions +n_possible_soln = size(possible_soln,1); +for n_graph = 1:n_possible_soln + figure(n_graph+2) + w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(possible_soln(n_graph,:), possible_lens_pos(index(n_graph),:)), lambda); + title('Other Solutions'); +end + w_final_handmade; x_sol |