LSTM for Battery prediction
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);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); 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); deep learning, neural networks MATLAB Answers — New Questions