[Bug] UnExpectedValueRangeError with unexpected value of estimated rho
shik-design opened this issue · comments
shik-design commented
Checkbox
- I agree to follow code of conduct and to engage in discussion actively.
- I agree to create a new issue with the other templates if this is not a bug.
- I used the latest version of covsirphy.
Summary
I received the following error after running:
**dyn_act.estimate()
print(f"Tau value [min]: {dyn_act.tau or 'un-set'}")
# Show summary
dyn_act.summary()**
covsirphy.util.error.UnExpectedValueRangeError: 'rho' is not in the expected value range (0, 1), but 5.398753490197095 was applied
Reproducible example script
import covsirphy as cs
print(cs.__version__)
eng = cs.DataEngineer()
eng.download(
country=None, province=None,
databases=["covid19dh", "japan", "owid"], directory="input", update_interval=24);
eng.clean()
eng.transform()
actual_df, status, _ = eng.subset(geo=None, variables="SIRF", complement=True)
print(status)
actual_df.tail()
dyn_act = cs.Dynamics.from_data(model=cs.SIRModel, data=actual_df, name="None")
# Show registered values
dyn_act.register().tail()
dyn_act.segment(algo="BottomUp-rbf", min_size=23);
dyn_act.summary().T
dyn_act.estimate()
print(f"Tau value [min]: {dyn_act.tau or 'un-set'}")
# Show summary
dyn_act.summary()
The current outputs
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\multiprocess\pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\pathos\helpers\mp_helper.py", line 15, in <lambda>
func = lambda args: f(*args)
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\dynamics.py", line 514, in _optimized_params
model_instance = model.from_data_with_optimization(
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\ode.py", line 457, in from_data_with_optimization
param_dict, score, n_trials, runtime = cls._estimate_params(
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\ode.py", line 520, in _estimate_params
study.optimize(objective_func, n_jobs=1, timeout=kwargs["timeout_iteration"])
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\optuna\study\study.py", line 419, in optimize
_optimize(
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\optuna\study\_optimize.py", line 66, in _optimize
_optimize_sequential(
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\optuna\study\_optimize.py", line 160, in _optimize_sequential
frozen_trial = _run_trial(study, func, catch)
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\optuna\study\_optimize.py", line 234, in _run_trial
raise func_err
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\optuna\study\_optimize.py", line 196, in _run_trial
value_or_values = func(trial)
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\ode.py", line 551, in _optuna_objective
return cls._optuna_score(param_dict, data, tau, metric)
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\ode.py", line 567, in _optuna_score
model = cls.from_data(data=cls.inverse_transform(df).reset_index(), param_dict=param_dict, tau=tau, digits=None)
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\ode.py", line 344, in from_data
return cls(
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\dynamics\sir.py", line 41, in __init__
self._rho = Validator(self._param_dict["rho"], "rho", accept_none=False).float(value_range=(0, 1))
File "C:\Users\USER\anaconda3\envs\VC\lib\site-packages\covsirphy\util\validator.py", line 119, in float
raise UnExpectedValueRangeError(self._name, value, value_range)
covsirphy.util.error.UnExpectedValueRangeError: 'rho' is not in the expected value range (0, 1), but 5.398753490197095 was applied.
"""
Expected outputs
No response
Environment
- CovsirPhy version: 2.80.0
- Python version: 3.9.13
Package manager (required if installation issue)
No response
Platform (required if installation issue)
No response
Additional Context
No response
Hirokazu Takaya commented
I have no solutions at this time, but a phase lead un-expected rho value (i.e. out of (0, 1) value range).
Abnormal values of Susceptible/Infected/Fatal/Recovered observed?
shik-design commented
The error is persisting.
Codes
dyn_act.estimate()
print(f"Tau value [min]: {dyn_act.tau or 'un-set'}")
Show summary
dyn_act.summary()
Results
UnExpectedValueRangeError Traceback (most recent call last)
Cell In [19], line 1
----> 1 dyn_act.estimate()
2 print(f"Tau value [min]: {dyn_act.tau or 'un-set'}")
3 # Show summary
File ~\anaconda3\envs\VVV\lib\site-packages\covsirphy\dynamics\dynamics.py:380, in Dynamics.estimate(self, **kwargs)
371 """Run covsirphy.Dynamics.estimate_tau() and covsirphy.Dynamics.estimate_params().
372
373 Args:
(...)
377 covsirphy.Dynamics: self
378 """
379 self.estimate_tau(**Validator(kwargs).kwargs(self.estimate_tau))
--> 380 self.estimate_params(**kwargs)
381 return self
File ~\anaconda3\envs\VVV\lib\site-packages\covsirphy\dynamics\dynamics.py:489, in Dynamics.estimate_params(self, metric, digits, n_jobs, **kwargs)
487 warnings.filterwarnings("ignore", category=FutureWarning)
488 r_df.update(est_df, overwrite=True)
--> 489 self.register(data=r_df)
490 return est_df
File ~\anaconda3\envs\VVV\lib\site-packages\covsirphy\dynamics\dynamics.py:185, in Dynamics.register(self, data)
182 raise EmptyError(
183 f"records on {self._first.strftime(self.DATE_FORMAT)}", details="Records must be registered for simulation")
184 if all_df.min().min() < 0:
--> 185 raise UnExpectedValueRangeError("minimum value of the data", all_df.min().min(), (0, None))
186 all_df.index.name = self.DATE
187 self._df = all_df.convert_dtypes()
UnExpectedValueRangeError: 'minimum value of the data' must be over or equal to 0, but -9355.104070541354 was applied.
Hirokazu Takaya commented
The error message says minus value exists as the (complemented) number of cases unexpectedly.
- Please identify the variable of the minus values using
actual_df
dataframe. - Does error exists when not complemented?