Skip to content

Commit

Permalink
Check spellings and make unit_test work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lht97 committed Dec 22, 2024
1 parent 27f91e4 commit f15d740
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ twoside
twostep
ubuntu
ucmmp
uistack
Ulbrich
ulcorner
ulem
Expand Down
112 changes: 55 additions & 57 deletions src/bds.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
random_stream = RandStream("mt19937ar", "Seed", options.seed);

% Set the default value of noisy.
if ~ifield(options, "is_noisy")
if ~isfield(options, "is_noisy")
options.noisy = get_default_constant("is_noisy");
end

Expand Down Expand Up @@ -660,85 +660,83 @@
end
output.fhist = fhist(1:nf);

% Plot alpha_hist and decrease.
if output_alpha_hist

x = 1:size(output.alpha_hist, 2);
y = mean(output.alpha_hist, 1);
% Create a plot to record the history of step sizes.
figure;
plot(x, y, '-o');
xlabel('iteration number');
ylabel('average step size');
title('average step size');
grid on;
% % Plot alpha_hist and decrease.
% if output_alpha_hist

set(gca, 'YScale', 'log');
% x = 1:size(output.alpha_hist, 2);
% y = mean(output.alpha_hist, 1);
% % Create a plot to record the history of step sizes.
% figure;
% plot(x, y, '-o');
% xlabel('iteration number');
% ylabel('average step size');
% title('average step size');
% grid on;

ylim([1e-8, 1e4]);
% set(gca, 'YScale', 'log');

yticks(10.^(-8:4));
% ylim([1e-8, 1e4]);

filePath = mfilename('fullpath');
[scriptPath, ~, ~] = fileparts(filePath);
% yticks(10.^(-8:4));

print(fullfile(scriptPath, 'average_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS
% filePath = mfilename('fullpath');
% [scriptPath, ~, ~] = fileparts(filePath);

% Create a plot to record the maximum of the step sizes.
figure;
plot(x, max(output.alpha_hist, [], 1), '-o');
xlabel('iteration number');
ylabel('maximum step size');
title('maximum step size');
grid on;
% print(fullfile(scriptPath, 'average_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS

set(gca, 'YScale', 'log');
% % Create a plot to record the maximum of the step sizes.
% figure;
% plot(x, max(output.alpha_hist, [], 1), '-o');
% xlabel('iteration number');
% ylabel('maximum step size');
% title('maximum step size');
% grid on;

ylim([1e-8, 1e4]);
% set(gca, 'YScale', 'log');

yticks(10.^(-8:4));
% ylim([1e-8, 1e4]);

% Save as EPS format to the path where the current file is located
print(fullfile(scriptPath, 'maximum_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS
% yticks(10.^(-8:4));

% % Save as EPS format to the path where the current file is located
% print(fullfile(scriptPath, 'maximum_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS

% Create a plot to record the minimum of the step sizes.
figure;
plot(x, min(output.alpha_hist, [], 1), '-o');
xlabel('iteration number');
ylabel('minimum step size');
title('minimum step size');
grid on;

set(gca, 'YScale', 'log');
% % Create a plot to record the minimum of the step sizes.
% figure;
% plot(x, min(output.alpha_hist, [], 1), '-o');
% xlabel('iteration number');
% ylabel('minimum step size');
% title('minimum step size');
% grid on;

ylim([1e-8, 1e4]);
% set(gca, 'YScale', 'log');

yticks(10.^(-8:4));
% ylim([1e-8, 1e4]);

% Save as EPS format to the path where the current file is located
print(fullfile(scriptPath, 'minimum_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS
% yticks(10.^(-8:4));

% Create a plot to record sufficient_decrease.
figure;
plot(1:length(sufficient_decrease), sufficient_decrease, '-o');
xlabel('X Axis Label');
ylabel('sufficient decrease');
title('sufficient decrease');
grid on;
% % Save as EPS format to the path where the current file is located
% print(fullfile(scriptPath, 'minimum_step_size.eps'), '-depsc'); % Use the -depsc option to save as a color EPS

set(gca, 'YScale', 'log');
% % Create a plot to record sufficient_decrease.
% figure;
% plot(1:length(sufficient_decrease), sufficient_decrease, '-o');
% xlabel('X Axis Label');
% ylabel('sufficient decrease');
% title('sufficient decrease');
% grid on;

ylim([1e-16, 1e4]);
% set(gca, 'YScale', 'log');

yticks(10.^(-16:4));
% ylim([1e-16, 1e4]);

% Save as EPS format to the path where the current file is located
print(fullfile(scriptPath, 'sufficient_decrease.eps'), '-depsc'); % Use the -depsc option to save as a color EPS

end
% yticks(10.^(-16:4));

% % Save as EPS format to the path where the current file is located
% print(fullfile(scriptPath, 'sufficient_decrease.eps'), '-depsc'); % Use the -depsc option to save as a color EPS

% end

% Set the message according to exitflag.
switch exitflag
Expand Down
20 changes: 18 additions & 2 deletions src/unit_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,30 @@ function get_default_constant_test(testCase)
constant_value = "cbds";
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "expand";
constant_name = "expand_small";
constant_value = 2;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "shrink";
constant_name = "shrink_small";
constant_value = 0.5;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "expand_big";
constant_value = 2;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "shrink_big";
constant_value = 0.5;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "expand_big_noisy";
constant_value = 1.25;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

constant_name = "shrink_big_noisy";
constant_value = 0.85;
verifyEqual(testCase, get_default_constant(constant_name), constant_value)

assert(strcmp(func2str(get_default_constant("forcing_function")), func2str(@(alpha) alpha^2)));

constant_name = "reduction_factor";
Expand Down

0 comments on commit f15d740

Please sign in to comment.