# state_decoder=(nn.Relu(ds, 1024) >> nn.Reshape([16, 16, 4]) # >> nn.Convolution([3, 3, 32]) >> nn.Relu() # >> nn.Deconvolution([2, 2, 32]) >> nn.Relu() # >> nn.Convolution([3, 3, 32]) >> nn.Relu() # >> nn.Convolution([2, 2, 2]) >> nn.Flatten() >> nn.Bernoulli()), state_encoder=nn.IdentityVariance(), state_decoder=nn.IdentityVariance(), action_encoder=nn.IdentityVariance(), action_decoder=nn.IdentityVariance(), # prior={'prior_type': 'none'}, # prior={'prior_type': 'normal'}, # prior={'prior_type': 'lds'}, # prior={'prior_type': 'blds'}, prior={ 'prior_type': 'nnds', 'network': nn.Relu(ds + da, 200) >> nn.Relu(200) >> nn.Gaussian(ds) }, ), train=dict( num_epochs=4000, learning_rate=1e-3, batch_size=16, dump_every=1000, summary_every=50 / 2, beta_start=1.0, beta_rate=0, ), data=dict( num_rollouts=100, init_std=.2, ),
def train(out_dir, dim, seed, load_model=None): out_path = out_dir / 'models' if not (out_path).exists(): out_path.mkdir() boards = {} for round in DATA: for location in DATA[round]: for board_id in DATA[round][location]: if board_id not in boards: boards[board_id] = set() boards[board_id].add((round, location)) if load_model is None: sensor_models = { board_id: nn.Relu(100) >> nn.Relu(100) >> nn.Linear(dim) for board_id in boards # board_id: nn.Linear(3, dim) for board_id in boards } calibration_model = nn.Relu(dim + 3, args.hidden_size) >> nn.Relu( args.hidden_size) >> nn.Linear(2) split_model = SplitModel(sensor_models, calibration_model, log_dir=out_dir, lr=args.lr, batch_size=args.batch_size) else: split_model = joblib.load(load_model) data = {} print("Filtering: %s" % ignore) for board_id in boards: board_train = [] for round, location in boards[board_id]: if (round, location, board_id) in ignore: print("Removing: ", round, location, board_id) continue board_train.append(load(*(round, location, board_id))[0]) if len(board_train) > 0: print("Loaded board[%u]: %u" % (board_id, len(board_train))) board_train = pd.concat(board_train) board_train['board'] = board_id if board_id not in data: data[board_id] = [] data[board_id].append(board_train) data = [pd.concat(ds) for ds in data.values()] max_size = max([d.shape[0] for d in data]) for i in range(len(data)): d = data[i] if d.shape[0] < max_size: data[i] = d.append(d.sample(max_size - d.shape[0], replace=True)) data = pd.concat(data) def cb(model): with open(str(out_path / 'model_latest.pkl'), 'wb') as fp: joblib.dump(split_model, fp) print("Total data size:", data.shape) split_model.fit(data[sensor_features], data[env_features], data['board'], data[Y_features], dump_every=(out_dir / 'models' / 'model_latest.pkl', 1000), n_iters=args.num_iters, cb=cb) with open(str(out_path / 'model.pkl'), 'wb') as fp: joblib.dump(split_model, fp)
joblib.dump( ( board_id, Model(X_features).fit(train_data[X_features], train_data[Y_features]) ), fp ) if __name__ == "__main__": args = parse_args() fs = s3fs.S3FileSystem(anon=False) experiment_dir = Path(BUCKET_NAME) / args.experiment out_dir = experiment_dir / args.name features = X_features[:] for feature in args.ignore_feature: features.remove(feature) if args.model == 'subu': Model = SubuForest elif args.model == 'linear': Model = Linear elif args.model == 'nn-2': Model = lambda features, : NeuralNetwork(features, nn.Relu(len(features), 200) >> nn.Relu(200) >> nn.Linear(2)) elif args.model == 'nn-4': Model = lambda features: NeuralNetwork(features, nn.Relu(len(features), 500) >> nn.Relu(500) >> nn.Relu(500) >> nn.Relu(500) >> nn.Linear(2)) if args.level1: level1(out_dir, features) if args.level2: level2(out_dir, features) if args.level3: level3(out_dir, features, args.seed)
ds = 10 du = da = env.get_action_dim() horizon = 50 experiment = dict( experiment_name='vae', experiment_type='train_vae', env=env_params, model=dict( do=do, du=du, ds=ds, da=da, horizon=horizon, state_encoder=(nn.Reshape(do, [64, 64, 3]) >> nn.Convolution( [7, 7, 64], strides=(1, 1)) >> nn.Relu() >> nn.Convolution( [5, 5, 32], strides=(2, 2)) >> nn.Convolution([3, 3, 8], strides=(2, 2)) >> nn.Flatten() >> nn.Relu(256) >> nn.Gaussian(ds)), state_decoder=( nn.Relu(ds, 512) >> nn.Reshape([8, 8, 8]) >> nn.Deconvolution( [3, 3, 32]) >> nn.Deconvolution([5, 5, 64]) >> nn.Deconvolution([7, 7, 3]) >> nn.Flatten() >> nn.Bernoulli()), action_encoder=nn.IdentityVariance(variance=1e-4), action_decoder=nn.IdentityVariance(variance=1e-4), prior=sweep([ dict(prior_type='blds', smooth=True, time_varying=True), dict(prior_type='normal'), ], ['blds-tv-smooth', 'normal']), cost=dict(cost_type='quadratic', learn_stdev=sweep([False, True])), ),
if __name__ == "__main__": args = parse_args() out_dir = Path('results') / args.name out_dir.mkdir(exist_ok=True, parents=True) features = X_features[:] for feature in args.ignore_feature: features.remove(feature) if args.model == 'subu': Model = SubuForest elif args.model == 'linear': Model = Linear elif args.model == 'nn-2': Model = lambda features, : NeuralNetwork( features, nn.Relu(len(features), 200) >> nn.Relu(200) >> nn.Linear(2)) elif args.model == 'nn-4': Model = lambda features: NeuralNetwork( features, nn.Relu(len(features), 500) >> nn.Relu(500) >> nn.Relu(500) >> nn. Relu(500) >> nn.Linear(2)) if args.level1: level1(out_dir, features) if args.level2: level2(out_dir, features) if args.level3: level3(out_dir, features, args.seed)
# >> nn.Convolution([3, 3, 32]) >> nn.Relu() # >> nn.Flatten() >> nn.Relu(200) >> nn.Gaussian(ds)), # state_decoder=(nn.Relu(ds, 1024) >> nn.Reshape([16, 16, 4]) # >> nn.Convolution([3, 3, 32]) >> nn.Relu() # >> nn.Deconvolution([2, 2, 32]) >> nn.Relu() # >> nn.Convolution([3, 3, 32]) >> nn.Relu() # >> nn.Convolution([2, 2, 2]) >> nn.Flatten() >> nn.Bernoulli()), state_encoder=nn.IdentityVariance(), state_decoder=nn.IdentityVariance(), action_encoder=nn.IdentityVariance(), action_decoder=nn.IdentityVariance(), # prior={'prior_type': 'none'}, # prior={'prior_type': 'normal'}, # prior={'prior_type': 'lds'}, # prior={'prior_type': 'blds'}, prior={'prior_type': 'nnds', 'network': nn.Relu(ds + da, 200) >> nn.Relu(200) >> nn.Gaussian(ds)}, ), train=dict( num_epochs=4000, learning_rate=1e-4, batch_size=2, dump_every=50, summary_every=50 / 2, ), data=dict( num_rollouts=100, init_std=0.1, ), out_dir='s3://parasol-experiments/vae/reacher-noimage', # out_dir='temp2/pm-noimage', )