Synthetic Data Loader
Bases: LightningDataModule
A class for a synthetic data loader that generates synthetic bindiing & perturbation effect data for training, validation, and testing a model This class contains all of the logic for generating and parsing the synthetic data, as well as splitting it into train, validation, and test sets It is a subclass of pytorch_lightning.LightningDataModule, which is similar to a regular PyTorch DataLoader but with added functionality for data loading.
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__init__(batch_size=32, num_genes=1000, bound=[0.1, 0.2, 0.2, 0.4, 0.5], bound_mean=3.0, n_sample=[1, 2, 2, 4, 4], val_size=0.1, test_size=0.1, random_state=42, max_mean_adjustment=0.0, adjustment_function=default_perturbation_effect_adjustment_function, tf_relationships={})
¶
Constructor of SyntheticDataLoader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size |
int
|
The number of samples in each mini-batch |
32
|
num_genes |
int
|
The number of genes in the synthetic data (this is the number of datapoints in our dataset) |
1000
|
bound |
list[float]
|
The proportion of genes in each sample group that are put in the bound grop (i.e. have a non-zero binding effect and expression response) |
[0.1, 0.2, 0.2, 0.4, 0.5]
|
n_sample |
list[int]
|
The number of samples to draw from each bound group |
[1, 2, 2, 4, 4]
|
val_size |
float
|
The proportion of the dataset to include in the validation split |
0.1
|
test_size |
float
|
The proportion of the dataset to include in the test split |
0.1
|
random_state |
int
|
The random seed to use for splitting the data (keep this consistent to ensure reproduceability) |
42
|
bound_mean |
float
|
The mean of the bound distribution |
3.0
|
max_mean_adjustment |
float
|
The maximum mean adjustment to apply to the mean of the bound (bound) perturbation effects |
0.0
|
adjustment_function |
Callable[[Tensor, float, float, float], Tensor]
|
A function that adjusts the mean of the bound (bound) perturbation effects |
default_perturbation_effect_adjustment_function
|
Raises:
Type | Description |
---|---|
TypeError
|
If batch_size is not an positive integer |
TypeError
|
If num_genes is not an positive integer |
TypeError
|
If bound is not a list of integers or floats |
TypeError
|
If n_sample is not a list of integers |
TypeError
|
If val_size is not a float between 0 and 1 (inclusive) |
TypeError
|
If test_size is not a float between 0 and 1 (inclusive) |
TypeError
|
If random_state is not an integer |
TypeError
|
If bound_mean is not a float |
ValueError
|
If val_size + test_size is greater than 1 (i.e. the splits are too large) |
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
prepare_data()
¶
Function to generate the raw synthetic data and save it in a tensor For explanations of the functions used to generate the data, see the generate_in_silico_data tutorial notebook in the docs No assertion checks are performed as that is handled in the functions in generate_data.py.
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
setup(stage=None)
¶
This function runs after prepare_data finishes and is used to split the data into train, validation, and test sets It ensures that these datasets are of the correct dimensionality and size to be used by the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage |
str | None
|
The stage of the data setup (either ‘fit’ for training, ‘validate’ for validation, or ‘test’ for testing), unused for now as the model is not complicated enough to necessitate this |
None
|
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
test_dataloader()
¶
Function to return the testing dataloader.
Returns:
Type | Description |
---|---|
DataLoader
|
The testing dataloader |
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
train_dataloader()
¶
Function to return the training dataloader, we shuffle to avoid learning based on the order of the data.
Returns:
Type | Description |
---|---|
DataLoader
|
The training dataloader |
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
val_dataloader()
¶
Function to return the validation dataloader.
Returns:
Type | Description |
---|---|
DataLoader
|
The validation dataloader |
Source code in yeastdnnexplorer/data_loaders/synthetic_data_loader.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|