Esempio n. 1
0
    def __init__(self,
                 sensor_models,
                 calibration_model,
                 lr=1e-4,
                 batch_size=20,
                 log_dir=None,
                 **kwargs):
        self.graph = T.core.Graph()
        self.log_dir = log_dir
        with self.graph.as_default():
            self.calibration_model = calibration_model
            self.board_ids = list(sensor_models.keys())
            self.board_map = {b: i for i, b in enumerate(self.board_ids)}
            self.sensor_map = sensor_models
            self.sensor_models = [
                sensor_models[board_id] for board_id in self.board_ids
            ]
            self.architecture = pickle.dumps(
                [sensor_models, calibration_model])
            self.batch_size = batch_size
            self.lr = lr

            self.learning_rate = T.placeholder(T.floatx(), [])
            self.sensors = T.placeholder(T.floatx(), [None, 3])
            self.env = T.placeholder(T.floatx(), [None, 3])
            self.board = T.placeholder(T.core.int32, [None])
            self.boards = T.transpose(
                T.pack([self.board,
                        T.range(T.shape(self.board)[0])]))
            self.rep = T.gather_nd(
                T.pack([
                    sensor_model(self.sensors)
                    for sensor_model in self.sensor_models
                ]), self.boards)
            self.rep_ = T.placeholder(T.floatx(),
                                      [None, self.rep.get_shape()[-1]])
            rep_env = T.concat([self.rep, self.env], -1)
            rep_env_ = T.concat([self.rep_, self.env], -1)
            self.y_ = self.calibration_model(rep_env)
            self.y_rep = self.calibration_model(rep_env_)
            self.y = T.placeholder(T.floatx(), [None, 2])
            self.loss = T.mean((self.y - self.y_)**2)
            self.mae = T.mean(T.abs(self.y - self.y_))
            T.core.summary.scalar('MSE', self.loss)
            T.core.summary.scalar('MAE', self.mae)
            self.summary = T.core.summary.merge_all()
            self.train_op = T.core.train.AdamOptimizer(
                self.learning_rate).minimize(self.loss)

        self.session = T.interactive_session(graph=self.graph)
Esempio n. 2
0
 def sample(self, num_samples=None):
     if num_samples is None:
         return self.value
     return T.pack([self.value for _ in range(num_samples)])
Esempio n. 3
0
 def _statistic(self, stat):
     return T.pack([stat(self.tensor) for _ in range(self.num)])