Skip to content

Commit

Permalink
changed metric computation to suppress future warnings, removed verbo…
Browse files Browse the repository at this point in the history
…se copula fitting message
  • Loading branch information
nepslor committed Jan 25, 2024
1 parent 88ea395 commit 3121bb8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyforecaster/copula.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GaussianCopula:
def __init__(self, cov_est_method='vanilla', logger=None):
self.pars = None
self.cov_est_method = cov_est_method
self.logger = logger if logger is not None else get_logger(name='Copula')
self.logger = logger if logger is not None else get_logger(name='Copula', level=logging.WARNING)
self.dim = None

def fit(self, y, x=None, do_plot=True):
Expand Down
24 changes: 21 additions & 3 deletions pyforecaster/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,36 @@ def squerr(x, t):

def rmse(x, t, agg_index=None, **kwargs):
agg_index = np.ones_like(x.index) if agg_index is None else agg_index
return squerr(x, t).groupby(agg_index, axis=chose_axis(x, agg_index)).mean() ** 0.5
res = squerr(x, t)
axis = chose_axis(x, agg_index)
if axis == 0:
res = res.groupby(agg_index).mean() ** 0.5
else:
res = res.T.groupby(agg_index).mean() ** 0.5
return res


def mape(x, t, agg_index=None, **kwargs):
agg_index = np.ones_like(x.index) if agg_index is None else agg_index
return (err(x, t)/(t + 1e-5)).abs().groupby(agg_index, axis=chose_axis(x, agg_index)).mean()
res = (err(x, t)/(np.abs(t) + 1e-5)).abs()
axis = chose_axis(x, agg_index)
if axis == 0:
res = res.groupby(agg_index).mean()
else:
res = res.T.groupby(agg_index).mean()
return res


def nmae(x, t, agg_index=None, inter_normalization=True, **kwargs):
agg_index = np.ones_like(x.index) if agg_index is None else agg_index
offset = t.abs().mean(axis=1).quantile(0.5) * 0.01 + 1e-12 if inter_normalization else 1e-12
return (err(x, t) / (t.abs().mean(axis=1).values.reshape(-1,1) + offset)).abs().groupby(agg_index, axis=chose_axis(x, agg_index)).mean()
axis = chose_axis(x, agg_index)
res = (err(x, t) / (t.abs().mean(axis=1).values.reshape(-1,1) + offset)).abs()
if axis == 0:
res = res.groupby(agg_index).mean()
else:
res = res.T.groupby(agg_index).mean()
return res


def quantile_scores(q_hat, t, alphas=None, agg_index=None, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion pyforecaster/scenarios_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from scipy.interpolate import interp1d
from .scenred import superimpose_signal_to_tree
from pyforecaster.utilities import get_logger
from logging import WARNING
import pandas as pd
import pyforecaster.dictionaries
import numpy as np
Expand All @@ -17,7 +18,7 @@ class ScenGen:
def __init__(self, copula_type: str = 'HourlyGaussianCopula', tree_type:str = 'ScenredTree',
online_tree_reduction=True, q_vect=None, nodes_at_step=None, max_iterations=100,
parallel_preds=False, additional_node=False, prefit_trees=False, **kwargs):
self.logger = get_logger()
self.logger = get_logger(level=WARNING)
self.copula_type = copula_type
self.tree_type = tree_type
self.copula_class = pyforecaster.dictionaries.COPULA_MAP[copula_type]
Expand Down

0 comments on commit 3121bb8

Please sign in to comment.