Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Functions #236

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
715 changes: 553 additions & 162 deletions python/smooth/adam_general/core/adam.py

Large diffs are not rendered by default.

1,753 changes: 1,753 additions & 0 deletions python/smooth/adam_general/core/checker.py

Large diffs are not rendered by default.

1,100 changes: 542 additions & 558 deletions python/smooth/adam_general/core/creator.py

Large diffs are not rendered by default.

1,402 changes: 703 additions & 699 deletions python/smooth/adam_general/core/estimator.py

Large diffs are not rendered by default.

534 changes: 288 additions & 246 deletions python/smooth/adam_general/core/utils/cost_functions.py

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions python/smooth/adam_general/core/utils/dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# estimator commented out lines 2754 to 2821
adam_created_arima = filler(
b_values['B'],
ets_model, e_type, t_type, s_type, model_is_trendy, model_is_seasonal,
components_number_ets, components_number_ets_non_seasonal,
components_number_ets_seasonal, components_number_arima,
lags, lags_model, lags_model_max,
adam_created['mat_vt'], adam_created['mat_wt'], adam_created['mat_f'], adam_created['vec_g'],
persistence_estimate, persistence_level_estimate, persistence_trend_estimate,
persistence_seasonal_estimate, persistence_xreg_estimate,
phi_estimate,
initial_type, initial_estimate,
initial_level_estimate, initial_trend_estimate, initial_seasonal_estimate,
initial_arima_estimate, initial_xreg_estimate,
arima_model, ar_estimate, ma_estimate, ar_orders, i_orders, ma_orders,
ar_required, ma_required, arma_parameters,
non_zero_ari, non_zero_ma, adam_created['arima_polynomials'],
xreg_model, xreg_number,
xreg_parameters_missing, xreg_parameters_included,
xreg_parameters_estimated, xreg_parameters_persistence, constant_estimate
)

# Write down the initials in the recent profile
profiles_recent_table[:] = adam_created_arima['mat_vt'][:, :lags_model_max]

# Do initial fit to get the state values from the backcasting
adam_fitted = adam_fitter_wrap(
adam_created_arima['mat_vt'], adam_created_arima['mat_wt'], adam_created_arima['mat_f'], adam_created_arima['vec_g'],
lags_model_all, index_lookup_table, profiles_recent_table,
e_type, t_type, s_type, components_number_ets, components_number_ets_seasonal,
components_number_arima, xreg_number, constant_required,
y_in_sample, ot, True
)

adam_created['mat_vt'][:, :lags_model_max] = adam_fitted['mat_vt'][:, :lags_model_max]
# Produce new initials
b_values_new = initialiser(
ets_model, e_type, t_type, s_type, model_is_trendy, model_is_seasonal,
components_number_ets_non_seasonal, components_number_ets_seasonal, components_number_ets,
lags, lags_model, lags_model_seasonal, lags_model_arima, lags_model_max,
adam_created['mat_vt'],
persistence_estimate, persistence_level_estimate, persistence_trend_estimate,
persistence_seasonal_estimate, persistence_xreg_estimate,
phi_estimate, initial_type, initial_estimate,
initial_level_estimate, initial_trend_estimate, initial_seasonal_estimate,
initial_arima_estimate, initial_xreg_estimate,
arima_model, ar_required, ma_required, ar_estimate, ma_estimate, ar_orders, ma_orders,
components_number_arima, components_names_arima, initial_arima_number,
xreg_model, xreg_number,
xreg_parameters_estimated, xreg_parameters_persistence,
constant_estimate, constant_name, other_parameter_estimate
)
B = b_values_new['B']
# Failsafe, just in case if the initial values contain NA / NaN
B[np.isnan(B)] = b_values['B'][np.isnan(B)]



# Fix for mixed ETS models producing negative values
if (e_type == "M" and any(t in ["A", "Ad"] for t in [t_type, s_type]) or
t_type == "M" and any(t in ["A", "Ad"] for t in [e_type, s_type]) or
s_type == "M" and any(t in ["A", "Ad"] for t in [e_type, t_type])):
if e_type == "M" and ("level" in B) and (B["level"] <= 0):
B["level"] = y_in_sample[0]
if t_type == "M" and ("trend" in B) and (B["trend"] <= 0):
B["trend"] = 1
seasonal_params = [p for p in B.keys() if p.startswith("seasonal")]
if s_type == "M" and any(B[p] <= 0 for p in seasonal_params):
for p in seasonal_params:
if B[p] <= 0:
B[p] = 1
13 changes: 8 additions & 5 deletions python/smooth/adam_general/core/utils/ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def BICc(loglik, nobs=None, df=None):
bic = BIC(loglik, nobs, df)
return bic + (np.log(nobs) * df * (df + 1)) / (nobs - df - 1)

def ic_function(ic_name):
def ic_function(ic_name, loglik):
"""
Select information criterion function based on name

Expand All @@ -128,11 +128,14 @@ def ic_function(ic_name):
function
Selected information criterion function
"""
value = loglik['value']
nobs = loglik['nobs']
df = loglik['df']
ic_functions = {
'AIC': AIC,
'AICc': AICc,
'BIC': BIC,
'BICc': BICc
'AIC': AIC(value, nobs, df),
'AICc': AICc(value, nobs, df),
'BIC': BIC(value, nobs, df),
'BICc': BICc(value, nobs, df)
}

if ic_name not in ic_functions:
Expand Down
2 changes: 2 additions & 0 deletions python/smooth/adam_general/core/utils/ic.pyZone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ZoneTransfer]
ZoneId=3
Empty file.
8 changes: 8 additions & 0 deletions python/smooth/adam_general/core/utils/polynomials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def adam_polynomialiser(parameters, ar_orders, i_orders, ma_orders,
ar_estimate, ma_estimate, arma_parameters, lags):
"""
Creates polynomials for ARIMA models.
"""
# Implementation of adam_polynomialiser goes here
# You'll need to move this function from wherever it's currently defined
pass
Loading
Loading