def learn(self):
        self.time_step += 1
        replay = self.memory.get_batch(BATCH_SIZE)
        bm_sd = np.asarray([data[0] for data in replay])
        bp = np.asarray([data[1] for data in replay])
        bloc = np.asarray([data[2] for data in replay])
        bs = np.asarray([data[3] for data in replay])
        ba = np.asarray([data[4] for data in replay])
        br = np.reshape(np.asarray([data[5] for data in replay]), [-1, 1])
        bs_ = np.asarray([data[6] for data in replay])
        bloc_ = np.asarray([data[7] for data in replay])
        bgm = np.zeros([BATCH_SIZE, self.m_dim, self.m_dim, 1])
        for batch in range(BATCH_SIZE):
            sd1 = bm_sd[batch]
            terrian_map = grid_map(sd1, self.m_dim, self.pixel_meter, bp[batch])
            bgm[batch, :, :, 0] = terrian_map.map_matrix
        blocm = np.zeros([BATCH_SIZE, self.att_dim*2+1, self.att_dim*2+1, 4])
        blocm_ = np.zeros([BATCH_SIZE, self.att_dim * 2 + 1, self.att_dim * 2 + 1, 4])
        for i in range(BATCH_SIZE):
            for j in range(self.att_dim*2+1):
                for k in range(self.att_dim*2+1):
                    blocm[i, j, k, :] = np.array([i, bloc[i, 0]-self.att_dim+j, bloc[i, 1]-self.att_dim+k, 0])
                    blocm_[i, j, k, :] = np.array([i, bloc_[i, 0] - self.att_dim + j, bloc_[i, 1] - self.att_dim + k, 0])

        self.sess.run(self.atrain, {self.S: bs, self.GM: bgm, self.LM: blocm})
        self.sess.run(self.ctrain, {self.GM: bgm, self.S: bs, self.LM: blocm, self.a: ba, self.R: br, self.S_: bs_, self.LM_: blocm_})
Example #2
0
def calSpec(wavelength, spotList, specBck, specSpot, omega, radius, inclination):
    """ calculate the spectrum
    TODO incorporate limb darkening in the weight calculation
    """
    # get the grid_map
    areaGrid, projAreaGrid, vGrid = grid_map(omega, radius, inclination)
    totalArea = projAreaGrid.sum()
    sMap = spot_map(spotList)
    # calculate the map
    NLat, NLon = areaGrid.shape
    spectrum = np.zeros_like(wavelength)
    for i in range(NLat):
        print(i)
        for j in range(NLon):
            if sMap[i, j] == 0:  # photosphere scenerio
                spec_i = projAreaGrid[i, j] / totalArea * \
                    dopplerShift(specBck['wavelength'],
                                 specBck['flux'],
                                 vGrid[i, j],
                                 wavelength)
            else:
                print('Spotty grid')
                spec_i = projAreaGrid[i, j] / totalArea * \
                    dopplerShift(specSpot['wavelength'],
                                 specSpot['flux'],
                                 vGrid[i, j],
                                 wavelength)
            spectrum += spec_i
    return spectrum
Example #3
0
 def __init__(self, map_dim, pixel_meter):
     self.t = 0
     self.map_dim = map_dim
     self.pixel_meter = pixel_meter
     self.map = grid_map(0, map_dim, pixel_meter, 0)
     self.state = array([
         0, 0, 3, 0.12, -0.08, 0, 1, 0, 0, 0, 0.2, -0.1, 0.15, -1.9, 1.5,
         -1.2
     ])
     self.state0 = array([
         0, 0, 3, 0.12, -0.08, 0, 1, 0, 0, 0, 0.2, -0.1, 0.15, -1.9, 1.5,
         -1.2
     ])
     self.r_obj = 20
Example #4
0
import grid_map as gm
import node_graph as ng

import operator


def update_v(rows, cols, nodes, v_data):
    color = 1
    for node in nodes:
        color = color + 1
        for line in node.space:
            for cell in line:
                v_data[cell.row, cell.col] = color


ROBOT_SIZE = 3
rows = 20
cols = 20
g = gm.grid_map(rows, cols)
g.init_map()
g.update_weight(ROBOT_SIZE)
graph = ng.node_graph(g)
nodes = graph.close
fig, ax = plt.subplots()
ax.set_aspect('equal')
v_data = np.zeros((rows, cols))
update_v(rows, cols, nodes, v_data)
#ax.pcolor(v_data,cmap=plt.cm.Reds,edgecolors='k')
ax.pcolor(v_data, edgecolors='k')
plt.show()
Example #5
0
 def map_reset(self, p, sd=random.randint(0, 100000)):
     self.map = grid_map(sd, self.map_dim, self.pixel_meter, p)
Example #6
0
from enum import Enum
import numpy as np
from dstar import dstar_planner
import matplotlib.pyplot as plt
from grid_map import grid_map


def update_v(rows, cols, map_data, v_data):
    for i in range(rows):
        for j in range(cols):
            v_data[i, j] = map_data[i][j].h


ROBOT_SIZE = 3

g = grid_map(100, 100)
g.init_map()
g.update_weight(ROBOT_SIZE)
dstar = dstar_planner(g)
dstar.add_start(g.map_data[0][0])
dstar.init_plan()
v_data = np.zeros((100, 100))
update_v(100, 100, g.map_data, v_data)

fig, ax = plt.subplots()
ax.set_aspect('equal')
ax.pcolor(v_data, cmap=plt.cm.Reds, edgecolors='k')
#print v_data
plt.show()