File size: 9,041 Bytes
c176aea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# Table of Contents
- [Table of Contents](#table-of-contents)
- [main](#main)
- [:orange\[PINN\]](#orangepinn)
- [PINN.pinns](#pinnpinns)
- [PINNd\_p Objects](#pinnd_p-objects)
- [PINNhd\_ma Objects](#pinnhd_ma-objects)
- [PINNT\_ma Objects](#pinnt_ma-objects)
- [:orange\[utils\]](#orangeutils)
- [utils.test](#utilstest)
- [utils.dataset\_loader](#utilsdataset_loader)
- [get\_dataset](#get_dataset)
- [utils.ndgan](#utilsndgan)
- [DCGAN Objects](#dcgan-objects)
- [define\_discriminator](#define_discriminator)
- [generate\_latent\_points](#generate_latent_points)
- [define\_gan](#define_gan)
- [summarize\_performance](#summarize_performance)
- [train\_gan](#train_gan)
- [utils.data\_augmentation](#utilsdata_augmentation)
- [dataset Objects](#dataset-objects)
- [\_\_init\_\_](#__init__)
- [:orange\[nets\]](#orangenets)
- [nets.envs](#netsenvs)
- [SCI Objects](#sci-objects)
- [data\_flow](#data_flow)
- [init\_seed](#init_seed)
- [compile](#compile)
- [train](#train)
- [inference](#inference)
- [RCI Objects](#rci-objects)
- [data\_flow](#data_flow-1)
- [compile](#compile-1)
- [nets.dense](#netsdense)
- [Net Objects](#net-objects)
- [\_\_init\_\_](#__init__-1)
- [nets.design](#netsdesign)
- [B\_field\_norm](#b_field_norm)
- [nets.deep\_dense](#netsdeep_dense)
- [dmodel Objects](#dmodel-objects)
- [\_\_init\_\_](#__init__-2)
<a id="main"></a>
# main
<a id="PINN"></a>
# :orange[PINN]
<a id="PINN.pinns"></a>
## PINN.pinns
<a id="PINN.pinns.PINNd_p"></a>
## PINNd\_p Objects
```python
class PINNd_p(nn.Module)
```
$d \mapsto P$
<a id="PINN.pinns.PINNhd_ma"></a>
## PINNhd\_ma Objects
```python
class PINNhd_ma(nn.Module)
```
$h,d \mapsto m_a $
<a id="PINN.pinns.PINNT_ma"></a>
## PINNT\_ma Objects
```python
class PINNT_ma(nn.Module)
```
$ m_a, U \mapsto T$
<a id="utils"></a>
---
# :orange[utils]
<a id="utils.test"></a>
## utils.test
<a id="utils.dataset_loader"></a>
## utils.dataset\_loader
<a id="utils.dataset_loader.get_dataset"></a>
#### get\_dataset
```python
def get_dataset(raw: bool = False,
sample_size: int = 1000,
name: str = 'dataset.pkl',
source: str = 'dataset.csv',
boundary_conditions: list = None) -> _pickle
```
Gets augmented dataset
**Arguments**:
- `raw` _bool, optional_ - either to use source data or augmented. Defaults to False.
- `sample_size` _int, optional_ - sample size. Defaults to 1000.
- `name` _str, optional_ - name of wanted dataset. Defaults to 'dataset.pkl'.
- `boundary_conditions` _list,optional_ - y1,y2,x1,x2.
**Returns**:
- `_pickle` - pickle buffer
<a id="utils.ndgan"></a>
## utils.ndgan
<a id="utils.ndgan.DCGAN"></a>
### DCGAN Objects
```python
class DCGAN()
```
<a id="utils.ndgan.DCGAN.define_discriminator"></a>
#### define\_discriminator
```python
def define_discriminator(inputs=8)
```
function to return the compiled discriminator model
<a id="utils.ndgan.DCGAN.generate_latent_points"></a>
#### generate\_latent\_points
```python
def generate_latent_points(latent_dim, n)
```
generate points in latent space as input for the generator
<a id="utils.ndgan.DCGAN.define_gan"></a>
#### define\_gan
```python
def define_gan(generator, discriminator)
```
define the combined generator and discriminator model
<a id="utils.ndgan.DCGAN.summarize_performance"></a>
#### summarize\_performance
```python
def summarize_performance(epoch, generator, discriminator, latent_dim, n=200)
```
evaluate the discriminator and plot real and fake samples
<a id="utils.ndgan.DCGAN.train_gan"></a>
#### train\_gan
```python
def train_gan(g_model,
d_model,
gan_model,
latent_dim,
num_epochs=2500,
num_eval=2500,
batch_size=2)
```
function to train gan model
<a id="utils.data_augmentation"></a>
## utils.data\_augmentation
<a id="utils.data_augmentation.dataset"></a>
## dataset Objects
```python
class dataset()
```
Creates dataset from input source
<a id="utils.data_augmentation.dataset.__init__"></a>
#### \_\_init\_\_
```python
def __init__(number_samples: int,
name: str,
source: str,
boundary_conditions: list = None)
```
_summary_
**Arguments**:
- `number_samples` _int_ - _description_
- `name` _str_ - _description_
- `source` _str_ - _description_
- `boundary_conditions` _list_ - y1,y2,x1,x2
<a id="nets"></a>
# :orange[nets]
<a id="nets.envs"></a>
## nets.envs
<a id="nets.envs.SCI"></a>
### SCI Objects
```python
class SCI()
```
<a id="nets.envs.SCI.data_flow"></a>
#### data\_flow
```python
def data_flow(columns_idx: tuple = (1, 3, 3, 5),
idx: tuple = None,
split_idx: int = 800) -> torch.utils.data.DataLoader
```
Data prep pipeline
**Arguments**:
- `columns_idx` _tuple, optional_ - Columns to be selected (sliced 1:2 3:4) for feature fitting. Defaults to (1,3,3,5).
- `idx` _tuple, optional_ - 2|3 indexes to be selected for feature fitting. Defaults to None. Use either idx or columns_idx (for F:R->R idx, for F:R->R2 columns_idx)
split_idx (int) : Index to split for training
**Returns**:
- `torch.utils.data.DataLoader` - Torch native dataloader
<a id="nets.envs.SCI.init_seed"></a>
#### init\_seed
```python
def init_seed(seed)
```
Initializes seed for torch optional()
<a id="nets.envs.SCI.compile"></a>
#### compile
```python
def compile(columns: tuple = None,
idx: tuple = None,
optim: torch.optim = torch.optim.AdamW,
loss: nn = nn.L1Loss,
model: nn.Module = dmodel,
custom: bool = False) -> None
```
Builds model, loss, optimizer. Has defaults
**Arguments**:
- `columns` _tuple, optional_ - Columns to be selected for feature fitting. Defaults to (1,3,3,5).
optim - torch Optimizer
loss - torch Loss function (nn)
<a id="nets.envs.SCI.train"></a>
#### train
```python
def train(epochs: int = 10) -> None
```
Train model
If sklearn instance uses .fit()
<a id="nets.envs.SCI.inference"></a>
#### inference
```python
def inference(X: tensor, model_name: str = None) -> np.ndarray
```
Inference of (pre-)trained model
**Arguments**:
- `X` _tensor_ - your data in domain of train
**Returns**:
- `np.ndarray` - predictions
<a id="nets.envs.RCI"></a>
### RCI Objects
```python
class RCI(SCI)
```
<a id="nets.envs.RCI.data_flow"></a>
#### data\_flow
```python
def data_flow(columns_idx: tuple = (1, 3, 3, 5),
idx: tuple = None,
split_idx: int = 800) -> torch.utils.data.DataLoader
```
Data prep pipeline
**Arguments**:
- `columns_idx` _tuple, optional_ - Columns to be selected (sliced 1:2 3:4) for feature fitting. Defaults to (1,3,3,5).
- `idx` _tuple, optional_ - 2|3 indexes to be selected for feature fitting. Defaults to None. Use either idx or columns_idx (for F:R->R idx, for F:R->R2 columns_idx)
split_idx (int) : Index to split for training
**Returns**:
- `torch.utils.data.DataLoader` - Torch native dataloader
<a id="nets.envs.RCI.compile"></a>
#### compile
```python
def compile(columns: tuple = None,
idx: tuple = (3, 1),
optim: torch.optim = torch.optim.AdamW,
loss: nn = nn.L1Loss,
model: nn.Module = PINNd_p,
lr: float = 0.001) -> None
```
Builds model, loss, optimizer. Has defaults
**Arguments**:
- `columns` _tuple, optional_ - Columns to be selected for feature fitting. Defaults to None.
- `idx` _tuple, optional_ - indexes to be selected Default (3,1)
optim - torch Optimizer
loss - torch Loss function (nn)
<a id="nets.dense"></a>
## nets.dense
<a id="nets.dense.Net"></a>
### Net Objects
```python
class Net(nn.Module)
```
4 layer model, different activations and neurons count on layer
<a id="nets.dense.Net.__init__"></a>
#### \_\_init\_\_
```python
def __init__(input_dim: int = 2, hidden_dim: int = 200)
```
Init
**Arguments**:
- `input_dim` _int, optional_ - Defaults to 2.
- `hidden_dim` _int, optional_ - Defaults to 200.
<a id="nets.design"></a>
## nets.design
<a id="nets.design.B_field_norm"></a>
#### B\_field\_norm
```python
def B_field_norm(Bmax, L, k=16, plot=True)
```
Returns vec B_z
**Arguments**:
- `Bmax` _any_ - maximum B in thruster
k - magnetic field profile number
<a id="nets.deep_dense"></a>
## nets.deep\_dense
<a id="nets.deep_dense.dmodel"></a>
### dmodel Objects
```python
class dmodel(nn.Module)
```
4 layers Torch model. Relu activations, hidden layers are same size.
<a id="nets.deep_dense.dmodel.__init__"></a>
#### \_\_init\_\_
```python
def __init__(in_features=1, hidden_features=200, out_features=1)
```
Init
**Arguments**:
- `in_features` _int, optional_ - Input features. Defaults to 1.
- `hidden_features` _int, optional_ - Hidden dims. Defaults to 200.
- `out_features` _int, optional_ - Output dims. Defaults to 1.
|