|
8 | 8 | from keras.models import Model |
9 | 9 |
|
10 | 10 | class DAE(DNN): |
11 | | - """Denoising AutoEncoder class""" |
| 11 | + """ |
| 12 | + This class implements the Denoising Auto-Encoder model. |
| 13 | +
|
| 14 | + Attributes |
| 15 | + ---------- |
| 16 | + __encLayersArgs : list |
| 17 | + List of arguments for the encoder layer. |
| 18 | + __hidLayersArgs : list |
| 19 | + List of arguments for the hidden layers. |
| 20 | + __decLayersArgs : list |
| 21 | + List of arguments for the decoder layers. |
| 22 | + __modelParams : dict |
| 23 | + Dictionary containing the parameters to be passed to the model for its compilation. |
| 24 | + |
| 25 | + Methods |
| 26 | + ------- |
| 27 | + setEncoderLayer(layersArgs: list) |
| 28 | + Set the encoder layer arguments for the DAE. |
| 29 | + getEncoderLayer() |
| 30 | + Get the encoder layer arguments for the DAE. |
| 31 | + setHiddenLayers(layersArgs: list) |
| 32 | + Set the hidden layer arguments for the DAE. |
| 33 | + getHiddenLayers() |
| 34 | + Get the hidden layer arguments for the DAE. |
| 35 | + setDecoderLayer(layersArgs: list) |
| 36 | + Set the decoder layer arguments for the DAE. |
| 37 | + getDecoderLayer() |
| 38 | + Get the decoder layer arguments for the DAE. |
| 39 | + setModelConfiguration(modelParams: dict) |
| 40 | + Set the parameters for the DAE model (used for its compilation). |
| 41 | + getModelConfiguration() |
| 42 | + Get the parameters of the DAE model (used for its compilation). |
| 43 | + build() |
| 44 | + Build the model. |
| 45 | + """ |
12 | 46 |
|
13 | | - # Constructor |
14 | 47 | def __init__(self, name: str, inputN: int=1) -> None: |
15 | 48 | super().__init__(name,inputN) |
16 | 49 | self.__encLayersArgs: list = [] |
17 | 50 | self.__hidLayersArgs: list = [] |
18 | 51 | self.__decLayersArgs: list = [] |
19 | 52 | self.__modelParams: dict=None |
20 | 53 |
|
21 | | - # Setter and getter for encoder Layer arguments |
22 | 54 | def setEncoderLayer(self, layersArgs: list) -> None: |
| 55 | + ''' |
| 56 | + This method is used to set the encoder layers of the DAE model. |
| 57 | +
|
| 58 | + Parameters |
| 59 | + ---------- |
| 60 | + layersArgs : list |
| 61 | + The arguments for the encoder layers. |
| 62 | + |
| 63 | + Returns |
| 64 | + ------- |
| 65 | + None |
| 66 | + ''' |
23 | 67 | self.__encLayersArgs = layersArgs |
24 | 68 | return |
25 | 69 |
|
26 | 70 | def getEncoderLayer(self) -> list: |
| 71 | + ''' |
| 72 | + This method is used to get the encoder layers of the DAE model. |
| 73 | +
|
| 74 | + Parameters |
| 75 | + ---------- |
| 76 | + None |
| 77 | +
|
| 78 | + Raises |
| 79 | + ------ |
| 80 | + ValueError: |
| 81 | + If the model has no encoder layers arguments set yet. |
| 82 | +
|
| 83 | + Returns |
| 84 | + ------- |
| 85 | + list : |
| 86 | + The list of encoder layers arguments. |
| 87 | + ''' |
27 | 88 | if self.__encLayersArgs is not []: |
28 | 89 | return self.__encLayersArgs |
29 | 90 | else: |
30 | | - print('[DF] Model has no layers arguments set yet.') |
31 | | - return |
| 91 | + raise ValueError('[DF] Model has no layers arguments set yet.') |
32 | 92 |
|
33 | | - # Setter and getter for hidden Layer arguments |
34 | 93 | def setHiddenLayers(self, layersArgs: list) -> None: |
| 94 | + ''' |
| 95 | + This method is used to set the hidden layers of the DAE model. |
| 96 | +
|
| 97 | + Parameters |
| 98 | + ---------- |
| 99 | + layersArgs : list |
| 100 | + The arguments for the hidden layers. |
| 101 | + |
| 102 | + Returns |
| 103 | + ------- |
| 104 | + None |
| 105 | + ''' |
35 | 106 | self.__hidLayersArgs = layersArgs |
36 | 107 | return |
37 | 108 |
|
38 | 109 | def getHiddenLayers(self) -> list: |
| 110 | + ''' |
| 111 | + This method is used to get the hidden layers of the DAE model. |
| 112 | +
|
| 113 | + Parameters |
| 114 | + ---------- |
| 115 | + None |
| 116 | +
|
| 117 | + Raises |
| 118 | + ------ |
| 119 | + ValueError: |
| 120 | + If the model has no hidden layers arguments set yet. |
| 121 | +
|
| 122 | + Returns |
| 123 | + ------- |
| 124 | + list : |
| 125 | + The list of hidden layers arguments. |
| 126 | + ''' |
39 | 127 | if self.__hidLayersArgs is not []: |
40 | 128 | return self.__hidLayersArgs |
41 | 129 | else: |
42 | | - print('[DF] Model has no layers arguments set yet.') |
43 | | - return |
| 130 | + raise ValueError('[DF] Model has no layers arguments set yet.') |
44 | 131 |
|
45 | | - # Setter and getter for decoder Layer arguments |
46 | 132 | def setDecoderLayer(self, layersArgs: list) -> None: |
| 133 | + ''' |
| 134 | + This method is used to set the decoder layers of the DAE model. |
| 135 | +
|
| 136 | + Parameters |
| 137 | + ---------- |
| 138 | + layersArgs : list |
| 139 | + The arguments for the decoder layers. |
| 140 | + |
| 141 | + Returns |
| 142 | + ------- |
| 143 | + None |
| 144 | + ''' |
47 | 145 | self.__decLayersArgs = layersArgs |
48 | 146 | return |
49 | 147 |
|
50 | 148 | def getDecoderLayer(self) -> list: |
| 149 | + ''' |
| 150 | + This method is used to get the decoder layers of the DAE model. |
| 151 | +
|
| 152 | + Parameters |
| 153 | + ---------- |
| 154 | + None |
| 155 | +
|
| 156 | + Raises |
| 157 | + ------ |
| 158 | + ValueError: |
| 159 | + If the model has no decoder layers arguments set yet. |
| 160 | +
|
| 161 | + Returns |
| 162 | + ------- |
| 163 | + list : |
| 164 | + The list of decoder layers arguments. |
| 165 | + ''' |
51 | 166 | if self.__decLayersArgs is not []: |
52 | 167 | return self.__decLayersArgs |
53 | 168 | else: |
54 | | - print('[DF] Model has no layers arguments set yet.') |
55 | | - return |
| 169 | + raise ValueError('[DF] Model has no layers arguments set yet.') |
56 | 170 |
|
57 | | - # Setter and getter for model configuration |
58 | 171 | def setModelConfiguration(self, **modelParams: dict) -> None: |
| 172 | + ''' |
| 173 | + This method is used to set the model configuration for the DAE model. |
| 174 | +
|
| 175 | + Parameters |
| 176 | + ---------- |
| 177 | + modelParams : dict |
| 178 | + The model parameters used in the training/fit phase. |
| 179 | + |
| 180 | + Returns |
| 181 | + ------- |
| 182 | + None |
| 183 | + ''' |
59 | 184 | self.__modelParams = modelParams |
60 | 185 | return |
61 | 186 |
|
62 | 187 | def getModelConfiguration(self) -> dict: |
| 188 | + ''' |
| 189 | + This method is used to get the model configuration for the DAE model. |
| 190 | +
|
| 191 | + Parameters |
| 192 | + ---------- |
| 193 | + None |
| 194 | +
|
| 195 | + Raises |
| 196 | + ------ |
| 197 | + ValueError: |
| 198 | + If the model has no configuration arguments set yet. |
| 199 | +
|
| 200 | + Returns |
| 201 | + ------- |
| 202 | + dict : |
| 203 | + The dictionary of the model parameters. |
| 204 | + ''' |
63 | 205 | if self.__modelParams is not None: |
64 | 206 | return self.__modelParams |
65 | 207 | else: |
66 | | - print('[DF] Model has no configuration arguments set yet.') |
67 | | - return |
| 208 | + raise ValueError('[DF] Model has no configuration arguments set yet.') |
68 | 209 |
|
69 | | - # Build model |
70 | 210 | def build(self) -> None: |
| 211 | + ''' |
| 212 | + This method is used to build the model for the DAE model. |
| 213 | +
|
| 214 | + Parameters |
| 215 | + ---------- |
| 216 | + None |
| 217 | +
|
| 218 | + Returns |
| 219 | + ------- |
| 220 | + None |
| 221 | + ''' |
71 | 222 | print("[DF] Building model...") |
72 | 223 |
|
73 | 224 | # Build encoder layer |
|
0 commit comments