R/projection_C.R

Defines functions projection_C

Documented in projection_C

projection_C<-function(lambda,family=c("rectangle","nonnegative"),input,bound=c(-1,1)){
  x<-input/lambda
  out<-numeric()
  if(family=="rectangle"){
    for (j in 1:length(x)){
      if(x[j]<=bound[1]){
        out[j]<-bound[1]
      }else if (x[j]>=bound[2]){
        out[j]<-bound[2]
      }else{
        out[j]<-x[j]
      }
    }
  }
  if(family=="nonnegative"){
    out<-x
    out[which(x<0)]<-0
  }
  return(lambda*out)
}

Try the sharpPen package in your browser

Any scripts or data that you put into this service are public.

sharpPen documentation built on April 3, 2025, 7:10 p.m.