Skip to content

Commit 1eddb5a

Browse files
committed
Add new example: Estimate BSOC using Monotonic Networks
1 parent a4e4255 commit 1eddb5a

15 files changed

+578
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ remaining useful life (RUL) tasks by combining partially and fully monotonic
113113
networks. This example looks at predicting the RUL for turbofan engine
114114
degradation.
115115

116+
- [Battery State of Charge Estimation Using Monotonic Neural Networks](examples/monotonic/BSOCEstimateUsingMonotonicNetworks/BatteryStateOfChargeEstimationUsingMonotonicNeuralNetworks.md)
117+
This example shows how to train two monotonic neural networks to estimate the state of charge (SOC) of a battery, one to model the charging behavior, and one to model the discharging behavior. In this example, you train the networks to predict the rate of change of the state of charge and force the output to be positive or negative for the charging and discharging networks, respectively. This way, you enforce monotonicity of the battery state of charge by constraining its derivative to be positive or negative.
118+
116119
- [Train Image Classification Lipschitz Constrained Networks and Measure
117120
Robustness to Adversarial
118121
Examples](examples/lipschitz/classificationDigits/LipschitzClassificationNetworksRobustToAdversarialExamples.md)
@@ -125,17 +128,12 @@ more robust classification network.
125128

126129
## Functions
127130

128-
This repository introduces the following functions that are used throughout the
129-
examples:
130-
131-
- [`buildConstrainedNetwork`](conslearn/buildConstrainedNetwork.m) - Build a multi-layer perceptron (MLP) with constraints on the architecture and initialization of the weights.
132-
- [`buildConvexCNN`](conslearn/buildConvexCNN.m) - Build a fully-inpt convex convolutional neural network (CNN).
133-
- [`trainConstrainedNetwork`](conslearn/trainConstrainedNetwork.m) - Train a
134-
constrained network and maintain the constraint during training.
135-
- [`lipschitzUpperBound`](conslearn/lipschitzUpperBound.m) - Compute an upper
136-
bound on the Lipschitz constant for a Lipschitz neural network.
137-
- [`convexNetworkOutputBounds`](conslearn/convexNetworkOutputBounds.m) - Compute
138-
guaranteed upper and lower bounds on hypercubic grids for convex networks.
131+
This repository introduces the following functions that are used throughout the examples:
132+
- [`buildConstrainedNetwork`](conslearn/buildConstrainedNetwork.m) - Build a multi-layer perceptron (MLP) with specific constraints on the architecture and initialization of the weights.
133+
- [`buildConvexCNN`](conslearn/buildConvexCNN.m) - Build a convolutional neural network (CNN) with convex constraints on the architecture and initialization of the weights.
134+
- [`trainConstrainedNetwork`](conslearn/trainConstrainedNetwork.m) - Train a constrained network and maintain the constraint during training.
135+
- [`lipschitzUpperBound`](conslearn/lipschitzUpperBound.m) - Compute an upper bound on the Lipschitz constant for a Lipschitz neural network.
136+
- [`convexNetworkOutputBounds`](conslearn/convexNetworkOutputBounds.m) - Compute guaranteed upper and lower bounds on hypercubic grids for convex networks.
139137

140138
## Tests
141139

examples/monotonic/BSOCEstimateUsingMonotonicNetworks/BatteryStateOfChargeEstimationUsingMonotonicNeuralNetworks.md

Lines changed: 529 additions & 0 deletions
Large diffs are not rendered by default.
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function [chargingNet,dischargingNet,chargingDiffNet,dischargingDiffNet] = trainUnconstrainedNetworks(XTrainCharging,YTrainCharging,XTrainDischarging,YTrainDischarging,XTrainChargingDifference,YTrainChargingDifference,XTrainDischargingDifference,YTrainDischargingDifference, chargingOptions, dischargingOptions)
2+
3+
% Don't plot training progress
4+
5+
chargingOptions.Plots = "none";
6+
dischargingOptions.Plots = "none";
7+
8+
% Train unconstrained RNN
9+
10+
numFeatures = size(XTrainCharging{1},2);
11+
numHiddenUnits = 32;
12+
numResponses = size(YTrainCharging{1},2);
13+
14+
layers = [sequenceInputLayer(numFeatures,"Normalization","rescale-zero-one")
15+
lstmLayer(numHiddenUnits)
16+
dropoutLayer(0.2)
17+
lstmLayer(numHiddenUnits/2)
18+
dropoutLayer(0.2)
19+
fullyConnectedLayer(numResponses)
20+
sigmoidLayer];
21+
22+
23+
chargingNet = trainnet(XTrainCharging,YTrainCharging,layers,"mse",chargingOptions);
24+
25+
dischargingNet = trainnet(XTrainDischarging,YTrainDischarging,layers,"mse",dischargingOptions);
26+
27+
% Train network on differences
28+
29+
layersDiff = [sequenceInputLayer(numFeatures,"Normalization","rescale-zero-one")
30+
lstmLayer(numHiddenUnits)
31+
dropoutLayer(0.2)
32+
lstmLayer(numHiddenUnits/2)
33+
dropoutLayer(0.2)
34+
fullyConnectedLayer(numResponses)];
35+
36+
chargingDiffNet = trainnet(XTrainChargingDifference,YTrainChargingDifference,layersDiff,"mse",chargingOptions);
37+
38+
dischargingDiffNet = trainnet(XTrainDischargingDifference,YTrainDischargingDifference,layersDiff,"mse",dischargingOptions);
39+
40+
end

0 commit comments

Comments
 (0)