0

I know there are plenty of similar questions but I need to solve the problem specifically with Bernstein polynomials

I tried something like this:

library(pracma)

train <- rnorm(100)
test <- rnorm(50)

eCDF <- ecdf(train)

# squeeze eCDF support between 0 and 1
Fy <- function(y){
  b <- max(train)
  a <- min(train)
  eCDF((b-a)*y+a)
}

m <- min(test)
M <- max(test)
# squeeze points between 0 and 1
x_to_y <- function(x) return ((x-m)/(M-m))

# polynomial order
k = 10

x <- x_to_y(test)

# bernstein Args: function to be approximated, order, points to estimates
y <- bernstein(Fy,k, x)

plot(x, y)

At this point I get just points. It's not very clear to me... I thought Bernstein method should do some function smoothing but How?

I tried

lo <- loess(y~x)
plot(x,y)
lines(predict(lo), col='red', lwd=2)

but: 1. It doesn't work 2. It's kind of nonsense

Thank you for any help

  • 1
    Try creating a reproducable example, then you are more likely for people to help you. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Koot6133 Feb 05 '20 at 15:03
  • It should be ok now, thanks – Flavio Cannavò Feb 05 '20 at 21:06
  • 1
    I don't know what you expect. If you type `plot(x, Fy(x))` and then `lines(x, y)`, you can clearly see that `bernstein()` does fit your data points. Maybe you expect the function to return the coefficients of the Bernstein polynomials, too. Well, one could think about adding this functionality, but at the moment it doesn't. – Hans W. Feb 06 '20 at 08:06

0 Answers0