%% Apply GRU Operation to Sequence Data
% Perform a GRU operation using 100 hidden units.
% Create the input sequence data as 32 observations with ten channels and a sequence length of 64.

numFeatures = 10;
numObservations = 32;
sequenceLength = 64;

X = randn(numFeatures,numObservations,sequenceLength);
dlX = dlarray(X,'CBT');

% Create the initial hidden state with 100 hidden units. Use the same initial hidden state for all observations.

numHiddenUnits = 100;
H0 = zeros(numHiddenUnits,1);

% Create the learnable parameters for the GRU operation.

weights = dlarray(randn(3*numHiddenUnits,numFeatures));
recurrentWeights = dlarray(randn(3*numHiddenUnits,numHiddenUnits));
bias = dlarray(randn(3*numHiddenUnits,1));

% Perform the GRU calculation.

[dlY,hiddenState] = gru(dlX,H0,weights,recurrentWeights,bias);

% View the size and dimension labels of dlY.

size(dlY)
dlY.dims

% View the size of hiddenState.

size(hiddenState)

% You can use the hidden state to keep track of the state of the GRU operation and input further sequential data.
% Copyright 2019 The MathWorks, Inc.