Skip to content

could not find function "get_cost" #16

@tdhock

Description

@tdhock

Hey @IshmaelBelghazi nice to see that you wrote some demos. However I am getting an error when I try to run them. Maybe you need to export get_cost?

thocking@silene:~/R$ R --vanilla

R version 3.2.1 (2015-06-18) -- "World-Famous Astronaut"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(bigoptim)
Loading required package: Matrix
demo> demo("example_SAG", package="bigoptim")


    demo(example_SAG)
    ---- ~~~~~~~~~~~

Type  <Return>   to start : 

> library(Matrix)

> data(rcv1_train)

> X <- rcv1_train$X

> ##X <- cBind(rep(1, NROW(X), X), X)
> y <- rcv1_train$y

> n <- NROW(X)

> p <- NCOL(X)

> ## Setting seed
> ##set.seed(0)
> maxIter <- n * 20 

> lambda <- 1/n

> tol <- 0

> print("Running Stochastic average gradient with constant step size\n")
[1] "Running Stochastic average gradient with constant step size\n"

> ## -----------------------------------------------------------------------------
> ## SAG with Constant step size
> sag_constant_fit <- sag_fit(X=X, y=y, lambda=lambda, maxiter=maxIter,
+                             tol=0, fit_alg="constant", model="binomial")

> cost_constant <- get_cost(sag_constant_fit, X=X, y=y) 
Error in eval(expr, envir, enclos) : could not find function "get_cost"
> demo("example_SAG2", package="bigoptim")


    demo(example_SAG2)
    ---- ~~~~~~~~~~~~

Type  <Return>   to start : 

> ## Loading Data set
> data(covtype.libsvm)

> ## Normalizing Columns and adding intercept
> X <- cbind(rep(1, NROW(covtype.libsvm$X)), scale(covtype.libsvm$X))

> y <- covtype.libsvm$y

> y[y == 2] <- -1

> n <- NROW(X)

> p <- NCOL(X)

> ## Setting seed
> #set.seed(0)
> ## Setting up problem
> maxiter <- n * 20  ## 10 passes throught the dataset

> lambda <- 1/n 

> tol <- 1e-4

> ## -----------------------------------------------------------------------------
> ## SAG with Constant step size
> print("Running Stochastic Average Gradient with constant step size")
[1] "Running Stochastic Average Gradient with constant step size"

> sag_constant_fit <- sag_fit(X=X, y=y, lambda=lambda, maxiter=maxiter,
+                             tol=tol, family="binomial",
+                             fit_alg="constant", standardize=FALSE)

> cost_constant <- get_cost(sag_constant_fit, X, y)
Error in eval(expr, envir, enclos) : could not find function "get_cost"
In addition: Warning message:
In sag_fit(X = X, y = y, lambda = lambda, maxiter = maxiter, tol = tol,  :
  Optimisation stopped before convergence. Try incrasing maximum number of iterations
> demo("monitoring_training", package="bigoptim")


    demo(monitoring_training)
    ---- ~~~~~~~~~~~~~~~~~~~

Type  <Return>   to start : 

> suppressPackageStartupMessages(library(ggplot2))

> suppressPackageStartupMessages(library(glmnet))

> ## Loading Data set
> data(covtype.libsvm)

> ## Normalizing Columns and adding intercept
> X <- cbind(rep(1, NROW(covtype.libsvm$X)), scale(covtype.libsvm$X))

> y <- covtype.libsvm$y

> y[y == 2] <- -1

> n <- NROW(X)

> p <- NCOL(X)

> ## Setting seed
> #set.seed(0)
> ## Setting up problem
> n_passes <- 50  ## number of passses trough the dataset

> maxiter <- n * n_passes

> lambda <- 1/n 

> tol <- 0

> family <- "binomial"

> fit_algs <- list(constant="constant",
+                  linesearch="linesearch",
+                  adaptive="adaptive")

> sag_fits <- lapply(fit_algs, function(fit_alg) sag_fit(X, y,
+                                                    lambda=lambda,
+                                                    maxiter=maxiter,
+                                                    family=family,
+                                                    fit_alg=fit_alg,
+                                                    standardize=FALSE,
+                                                    tol=tol, monitor=TRUE))

> print(lapply(sag_fits, function(sag_fit) get_cost(sag_fit, X, y)))
Warning message:
In sag_fit(X, y, lambda = lambda, maxiter = maxiter, family = family,  :
  Optimisation stopped before convergence. Try incrasing maximum number of iterations
Error in print(lapply(sag_fits, function(sag_fit) get_cost(sag_fit, X,  : 
  error in evaluating the argument 'x' in selecting a method for function 'print': Error in FUN(X[[i]], ...) : could not find function "get_cost"
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] glmnet_1.9-5        ggplot2_1.0.1       bigoptim_0.0.0.9000
[4] Matrix_1.2-1       

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6        lattice_0.20-31    digest_0.6.4       MASS_7.3-40       
 [5] grid_3.2.1         plyr_1.8.1         gtable_0.1.2       scales_0.2.3      
 [9] reshape2_1.2.2     labeling_0.2       proto_1.0.0        RColorBrewer_1.0-5
[13] tools_3.2.1        stringr_0.6.2      dichromat_2.0-0    munsell_0.4.2     
[17] colorspace_1.2-4  
> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions