Metric(评价指标) 模块¶
ppsci.metric
¶
Metric
¶
FunctionalMetric
¶
Bases: Metric
Functional metric class, which allows to use custom metric computing function from given metric_expr for complex computation cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_expr |
Callable
|
expression of metric calculation. |
required |
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
>>> import ppsci
>>> import paddle
>>> def metric_expr(output_dict, *args):
... rel_l2 = 0
... for key in output_dict:
... length = int(len(output_dict[key])/2)
... out_dict = {key: output_dict[key][:length]}
... label_dict = {key: output_dict[key][length:]}
... rel_l2 += paddle.norm(out_dict - label_dict) / paddle.norm(label_dict)
... return {"l2": rel_l2}
>>> metric_dict = ppsci.metric.FunctionalMetric(metric_expr)
Source code in ppsci/metric/func.py
MAE
¶
Bases: Metric
Mean absolute error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
Source code in ppsci/metric/mae.py
MSE
¶
Bases: Metric
Mean square error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
Source code in ppsci/metric/mse.py
RMSE
¶
Bases: Metric
Root mean square error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
Source code in ppsci/metric/rmse.py
L2Rel
¶
Bases: Metric
Class for l2 relative error.
NOTE: This metric API is slightly different from MeanL2Rel
, difference is as below:
L2Rel
regards the input sample as a whole and calculates the l2 relative error of the whole;MeanL2Rel
will calculate L2Rel separately for each input sample and return the average of l2 relative error for all samples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
Source code in ppsci/metric/l2_rel.py
MeanL2Rel
¶
Bases: Metric
Class for mean l2 relative error.
NOTE: This metric API is slightly different from L2Rel
, difference is as below:
MeanL2Rel
will calculate L2Rel separately for each input sample and return the average of l2 relative error for all samples.L2Rel
regards the input sample as a whole and calculates the l2 relative error of the whole;
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
Examples:
Source code in ppsci/metric/l2_rel.py
LatitudeWeightedACC
¶
Bases: Metric
Latitude weighted anomaly correlation coefficient.
\(lat_m\) is the latitude at m.
\(N_{lat}\) is the number of latitude set by num_lat
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_lat |
int
|
Number of latitude. |
required |
mean |
Optional[Union[array, Tuple[float, ...]]]
|
Mean of training data. Defaults to None. |
required |
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
variable_dict |
Optional[Dict[str, int]]
|
Variable dictionary, the key is the name of a variable and the value is its index. Defaults to None. |
None
|
unlog |
bool
|
whether calculate expm1 for all elements in the array. Defaults to False. |
False
|
scale |
float
|
The scale value used after expm1. Defaults to 1e-5. |
1e-05
|
Examples:
>>> import numpy as np
>>> import ppsci
>>> mean = np.random.randn(20, 720, 1440)
>>> metric = ppsci.metric.LatitudeWeightedACC(720, mean=mean)
Source code in ppsci/metric/anomaly_coef.py
LatitudeWeightedRMSE
¶
Bases: Metric
Latitude weighted root mean square error.
\(lat_m\) is the latitude at m.
\(N_{lat}\) is the number of latitude set by num_lat
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_lat |
int
|
Number of latitude. |
required |
std |
Optional[Union[array, Tuple[float, ...]]]
|
Standard Deviation of training dataset. Defaults to None. |
None
|
keep_batch |
bool
|
Whether keep batch axis. Defaults to False. |
False
|
variable_dict |
Optional[Dict[str, int]]
|
Variable dictionary, the key is the name of a variable and the value is its index. Defaults to None. |
None
|
unlog |
bool
|
whether calculate expm1 for all elements in the array. Defaults to False. |
False
|
scale |
float
|
The scale value used after expm1. Defaults to 1e-5. |
1e-05
|
Examples:
>>> import numpy as np
>>> import ppsci
>>> std = np.random.randn(20, 1, 1)
>>> metric = ppsci.metric.LatitudeWeightedRMSE(720, std=std)
Source code in ppsci/metric/rmse.py
创建日期: November 6, 2023