Beispiel #1
0
""" Import Utils modules """
from utils.ExtractSignal import ExtractSignalFromCSV
from utils.ResampleAndInterpolate import ResampleAndInterpolate

""" Import wanted module with every parent packages """
import DataFrom2Persons.Monovariate.Continuous.Linear.GrangerCausality as GC

""" Import signal from a .csv file """
filename = 'data_examples/2Persons_Monovariate_Continuous_data.csv'
print "\nLoading signals from csv files : ", filename,"\n"
x1 = ExtractSignalFromCSV(filename, columns = ['x1'])
x2 = ExtractSignalFromCSV(filename, columns = ['x2'])

# Resample and Interpolate data to have constant frequency
x1 = ResampleAndInterpolate(x1, rule='200ms', limit=5)
x2 = ResampleAndInterpolate(x2, rule='200ms', limit=5)

""" Define class attributes """
max_lag = 3 			# Define the maximum lag acceptable to estimate autoregressive models
criterion = 'bic'   	# Define the criterion to estimate the optimal number of lags to estimate autoregressive models
plot = True				# Authorize the plot of the results

""" Instanciate the class with its attributes """
print("\n")

try : 
	gc = GC.GrangerCausality(max_lag = max_lag, criterion = criterion, plot = plot)
except TypeError, err :
	print("TypeError in GrangerCausality constructor : \n" + str(err))
	sys.exit(-1)
Beispiel #2
0
N = 20             # number of samples
f = 1.0             # sinewave frequency (Hz)
Fs = 200            # sampling frequency (Hz)
n = np.arange(0,N)  # number of samples
# input time series
x = pd.DataFrame({'X':np.sin(2*3.14*f*n/Fs)})
y = pd.DataFrame({'Y':np.sin(2*3.14*2*f*n/Fs)})
'''
"""OR"""
""" Import signal from a .csv file """
filename = 'data_examples/2Persons_Monovariate_Continuous_data_2.csv'
x = ExtractSignalFromCSV(filename, columns=['x'], unit='s')
y = ExtractSignalFromCSV(filename, columns=['y'], unit='s')

# Resample and Interpolate data to have constant frequency
x = ResampleAndInterpolate(x, rule='500ms', limit=5)
y = ResampleAndInterpolate(y, rule='500ms', limit=5)
'''
"""OR"""
""" Import signal from a .mat file """
filename = 'data_examples/data_example_MAT.mat'
x = ExtractSignalFromMAT(filename, columns_index =[0,2], columns_wanted_names=['Time', 'GlobalBodyActivity0'])
y = ExtractSignalFromMAT(filename, columns_index =[10], columns_wanted_names=['GlobalBodyActivity1'])
'''
""" Plot input signals """
n = [float(i) / 2 for i in range(x.size)]  # create x axis values
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid(True)
ax.set_xlabel('Samples')
Beispiel #3
0
""" Import Utils modules """
from utils.ExtractSignal import ExtractSignalFromCSV
from utils.ResampleAndInterpolate import ResampleAndInterpolate
""" Import wanted module with every parent packages """
import DataFromManyPersons.Univariate.Continuous.Linear.ConditionalGrangerCausality as CGC
""" Import signal from a .csv file """
filename = 'data_examples/data_jouet_3.csv'
print "\nLoading signals from csv files : ", filename, "\n"
x1 = ExtractSignalFromCSV(filename, columns=['x1'])
x2 = ExtractSignalFromCSV(filename, columns=['x2'])
x3 = ExtractSignalFromCSV(filename, columns=['x3'])
x4 = ExtractSignalFromCSV(filename, columns=['x4'])
x5 = ExtractSignalFromCSV(filename, columns=['x5'])

# Resample and Interpolate data to have constant frequency
x1 = ResampleAndInterpolate(x1, rule='200ms', limit=5)
x2 = ResampleAndInterpolate(x2, rule='200ms', limit=5)
x3 = ResampleAndInterpolate(x3, rule='200ms', limit=5)
x4 = ResampleAndInterpolate(x4, rule='200ms', limit=5)
x5 = ResampleAndInterpolate(x5, rule='200ms', limit=5)
""" Define class attributes """
max_lag = 10  # Define the maximum lag acceptable to estimate autoregressive models
criterion = 'bic'  # Define the criterion to estimate the optimal number of lags to estimate autoregressive models
plot = True  # Authorize the plot of the results
""" Instanciate the class with its attributes """
print("\n")
try:
    cgc = CGC.ConditionalGrangerCausality(max_lag=max_lag,
                                          criterion=criterion,
                                          plot=plot)
except TypeError, err: