Click here to Skip to main content
13,829,868 members
Rate this:
Please Sign up or sign in to 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?

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Did you Google for?
A starting point could be Wikipedia's Time series[^] page.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)

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
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190114.1 | Last Updated 29 Mar 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100