dllaplacian - Laplacian of deep learning data - MATLAB (original) (raw)
Laplacian of deep learning data
Since R2024b
Syntax
Description
The Laplacian deep learning operation returns the Laplacian of neural network and model function outputs with respect to the specified input data and operation dimension.
[lap](#mw%5F9d1fa64f-291e-4415-9661-07852f8bc8d3) = dllaplacian([u](#mw%5Fb663e1b2-6817-4b57-9be0-85c2657bcff7),[x](#mw%5Fa79518cf-608f-49ff-a55b-6624cc394c16),[dim](#mw%5F3c56040f-c849-49c5-9685-44783bde60bb%5Fsep%5Fmw%5F0b104bed-154d-4196-9863-3f92d131e34b))
returns the Laplacian of the neural network or model function output u
with respect to the input data x
and operation dimensiondim
.
[lap](#mw%5F9d1fa64f-291e-4415-9661-07852f8bc8d3) = dllaplacian([u](#mw%5Fb663e1b2-6817-4b57-9be0-85c2657bcff7),[x](#mw%5Fa79518cf-608f-49ff-a55b-6624cc394c16),[dim](#mw%5F3c56040f-c849-49c5-9685-44783bde60bb%5Fsep%5Fmw%5F0b104bed-154d-4196-9863-3f92d131e34b),EnableHigherDerivatives=[tf](#mw%5F3c56040f-c849-49c5-9685-44783bde60bb%5Fsep%5Fmw%5F2cd7ab1d-ffc3-4f5f-863c-a43eacad66c3))
also specifies whether to enable higher-order derivatives by tracing the backward pass.
Examples
Create a neural network.
numInputChannels = 3; numOutputChannels = 1;
layers = [ featureInputLayer(numInputChannels) fullyConnectedLayer(numOutputChannels) tanhLayer];
net = dlnetwork(layers);
Load the training data. For the purposes of this example, generate some random data.
numObservations = 128;
X = rand(numInputChannels,numObservations); X = dlarray(X,"CB");
T = rand(numOutputChannels,numObservations); T = dlarray(T,"CB");
Define a model loss function that takes the network and data as input and returns the loss, gradients of the loss with respect to the learnable parameters, and the Laplacian of the predictions with respect to the input data.
function [loss,gradients,lap] = modelLoss(net,X,T)
Y = forward(net,X); loss = l1loss(Y,T);
X = stripdims(X); Y = stripdims(Y);
lap = dllaplacian(Y,X,1); gradients = dlgradient(loss,net.Learnables);
end
Evaluate the model loss function using the dlfeval
function.
[loss,gradients,lap] = dlfeval(@modelLoss,net,X,T);
View the size of the Laplacian.
Input Arguments
Neural network or model function output, specified as a traceddlarray
vector.
When evaluating a function with automatic differentiation enabled, the software traces the input dlarray
objects. Contexts in which the software tracesdlarray
include:
- Inside loss functions that the
trainnet
function evaluates - Inside forward functions that custom layers evaluate
- Inside model and model loss functions that the
dlfeval
function evaluates
The sizes of the dimensions not specified by the dim argument must match.
Input data, specified as a traced dlarray
matrix.
When evaluating a function with automatic differentiation enabled, the software traces the input dlarray
objects. Contexts in which the software tracesdlarray
include:
- Inside loss functions that the
trainnet
function evaluates - Inside forward functions that custom layers evaluate
- Inside model and model loss functions that the
dlfeval
function evaluates
The sizes of the dimensions not specified by the dim argument must match.
Operation dimension of u, specified as a positive integer.
The dllaplacian
function treats the remaining dimensions of the data as independent batch dimensions.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Flag to enable higher-order derivatives, specified as one of these values:
- Numeric or logical
1
(true
) — Enable higher-order derivatives. Trace the backward pass so that the returned values can be used in further computations for subsequent calls to functions that compute derivatives using automatic differentiation (for example,dlgradient
,dljacobian
,dldivergence
, anddllaplacian
). - Numeric or logical
0
(false
) — Disable higher-order derivatives. Do not trace the backward pass. When you want to compute only first-order derivatives, this option is usually quicker and requires less memory.
Output Arguments
Laplacian, returned as an unformatted 1-by-N dlarray
object, where N is the size of the batch dimension of the data. The value of lap(n)
is Δun=∑i=1K∂2un∂x(i,n)2, where i indexes into the operation dimensions and_n_ indexes into the batch dimension.
Version History
Introduced in R2024b