<jupyter_start><jupyter_text>Mars Uniform Dataset<jupyter_code># Get everything in line before we start
import sys
sys.path.append('../../')
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from Optimisation import HSS
from Trajectory import *
import pandas as pdNo
#%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
# Assemble each core's dataset into one
'''
sets = [1,2,3,4]
ds = []
for i in sets:
    path = '../../Data/Mars/HSS_10_Alpha_' + str(i) + '.npy'
    z = np.load(path)
    ds.append(z)
ds = np.vstack(ds)
np.save('../../Data/Mars/HSS_10_Alpha_Full.npy', ds)
'''
ds = np.load('../../Data/Mars/HSS_10_Alpha_Full.npy')
ds.shape
# Decode each trajectory
plt.close('all')
model = Point_Lander_Drag()
prob = HSS(model, nsegs=10)
dpts = []
for traj in ds:
    tf, sb, cb, s, c = prob.Decode(traj)
    plt.plot(s[:,0], s[:,1])
    plt.axes().set_aspect('equal', 'datalim')
    s = np.vstack((s, sb[1:,:]))
    c = np.vstack((c, cb[1:,:]))
    dp = np.hstack((s, c))
    dpts.append(dp)
traj = np.vstack(dpts)
traj.shape

plt.xlabel('Cross-Range [m]')
plt.ylabel('Altitude [m]')
plt.title('Database of Optimal Control Trajectories')
#plt.savefig('../../Data/Figs/New/Traj.pdf', format='pdf',
        #transparent=True, bbox_inches='tight')
plt.show()

dpts = array(dpts)
dpts
shape = (8000, 11, 8)
ntraj, nnodes, nfeat = shape

trajs = np.empty(shape)
for i in range(ntraj):
    tf, sb, cb, s, c = prob.Decode(ds[i])
    t = np.linspace(0, tf, nnodes).reshape(nnodes,1)
    trajdp = hstack((s,c,t))
    trajs[i,:,:] = trajdp
np.save('../../Data/Mars/HSS_10_Traj', trajs)
trajs[:,0,1]
plt.close('all')
plt.plot(trajs[:,:,0], trajs[:,:,1],'.')
plt.show()
np.save('../../Data/Mars/HSS_10_Alpha_Full_Tensor', dpts)
dpts = np.load('../../Data/Mars/HSS_10_Alpha_Full_Tensor.npy')
dpts[0,:,4]
dptss = np.empty(shape=(0,7))
for traj in dpts:
    dptss = np.vstack((dptss,traj))
dptss
np.savetxt('../../Data/Mars/HSS_10_Alpha_Full_Tensor_Text',dptss)
plt.close('all')
for traj in dpts:
    plt.subplot(121)
    plt.plot(traj[:,0], traj[:,1],'.')
    plt.axes().set_aspect('equal', 'datalim')
    plt.subplot(122)
    plt.plot(traj[:,2], traj[:,3],'.')
plt.show()
from ML import MLP
net = MLP('../../Data/Mars/Nets/Mars_Regular_20x4')
data = np.load('../../Data/Mars/HSS_10_Alpha_dps.npy')
iin = [0,1,2,3,4]
iout = [5,6]
layers = [20]*4
net.build(data, iin, iout, layers)
import tensorflow as tf
sess = tf.Session()
dfp = pd.DataFrame(net.predict(data[:,iin], sess), columns = ['$u_p$', '$\\theta_p$'])
df = pd.DataFrame(data, columns = ['$x$', '$y$', '$v_x$', '$v_y$', '$m$', '$u$', '$\\theta$'])
from Trajectory import Point_Lander_Drag<jupyter_output><empty_output><jupyter_text>Controlled Trajectory<jupyter_code># Random state samples
test_si = data[]
test_si = data[np.random.choice(range(len(data)), 10),0:5]
si = test_si[0]
model = Point_Lander_Drag(si)
model.controller = Neural(model, 'HSS_10_Alpha', (20,4)).Control
# Time should not matter much
tf = 50
# The resolution of the integration
nnodes = 200
# We now propagate the model with the trained neural network
sl, cl = [], []
for si in test_si:
    s, c = model.Propagate.Neural(si, tf, nnodes, False)
    sl.append(s)
    cl.append(c)
plt.close('all')
for s,c in zip(sl, cl):
    gi = s[:,1]>0
    plt.figure(1)
    plt.plot(s[gi,0], s[gi,1])
    plt.axes().set_aspect('equal', 'datalim')
    plt.xlim(model.silb[0], model.siub[0])
    plt.ylim(model.slb[1], model.siub[1])
    plt.xlabel('Cross-Range [m]')
    plt.ylabel('Altitude [m]')
    plt.title('Neuro-Controlled Trajectories (20x4 Network)')
    #plt.savefig('../../Data/Figs/New/20x4_Traj.pdf', format='pdf',transparent=True, bbox_inches='tight')
    plt.figure(2)
    plt.plot(s[s[:,4]>6000,4])
    plt.ylabel('Mass [kg]')
    plt.xlabel('Node Index')
    plt.title('Fuel Expenditure (20x4 Network)')
    #plt.savefig('../../Data/Figs/New/20x4_Fuel.pdf', format='pdf',transparent=True, bbox_inches='tight')
    plt.figure(3)
    plt.plot(c[:,0],'.')
    plt.xlabel('Node Index')
    plt.ylabel('Thrust Throttle')
    plt.title('Control Profile (20x4 Network)')
    #plt.savefig('../../Data/Figs/New/20x4_Throttle.pdf', format='pdf',transparent=True, bbox_inches='tight')
    plt.figure(4)
    #plt.plot(s[:,2])
    plt.plot(s[:,3])
    plt.xlabel('Node Index')
    plt.ylabel('Velocity [m/s]')
    plt.title('Velocity Profile (20x4 Network)')
    #plt.savefig('../../Data/Figs/New/20x4_Throttle.pdf', format='pdf',transparent=True, bbox_inches='tight')
    
plt.show()
data.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2100656455142232, 'fraction_numerical': 0.027571115973741796, 'mean_word_length': 4.182539682539683, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '128643', 'license': 'MIT', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1921, 'n_words': 355, 'path': 'src/Notebook/Machine_Learning/Mars_Uniform.ipynb', 'repo_name': 'cisprague/Astro.IQ', 'size': '4570'}