Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear all,
I'd like to use time series analysis for predicting a future value i.e. energy consumption in simuator but i don't know how to do it in c++.Can anyone guide me or give me some example?

thanks
Posted

Did you Google for?
A starting point could be Wikipedia's Time series[^] page.
 
Share this answer
 
Hi,
The best and faster way to do this is use a numeric software, like matlab.
if you want to implement it in c++, i advice you to use some existent forecast library.

You have a lot of models to forecast, such as auto regressive models (AR, ARX, ARMA, ARMAX, ARIMA, ...), fuzzy models, neural networks models, support vector machines models, markov chains, and so on...

This is just a simple model:
y(k)+a1y(k-1)+a2y(k-2)+...+any(k-n) = b1u(k)+b2u(k-1)+...+bmu(k-m)

Where y is your output and u is your input. 'a' and 'b' are coefficients that you can calculate them by minimizing some cost function.

Here is a example in c++ to calculate the future value (i did not tested it, there may be errors)

C++
double forecast(double *y, double *u, bouble *a, double b)
{
	double future_value = 0.0;
	
	//y to the instant k 
	future_value = b[0]*u[0]+b[1]*u[1]+...+b[m-1]*u[m-1]-a[0]*y[0]+a[1]*y[1]+...+a[n-1]*y[n-1];

	for(int i = 1; i < n; i++)
	{
		y[i] = y[i-1];
	}
	y[0] = future_value ;

	//I assume that the input array is updated before you call this function
}


Again, I suggest to use some numerical software that brings such algorithms implemented.

Otherwise, google is the best way to start

Best regards
Filipe Marques
 
Share this answer
 
thank you for all of your comments.At first i'm thinking to use matlab but my value got from network simulator(ns2).I think it will be tough to link these two program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900