Skip to content

Commit

Permalink
A simple MLP naural network for wet-dry classification:
Browse files Browse the repository at this point in the history
Update: The MLP was retrained using more CMLs and a larger validation dataset.

Wet dry example.ipynb:
- re run notebook with retrained weights

mlp.py:
- updated docstring to match retrained architecture

model_mlp.keras:
- updated weights and architecture

test_wet_dry_mlp:
- updated to run with new weights
  • Loading branch information
eoydvin committed Jan 2, 2024
1 parent 560e069 commit a2dee2f
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 65 deletions.
162 changes: 118 additions & 44 deletions notebooks/Wet dry example.ipynb

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pycomlink/processing/wet_dry/mlp.py
Expand Up @@ -2,6 +2,7 @@
from numpy.lib.stride_tricks import sliding_window_view
import tensorflow as tf
import pkg_resources
import pandas as pd

def get_model_file_path():
return pkg_resources.resource_filename(
Expand All @@ -21,9 +22,9 @@ def mlp_wet_dry(
This MLP calculates wet and dry periods using a 40 minutes rolling window
for the CML signal loss from two sublinks (trsl_channel_1 and
trsl_channel_2) with temporal resolution equal to 1 minute. It consists of
two fully connected hidden layers with 13 and 5 neurons using the relu
one fully connected hidden layers with 20 neurons using the relu
activation function. The MLP was trained to predict rainfall recorded
at narby disdrometers at 10 minute resolution for one month of data with 6
at narby disdrometers at 10 minute resolution for one month of data with 14
pairs of CMLs and disdrometers from different locations in Norway. The MLP
was trained using MLPClassifier from sklearn and then transformed
to tensorflow to be compatible with the pycomlink environment.
Expand Down Expand Up @@ -58,7 +59,7 @@ def mlp_wet_dry(
"""
# Normalization
trsl_channel_1_norm = (trsl_channel_1 - np.nanmean(trsl_channel_1)) / np.nanstd(trsl_channel_1)
trsl_channel_1_norm = (trsl_channel_1 - np.nanmean(trsl_channel_1)) / np.nanstd(trsl_channel_1)
trsl_channel_2_norm = (trsl_channel_2 - np.nanmean(trsl_channel_2)) / np.nanstd(trsl_channel_2)

# add nan to start and end
Expand Down
Binary file modified pycomlink/processing/wet_dry/mlp_model_files/model_mlp.keras
Binary file not shown.
35 changes: 17 additions & 18 deletions pycomlink/tests/test_wet_dry_mlp.py
Expand Up @@ -23,27 +23,27 @@ def test_mlppred(self):
pred = mlp_wet_dry(
trsl_channel_1,
trsl_channel_2,
threshold=0.1, # low threshold for testing
threshold=0.197, # low threshold for testing
)

# check if length of array is the same
assert len(pred_raw) == 60 * 8
assert len(pred) == 60 * 8

# check if array is as expected
truth_raw = np.array(
[
0.08784304,
0.08941595,
0.09101421,
0.09263814,
0.09428804,
0.09596423,
0.09766698,
0.09939668,
0.10115347,
0.10293788,
0.10475004,
0.19271295,
0.19395444,
0.19520202,
0.19645563,
0.19771534,
0.19898114,
0.20025298,
0.20153098,
0.20281503,
0.20410511,
0.20540135,
np.nan,
np.nan,
]
Expand All @@ -54,17 +54,16 @@ def test_mlppred(self):
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
1,
np.nan,
np.nan,
]
)

np.testing.assert_almost_equal(pred[280:293], truth)
np.testing.assert_almost_equal(pred_raw[280:293], truth_raw, decimal=7)

0 comments on commit a2dee2f

Please sign in to comment.