diff options
author | Matt Argao <mcargao@email.wm.edu> | 2012-10-18 16:23:40 -0400 |
---|---|---|
committer | Matt Argao <mcargao@email.wm.edu> | 2012-10-18 16:23:40 -0400 |
commit | 0564d364c58758dcf61ebe5cad14b47c474ee57c (patch) | |
tree | bf6a09bb93211824829b89d77274e223d401d571 | |
parent | 9773dd0f1a6f9941a9a3ec5308bd3845d77bcf52 (diff) | |
download | mode_match-0564d364c58758dcf61ebe5cad14b47c474ee57c.tar.gz mode_match-0564d364c58758dcf61ebe5cad14b47c474ee57c.zip |
First attempt at automatic optimization.
-rw-r--r-- | fitness.m | 21 | ||||
-rw-r--r-- | fitter_check.m | 64 | ||||
-rw-r--r-- | optics_placer.m | 1 | ||||
-rw-r--r-- | solution_visualization.m | 11 |
4 files changed, 83 insertions, 14 deletions
@@ -25,9 +25,9 @@ function Energy = fitness( q_0, q_final, x_final, optics_positions ) d=cat(2, d, d_from_start, d_from_end);
- coef = 1e-1;
-
- penalty=coef*sum( exp(-(d/lens_size).^2) );
+ coef = 1;
+
+ penalty=coef*sum( exp(-(d/(lens_size)).^12) );
Energy = Energy + penalty;
@@ -37,11 +37,22 @@ function Energy = fitness( q_0, q_final, x_final, optics_positions ) d = cat(2, d_from_start, d_from_end);
- coef = 1e-1;
+ coef = 1e-2;
- penalty = coef * sum(1 + tanh(d.^2));
+ penalty = coef * sum(1 + tanh(10*d));
Energy = Energy + penalty;
+ % make collimated region between 2nd and 3rd lens
+ %intialize intermediate points between lenses
+ intermediate_positions = linspace(optics_positions(2), optics_positions(3),10);
+ f_q_x = @(x) gbeam_propagation(x,q_0,x0,optics_placer(optics_positions));
+ q_intermediate = arrayfun(f_q_x,intermediate_positions);
+ lambda_over_waist_sq = (-imag(1./q_intermediate)); %with numerical factor
+
+
+ coef = 1e-2;
+ penalty = coef * sum(exp((std(lambda_over_waist_sq)/mean(lambda_over_waist_sq))));
+ Energy = Energy + penalty;
end
diff --git a/fitter_check.m b/fitter_check.m new file mode 100644 index 0000000..0639e10 --- /dev/null +++ b/fitter_check.m @@ -0,0 +1,64 @@ + +% ########################################## +clear; +lambda= 1.064E-6 ; +Ltot= 1.010675025828971 ; +r0= 1.0E+100 ; +w0= 2.563E-5 ; +x0= 0 ; +lns1.abcd=abcd_lens( 0.075 ) ; +lns1.x= 0.21358727296049 ; +lns2.abcd=abcd_lens( 0.075 ) ; +lns2.x= 0.40361319425309 ; +lns3.abcd=abcd_lens( 0.203 ) ; +lns3.x= 0.80361319425309 ; +wf= 3.709E-5 ; +rf= 1.0E+100 ; +xf= Ltot; + +q0=wr2q(w0,r0,lambda); +x0=0; +qf=wr2q(wf,rf,lambda); +xf=Ltot; + +optics={lns1,lns2,lns3}; +figure(1) +w_final_handmade = solution_visualization(q0,x0, qf, xf, optics, lambda); +% ########################################## + +%Initialize sample arrays +sample_energy = []; +sample_x = []; + +for iteration = 1:10 + optics_x_rand = sort(rand(1,3)); + + test_optics_x = optics_x_rand - min(optics_x_rand(:)); + test_optics_x(1) = []; %delete first element in array + + %Prevent random placements that are too close + while any(test_optics_x < .03) == 1 + optics_x_rand = sort(rand(1,3)); + test_optics_x = optics_x_rand - min(optics_x_rand(:)); + test_optics_x(1) = []; + end + + fitness_simplified=@(x) fitness(q0, qf, Ltot, x ); + [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]; + + iteration + +end + +energy_min = min(sample_energy(:)); +index_of_energy_min = find(sample_energy == energy_min); +x_sol = sample_x(index_of_energy_min,:); + +figure(2) +w_final_trial = solution_visualization(q0,x0, qf, xf, optics_placer(x_sol), lambda) + +w_final_handmade +x_sol diff --git a/optics_placer.m b/optics_placer.m index ec08ab2..2287e1b 100644 --- a/optics_placer.m +++ b/optics_placer.m @@ -12,4 +12,3 @@ function optics = optics_placer( x ) optics={lns1,lns2,lns3};
end
-
diff --git a/solution_visualization.m b/solution_visualization.m index b886722..e3c0b71 100644 --- a/solution_visualization.m +++ b/solution_visualization.m @@ -1,4 +1,4 @@ -function solution_visualization(q0,x0, qf, xf, optics, lambda) +function waste_at_the_end = solution_visualization(q0,x0, qf, xf, optics, lambda) @@ -20,13 +20,8 @@ plot ( ... x, -w_backward, '-.b') legend({'forward propagation', '', 'backward propagation', ''}) -fprintf('======= final check =============\n') -fprintf('following are desired values: \n') - -fprintf('======= after propagation ========\n') -fprintf('values below should match wf and rf: \n') [waste_at_the_end,radius_at_the_end] = q2wr(q_forward(end), lambda); -waste_at_the_end -radius_at_the_end +%waste_at_the_end +%radius_at_the_end |