diff options
author | Matt Argao <mcargao@email.wm.edu> | 2012-11-06 17:33:27 -0500 |
---|---|---|
committer | Matt Argao <mcargao@email.wm.edu> | 2012-11-06 17:33:27 -0500 |
commit | 9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e (patch) | |
tree | 420d433d2b43301d8d01f33c414bf3f08dcff498 | |
parent | 6a755b5f70bc4960e818de260b8b5d057295eb5f (diff) | |
download | mode_match-9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e.tar.gz mode_match-9967bdc8f5c9ab51ea69cacdf694a3ddc5fd233e.zip |
Assorted code cleanup, addition of mode_match.m
Refinement of fitness function
-rw-r--r-- | fitness.m | 30 | ||||
-rw-r--r-- | fitter_check.m | 78 | ||||
-rw-r--r-- | mode_match.m | 50 |
3 files changed, 80 insertions, 78 deletions
@@ -1,17 +1,21 @@ -function [Energy, Waist_backward, Waist_forward, Penalty] = fitness( q_0, q_final, x_final, optics_positions, optics_focal_length, lambda )
+function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_positions, optics_focal_length, lambda )
%FITNESS Summary of this function goes here
% Detailed explanation goes here
x0 = 0;
- x_forward=linspace(0,x_final,15);
- q_forward = gbeam_propagation(x_forward,q_0,x0,optics_placer(optics_positions, optics_focal_length));
- [Waist_forward, Radius_forward] = q2wr(q_forward, lambda);
-
- x_backward=(x_forward);
- q_backward = gbeam_propagation(x_backward,q_final,x_final,optics_placer(optics_positions, optics_focal_length));
- [Waist_backward, Radius_backward] = q2wr(q_backward, lambda);
-
- Energy = sum((Waist_backward - Waist_forward).^2)/(mean(Waist_backward))^2;
-
+ Np=20;
+ x=linspace(x0,x_final,Np);
+ q_f_trial_forward = gbeam_propagation(x,q_0,x0,optics_placer(optics_positions, optics_focal_length));
+ [Waist_trial_forward, Radius_trial_forward] = q2wr(q_f_trial_forward, lambda);
+ q_f_trial_backward = gbeam_propagation(x,q_final,x_final,optics_placer(optics_positions, optics_focal_length));
+ [Waist_trial_backward, Radius_trial_backward] = q2wr(q_f_trial_backward, lambda);
+
+ Energy = 0;
+ Penalty_waist_mismatch = sum(abs((Waist_trial_forward-Waist_trial_backward)./min(Waist_trial_forward, Waist_trial_backward)))/Np;
+ Penalty_waist_mismatch = 0*Penalty_waist_mismatch + 1e9*sum(abs((Waist_trial_forward-Waist_trial_backward)))/Np;
+ Penalty_radius_mismatch = sum(abs((Radius_trial_forward-Radius_trial_backward)./max(Radius_trial_forward, Radius_trial_backward)))/Np;
+
+ Energy = 0*Penalty_radius_mismatch + Penalty_waist_mismatch;
+
% penalty calculation
% do not put lenses too close to each other and end positions
lens_size=0.03;
@@ -44,8 +48,8 @@ function [Energy, Waist_backward, Waist_forward, Penalty] = fitness( q_0, q_fina d = cat(2, d_from_start, d_from_end);
coef = 1e-2;
-
- penalty_lenses_outside_optical_path = coef * sum(1 + tanh(10*d));
+ distance_scaling=100;
+ penalty_lenses_outside_optical_path = coef * sum(1 + tanh(distance_scaling*d));
Energy = Energy + penalty_lenses_outside_optical_path;
diff --git a/fitter_check.m b/fitter_check.m index 37ff237..20a7e9d 100644 --- a/fitter_check.m +++ b/fitter_check.m @@ -1,9 +1,6 @@ lens_set = [.075, .203, .05, .03]; lens_set = [.075,.203]; lens_permutations = pick(lens_set,3,'or'); -n_perms = size(lens_permutations,1); -n_shuffles=20; %number of random placements of lenses - % ########################################## % Sample Solution @@ -12,16 +9,6 @@ Ltot= 1.010675025828971 ; r0= 1.0E+100 ; w0= 2.563E-5 ; x0= 0 ; -% focal_length1 = .075; -% focal_length2 = .075; -% focal_length3 = .203; -% -% lns1.abcd=abcd_lens( focal_length1 ) ; -% lns1.x= 0.21358727296049 ; -% lns2.abcd=abcd_lens( focal_length2 ) ; -% lns2.x= 0.40361319425309 ; -% lns3.abcd=abcd_lens( focal_length3 ) ; -% lns3.x= 0.80361319425309 ; wf= 3.709E-5 ; rf= 1.0E+100 ; xf= Ltot; @@ -35,62 +22,13 @@ xf=Ltot; % figure(1) % w_final_handmade = solution_visualization(q0,x0, qf, xf, optics, lambda); % title('Hand made'); -%% ########################################## - - -%Initialize sample arrays - -N = n_perms * n_shuffles; -possible_lens_placement = zeros(N,3); -possible_lens_set = zeros(N,3); -possible_sample_energy = zeros(N,1); -initial_rand_lens_placement=zeros(N,3); - -lens_size = .03; % physical size of the lens - -for ip = 1:n_perms - f3=lens_permutations(ip,3); - x3=xf-f3; % last lense transfer collimated region to focused spot - for is = 1:n_shuffles - possible_lens_set((ip-1)*n_shuffles + is,:) = lens_permutations(ip,:); - - initial_rand_lens_placement_tmp = sort(lens_size+(x3-2*lens_size)*rand(1,2)); - initial_rand_lens_placement((ip-1)*n_shuffles + is,:) = [initial_rand_lens_placement_tmp, x3]; - end -end - -parfor i = 1:N - - fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda ); - [x_sol, energy]=fminsearch(fitness_simplified, initial_rand_lens_placement(i,:), optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200)); - - possible_lens_placement(i,:) =x_sol; - possible_sample_energy(i) = energy; - - %Visualize solution -% figure(2) -% solution_visualization(q0,x0, qf, xf, optics_placer(x_sol, lens_permutations(ip,:)), lambda); -% title('Testing Points'); -% drawnow; - -end - - - -%Sorting possible solution according to energy -[possible_sample_energy, index] = sort(possible_sample_energy); -possible_lens_placement = possible_lens_placement(index,:); -possible_lens_set = possible_lens_set(index,:); +% ########################################## -%Truncate other possible solutions to an accuracy of n decimal places -n=4; -possible_lens_placement_trunc = round(possible_lens_placement*10^n)./10^n; -[possible_lens_placement_uniq, index] = unique(possible_lens_placement_trunc,'rows','stable'); %Unique solutions only +[ possible_lens_placement, possible_lens_set, possible_sample_energy, n_possible_lens_placement, index ] = mode_match( q0, qf, Ltot, lambda, lens_permutations ); %Visualize five best solutions -n_possible_lens_placement = min(5,size(possible_lens_placement_uniq,1)); for n_graph = 1:n_possible_lens_placement - figure(n_graph+1) + figure(n_graph) w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(possible_lens_placement(index(n_graph),:), possible_lens_set(index(n_graph),:)), lambda); title('Other Solutions'); end @@ -98,3 +36,13 @@ end possible_lens_placement(index(1:n_graph),:) possible_lens_set(index(1:n_graph),:) possible_sample_energy(index(1:n_graph),:) + + +%Visualize fitness function for fixed f2 and f3 +lens_set = [.075, .075, .203]; +f2= 0.40361319425309 ; +f3= 0.80361319425309 ; + +fitness_simplified=@(x) fitness(q0, qf, Ltot, [x, f2, f3], lens_set, lambda ); +figure(6) +ezplot(fitness_simplified, [0,Ltot])
\ No newline at end of file diff --git a/mode_match.m b/mode_match.m new file mode 100644 index 0000000..596cff1 --- /dev/null +++ b/mode_match.m @@ -0,0 +1,50 @@ +function [ possible_lens_placement, possible_lens_set, possible_sample_energy, n_possible_lens_placement, index ] = mode_match( q0, qf, Ltot, lambda, lens_permutations ) +%MODE_MATCH Summary of this function goes here +% Detailed explanation goes here + +n_perms = size(lens_permutations,1); +n_shuffles=1; %number of random placements of lenses + +%Initialize sample arrays +N = n_perms * n_shuffles; +possible_lens_placement = zeros(N,3); +possible_lens_set = zeros(N,3); +possible_sample_energy = zeros(N,1); +initial_rand_lens_placement=zeros(N,3); + +lens_size = .03; % physical size of the lens + +for ip = 1:n_perms + f3=lens_permutations(ip,3); + x3=Ltot-f3; % last lense transfer collimated region to focused spot + for is = 1:n_shuffles + possible_lens_set((ip-1)*n_shuffles + is,:) = lens_permutations(ip,:); + + initial_rand_lens_placement_tmp = sort(lens_size+(x3-2*lens_size)*rand(1,2)); + initial_rand_lens_placement((ip-1)*n_shuffles + is,:) = [initial_rand_lens_placement_tmp, x3]; + end +end + +parfor i = 1:N + + fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda ); + [x_sol, energy]=fminsearch(fitness_simplified, initial_rand_lens_placement(i,:), optimset('TolX',1e-8,'TolFun',1e-8,'MaxFunEvals',1e8,'MaxIter',200)); + + possible_lens_placement(i,:) =x_sol; + possible_sample_energy(i) = energy; + +end + +%Sorting possible solution according to energy +[possible_sample_energy, index] = sort(possible_sample_energy); +possible_lens_placement = possible_lens_placement(index,:); +possible_lens_set = possible_lens_set(index,:); + +%Truncate other possible solutions to an accuracy of n decimal places +n=4; +possible_lens_placement_trunc = round(possible_lens_placement*10^n)./10^n; +[possible_lens_placement_uniq, index] = unique(possible_lens_placement_trunc,'rows','stable'); %Unique solutions only + +n_possible_lens_placement = min(5,size(possible_lens_placement_uniq,1)); + +end |