コード例 #1
0
ファイル: env.py プロジェクト: LunaDash/AAS-18-290-6DOF
    def show_stats(self):
        et = time() - self.last_time
        self.last_time = time()

        r_f = np.linalg.norm(self.stats['r_f'], axis=1)
        v_f = np.linalg.norm(self.stats['v_f'], axis=1)

        f = '{:6.2f}'
        print('Update Cnt = %d    ET = %8.1f   Stats:  Mean, Std, Min, Max' %
              (self.update_cnt, et))
        for k in self.keys:
            f = self.formats[k]
            v = self.stats[k]
            if k == 'thrust' or k == 'tracking_error' or k == 'norm_thrust' or k == 'attitude' or k == 'w':
                v = np.concatenate(v)
            v = np.asarray(v)
            if len(v.shape) == 1:
                v = np.expand_dims(v, axis=1)
            s = '%-8s' % (k)
            #print('foo: ',k,v)
            s += envu.print_vector(' |', np.mean(v, axis=0), f)
            s += envu.print_vector(' |', np.std(v, axis=0), f)
            s += envu.print_vector(' |', np.min(v, axis=0), f)
            s += envu.print_vector(' |', np.max(v, axis=0), f)
            print(s)
コード例 #2
0
    def show_episode(self, idx=0):

        traj = self.trajectory_list[idx]
        t = np.asarray(traj['time'])
        p = np.asarray(traj['position'])
        v = np.asarray(traj['velocity'])
        c = np.asarray(traj['thrust'])

        f1 = '{:8.1f}'
        f2 = '{:8.3f}'
        for i in range(t.shape[0]):

            s = 't: %6.1f' % (t[i])
            s += envu.print_vector(' |', p[i], f1)
            s += envu.print_vector(' |', v[i], f2)
            s += envu.print_vector(' |', c[i], f2)
            print(s)
コード例 #3
0
    def show_final_stats(self, type='final'):
        if type == 'final':
            print('Final Stats (mean,std,min,max)')
            idx = -1
        else:
            print('Initial Stats (mean,std,min,max)')
            idx = 0

        stats = {}
        keys = ['position', 'velocity', 'fuel', 'attitude', 'w', 'glideslope']
        formats = {
            'position': '{:8.1f}',
            'velocity': '{:8.3f}',
            'fuel': '{:6.2f}',
            'attitude': '{:8.3f}',
            'w': '{:8.3f}',
            'glideslope': '{:8.3f}'
        }

        for k in keys:
            stats[k] = []
        for traj in self.trajectory_list:
            for k in keys:
                v = traj[k]
                v = np.asarray(v)
                if len(v.shape) == 1:
                    v = np.expand_dims(v, axis=1)
                if k == 'attitude':
                    foo = self.attitude_parameterization.q2Euler321(v[idx])
                else:
                    foo = v[idx]
                stats[k].append(foo)

        for k in keys:
            f = formats[k]
            v = stats[k]
            s = '%-8s' % (k)
            s += envu.print_vector(' |', np.mean(v, axis=0), f)
            s += envu.print_vector(' |', np.std(v, axis=0), f)
            s += envu.print_vector(' |', np.min(v, axis=0), f)
            s += envu.print_vector(' |', np.max(v, axis=0), f)
            print(s)
コード例 #4
0
    def show_cum_stats(self):
        print('Cumulative Stats (mean,std,max,argmax)')
        stats = {}
        argmax_stats = {}
        keys = ['thrust', 'glideslope', 'sc_margin']
        formats = {
            'thrust': '{:6.2f}',
            'glideslope': '{:6.3f}',
            'sc_margin': '{:6.3f}'
        }
        for k in keys:
            stats[k] = []
            argmax_stats[k] = []
        for traj in self.trajectory_list:
            for k in keys:
                v = traj[k]
                v = np.asarray(v)
                if len(v.shape) == 1:
                    v = np.expand_dims(v, axis=1)
                wc = np.max(np.linalg.norm(v, axis=1))
                argmax_stats[k].append(wc)
                stats[k].append(np.linalg.norm(v, axis=1))

        for k in keys:
            f = formats[k]
            v = stats[k]
            v = np.concatenate(v)
            #v = np.asarray(v)
            s = '%-8s' % (k)
            #print('foo: ',k,v,v.shape)
            s += envu.print_vector(' |', np.mean(v), f)
            s += envu.print_vector(' |', np.std(v), f)
            s += envu.print_vector(' |', np.min(v), f)
            s += envu.print_vector(' |', np.max(v), f)
            argmax_v = np.asarray(argmax_stats[k])
            s += ' |%6d' % (np.argmax(argmax_v))
            print(s)