Singlevariate Model fitting for a Simulation Data without any prior i/o relation knowledge using Taylor Series Method
In this example we will talk about how we can fit a model/function in a single variate simulation data. In many practical cases, we get some observation data after changing an input variable and our aim is to find the relation between input and output. If we know the relation form atleast (like y=mx+c or y=d*sin(x)^2), then we can find the values of these coeefficients y,c or d by linear/non linear regression. But what if we dont know the relation form, we dont have any information about whether they follow exponential form or logarthim relation. Here is a trick which we are going to discuss in this example.
Taylor Series fit
Let i/o relation be represented by a function z=f(x). We assume here that f(x) is continuous and differentiable, which is generally the case with practical/real time systems. Now each such function can be represented using a taylor's series
\[ f(x) = \sum_n{b_n x^n} \] we will limit the summation to n=N
Since we know the data x and z=f(x), we can calculate the coefficients bi .
Let \[B=\left[\begin{array}{ccccc} b_0 & b_1 & b_2 & ... & b_N \end{array} \right]^T \] and \[ Xmat =\left[ \begin{array}{ccccc} 1 & x^1 & x^2 & ... & x^N \end{array} \right] \]
so \[ z=f(x)= Xmat B \]
This is also true when x is a column vector mx1 and contains m data points and z contains values of f at those m point.
So B can be calculated as \[B=Xmat^{-1} Z\]
function: taylorseriesfit()
Writing the function in matlab is very easy. we just need to follow the steps as explained above.
Since our function need to matrixs x and z, these will be input to the function and B will be the output of the function. We will take N=4 here. Increasing the value may result in accuracy of your fit.
Generation of Simulation Data
We will generate a sample Simulation data for our example. In real example, you will get this data from some experiment after changing an input parameter(x) and observing the output(z).
\[ z= x*B = B(1)+B(2)x+B(3)x^2+B(4)x^3+B(5)x^4 \] \[ z= 1+0.99x+0.50 x^2+0.14x^3+.07x^4 \]
Error
we can calculate the modelling error (MMSE) by comparing the actual output and the simulation output.
you will get something like
Final Observation
Now if we observe the coefficients and plot them with respect with n, we may guess the actual function. Fig1 represents such a graph for N=7 case.
like for this example, it looks like 1/n!, so this is an exponential relations. Well, if we can guess, it is good. But if we cannot, still we have a relation which is sufficient for all numerical purposes.
In this example we will talk about how we can fit a model/function in a single variate simulation data. In many practical cases, we get some observation data after changing an input variable and our aim is to find the relation between input and output. If we know the relation form atleast (like y=mx+c or y=d*sin(x)^2), then we can find the values of these coeefficients y,c or d by linear/non linear regression. But what if we dont know the relation form, we dont have any information about whether they follow exponential form or logarthim relation. Here is a trick which we are going to discuss in this example.
Taylor Series fit
Let i/o relation be represented by a function z=f(x). We assume here that f(x) is continuous and differentiable, which is generally the case with practical/real time systems. Now each such function can be represented using a taylor's series
\[ f(x) = \sum_n{b_n x^n} \] we will limit the summation to n=N
Since we know the data x and z=f(x), we can calculate the coefficients bi .
Let \[B=\left[\begin{array}{ccccc} b_0 & b_1 & b_2 & ... & b_N \end{array} \right]^T \] and \[ Xmat =\left[ \begin{array}{ccccc} 1 & x^1 & x^2 & ... & x^N \end{array} \right] \]
so \[ z=f(x)= Xmat B \]
This is also true when x is a column vector mx1 and contains m data points and z contains values of f at those m point.
So B can be calculated as \[B=Xmat^{-1} Z\]
function: taylorseriesfit()
Writing the function in matlab is very easy. we just need to follow the steps as explained above.
Since our function need to matrixs x and z, these will be input to the function and B will be the output of the function. We will take N=4 here. Increasing the value may result in accuracy of your fit.
function B= taylorseriesfit(x,z)Here x and z are column vectors representing data points.
Xmat=[ones(size(x)) x x.^2 x.^3 x^4];
B=Xmat\z;
Generation of Simulation Data
We will generate a sample Simulation data for our example. In real example, you will get this data from some experiment after changing an input parameter(x) and observing the output(z).
Calling the defined functionx=[0:0.1:1]';z=exp(x);
B=taylorseriesfit(x,z);You will get B as
disp(B);
B =Now your model is
1.0000
0.9988
0.5099
0.1400
0.0696
\[ z= x*B = B(1)+B(2)x+B(3)x^2+B(4)x^3+B(5)x^4 \] \[ z= 1+0.99x+0.50 x^2+0.14x^3+.07x^4 \]
Error
we can calculate the modelling error (MMSE) by comparing the actual output and the simulation output.
z_o = Xmat*B;
e=sqrt(sum((z-z_o).^2));
disp(e);
you will get something like
which is pretty good.e= 6.9400e-005
Final Observation
Now if we observe the coefficients and plot them with respect with n, we may guess the actual function. Fig1 represents such a graph for N=7 case.
Fig1 : b_i plotted versus i |
Packers Football Live
ReplyDeletePatriots NFL Game Live
Seahawks Football Live
Raiders NFL Game Live
Titans Game Live
ReplyDeleteChiefs Game Live Online
Watch Chiefs Game Live
Kansas City Chiefs Game Live
Chiefs NFL Game Live
Seahawks Football Live Online
Seahawks Football Game Live
Seahawks Game Live Online
2020 Seahawks Game Live Streaming
Objective C development companies
ReplyDeleteToptal is a marketplace for top Objective-C developers, engineers, programmers, coders, architects, and consultants. Top companies and start-ups choose Toptal Objective-C freelancers for their mission-critical software projects.
Unity game development companies
ReplyDeleteAppventurez has a team of game developers who are known for delivering unmatched gaming experience through their skills and knowledge. Moreover, our team of Unity app development provides a platform for developers to focus more on their skills.
wearable app development companies
ReplyDeleteWearable Technology has opened up a new space in the mobile industry. Devices such as Apple Watch, Android wear, Google Glass, Smart Watch, and healthcare wearables have taken the market by storm and their popularity is only growing with time.
SaaS Management Software
ReplyDeleteSaaS management is the business practice of proactively monitoring and managing the purchasing, onboarding, licensing, renewals, and offboarding of all the software-as-a-service (SaaS) applications within a company’s technology portfolio.
Developed in response to the unique attributes of SaaS applications in a business environment, SaaS management is quickly developing into a specialized practice for IT, Procurement, and business leaders.