-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathcost_func.py
More file actions
40 lines (28 loc) · 1.39 KB
/
cost_func.py
File metadata and controls
40 lines (28 loc) · 1.39 KB
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
"""
This file is part of CLIMADA.
Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS.
CLIMADA is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free
Software Foundation, version 3.
CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with CLIMADA. If not, see <https://www.gnu.org/licenses/>.
---
Cost functions for impact function calibration module
"""
import numpy as np
from sklearn.metrics import mean_squared_error, mean_squared_log_error
def mse(data: np.ndarray, predicted: np.ndarray, weights: np.ndarray | None) -> float:
"""Weighted mean squared error
See
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html
"""
return mean_squared_error(data, predicted, sample_weight=weights)
def msle(data: np.ndarray, predicted: np.ndarray, weights: np.ndarray | None) -> float:
"""Weighted mean squared logarithmic error
See
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_log_error.html
"""
return mean_squared_log_error(data, predicted, sample_weight=weights)