The code indicates error with response Invalid value for OPTIONS parameter Algorithm

2 ビュー (過去 30 日間)
Mathew
Mathew 2025 年 6 月 11 日
回答済み: Walter Roberson 2025 年 6 月 11 日
% Physics-Informed Neural Network (PINN) for 1D Poisson Equation
clear; clc;
% Define training data
N_f = 100; % Collocation points for PDE
x_f = rand(N_f,1); % Collocation points in (0,1)
N_b = 2; % Boundary points
x_b = [0; 1]; % Dirichlet boundary
% Neural network architecture
layers = [1, 20, 20, 1]; % [input, hidden1, hidden2, output]
% Initialize weights and biases
params = initializeNN(layers);
% Train the PINN using fmincon
lossFunc = @(p) PINNLoss(p, x_f, x_b);
options = optimoptions('fmincon','MaxIterations',500,'Display','iter','Algorithm','quasi-newton');
Error using optimoptions (line 124)
Invalid value for OPTIONS parameter Algorithm:
must be 'interior-point', 'sqp', 'trust-region-reflective', 'active-set', or 'sqp-legacy'.
params_opt = fmincon(lossFunc, params, [], [], [], [], [], [], [], options);
% Predict using trained network
x_test = linspace(0,1,100)';
u_pred = neuralNet(x_test, params_opt, layers);
% Exact solution
u_exact = sin(pi*x_test);
% Plot
figure;
plot(x_test, u_pred, 'r--', 'LineWidth', 2); hold on;
plot(x_test, u_exact, 'b-', 'LineWidth', 2);
legend('PINN Prediction','Exact Solution');
xlabel('x'); ylabel('u(x)');
title('PINN vs Exact Solution');
grid on;
%% --- Helper Functions ---
function params = initializeNN(layers)
params = [];
for i = 1:length(layers)-1
W = randn(layers(i+1),layers(i));
b = randn(layers(i+1),1);
params = [params; W(:); b(:)];
end
end
function y = neuralNet(x, params, layers)
idx = 1;
a = x';
for i = 1:length(layers)-1
in = layers(i);
out = layers(i+1);
W = reshape(params(idx:idx+out*in-1), out, in);
idx = idx + out*in;
b = reshape(params(idx:idx+out-1), out, 1);
idx = idx + out;
a = W*a + b;
if i < length(layers)-1
a = tanh(a); % Activation
end
end
y = a';
end
function loss = PINNLoss(params, x_f, x_b)
layers = [1, 20, 20, 1];
% PDE loss at collocation points
u = @(x) neuralNet(x, params, layers);
du = @(x) gradient(u, x);
d2u = @(x) gradient(du, x);
f = @(x) pi^2 * sin(pi*x);
pde_loss = mean((d2u(x_f) + f(x_f)).^2);
% Boundary loss
u_b = u(x_b);
bc_loss = mean(u_b.^2);
loss = pde_loss + bc_loss;
end
function df = gradient(f, x)
h = 1e-4;
df = (f(x + h) - f(x - h)) / (2*h);
end
  1 件のコメント
Torsten
Torsten 2025 年 6 月 11 日
You are correct. As you can see, "quasi-newton" is not a valid algorithm for "fmincon":
options = optimoptions('fmincon')
options =
fmincon options: Options used by current Algorithm ('interior-point'): (Other available algorithms: 'active-set', 'sqp', 'sqp-legacy', 'trust-region-reflective') Set properties: No properties. Default properties: Algorithm: 'interior-point' BarrierParamUpdate: 'monotone' ConstraintTolerance: 1.0000e-06 Display: 'final' EnableFeasibilityMode: 0 FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' HessianApproximation: 'bfgs' HessianFcn: [] HessianMultiplyFcn: [] HonorBounds: 1 MaxFunctionEvaluations: 3000 MaxIterations: 1000 ObjectiveLimit: -1.0000e+20 OptimalityTolerance: 1.0000e-06 OutputFcn: [] PlotFcn: [] ScaleProblem: 0 SpecifyConstraintGradient: 0 SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-10 SubproblemAlgorithm: 'factorization' TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Options not used by current Algorithm ('interior-point') Default properties: FunctionTolerance: 1.0000e-06 UseCodegenSolver: 0

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 6 月 11 日
quasi-newton is a valid option for fminunc but not for fmincon

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by