def main(): 'main function' ctrlLimits = CtrlLimits() flightLimits = FlightLimits() llc = LowLevelController(ctrlLimits) setpoint = 2220 p_gain = 0.01 ap = FixedSpeedAutopilot(setpoint, p_gain, llc.xequil, llc.uequil, flightLimits, ctrlLimits) pass_fail = AirspeedPFA(60, setpoint, 5) ### Initial Conditions ### power = 0 # Power # Default alpha & beta alpha = deg2rad(2.1215) # Trim Angle of Attack (rad) beta = 0 # Side slip angle (rad) alt = 20000 # Initial Attitude Vt = 1000 # Initial Speed phi = 0 #(pi/2)*0.5 # Roll angle from wings level (rad) theta = 0 #(-pi/2)*0.8 # Pitch angle from nose level (rad) psi = 0 #-pi/4 # Yaw angle from North (rad) # Build Initial Condition Vectors # state = [VT, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] initialState = [ Vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power ] # Select Desired F-16 Plant f16_plant = 'morelli' # 'stevens' or 'morelli' tMax = 70 # simulation time def der_func(t, y): 'derivative function' der = controlledF16(t, y, f16_plant, ap, llc)[0] rv = np.zeros((y.shape[0], )) rv[0] = der[0] # speed rv[12] = der[12] # power lag term return rv passed, times, states, modes, ps_list, Nz_list, u_list = \ RunF16Sim(initialState, tMax, der_func, f16_plant, ap, llc, pass_fail, sim_step=0.1) print "Simulation Conditions Passed: {}".format(passed) # plot filename = None # engine_e.png plot2d(filename, times, [(states, [(0, 'Vt'), (12, 'Pow')]), (u_list, [(0, 'Throttle')])])
def simulate(self): clock = 0 self.file = open(self.data, "w") X, Y = update_data(self.N, self.file, clock, self, [], []) for i in range(self.iterations): self.next_iter() print(i, len(self.marked)) clock += self.dtime X, Y = update_data(self.N, self.file, clock, self, X, Y) plot2d(X, Y) self.file.close()
with open("data/" + DATASET + ".csv", 'rb') as rawcsv: # np.set_printoptions(threshold=np.inf, suppress=True) data_orig = csv.reader(rawcsv, delimiter=',') data, dates, wind = utils.format_data(data_orig) date_vector = dates[:, 0] date_vector *= 12.0 date_vector += 1 print(data.shape) print(date_vector.shape) plot.plot2d((date_vector, data[:, 1]), DATASET + "-temp-time", c="black", a=0.2) plot.plot2d((date_vector, data[:, 7]), DATASET + "-humidity-time", c="black", a=0.2) plot.plot2d((date_vector, wind), DATASET + "-winddir-time", c="black", a=0.2) plot.plot2d((date_vector, wind), DATASET + "-winddir-speed", c=data[:, 16], a=0.2) plot.plot2d((date_vector, wind), DATASET + "-winddir-moisture-time",
from sklearn import manifold, decomposition, cluster import plot import utils # Only looks at MDW cuz this is slow, # and MDW offers enough interesting things to see (or lack thereof) with open('data/MDW.csv', 'rb') as MDWcsv: # np.set_printoptions(threshold=np.inf, suppress=True) csv = csv.reader(MDWcsv, delimiter=',') data = utils.format_data(csv)[0] print("Using PCA, n=2") pca = decomposition.PCA(n_components=2) output = pca.fit_transform(data) plot.plot2d(tuple(output[::7].T), "humidity-pca", c=data[::7, 7], a=0.8) plot.plot2d(tuple(output[::7].T), "temperature-pca", c=data[::7, 1], a=0.8) print("Using PCA, n=3") pca = decomposition.PCA(n_components=3) output = pca.fit_transform(data) plot.plot3d_anim(tuple(output[::7].T), "humidity-pca3d", c=data[::7, 7], a=0.8) plot.plot3d_anim(tuple(output[::7].T), "temperature-pca3d", c=data[::7, 1], a=0.8) print("Using tSNE, n=2, p=100, training on [::7]")
(griewank, 0, (-100, 100), (0, 0))] table_data = [] for objective_function in objective_function_list: for topology in topology_list: for pso_variant in pso_variant_list: for influence_model in influence_model_list: solution, objective_function_value, error_value = pso.run(topology, pso_variant, influence_model, objective_function) table_data += [[objective_function[0].__name__, pso_variant, topology, str(influence_model), str(solution), objective_function_value, error_value]] print_table_data(table_data) if __name__ == "__main__": # main() plot2d(rosenbrock, [-0.7, 0.8]) plot2d(sphere, [-5, 5]) plot2d(rastrigin, [-5, 5]) plot2d(griewank, [-10, 10])
def main(): 'main function' ctrlLimits = CtrlLimits() flightLimits = FlightLimits() llc = LowLevelController(ctrlLimits) setpoint = 550 # altitude setpoint ap = FixedAltitudeAutopilot(setpoint, llc.xequil, llc.uequil, flightLimits, ctrlLimits) pass_fail = FlightLimitsPFA(flightLimits) pass_fail.break_on_error = False ### Initial Conditions ### power = 0 # Power # Default alpha & beta alpha = 0 # angle of attack (rad) beta = 0 # Side slip angle (rad) alt = 500 # Initial Attitude Vt = 540 # Initial Speed phi = 0 theta = alpha psi = 0 # Build Initial Condition Vectors # state = [VT, alpha, beta, phi, theta, psi, P, Q, R, pn, pe, h, pow] initialState = [Vt, alpha, beta, phi, theta, psi, 0, 0, 0, 0, 0, alt, power] # Select Desired F-16 Plant f16_plant = 'morelli' # 'stevens' or 'morelli' tMax = 15.0 # simulation time def der_func(t, y): 'derivative function for RK45' der = controlledF16(t, y, f16_plant, ap, llc)[0] rv = np.zeros((y.shape[0],)) rv[0] = der[0] # air speed rv[1] = der[1] # alpha rv[4] = der[4] # pitch angle rv[7] = der[7] # pitch rate rv[11] = der[11] # altitude rv[12] = der[12] # power lag term rv[13] = der[13] # Nz integrator return rv passed, times, states, modes, ps_list, Nz_list, u_list = \ RunF16Sim(initialState, tMax, der_func, f16_plant, ap, llc, pass_fail, sim_step=0.01) print("Simulation Conditions Passed: {}".format(passed)) # plot filename = None # longitudinal.png plot2d(filename, times, [ (states, [(0, 'Vt'), (11, 'Altitude')]), \ (u_list, [(0, 'Throttle'), (1, 'elevator')]), \ (Nz_list, [(0, 'Nz')]) \ ])