Skip to content

Commit

Permalink
fix updates -- use Polyak averaging
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Aug 28, 2024
1 parent 6b36a31 commit f47c199
Show file tree
Hide file tree
Showing 10 changed files with 684 additions and 391 deletions.
50 changes: 36 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean docs start setwd check install load render
.PHONY: buildsite check clean coverage docs getwd initialize install load render setwd start test usegit
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
Expand All @@ -25,35 +25,57 @@ export PRINT_HELP_PYSCRIPT

BROWSER := python3 -c "$$BROWSER_PYSCRIPT"

help:
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
buildsite: setwd ## create a website for the package
Rscript -e "pkgdown::build_site('.')"

check: clean setwd ## check package
Rscript -e "try(devtools::check('.'), silent=FALSE)"

clean: ## remove all build, test, coverage and Python artifacts
rm -f .Rbuildignore
clean: ## remove all build, and artifacts
rm -f .Rhistory
rm -f *.RData
rm -f *.Rproj
rm -rf .Rproj.user

start: ## start or restart R session
Rscript -e "system('R')"
coverage: ## get test coverage
Rscript -e "devtools::test_coverage('.')"

setwd: ## set working directory
Rscript -e "setwd(getwd())"
create: setwd ## create a new package in current directory
Rscript -e "usethis::create_package(path = getwd(), rstudio = FALSE)"
rm -f .here

docs: clean setwd ## generate docs
Rscript -e "devtools::document('.')"

check: clean setwd ## check package
Rscript -e "devtools::check('.')"
getwd: ## get current directory
Rscript -e "getwd()"

install: clean setwd ## install package
Rscript -e "devtools::install('.')"
Rscript -e "try(devtools::install('.'), silent = FALSE)"

initialize: setwd ## initialize: install packages devtools, usethis, pkgdown and rmarkdown
Rscript -e "utils::install.packages(c('devtools', 'usethis', 'pkgdown', 'rmarkdown'), repos='https://cloud.r-project.org')"

help: ## print menu with all options
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

load: clean setwd ## load all (when developing the package)
Rscript -e "devtools::load_all('.')"

render: ## run markdown file in /vignettes
render: ## run R markdown file in /vignettes, open rendered HTML file in the browser
@read -p "Enter the name of the Rmd file (without extension): " filename; \
Rscript -e "rmarkdown::render(paste0('./vignettes/', '$$filename', '.Rmd'))"; \
python3 -c "$$BROWSER_PYSCRIPT" "$$filename.html"
python3 -c "$$BROWSER_PYSCRIPT" "$$filename.html"

setwd: ## set working directory to current directory
Rscript -e "setwd('.')"

start: ## start or restart R session
Rscript -e "system('R')"

test: ## runs the the package tests
Rscript -e "devtools::test('.')"

usegit: ## initialize Git repo and initial commit
@read -p "Enter the first commit message: " message; \
Rscript -e "usethis::use_git('$$message')"
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ importFrom("stats", "median")
importFrom("stats", "predict")
importFrom("stats", "quantile")
importFrom("stats", "rnorm", "runif", "sd")
importFrom("stats", "approx", "density")
importFrom("tseries", "tsbootstrap")
importFrom("tseries", "surrogate")
importFrom("R6", "R6Class")
Expand Down
6 changes: 3 additions & 3 deletions R/Regressor.R
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,15 @@ Regressor <-
#' @description update model in an online fashion (for now, only implemented for 'rvfl' models")
#' @param newx a vector of new covariates (i.e explanatory variables)
#' @param newy a numeric, the new response's observation (i.e variable to be explained)
#'
update = function(newx, newy)
#' @param ... additional parameters to be passed to the underlying model's method `update`
update = function(newx, newy, ...)
{
if(!identical(self$method, "rvfl"))
{
stop(paste0("As of ", Sys.Date(), ", this method is only implemented for 'rvfl' models"))
}
self$set_model(update_rvfl_regressor(self$model,
newx=newx, newy=newy, method="rvfl"))
newx=newx, newy=newy, ...))
}
)
)
Expand Down
5 changes: 2 additions & 3 deletions R/utils_rvfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fit_rvfl_regression <- function(x, y,
compute_Sigma = FALSE,
method = "chol"),
input_list))

return(structure(out, class = "rvfl"))
}

Expand All @@ -37,7 +36,7 @@ predict_rvfl_regression <- function(object, newx, ...)
return (preds)
}

update_rvfl_regressor <- function(object, newx, newy, method="rvfl")
update_rvfl_regressor <- function(object, newx, newy, ...)
{
bayesianrvfl::update_params(fit_obj=object, newx=newx, newy=newy)
bayesianrvfl::update_params(fit_obj=object, newx=newx, newy=newy, ...)
}
18 changes: 0 additions & 18 deletions learningmachine.Rproj

This file was deleted.

4 changes: 3 additions & 1 deletion man/Regressor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vignettes/getting-started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,19 @@ newy <- y_test[2]
new_X_test <- X_test[-c(1, 2), ]
new_y_test <- y_test[-c(1, 2)]
```

```{r eval=TRUE}
t0 <- proc.time()[3]
obj$update(newx, newy)
cat("Elapsed: ", proc.time()[3] - t0, "s \n")
```

```{r}
```{r eval=TRUE}
obj$summary(new_X_test, y=new_y_test, show_progress=FALSE)
```

```{r fig.width=7.2}
```{r fig.width=7.2, eval=TRUE}
res <- obj$predict(X = new_X_test)
new_y_train <- c(y_train, y_test[c(1, 2)])
Expand Down
Loading

0 comments on commit f47c199

Please sign in to comment.