diff options
author | Matt Argao <mcargao@email.wm.edu> | 2012-10-23 17:29:42 -0400 |
---|---|---|
committer | Matt Argao <mcargao@email.wm.edu> | 2012-10-23 17:29:42 -0400 |
commit | a9779a948076f7e1edf1ef7c5c0b4abbd9866ad3 (patch) | |
tree | 0d5ff24493b1131e2baf25030d9703ba58cb98bd /fitter_check.m | |
parent | a8c9a7bbeeb09dabc4196d76cf3c9004eb5f65a3 (diff) | |
download | mode_match-a9779a948076f7e1edf1ef7c5c0b4abbd9866ad3.tar.gz mode_match-a9779a948076f7e1edf1ef7c5c0b4abbd9866ad3.zip |
Output of unique solns updated
Diffstat (limited to 'fitter_check.m')
-rw-r--r-- | fitter_check.m | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/fitter_check.m b/fitter_check.m index ff93c13..706429a 100644 --- a/fitter_check.m +++ b/fitter_check.m @@ -38,11 +38,12 @@ sample_energy = []; sample_x = []; possible_soln = []; possible_lens_pos = []; +possible_sample_energy = []; lens_size = .03; %Lens permutations lens_permutations = perms( [ focal_length1, focal_length2, focal_length3 ]); -n_shuffles=10; +n_shuffles=20; %Check if permutation has duplicates lens_permutations = unique(lens_permutations,'rows'); @@ -57,7 +58,7 @@ for i = 1:n_perms optics_x_rand = sort(lens_size+(xf-2*lens_size)*rand(1,3)); 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)); + [x_sol, energy]=fminsearch(fitness_simplified, optics_x_rand, optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200)); sample_energy = [sample_energy; energy]; sample_x = [sample_x; x_sol]; @@ -74,6 +75,7 @@ for i = 1:n_perms if compare_waist < tolerance possible_soln = [possible_soln; x_sol]; possible_lens_pos = [possible_lens_pos; lenses_choice]; + possible_sample_energy = [possible_sample_energy; energy]; end %Visualize solution @@ -86,31 +88,23 @@ for i = 1:n_perms end -%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),:); -figure(2) -w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lenses_choice), lambda); -title('Optimized made'); +%Sorting possible solution according to energy +[possible_sample_energy, index] = sort(possible_sample_energy); +possible_soln = possible_soln(index,:); +possible_lens_pos = possible_lens_pos(index,:); %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 +possible_soln_trunc = round(possible_soln*10^n)./10^n; +[possible_soln_uniq, index] = unique(possible_soln_trunc,'rows','stable'); %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); +%Visualize five best solutions +n_possible_soln = min(5,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); + figure(n_graph+1) + w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(possible_soln(index(n_graph),:), possible_lens_pos(index(n_graph),:)), lambda); title('Other Solutions'); end |