Getting an error while solving fractional differential equation using Physics-informed Neural Network

3 ビュー (過去 30 日間)
When I run the code below, I get the error
Not enough input arguments.
Error in solve_caputo_fractional (line 28)
t_points = linspace(0, T, 100);
I'm not sure how to fix this error because I'm not familiar with the concept of "physics-informed neural network." Any help is greatly appreciated. Thank you very much.
% solve_caputo_fractional.m
function solve_caputo_fractional(alpha, T)
% Parameters
hidden_layers = 3;
neurons_per_layer = 50;
layers = [
featureInputLayer(1, 'Name', 'input')
];
for i = 1:hidden_layers
layers = [
layers
fullyConnectedLayer(neurons_per_layer, 'Name', ['fc_' num2str(i)])
reluLayer('Name', ['relu_' num2str(i)])
];
end
layers = [
layers
fullyConnectedLayer(1, 'Name', 'output')
];
% Create the neural network
net = layerGraph(layers);
% Define the loss function
t_points = linspace(0, T, 100);
u_predicted = predict(net, t_points');
loss_eqn_fn = @(t_val, u_val) ...
(1/gamma(1-alpha)) * trapz(t_points, (u_val - interp1(t_points, u_val, t_points - t_val)) ./ (t_points - t_val).^alpha) + u_val;
loss_function = @(u_predicted) sum(arrayfun(@(i) loss_eqn_fn(t_points(i), u_predicted(i))^2, 1:length(t_points)));
% Training the PINN
options = trainingOptions('adam', ...
'MaxIterations', 10000, ...
'MiniBatchSize', 32, ...
'GradientThreshold', 1, ...
'InitialLearnRate', 0.001, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.5, ...
'LearnRateDropPeriod', 1000, ...
'Verbose', true, ...
'Plots', 'training-progress');
[net, trainingInfo] = trainNetwork(net, t_points', ones(length(t_points), 1), options);
% Plot the Results
u_predicted = predict(net, t_points');
figure;
plot(t_points, u_predicted, 'b', 'LineWidth', 2);
xlabel('t');
ylabel('u(t)');
title('Predicted Solution');
grid on;
end

採用された回答

Walter Roberson
Walter Roberson 2023 年 8 月 22 日
You are attempting to run the function solve_caputo_fractional without passing in two parameters, the second of which is the end time.
Possibly you are attempting to run the code by pressing the green Run button in the editor. When you press the green Run button then the function would be executed without passing any parameters. When you have a named parameter like the T for the function, then MATLAB will never try to look in an outside context to see if it can find a variable by that name.
  4 件のコメント
Walter Roberson
Walter Roberson 2023 年 8 月 22 日
It is not clear to me why you are using predict() on the layer graph ? Shouldn't you be trainNetwork() in which the layer graph is one of the input and the net is the output, and then you would predict() against the net? Just like you do further down in the code?
In other words it looks to me as if you have an extra call
u_predicted = predict(net, t_points');
that is too early, before you have trained the network.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by