Author(s): Borja V. Sorli Sanz - @borjavss
Other resources: coding process video recorded
In the mathematical field of numerical analysis, interpolation is a method of constructing new data points within the range of a discrete set of known data points.
Polynomial curves fitting points generated with a sine function
Red: 1st degree. Green: 2nd degree. Orange: 3rd degree. Blue: 4th degree polynomial.
In engineering and science, one often has a number of data points, obtained by sampling or experimentation, which represent the values of a function for a limited number of values of the independent variable. It is often required to interpolate (i.e. estimate) the value of that function for an intermediate value of the independent variable. This may be achieved by curve fitting or regression analysis.
Fitting of a noisy curve by an asymmetrical peak model, with an iterative process (Gauss Newton algorithm with variable damping factor ??).
Top: raw data and model. Bottom: evolution of the normalized sum of the squares of the errors.
A problem closely related to interpolation is the approximation of a complicated function by a simple function. Suppose the formula for some given function is known, but too complex to evaluate efficiently. A few known data points from the original function can be used to create an interpolation based on a simpler function.
Although we tend to think that using a simple function drives us to more interpolation errors, depending on the problem domain and the interpolation method used, the gain in simplicity is typically better than the resultant loss in accuracy.
In numerical analysis, polynomial interpolation is the interpolation of a given data set by a polynomial: given some points, find a polynomial which goes exactly through these points.
And, this is what we are going to do, we want to get our polynomial function based on these points:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | … | 25 |
| 0 | 5 | 25 | 60 | 110 | 180 | 275 | 400 | 555 | 671 | 750 | 790 | 810 | 810 | 810 | … | 810 |
based on a power conversion curve of a wind turbine (800kW), ENERCON E48.
Advanced methods like Newton interpolation or, directly, Lagrange polynomials could be used to get this goal. Nevertheless, we are going to create a simple artificial neural network (ANN) using R language and nnet package to get this polynomial interpolation. ### Unique hidden layer neural network to polynomial interpolation Some critics says Artificial neural networks (ANN) are more complex than simulators and they require more learning to fully operate and are more complicated to develop. We are going to show it as a simple example without do comparisons.
rm(list=ls()) #eliminating R environment previous values
powererror<-1 #initializing one variable
x<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
y<-c(0,0,5,25,60,110,180,275,400,555,671,750,790,810,810,810,810,810,810,810,810,810,810,810,810)
plot(x,y, col="blue", lwd=4, xlab="",ylab="") #plotting our data points
lines(x,y, col= "green", lwd=6) #plotting future desired line approximation
title(main="Power curve given by their points - Enercon E48 -", col.main="black", font.main=4)
title(ylab="Power (kW)"); title(xlab="Wind speed (m/s)")
Blue points are the given data (see previous table) and green line is the representation of our desired interpolation curve.
library(nnet) # we call the nnet CRAN library (it should be installed)
for(i in 1:100){ # we start a 100 iteration
temp<-nnet(x/20,y/800, size=8, linout=T, maxit=10000, abstol=1.0e-8, reltol=1.0e-12)
if(temp$value < powererror) {
powerfct <- temp
powererror <- powerfct$value
}
}; rm(i)
Although we start a 100 iteration for learning, it has a condition to stop the process when we get our purpose. Note two things: - Values are previously normalized - This ANN has only one hidden layer with 8 neurons in this one.
potencia <- function (velocidad){ # the income is the wind speed
potencia <- rep(0, length(velocidad)) #initializing power
for(i in 1:length(velocidad)){ # loop to see in what interval is the value
if((velocidad[i]>2) & (velocidad[i]<14)) #if wind speed is in correct interval
potencia[i] <- 800*predict(powerfct,velocidad[i]/20) #applying the ANN
if(velocidad[i]>=14) # if wind speed is outside desired interval
potencia[i]<-810
}
potencia # the returned value of the function
}
Once artificial neural network (ANN) is already created in previous point, the function to convert wind speed into power is written. Note that we de-normalized the ANN to get real values.
y_predicted<- potencia(x)
plot(y_predicted,y, col=rainbow(6), pch=3, lwd=15, ylab="Predicted Power (kW)", xlab="Given Power (kW)")
Always, all results should be tested. Remember that x is the vector of the wind speed values given by the previous data table. So, if we call the function created on point 3, by passing our x values (wind speed in m/s) we obtain our predicted power values. To compare it, we get plot predicted power in face of given effective power by data table. By obtaining a perfect straight line, we could claim perfect correlation.
To plot our new predicted power curve created by ANN, you can use the following chunk code:
plot(x,potencia(x), type="l", col="red",lwd=12, ylab="Power (kW)", xlab="Wind speed (m/s)")
title(main="Polynomial interpolation curve given by the ANN ", col.main="black", font.main=4)
The red curve show the results. The complete coding process video could be found online at https://www.youtube.com/watch?v=DCJY4jSxx80.
Artificial Neural Networks (ANN) could serve to create a polynomial interpolation by this prediction and classification power given on many intelligence artificial applications in recent days.