Exemple #1
0
def hist(infile):
    d = Dist(infile)
    angles = []

    for key in d.get_angles().keys():
        for ang in d.get_angles(key).split()[5:]:
            angles.append(float(ang))

    plt.hist(angles)
    plt.title(infile)
    plt.show(block=False)
Exemple #2
0
 def __init__(self, dry_run=False, args=None):
     self.ok_code = 0
     self.requires = []
     self.apt_pkgs = []
     self.provides = []
     self.distro = Dist()
     self.dry_run = dry_run
     self.args = args
     self.scriptname = os.path.basename(__file__)
     if args and not dry_run:
         # action = args.subparser_name
         self.log(self.__class__.__name__)
     self.now = datetime.datetime.now().strftime('%y-%m-%d-%X')
Exemple #3
0
# hyperparameters
class Config:
    batch_size = 1  # has to be 1


lr = 0.02
vis_iter = 50
epochs = 20000

# make environment and get environment details
env = gym.make('Nodeworld-v0')
num_states = int(env.observation_space.high - env.observation_space.low + 1)
num_acts = int(env.action_space.n)

# make matrix of distributions and their respective optimizers
Z = [[Dist(K=10, requires_grad=True) for _ in range(num_acts)]
     for _ in range(num_states)]
optimizers = [[
    torch.optim.Adam(Z[s][a].parameters(), lr=lr) for a in range(num_acts)
] for s in range(num_states)]

π = Model(LinearPolicy, env,
          3e-4)  # this is essentially a random π, and it never gets optimized

# get obseration tuples from random agent
storage = Storage(Config)
s = env.reset()
for _ in range(1000):
    with torch.no_grad():
        a = π(s)
    s2, r, d, _ = env.step(a)
Exemple #4
0
                      owner,
                      usernum,
                      itemnum,
                      consumed_items,
                      batch_size=args.batch_size,
                      n_workers=1)

sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))

#['dcprec','ball', 'dist', 'distball']
if args.alg == 'dcprec':
    model = Dcprec(usernum, itemnum, args)
elif args.alg == 'ball':
    model = Ball(usernum, itemnum, args)
elif args.alg == 'dist' or args.alg == 'distball':
    model = Dist(usernum, itemnum, args)
elif args.alg == 'fm':
    model = FM(usernum, itemnum, args)
else:
    model = None

sess.run(tf.initialize_all_variables())

best_iter = 0
best_valid_mrr = 1e-6
prev_valid_mrr = 1e-6

f = open(
    'out/%s/%s/%d_%g_%g_%g.txt' %
    (args.dataset, args.alg, args.latent_dimension, args.learning_rate,
     args.lambda1, args.margin), 'w')
Exemple #5
0
#!/usr/bin/env python

import math
import sys
import rospy
import tf.transformations as transform

from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry

from location import Location, necessary_heading
from dist import Dist

current_location = Location()
current_dists = Dist()

DELTA = .1
WALL_PADDING = .5

STRAIGHT = 0
LEFT = 1
RIGHT = 2
MSG_STOP = 3
RIGHTandSTRAIGHT = 4
LEFTandSTRAIGHT = 5


def init_listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber('/p3dx/base_pose_ground_truth', Odometry,
Exemple #6
0
from dist import Dist

x = Dist(True)

for i in range(2):
    print x.get_range()


Exemple #7
0
import torch

from dist import Dist
from visualize import *

epochs = 10000
lr = 0.05
batch_size = 64
vis_iter = 200

# make target distribution
P = Dist([.1, .3, .4, .1, .1], [-3, 3, 15, 10, -10], [1, 2, 3, 1, 5])
plot_dist(P, 'P', '#ff8200', (-20, 20))

# make training distribution
Q = Dist(K=10, requires_grad=True)
plot_dist(Q, 'Q', '#4A04D4', (-20, 20))

# make optimizer for training distribution
optimizer = torch.optim.Adam(Q.parameters(), lr=lr)

# run optimization steps on batches of output from target distribution
for epoch in range(int(epochs)):
    x = P.sample(batch_size)
    loss = torch.pow(Q(x) - P(x),
                     2).mean()  # MSE requires being able to calculate P(x)
    # loss = -Q.log_prob(x).mean()                                                # minimizing KL divergence doesn't, but it trains more slowly

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
Exemple #8
0
import torch

from dist import Dist
from visualize import *

lr = 0.05
epochs = 10000
vis_iter = 100

# next value distribution
z2 = Dist([0.2, 0.3, 0.5], [3, 7, 12], [1, 2, 1])
plot_dist(z2, 'Z\'', '#0df')

# approximate bellman definition of current value distribution
# assuming deterministic rewards
z = 3 + (0.99 * z2)
plot_dist(z, 'Z', '#00f')

# target network to fit to the bellman value distribution
Q = Dist(K=10, requires_grad=True)
optimizer = torch.optim.Adam(Q.parameters(), lr=lr)

for epoch in range(int(epochs)):
    x = z.sample(10)
    loss = -Q.log_prob(x).mean()

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

    if epoch % vis_iter == vis_iter - 1:
Exemple #9
0
 def __init__(self, *args, **kwargs):
     self.dist = Dist()
     super().__init__(*args, **kwargs)
     self.apt_pkgs = ['phpmyadmin']
Exemple #10
0
from sensor_msgs.msg import LaserScan  #to receive the laser data
from gazebo_msgs.msg import ModelStates  #for receiving position
from location import Location, necessary_heading  #importing the location class and its function
from dist import Dist  #import the distance class from distance file
import tf.transformations as transform  #import transformation to calculate euler angles
import sys  #provides functions and variables used to manipulate different parts of the Python runtime environment.
global tx1, ty1, tx2, ty2, tx3, ty3  #declaring global variables for the goals
tx1 = 0  #intialization of global variables
ty1 = 0
tx2 = 0
ty2 = 0
tx3 = 0
ty3 = 0

current_location = Location()  #initializing an object of location class
current_dists = Dist()  #initializing an object of distance class

delta = .1  #max acceptance level for location error
WALL_PADDING = .5  #min to be maintained from the distance

STRAIGHT = 0  #states for the direction
LEFT = 1
RIGHT = 2
MSG_STOP = 3


def init_listener(
):  #function to intialise the node and subscribe to different topics
    rospy.init_node('mini_project', anonymous=True)
    rospy.Subscriber('gazebo/model_states', ModelStates, location_callback)
    rospy.Subscriber('scan', LaserScan, sensor_callback)