Skip to content

Commit

Permalink
Fix online function for edge cases
Browse files Browse the repository at this point in the history
* Fixed online() function for cases where the regret is exactly zero. This can happen if:
* * Only a single expert is used
* * Only two experts are provided and they both have the same predictions (in the beginning).
  • Loading branch information
BerriJ committed Jan 12, 2024
1 parent 50cc7b8 commit 4cb2574
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: profoc
Type: Package
Title: Probabilistic Forecast Combination Using CRPS Learning
Version: 1.3.0
Version: 1.3.1
Date: 2024-01-09
Authors@R: c(
person(given = "Jonathan",
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
profoc 1.3.1
==============

## Improvements
* Adjusted the clock.h code so that a larger share of code can be shared between the R and Python versions of that file.

## Fixes
* Fixed an integer overflow in the clock.h code which caused the package to fail on some systems.
* Fixed online() function for cases where the regret is exactly zero. This can happen if:
* * Only a single expert is used
* * Only two experts are provided and they both have the same predictions (in the beginning).

profoc 1.3.0
==============

Expand Down
7 changes: 4 additions & 3 deletions src/conline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,13 @@ void conline::learn()
{
V(x).tube(dr, pr) = vectorise(V(x).tube(dr, pr)).t() * (1 - params["forget_regret"](x)) + square(r.t());

E(x).tube(dr, pr) = max(vectorise(E(x).tube(dr, pr)).t() * (1 - params["forget_regret"](x)), abs(r.t()));
E(x).tube(dr, pr) = pmax_arma(max(vectorise(E(x).tube(dr, pr)).t() * (1 - params["forget_regret"](x)), abs(r.t())), exp(-350));

eta(x).tube(dr, pr) =
eta(x)
.tube(dr, pr) =
pmin_arma(
min(1 / (2 * vectorise(E(x).tube(dr, pr))),
sqrt(-log(vectorise(beta0field(x).tube(dr, pr))) / vectorise(V(x).tube(dr, pr)))),
sqrt(-log(vectorise(beta0field(x).tube(dr, pr))) / pmax_arma(vectorise(V(x).tube(dr, pr)), exp(-350)))),
exp(350));

vec r_reg = r - vectorise(eta(x).tube(dr, pr)) % square(r);
Expand Down
40 changes: 40 additions & 0 deletions tests/testthat/test-single_same_experts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
skip_if(debug_mode)
# %% Test online "combination" of a single expert
set.seed(1)

mod <- online(
y = array(rnorm(30),
dim = c(5, 3)
), array(rnorm(30),
dim = c(5, 3, 1)
),
tau = .5,
trace = FALSE
)

expect_true(all(mod$weights == 1))
# %%


# %% Test online "combination" of two experts that are the same
set.seed(1)

experts <- array(NA,
dim = c(5, 3, 2)
)

experts[, , 1] <- array(rnorm(30),
dim = c(5, 3)
)
experts[, , 2] <- experts[, , 1]

mod <- online(
y = array(rnorm(30),
dim = c(5, 3)
), experts,
tau = .5,
trace = FALSE
)

expect_true(all(mod$weights == 0.5))
# %%

0 comments on commit 4cb2574

Please sign in to comment.