Hello everyone,
I hereby attach the code file on notepad. I have been successful in
defining the cxx function statement for the gradient descent algorithm
using bold driver method.
However, after executing the function statement with the parameters,
Rstudio/google colab crashes.
Could anyone help me in fixing this?
Sincerely,
Ankit Chakraborty
Machine Learning Engineer, EEGRAB
library(Rcpp)
library(inline)
# and define our version in C++
src <- 'int theta0 = as<int>(ns);
int j = as<int>(ns1);
int rel_ch = as<int>(ns2);
int min_f = as<int>(ns22);
int oldval = as<int>(rup);
int dif = as<int>(ank);
int newval = as<int>(saha);
int niter = as<int>(nit);
Rcpp::NumericVector theta = as<NumericVector>(theta1);
Rcpp::NumericVector thetavec = as<NumericVector>(thetavector);
double tol = as<double>(xs);
double alpha = as<double>(rt);
while(rel_ch>tol) j=j+1; theta[j] = theta[j-1] - alpha *
(4*pow(theta[j-1],3)-9*pow(theta[j-1],2)); oldval = (pow(theta0,4) -
3*pow(theta0,3) + 2); newval = (pow(theta[j-1],4) - 3*pow(theta[j-1],3) + 2);
dif = newval - oldval; if(dif<0) alpha = alpha + 0.05* alpha ; else alpha =
alpha - 0.50* alpha; rel_ch = abs((dif)/(oldval)) ;
theta = theta[j];
thetavec = theta;
min_f = newval;
niter = j;
return wrap(theta);
return wrap(thetavec);
return wrap(min_f);
return wrap(niter);
'
al <- cxxfunction(signature(ns="integer", ns1="integer",ns2 = "integer", ns22 =
"integer", rup = "integer", ank = "integer", saha = "integer", nit =
"integer", theta1="NumericVector",thetavector="NumericVector",
xs="numeric",rt="numeric"),
body=src, plugin="Rcpp")
y <-0.00000001
y1 <-as.double(y)
al(10,1,1,0,0,0,0,0,0,0,y1,0.01)
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel