def __init__(self, master): self._job = None self.max_time = 500 # Create a container self.frame = Tkinter.Frame(master) self.master = master # Create 2 buttons self.kp = Tkinter.Scale(self.frame, from_=1., to=10., resolution=0.1, label="K ", command=self.resetparam) self.kp.pack() self.tau = Tkinter.Scale(self.frame, from_=1., to=10., resolution=0.1, label="τ ", command=self.resetparam) self.tau.pack() self.theta = Tkinter.Scale(self.frame, from_=1., to=9., resolution=0.5, label="θ", command=self.resetparam) self.theta.pack() self.fig = Figure((10, 5)) self.ax = self.fig.add_subplot(111) self.ax.set_xlim(0, 500) self.fig2 = Figure((10, 5)) self.ax2 = self.fig2.add_subplot(111) sig = Signal(1, 1, 2, numPlots=0) sig.sys_simulation() self.masterRS = RollingSignal() self.masterRS.load_model( sig, directory= '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/Model Validation/MIMO 1x1/Checkpoints/' ) self._roll_over(initial=True)
import control as control import numpy as np import pandas as pd from Signal import Signal import matplotlib.pyplot as plt import seaborn as sns path = '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/Model Validation/Paper Results 3.csv' df = pd.read_csv(path) df = df.loc[:, ~df.columns.str.contains('Unnamed')] df[df['tau_python'] > 1] = 0 sig = Signal(1, 1, 10, numPlots=0) sig.sys_simulation(stdev=5, order=1) disturbances = np.zeros((1000, 600)) sses = [] for i in range(0, 1000): #plt.figure(i,dpi=200) #plt.plot(sig.ySteps[i,:,0]) #plt.plot(sig.test_sequence,'k--',linewidth=1,label='Excitation') u = sig.test_sequence allY = np.zeros((600, 1)) # Iterate over each of the input dimensions # and add to the numerator array numTemp = [df['kp_true'][i]] denTemp = [1., -df['tau_true'][i]] thetas = [df['theta_true'][i]]
#plt.plot(delay_arr, corr) plt.title('Lag: ' + str(np.round(delay, 3)) + ' s ' + 'Real =' + str(title)) plt.xlabel('Lag') plt.ylabel('Correlation coeff') plt.show() for (inDimension, outDimension) in zip(inDims, outDims): start_time = time.time() sig = Signal(inDimension, outDimension, numTrials, numPlots=plots) uArray, yArray, tauArray, KpArray, thetaArray, train, test = sig.sys_simulation( disturbance=False, b_possible_values=[.01, .99], a_possible_values=[.01, .99], k_possible_values=[0, 1], not_prbs=True) ''' array=np.zeros(10000) i=0 for (i,(u1,y1)) in enumerate(zip(uArray,yArray)): z1 = y1-u1 for (j,(u2,y2)) in enumerate(zip(uArray,yArray)): z2 = y2-u2 array[i*100+j] = sum(scipy.signal.correlate(z1,z2,mode='full')) ''' print("--- %s seconds ---" % (time.time() - start_time)) # These two lines are for training the model based on nstep and the sig data
# These constants are also defined in the Signal module # Don't change here unless you also change them there numTrials = 1000 batchSize = 64 plots = 0 inDims = range(1, 6) outDims = range(1, 6) for (inDimension, outDimension) in zip(inDims, outDims): start_time = time.time() sig = Signal(inDimension, outDimension, numTrials, numPlots=plots) uArray, yArray, tauArray, KpArray, thetaArray, train, test = sig.sys_simulation( ) uArray = uArray[:, :, 0] yArray = yArray[:, :, 0] if inDimension == 1: np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/u_1x1.csv', uArray, delimiter=',') np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/y_1x1.csv', yArray, delimiter=',') np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/tau_1x1.csv',
""" import control as control import numpy as np import pandas as pd from Signal import Signal import matplotlib.pyplot as plt import seaborn as sns path = '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/Model Validation/Paper Results_order2.csv' df = pd.read_csv(path) df = df.loc[:, ~df.columns.str.contains('Unnamed')] sig = Signal(1, 1, 10, numPlots=0) sig.sys_simulation(stdev='variable', order=1) sses = [] for i in range(10, 20): plt.figure(i, dpi=200) #plt.plot(sig.ySteps[i,:,0]) plt.plot(sig.test_sequence, 'k--', linewidth=1) u = sig.test_sequence allY = np.zeros((600, 1)) # Iterate over each of the input dimensions # and add to the numerator array numTemp = [df['kp_real'][i], 0] denTemp = [1., -df['tau_real_1'][i], -df['tau_real_2'][i]] thetas = [df['theta_real'][i]]
# These constants are also defined in the Signal module # Don't change here unless you also change them there numTrials = 1000 plots = 10 inDims = range(1, 2) outDims = range(1, 2) for (inDimension, outDimension) in zip(inDims, outDims): start_time = time.time() sig = Signal(inDimension, outDimension, numTrials, numPlots=plots, stdev=5) uArray, yArray, tauArray, KpArray, thetaArray, train, test = sig.sys_simulation( b_possible_values=[.01, .99], a_possible_values=[.01, .99], k_possible_values=[0, 1], order=False, disturbance=False) uArray = uArray[:, :, 0] yArray = yArray[:, :, 0] np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/u_1x1.csv', uArray) np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/y_1x1.csv', yArray) np.savetxt( '/Users/RileyBallachay/Documents/Fifth Year/RNNSystemIdentification/MATLAB code/taus_1x1.csv', tauArray)
# These constants are also defined in the Signal module # Don't change here unless you also change them there numTrials = 100000 batchSize = 100 plots = 5 inDims = range(1,10,2) outDims = range(1,10,2) for (inDimension,outDimension) in zip(inDims,outDims): start_time = time.time() sig = Signal(inDimension,outDimension,numTrials,numPlots=plots) uArray,yArray,tauArray,KpArray,thetaArray,train,test = sig.sys_simulation(disturbance=False,k_possible_values=[0,1]) print("--- %s seconds ---" % (time.time() - start_time)) # These two lines are for training the model based on nstep and the sig data # Only uncomment if you want to train and not predict trainModel = Model() trainModel.train_model(sig,epochs=1000,batchSize=batchSize,saveModel=False,plotLoss=bool(plots!=0),plotVal=bool(plots!=0),trainConvolutional=False) print("--- %s seconds ---" % (time.time() - start_time)) ''' # In this case, since we are only loading the model, not trying to train it, # we can use function simulate and preprocess xData,yData = sig.MIMO_validation() # Initialize the models that are saved using the parameters declared above predictor = Model(nstep)
# These constants are also defined in the Signal module # Don't change here unless you also change them there numTrials = 1000 batchSize = 256 plots = 10 inDims = range(1,2) outDims = range(1,2) for (inDimension,outDimension) in zip(inDims,outDims): start_time = time.time() sig = Signal(inDimension,outDimension,numTrials,numPlots=plots) uArray,yArray,tauArray,KpArray,thetaArray,train,test = sig.sys_simulation(stdev=10,disturbance=False,b_possible_values=[.49,.51],a_possible_values=[.49,.51], k_possible_values=[0,1]) array=np.zeros(1000000) for (i,(u1,y1)) in enumerate(zip(uArray,yArray)): z1 = y1-u1 for (j,(u2,y2)) in enumerate(zip(uArray,yArray)): z2 = y2-u2 if i==j: array[i*100+j] = 1000 else: array[i*100+j] = sum(abs(scipy.signal.correlate(z1,z2,mode='full'))) index = np.argmin(array) plt.plot(yArray[int(index/1000)]-uArray[int(index/1000)]) plt.plot(yArray[int(index%1000)]-uArray[int(index%1000)],'k--')