Clear Filters
Clear Filters

LSTM for Battery prediction

71 views (last 30 days)
hussein al-yasseri
hussein al-yasseri on 9 Jul 2024 at 4:44
Commented: Umar on 13 Jul 2024 at 14:56
Hello everyone,
I am currently working on estimating the lifespan of batteries using an LSTM network. The sequence length varies with each cycle. Unfortunately, the results have been very poor so far, as it seems the network is not reading the entire sequence of data correctly.
Below you will find the code for the neural network and a plot comparing the real data with the LSTM predictions.
I would greatly appreciate your support and advice!
Thank you in advance!
% Example data preparation
cycles = 167;
for i = 1:cycles
% Fill these with your actual data
voltageData{i} = normal(cha(i).data.Voltage_measured);
currentData{i} = normal(cha(i).data.Current_measured);
timeData{i} = normal(cha(i).data.Time);
temperatureData{i} = normal(cha(i).data.Temperature_measured);
%capacities(i) = ...; % Actual capacity value for the i-th cycle
end
for i = 1:cycles
X{i,:} = [voltageData{i}; currentData{i}; timeData{i}; temperatureData{i}];
end
Y=normal(capa)';
% Split data into training (70%), validation (15%), and test (15%) sets
TrainAmout = round(0.7 * cycles);
ValAmout = round(0.15 * cycles);
TestAmout = cycles - TrainAmout - ValAmout;
Index = randperm(cycles);
trainIndex = Index(1:TrainAmout);
valIndex = Index(TrainAmout+1:TrainAmout+ValAmout);
testIndex = Index(TrainAmout+ValAmout+1:end);
XTrain = X(trainIndex);
YTrain = Y(trainIndex);
XVal = X(valIndex);
YVal = Y(valIndex);
XTest = X(testIndex);
YTest = Y(testIndex);
inputSize = 4; % Four input features: voltage, current, time, temperature
numHiddenUnits = 50; % Number of hidden units in the LSTM layer
outputSize = 1; % Single output representing capacity
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits, 'OutputMode', 'last')
fullyConnectedLayer(outputSize)
regressionLayer];
% Set training options with validation data
options = trainingOptions('adam', ...
'MaxEpochs', 100, ...
'MiniBatchSize', 10, ...
'InitialLearnRate', 0.01, ...
'GradientThreshold', 1, ...
'ValidationData', {XVal, YVal}, ...
'ValidationFrequency', 30, ...
'Verbose', false, ...
'Plots', 'training-progress');
% Train the network
net = trainNetwork(XTrain, YTrain, layers, options);
  9 Comments
hussein al-yasseri
hussein al-yasseri on 13 Jul 2024 at 8:48
I try to do padding for the data with this code:
The data has diffrent sequence length, from 780 until 3900. maybe the gab is huge, i dont know
% Example data preparation
cycles = 167;
for i = 1:cycles
Dsize(i)=length(cha(i).data.Voltage_measured);
end
DimSize=max(Dsize);
for i = 1:cycles
voltageData{i} = [normal(cha(i).data.Voltage_measured) zeros(1,(DimSize-length(cha(i).data.Voltage_measured)))];
currentData{i} = [normal(cha(i).data.Current_measured) zeros(1,(DimSize-length(cha(i).data.Voltage_measured)))];
timeData{i} = [normal(cha(i).data.Time) zeros(1,(DimSize-length(cha(i).data.Voltage_measured)))];
temperatureData{i} = [normal(cha(i).data.Temperature_measured) zeros(1,(DimSize-length(cha(i).data.Voltage_measured)))];
end
Umar
Umar on 13 Jul 2024 at 14:56
Hi Hussein,
After analyzing your code, you are using 'length(cha(i).data.Voltage_measured)' instead of 'length(voltageData{i})' when calculating the padding for currentData, timeData, and temperatureData and this might lead to inconsistencies in padding based on voltage data length. My suggestion would be modifying the code to ensure consistency in padding across all data types by using 'DimSize-length(voltageData{i})' instead of 'DimSize-length(cha(i).data.Voltage_measured)'. Overall, your approach to padding data for different sequence lengths is valid.
Please let me know if you have any further questions.

Sign in to comment.

Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!