def timing_analysis(PV_str, curr_iter, t): PV_df = pd.read_csv(PV_str) PV = PV_df['Data'].tolist() responseMeasurementsObject = analyse.ResponseMeasurements(PV, t) rt = responseMeasurementsObject.riseTime st = responseMeasurementsObject.settlingTime os = responseMeasurementsObject.overshoot st_index = responseMeasurementsObject.settlingTimeIndex return [rt, st, os, st_index]
def getSetPoint(self): """ This method gets the set point of a given signal Args: - PV = signal to use to get set point Returns: - set point / target signal """ SP = analyse.ResponseMeasurements(self.PV, self.t).sp.sp return SP
2.81558045148153e62, 9.16930673102975e71, 1.68628748250276e81, 2.40236028415562e90, ] tf = signal.TransferFunction(num, den) tfs, _ = distort_tf.gen_tfs(num_facs=[1.0,1.2,1.4], a0_facs=[0.8], a1_facs=[0.7,0.8,1.2], a2_facs=[1.05,1.1,1.2], all_combos=False) # get initial output of initial signal and use to generate a target set point init_PV = distort_tf.getTransferFunctionOutput(tf,init_OP,t) sp = analyse.ResponseMeasurements(init_PV, t).sp.sp # run PSO tests in parallel with multiprocessing pso_objs = multiprocessing.Manager().list() jobs = [] test_nums = [test+1 for test in range(len(tfs))] direcs = [directory + '/test_{}'.format(test_num) for test_num in test_nums] for tf, direc in zip(tfs, direcs): if os.path.exists(direc) == False: os.mkdir(direc) p = multiprocessing.Process(target=run_test, args=(direc, tf, t, init_OP, n,
def __init__(self, t, PV=None, cost_function_label=None, st_importance_factor=None, SP=None): self.t = t self.PV = PV self.cost_function_label = cost_function_label # set factor by which want settling time to be larger/smaller than mean # squared error. Only (and must) specify if using s_mse+st cost_f: self.st_importance_factor = st_importance_factor self.SP = SP # num points at end of signal output to average over to find steady state: self.n_steady_state = 5 # find steady state and off indices if self.PV[-1] <= (2 * np.mean(self.PV[:5])): # signal has fallen at end for i in range(int(len(self.PV) / 2), int(len(self.PV))): if self.PV[i] >= (2 * np.mean(self.PV[:5])): self.index_signal_off = i break else: # signal never settles self.index_signal_off = int(len(self.PV)) # go back e.g. 10 points and use that to set steady state start_index = self.index_signal_off - 10 end_index = self.index_signal_off - 5 self.y_ss = np.mean(self.PV[start_index:end_index]) # steady stae # find more accurately where index turned off for i in range(int(len(self.PV) - 1), 0, -1): if self.PV[i] >= (0.95 * self.y_ss): # signal is within 5% of steady state self.index_signal_off = i break else: # signal has not fallen to 0 self.y_ss = np.mean(PV[-self.n_steady_state:]) self.num_points = int(len(self.PV)) self.measurements = get_fopdt_params.ResponseMeasurements( self.PV, self.t) self.index_signal_on = self.measurements.inflectionTimeIndex if self.cost_function_label == 'mSE': if self.SP is None: print('ERROR: To evaluate MSE, need to provide a set point to \ cost object. Please provide a set point (in the form of a \ step function)') self.costEval = self.__getMeanSquaredError(self.SP) elif self.cost_function_label == 'st': responseMeasurementsObject = analyse.ResponseMeasurements( self.PV, self.t, SP=self.SP) self.settlingTime = responseMeasurementsObject.settlingTime self.settlingTimeCost = self.settlingTime self.costEval = self.settlingTimeCost elif cost_function_label == 'mSE+st': self.mseCost = self.__getMeanSquaredError(self.SP) responseMeasurementsObject = analyse.ResponseMeasurements( self.PV, self.t, SP=self.SP) self.settlingTime = responseMeasurementsObject.settlingTime self.settlingTimeCost = self.settlingTime self.costEval = self.mseCost + self.settlingTimeCost elif cost_function_label == 's_mse+st': self.mse = self.__getMeanSquaredError(self.SP) responseMeasurementsObject = analyse.ResponseMeasurements( self.PV, self.t, SP=self.SP) self.settlingTime = responseMeasurementsObject.settlingTime self.settlingTimeCost = self.st_importance_factor * self.settlingTime # scale st to some importance factor self.costEval = (self.settlingTimeCost * self.mse) / (self.settlingTimeCost + self.mse) elif cost_function_label == 'mse+st+os': self.mseCost = self.__getMeanSquaredError(self.SP) * 10**3 responseMeasurementsObject = analyse.ResponseMeasurements( self.PV, self.t, SP=self.SP) self.settlingTime = responseMeasurementsObject.settlingTime self.overShoot = abs( responseMeasurementsObject.overshoot) * 10**(-10) self.costEval = self.mseCost + self.settlingTime + self.overShoot elif cost_function_label == 'zlpc': beta = 0.9 # set beta parameter responseMeasurementsObject = analyse.ResponseMeasurements( self.PV, self.t, SP=self.SP) self.overShoot = responseMeasurementsObject.overshoot self.riseTime = responseMeasurementsObject.riseTime self.settlingTime = responseMeasurementsObject.settlingTime self.mse = self.__getMeanSquaredError(self.SP) self.costEval = ((1-math.exp(-beta)) * \ (self.overShoot + (self.mse))) + ((math.exp(-beta)) * \ (self.settlingTime - self.riseTime)) else: print('Must specify cost function to use!')