Beispiel #1
0
def find_outdated(requirements):
    # Find specified versions in requirements.txt
    reqs = [ InstallRequirement.from_line(req) for req in requirements ]
    packages = [ req.name for req in reqs ]
    interact()

    # Determine latest versions from PyPi index
    jobs = [ gevent.spawn(lambda p: (p, find_versions(p)[0],), p) for p in packages ]
    gevent.joinall(jobs)
    available = [ job.value for job in jobs ]
    print available
Beispiel #2
0
def playaround():
    import pip
    from pip.index import PackageFinder
    from pip.req import InstallRequirement, RequirementSet

    req = InstallRequirement.from_line("django-hoptoad", None) 

    finder = PackageFinder(find_links=[], index_urls=["http://pypi.python.org/simple/"])
    ret = finder.find_requirement(req, False)
    print ret
    print type(ret)

    interact()
Beispiel #3
0
    def run(self):
        ret = interact.interact(
            self.bin.split(),
            self.code, self.timeout)

        ret = self.get_result(ret)
        self.check_expect(ret)
Beispiel #4
0
	def fit_interact_cfs(self, X, y, mode='uc', threshold=0,
			backward=True, look_ahead=1, **kwargs):
		cols1 = interact(X, y, threshold)
		cols2 = cfs(X, y, backward, look_ahead, mode)
		cols_set = set(cols1) | set(cols2)
		cols = list(cols_set)
		cols.sort()
		self.cols_ = cols
def main(argv):
    if len(argv) == 1:
        print("""Usage:
main start_date end_date
	where dates are in YYYY-MM-DD format""")
    else:
        cred = credentials.Certificate(
            '../../firebase_files/covid-spread-analyzer-firebase-adminsdk-hxchu-8c78edc7cd.json'
        )
        initialize_app(
            cred,
            {'databaseURL': 'https://covid-spread-analyzer.firebaseio.com/'})
        print("downloading from database")
        interact([None, "-d", argv[1], argv[2]])
        print("\nenriching data from database")
        update([None, argv[1], argv[2]])
        print("\nsaving data to database")
        interact([None, "-u"])
Beispiel #6
0
    def run(self):
        code = self.code
        for name in self.modules:
            code = "[%s].\n" % name + code  # load modules

        ret = interact.interact(self.bin.split(), code, self.timeout)

        ret = self.get_result(ret)
        self.check_expect(ret)
        for name in self.modules:
            os.remove("%s.pl" % name)
    def run(self):
        code = self.code
        for name in self.modules:
            code = "[%s].\n" % name + code  # load modules

        ret = interact.interact(
            self.bin.split(),
            code, self.timeout)

        ret = self.get_result(ret)
        self.check_expect(ret)
        for name in self.modules:
            os.remove("%s.pl" % name)
Beispiel #8
0
def train(nb_steps: int, env: Env, agent: Agent, start_obs: Arrayable):
    """Trains for one epoch.

    :args nb_steps: number of interaction steps
    :args env: environment
    :args agent: interacting agent
    :start_obs: starting observation

    :return: final observation
    """
    agent.train()
    agent.reset()
    obs = start_obs
    for _ in range(nb_steps):
        # interact
        obs, _, _ = interact(env, agent, obs)
    return obs
Beispiel #9
0
def evaluate(
        dt: float,
        epoch: int,
        env: Env,
        agent: Agent,
        eval_gap: float,  # noqa: C901
        time_limit: Optional[float] = None,
        eval_return: bool = False,
        progress_bar: bool = False,
        video: bool = False,
        no_log: bool = False,
        test: bool = False,
        eval_policy: bool = True) -> Optional[float]:
    """Evaluate agent in environment.

    :args dt: time discretization
    :args epoch: index of the current epoch
    :args env: environment
    :args agent: interacting agent
    :args eval_gap: number of normalized epochs (epochs divided by dt)
        between training steps
    :args time_limit: maximal physical time (number of steps divided by dt)
        spent in the environment
    :args eval_return: do we only perform specific evaluation?
    :args progress_bar: use a progress bar?
    :args video: log a video of the interaction?
    :args no_log: do we log results
    :args test: log to a different test summary
    :args eval_policy: if the exploitation policy is noisy,
        remove the noise before evaluating

    :return: return evaluated, None if no return is evaluated
    """
    log_gap = int(eval_gap / dt)
    agent.eval()
    if not eval_policy and isinstance(agent, OnlineAgent):
        agent.noisy_eval()
    agent.reset()
    R = None
    if eval_return:
        rewards, dones = [], []
        imgs = []
        time_limit = time_limit if time_limit else 10
        nb_steps = int(time_limit / dt)
        info(f"eval> evaluating on a physical time {time_limit}"
             f" ({nb_steps} steps in total)")
        obs = env.reset()
        iter_range = tqdm(range(nb_steps)) if progress_bar else range(nb_steps)
        for _ in iter_range:
            obs, reward, done = interact(env, agent, obs)
            rewards.append(reward)
            dones.append(done)
            if video:
                imgs.append(env.render(mode='rgb_array'))
        R = compute_return(np.stack(rewards, axis=0), np.stack(dones, axis=0))
        tag = "noisy" if not eval_policy else ""
        info(f"eval> At epoch {epoch}, {tag} return: {R}")
        if not no_log:
            if not eval_policy:
                log("Return_noisy", R, epoch)
            elif not video:  # don't log when outputing video
                if not test:
                    log("Return", R, epoch)
                else:
                    log("Return_test", R, epoch)
        if video:
            log_video("demo", epoch, np.stack(imgs, axis=0))

    if not no_log:
        specific_evaluation(epoch, log_gap, dt, env, agent)
    return R
Beispiel #10
0
	def fit_interact(self, X, y, threshold=0):
		self.cols_ = interact(X, y, threshold)
Beispiel #11
0
 
 clog = np.log10(p)
 cmin = np.log10(0.1)
 cmax = np.log10(5)
 if clog<cmin: clog = cmin
 if clog>cmax: clog = cmax
 cindex = (clog - cmin)/(cmax - cmin)
 color = cmap_borange(cindex)
 
 for ef, f in enumerate(f_array[:]):
     fsq = np.sqrt(f)
     finv = 1/f
     #fsqinv = np.sqrt(finv)
     
     if case==0:
         x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, fsq*B_.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, (x*0.5/np.sqrt(p)).si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
     elif case==1:
         x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, fsq*B_.si.value, phi.rad, finv*V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
     elif case==2:
         x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B_.si.value, phi.rad, f*V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
     elif case==3:
         x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B_.si.value, phi.rad, V.si.value, theta.rad, finv*Tenc.si.value, finv*T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
     
     stream = {}
     stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
     stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
     
     plt.sca(ax[ep][ef])
     plt.plot(stream['x'][0]/(fsq*B_), stream['x'][1]/(fsq*B_), '.', color=color, ms=3, alpha=0.02)
     plt.gca().set_aspect('equal')
     
Beispiel #12
0
# Richard Darst, May 2009

"""If you do 'import fitz.interactnow', it will do a better code.interact()
"""

import interact
interact.interact(stackLevel=2)

Beispiel #13
0
def phases(seed=8264):
    """"""
    # impact parameters
    M = 1e5*u.Msun
    B = 100*u.pc
    V = 100*u.km/u.s
    phi = coord.Angle(180*u.deg)
    #theta = coord.Angle(th*u.deg)
    Tenc = 1*u.Gyr
    T = 1*u.Gyr
    dt = 0.1*u.Myr
    rs = 0*u.pc
    
    # setup tube
    Nstar = 500
    wx = 5*u.kpc
    wy = 2*u.pc
    wz = 2*u.pc
    sx = 0*u.km/u.s
    
    np.random.seed(seed)
    x = (np.random.rand(Nstar) - 0.5) * wx
    y = (np.random.randn(Nstar) - 0.5) * wy
    z = (np.random.randn(Nstar) - 0.5) * wz
    vx = (np.random.randn(Nstar) - 0.5) * sx
    vy = (np.random.randn(Nstar) - 0.5) * sx
    vz = (np.random.randn(Nstar) - 0.5) * sx
    
    angles = [5, 18, 90]
    times = [0.01]
    
    for th in angles:
        theta = coord.Angle(th*u.deg)
        T = B**2*V*np.abs(np.sin(theta.rad))/(2*G*M)
        times += [T.to(u.Gyr).value]
    
    times += [4]
    times = np.array(times) * u.Gyr
    
    cmap_navy = mpl.colors.LinearSegmentedColormap.from_list('cmap_navy', [(0,'#78aadd'), (1,'#00187f')], N=256)
    
    plt.close()
    fig, ax = plt.subplots(5, 3, figsize=(10,10), sharex=True)
    
    for et, T in enumerate(times):
        for ea, th in enumerate(angles):
            theta = coord.Angle(th*u.deg)
            p = (G*M*T/(B**2*V*np.abs(np.sin(theta.rad)))).decompose()
            print(et, T, p)
            
            x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
            stream = {}
            stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
            stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
                    
            plt.sca(ax[et][ea])
            clog = np.log10(p.value)
            cmin = np.log10(5e-2)
            cmax = np.log10(20)
            if clog<cmin: clog = cmin
            if clog>cmax: clog = cmax
            cindex = (clog - cmin)/(cmax - cmin)
            plt.plot(stream['x'][0], stream['x'][1], 'o', color=cmap_navy(cindex), ms=1.5, alpha=0.6)

            #plt.plot(stream['x'][0], stream['x'][1], 'o', color=cmap_navy(min(1.,p.value/7)), ms=1.5, alpha=0.6)
            
            txt = plt.text(0.9, 0.15, '$\psi$={:.2f}'.format(p), ha='right', va='center', transform=plt.gca().transAxes, fontsize='small')
            txt.set_bbox(dict(facecolor='w', alpha=0.7, ec='none'))
            
            if et==0:
                plt.title('$\\theta$ = {:.0f}$^\circ$'.format(th), fontsize='medium')
            
            if et==np.size(times)-1:
                plt.xlabel('x [pc]')
            
            if ea==0:
                plt.ylabel('y [pc]')
            
            if ea==np.size(angles)-1:
                plt.ylabel('T = {:.2f}'.format(T), labelpad=20, fontsize='small', rotation=270)
                plt.gca().yaxis.set_label_position('right')
            
    
    plt.tight_layout(h_pad=0.1, w_pad=0.15)
    plt.savefig('../plots/freespace_phases.png')
    plt.savefig('../plots/freespace_phases.pdf')
Beispiel #14
0
def scaling_norm(seed=473):
    """"""
    
    # impact parameters
    M = 1e5*u.Msun
    B = 100*u.pc
    V = 100*u.km/u.s
    phi = coord.Angle(180*u.deg)
    theta=coord.Angle(45*u.deg)
    Tenc = 1*u.Gyr
    T = 1*u.Gyr
    dt = 0.05*u.Myr
    rs = 0*u.pc
    
    # setup tube
    Nstar = 500
    wx = 5*u.kpc
    wy = 2*u.pc
    wz = 0*u.pc
    sx = 0*u.km/u.s
    
    np.random.seed(seed)
    x = (np.random.rand(Nstar) - 0.5) * wx
    y = (np.random.randn(Nstar) - 0.5) * wy
    z = (np.random.randn(Nstar) - 0.5) * wz
    vx = np.zeros(Nstar)*u.km/u.s
    vy = np.zeros(Nstar)*u.km/u.s
    vz = np.zeros(Nstar)*u.km/u.s
    
    # nonscaled
    x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
    stream0 = {}
    stream0['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream0['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
    
    # scaling
    Nf = 10
    f1_array = np.logspace(np.log10(0.2),np.log10(10),Nf)
    f2_array = np.logspace(np.log10(0.1),np.log10(5),Nf)
    f3_array = np.logspace(np.log10(np.sqrt(0.1)),np.log10(np.sqrt(5)),Nf)
    sigma_x_mt = np.zeros(Nf)
    sigma_v_mt = np.zeros(Nf)
    sigma_x_mv = np.zeros(Nf)
    sigma_v_mv = np.zeros(Nf)
    sigma_x_vt = np.zeros(Nf)
    sigma_v_vt = np.zeros(Nf)
    
    for e, f in enumerate(f1_array):
        finv = 1/f
        x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, finv*Tenc.si.value, finv*T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
        stream = {}
        stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
        stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
        
        sigma_x_mt[e] = np.linalg.norm(stream['x']-stream0['x'])/Nstar
        sigma_v_mt[e] = np.linalg.norm(stream['v']-stream0['v'])/Nstar
        
        f = f2_array[e]
        x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B.si.value, phi.rad, f*V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
        stream = {}
        stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
        stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
        
        sigma_x_mv[e] = np.linalg.norm(stream['x']-stream0['x'])/Nstar
        sigma_v_mv[e] = np.linalg.norm(stream['v']-stream0['v'])/Nstar
        
        f = f3_array[e]
        x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, f*V.si.value, theta.rad, f*Tenc.si.value, f*T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
        stream = {}
        stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
        stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
        
        sigma_x_vt[e] = np.linalg.norm(stream['x']-stream0['x'])/Nstar
        sigma_v_vt[e] = np.linalg.norm(stream['v']-stream0['v'])/Nstar
    
    print(sigma_v_mt)
    print(sigma_v_mv)
    print(sigma_v_vt)
    
    dblue = mpl.cm.Blues(0.9)
    mblue = mpl.cm.Blues(0.7)
    lblue = mpl.cm.Blues(0.5)
    
    plt.close()
    fig, ax = plt.subplots(2,1,figsize=(8,8), sharex=True)
    
    plt.sca(ax[0])
    plt.plot(1/f1_array, sigma_x_mt, '-', color=lblue, lw=6)
    plt.plot(f2_array, sigma_x_mv, '-', color=mblue, lw=4)
    plt.plot(f3_array**2, sigma_x_vt, color=dblue, lw=2)
    
    plt.ylabel('$\left< \Sigma_x\\right>$ [pc]')
    
    plt.sca(ax[1])
    plt.plot(1/f1_array, sigma_v_mt, '-', color=lblue, lw=6)
    plt.plot(f2_array, sigma_v_mv, '-', color=mblue, lw=4)
    plt.plot(f3_array**2, sigma_v_vt, color=dblue, lw=2)
    
    #plt.xlabel('f')
    plt.gca().set_yscale('log')
    plt.xlabel('Fastness')
    plt.ylabel('$\left< \Sigma_v \\right>$ [km s$^{-1}$]')
    
    plt.tight_layout()
    plt.savefig('../plots/scaling_norm.png')
Beispiel #15
0
def scaling(seed=98, f=2):
    """"""
    
    # impact parameters
    M = 1e5*u.Msun
    B = 100*u.pc
    V = 100*u.km/u.s
    phi = coord.Angle(180*u.deg)
    theta=coord.Angle(45*u.deg)
    Tenc = 1*u.Gyr
    T = 10*u.Gyr
    dt = 0.1*u.Myr
    rs = 0*u.pc
    
    # setup tube
    Nstar = 500
    wx = 5*u.kpc
    wy = 2*u.pc
    wz = 0*u.pc
    sx = 0*u.km/u.s
    
    np.random.seed(seed)
    x = (np.random.rand(Nstar) - 0.5) * wx
    y = (np.random.randn(Nstar) - 0.5) * wy
    z = (np.random.randn(Nstar) - 0.5) * wz
    vx = np.zeros(Nstar)*u.km/u.s
    vy = np.zeros(Nstar)*u.km/u.s
    vz = np.zeros(Nstar)*u.km/u.s
    
    # limits
    print('dense:{:.2g} << 1'.format(rs/B))
    print('fast: {:.2g} << 1'.format((G*M/(V**2*B)).decompose()) )
    print('thin: {:.2g} << 1'.format((np.sqrt(wy**2 + wz**2)/B).decompose()) )
    print('long: {:.2g} >> 1'.format((wx/B).decompose()) )
    print('cold: {:.2g} << 1'.format((sx/V).decompose()) )
    
    x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
    stream1 = {}
    stream1['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream1['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
    
    finv = 1/f
    fsq = np.sqrt(f)
    
    x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, finv*Tenc.si.value, finv*T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
    
    stream2 = {}
    stream2['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream2['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)

    x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, B.si.value, phi.rad, f*V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
    
    stream3 = {}
    stream3['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream3['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)

    x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, f*V.si.value, theta.rad, f*Tenc.si.value, f*T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)

    stream4 = {}
    stream4['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream4['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
    
    #x1, x2, x3, v1, v2, v3 = interact.interact(f*M.si.value, f*B.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)

    #stream5 = {}
    #stream5['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    #stream5['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
    
    dblue = mpl.cm.Blues(0.8)
    lblue = mpl.cm.Blues(0.5)
    ms = 2
    streams = [stream1, stream2, stream3, stream4]
    labels = ['M,T,V', '{0:.1f}M,T/{0:.1f},V'.format(f), '{0:.1f}M,T,{0:.1f}V'.format(f),'M,{0:.1f}T,{0:.1f}V'.format(f), '{0:.1f}M,sqrt{0:.1f}B'.format(f)]
    
    plt.close()
    fig, ax = plt.subplots(1,2,figsize=(10,5))
    
    for e, stream in enumerate(streams):
        color = mpl.cm.Blues(e/5+0.1)
        ms = 14 - 2*e
        
        plt.sca(ax[0])
        plt.plot(stream['x'][0], stream['x'][1], 'o', color=color, ms=ms)
    
        plt.sca(ax[1])
        plt.plot(stream['x'][0], stream['x'][2], 'o', color=color, ms=ms, label=labels[e])
    
    plt.sca(ax[0])
    plt.xlabel('x (pc)')
    plt.ylabel('y (pc)')
    
    plt.sca(ax[1])
    plt.xlabel('x (pc)')
    plt.ylabel('z (pc)')
    plt.legend(fontsize='small', loc=1)
    
    plt.tight_layout()
    plt.savefig('../plots/scaling_{:.1f}.png'.format(f))
Beispiel #16
0
def atlas_freespace(th=90, seed=51835):
    """"""
    
    # impact parameters
    M = 1e5*u.Msun
    B = 100*u.pc
    V = 100*u.km/u.s
    phi = coord.Angle(180*u.deg)
    theta=coord.Angle(th*u.deg)
    Tenc = 1*u.Gyr
    T = 1*u.Gyr
    dt = 0.1*u.Myr
    rs = 0*u.pc
    
    # setup tube
    Nstar = 500
    wx = 5*u.kpc
    wy = 0*u.pc
    wz = 0*u.pc
    sx = 0*u.km/u.s
    
    np.random.seed(seed)
    x = (np.random.rand(Nstar) - 0.5) * wx
    y = (np.random.randn(Nstar) - 0.5) * wy
    z = (np.random.randn(Nstar) - 0.5) * wz
    vx = (np.random.randn(Nstar) - 0.5) * sx
    vy = (np.random.randn(Nstar) - 0.5) * sx
    vz = (np.random.randn(Nstar) - 0.5) * sx
    
    x1, x2, x3, v1, v2, v3 = interact.interact(M.si.value, B.si.value, phi.rad, V.si.value, theta.rad, Tenc.si.value, T.si.value, dt.si.value, x.si.value, y.si.value, z.si.value, vx.si.value, vy.si.value, vz.si.value)
    stream = {}
    stream['x'] = (np.array([x1, x2, x3])*u.m).to(u.pc)
    stream['v'] = (np.array([v1, v2, v3])*u.m/u.s).to(u.km/u.s)
    
    ms = 8
    alpha = 0.3
    
    plt.close()
    fig, ax = plt.subplots(2,1,figsize=(8,8), sharex=True)
    plt.sca(ax[0])
    plt.plot(stream['x'][0], stream['x'][1], 'o', ms=ms, alpha=alpha)
    plt.ylabel('y (pc)')
    plt.xlim(-3000,3000)
    plt.ylim(-1100,20)
    plt.title('$\\theta$ = {:3.0f}$^\circ$'.format(th), fontsize='medium')
    
    # circle
    phi_ = np.linspace(0,2*np.pi,100)
    r = 0.05
    x0 = 0.3
    y0 = 0.65
    x = r*np.cos(phi_) + x0
    y = r*np.sin(phi_) + y0
    
    xp = r*np.cos(2*np.pi-theta.rad) + x0
    yp = r*np.sin(2*np.pi-theta.rad) + y0
    
    Ns = 9
    xs = np.linspace(-1.5*r, 1.5*r, Ns) + x0
    ys = np.zeros(Ns) + y0
    
    plt.plot(x, y, '-', color='0.3', alpha=0.5, lw=2, transform=fig.transFigure)
    plt.plot(xp, yp, 'o', color='0.3', ms=10, transform=fig.transFigure)
    plt.plot(xs, ys, 'o', color='tab:blue', ms=5, alpha=0.5, transform=fig.transFigure)
    
    plt.sca(ax[1])
    plt.plot(stream['x'][0], stream['x'][2], 'o', ms=ms, alpha=alpha)
    plt.ylabel('z (pc)')
    plt.xlabel('x (pc)')
    plt.xlim(-3000,3000)
    plt.ylim(-30,30)
    
    plt.tight_layout()
    plt.savefig('../plots/animations/angles/angles_{:03.0f}.png'.format(th/5))
Beispiel #17
0
            self.content = f"""ves: {Console}
ves.c_ves: {CVESClient}"""

        def __str__(self):
            return self.content

        def __repr__(self):
            return self.content

        def __call__(self, obj):
            return help(obj)

    import sys

    banner = '=' * 30 + '   ves client console   ' + '=' * 30
    banner += f"""
Python {sys.version} on {sys.platform}
Type "desc" for more information"""

    ves = Console()
    utils = Utils()
    desc = ConsoleDesc()
    main_load_cfg()

    print('entering ves console...')
    interact(
        banner=banner,
        exitmsg='exiting ves client console...',
        local=create_local(),
    )
    from agents.DDPG import DDPG
    agent = DDPG(env, "continousStateAction")  # continousStateAction imageStateContinuousAction

if selectedAgent == 3:
    # Create DDPG network agent
    obsSpace = env.observation_space.shape
    print("env.observation_space: ", obsSpace)
    from agents.DDPG import DDPG
    agent = DDPG(env, "imageStateContinuousAction")  # continousStateAction imageStateContinuousAction
    
"""
# run the simulation
"""
import interact as sim
num_episodes=500
sim.interact(agent, env, num_episodes, mode='train', file_output=file_output_train, renderSkip=100)

"""
# Plot training scores obtained per episode
"""
from visuals import plot_q_table, plot_score_from_file
plot_score_from_file(file_output_train, -300, 300, 1)
if selectedAgent == 0 or selectedAgent == 1:
    plot_q_table(agent.q_table)


"""
# save model and architecture to single file
# https://machinelearningmastery.com/save-load-keras-deep-learning-models/
"""
if selectedAgent == 2 or selectedAgent == 3:
Beispiel #19
0
        w = pickle.load(f)
        temp = None  # prevent pickling mem leak
    cv = KFold(len(y), n_folds=5)

    """ Exhaustive Search """
    params = params_lst[i_reduced]
    records = []
    for discrete in params["discrete"]:
        # discrete?
        if discrete:
            Xt = Xd
        else:
            Xt = Xc
        for t, it in enumerate(params["interact_threshold"]):
            # INTERACT
            cols = interact(Xd, y, it)
            cols.sort()
            if len(cols) == 0:
                continue
            X = Xt[:, cols]
            xgmats = []
            for train, valid in cv:
                Xcv = X[train]
                ycv = y[train]
                wcv = w[train] * float(test_size) / len(ycv)  # ASM normalization
                xgmats.append(xgb.DMatrix(Xcv, label=ycv, weight=wcv))

            for p, model_params in enumerate(ParameterGrid(params["param_grid"])):
                n_trees = model_params["n_trees"]
                pos_weight_ratio = model_params["pos_weight_ratio"]
                subparams = {}
Beispiel #20
0
        y = pickle.load(f)
        w = pickle.load(f)
        temp = None  # prevent pickling mem leak
    cv = KFold(len(y), n_folds=5)
    ''' Exhaustive Search '''
    params = params_lst[i_reduced]
    records = []
    for discrete in params["discrete"]:
        # discrete?
        if discrete:
            Xt = Xd
        else:
            Xt = Xc
        for t, it in enumerate(params["interact_threshold"]):
            # INTERACT
            cols = interact(Xd, y, it)
            cols.sort()
            if len(cols) == 0: continue
            X = Xt[:, cols]
            xgmats = []
            for train, valid in cv:
                Xcv = X[train]
                ycv = y[train]
                wcv = w[train] * float(test_size) / len(
                    ycv)  # ASM normalization
                xgmats.append(xgb.DMatrix(Xcv, label=ycv, weight=wcv))

            for p, model_params in enumerate(
                    ParameterGrid(params["param_grid"])):
                n_trees = model_params["n_trees"]
                pos_weight_ratio = model_params["pos_weight_ratio"]