Validate(评估) 模块¶
ppsci.validate
¶
Validator
¶
Base class for validators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
Dataset
|
Dataset for validator. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
metric |
Optional[Dict[str, Metric]]
|
Named metric functors in dict. |
required |
name |
str
|
Name of validator. |
required |
Source code in ppsci/validate/base.py
GeometryValidator
¶
Bases: Validator
Validator for geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_expr |
Dict[str, Callable]
|
Function in dict for computing output. e.g. {"u_mul_v": lambda out: out["u"] * out["v"]} means the model output u will be multiplied by model output v and the result will be named "u_mul_v". |
required |
label_dict |
Dict[str, Union[float, Callable]]
|
Function in dict for computing label, which will be a reference value to participate in the loss calculation. |
required |
geom |
Geometry
|
Geometry where data sampled from. |
required |
dataloader_cfg |
Dict[str, Any]
|
Dataloader config. |
required |
loss |
Loss
|
Loss functor. |
required |
random |
Literal['pseudo', 'Halton', 'LHS']
|
Random method for sampling data in geometry. Defaults to "pseudo". |
'pseudo'
|
criteria |
Optional[Callable]
|
Criteria for refining specified domain. Defaults to None. |
None
|
evenly |
bool
|
Whether to use evenly distribution sampling. Defaults to False. |
False
|
metric |
Optional[Dict[str, Metric]]
|
Named metric functors in dict. Defaults to None. |
None
|
with_initial |
bool
|
Whether the data contains time t0. Defaults to False. |
False
|
name |
Optional[str]
|
Name of validator. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> rect = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> geom_validator = ppsci.validate.GeometryValidator(
... {"u": lambda out: out["u"]},
... {"u": 0},
... rect,
... {
... "dataset": "IterableNamedArrayDataset",
... "iters_per_epoch": 1,
... "total_size": 32,
... "batch_size": 16,
... },
... ppsci.loss.MSELoss("mean"),
... )
Source code in ppsci/validate/geo_validator.py
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 |
|
SupervisedValidator
¶
Bases: Validator
Validator for supervised models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloader_cfg |
Dict[str, Any]
|
Config of building a dataloader. |
required |
loss |
Loss
|
Loss functor. |
required |
output_expr |
Optional[Dict[str, Callable]]
|
List of label expression. |
None
|
metric |
Optional[Dict[str, Metric]]
|
Named metric functors in dict. Defaults to None. |
None
|
name |
Optional[str]
|
Name of validator. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> valid_dataloader_cfg = {
... "dataset": {
... "name": "MatDataset",
... "file_path": "/path/to/file.mat",
... "input_keys": ("t_f",),
... "label_keys": ("eta", "f"),
... },
... "batch_size": 32,
... "sampler": {
... "name": "BatchSampler",
... "drop_last": False,
... "shuffle": False,
... },
... }
>>> eta_mse_validator = ppsci.validate.SupervisedValidator(
... valid_dataloader_cfg,
... ppsci.loss.MSELoss("mean"),
... {"eta": lambda out: out["eta"]},
... metric={"MSE": ppsci.metric.MSE()},
... name="eta_mse",
... )