DFP/extended_network.py
def dfp_network(input_shape, measurement_size, goal_size, action_size, num_timesteps, learning_rate):
        """
        Neural Network for Direct Future Predition (DFP)
        """

        # Perception Feature
        state_input = Input(shape=(input_shape))
        perception_feat = Convolution2D(32, 8, 8, subsample=(4,4), activation='relu')(state_input)
        perception_feat = Convolution2D(64, 4, 4, subsample=(2,2), activation='relu')(perception_feat)
        perception_feat = Convolution2D(64, 3, 3, activation='relu')(perception_feat)
        perception_feat = Flatten()(perception_feat)
        perception_feat = Dense(512, activation='relu')(perception_feat)

        # Measurement Feature
        measurement_input = Input(shape=((measurement_size,)))
        measurement_feat = Dense(128, activation='relu')(measurement_input)
        measurement_feat = Dense(128, activation='relu')(measurement_feat)
        measurement_feat = Dense(128, activation='relu')(measurement_feat)

        # Goal Feature
        goal_input = Input(shape=((goal_size,)))
        goal_feat = Dense(128, activation='relu')(goal_input)
        goal_feat = Dense(128, activation='relu')(goal_feat)
        goal_feat = Dense(128, activation='relu')(goal_feat)

        concat_feat = merge([perception_feat, measurement_feat, goal_feat], mode='concat')

        measurement_pred_size = measurement_size * num_timesteps # 3 measurements, 6 timesteps

        action_stream = []
        for i in range(action_size):
            action_stream.append(Dense(measurement_pred_size, activation='relu')(concat_feat))

        avg = Average()(action_stream)

        expectation_stream = Dense(measurement_pred_size, activation='relu')(concat_feat)

        prediction_list = []
        for i in range(action_size):
            prediction_list.append(merge([Subtract()([action_stream[i], avg]), expectation_stream], mode='sum'))

        model = Model(input=[state_input, measurement_input, goal_input], output=prediction_list)

        adam = Adam(lr=learning_rate)
        model.compile(loss='mse', optimizer=adam)
        model.summary()
        return model

        Neural Network for Direct Future Predition (DFP)
        
Neural Network for Direct Future Predition (DFP)
Neural Network for Direct Future Predition ( DFP )
def dfp_network(input_shape, measurement_size, goal_size, action_size, num_timesteps, learning_rate):
        state_input = Input(shape=(input_shape))
        perception_feat = Convolution2D(32, 8, 8, subsample=(4,4), activation='relu')(state_input)
        perception_feat = Convolution2D(64, 4, 4, subsample=(2,2), activation='relu')(perception_feat)
        perception_feat = Convolution2D(64, 3, 3, activation='relu')(perception_feat)
        perception_feat = Flatten()(perception_feat)
        perception_feat = Dense(512, activation='relu')(perception_feat)
        measurement_input = Input(shape=((measurement_size,)))
        measurement_feat = Dense(128, activation='relu')(measurement_input)
        measurement_feat = Dense(128, activation='relu')(measurement_feat)
        measurement_feat = Dense(128, activation='relu')(measurement_feat)
        goal_input = Input(shape=((goal_size,)))
        goal_feat = Dense(128, activation='relu')(goal_input)
        goal_feat = Dense(128, activation='relu')(goal_feat)
        goal_feat = Dense(128, activation='relu')(goal_feat)
        concat_feat = merge([perception_feat, measurement_feat, goal_feat], mode='concat')
        measurement_pred_size = measurement_size * num_timesteps 
        action_stream = []
        for i in range(action_size):
            action_stream.append(Dense(measurement_pred_size, activation='relu')(concat_feat))
        avg = Average()(action_stream)
        expectation_stream = Dense(measurement_pred_size, activation='relu')(concat_feat)
        prediction_list = []
        for i in range(action_size):
            prediction_list.append(merge([Subtract()([action_stream[i], avg]), expectation_stream], mode='sum'))
        model = Model(input=[state_input, measurement_input, goal_input], output=prediction_list)
        adam = Adam(lr=learning_rate)
        model.compile(loss='mse', optimizer=adam)
        model.summary()
        return model
def dfp_network ( input_shape , measurement_size , goal_size , action_size , num_timesteps , learning_rate ) : state_input = Input ( shape = ( input_shape ) ) perception_feat = Convolution2D ( 32 , 8 , 8 , subsample = ( 4 , 4 ) , activation = 'relu' ) ( state_input ) perception_feat = Convolution2D ( 64 , 4 , 4 , subsample = ( 2 , 2 ) , activation = 'relu' ) ( perception_feat ) perception_feat = Convolution2D ( 64 , 3 , 3 , activation = 'relu' ) ( perception_feat ) perception_feat = Flatten ( ) ( perception_feat ) perception_feat = Dense ( 512 , activation = 'relu' ) ( perception_feat ) measurement_input = Input ( shape = ( ( measurement_size , ) ) ) measurement_feat = Dense ( 128 , activation = 'relu' ) ( measurement_input ) measurement_feat = Dense ( 128 , activation = 'relu' ) ( measurement_feat ) measurement_feat = Dense ( 128 , activation = 'relu' ) ( measurement_feat ) goal_input = Input ( shape = ( ( goal_size , ) ) ) goal_feat = Dense ( 128 , activation = 'relu' ) ( goal_input ) goal_feat = Dense ( 128 , activation = 'relu' ) ( goal_feat ) goal_feat = Dense ( 128 , activation = 'relu' ) ( goal_feat ) concat_feat = merge ( [ perception_feat , measurement_feat , goal_feat ] , mode = 'concat' ) measurement_pred_size = measurement_size * num_timesteps action_stream = [ ] for i in range ( action_size ) : action_stream . append ( Dense ( measurement_pred_size , activation = 'relu' ) ( concat_feat ) ) avg = Average ( ) ( action_stream ) expectation_stream = Dense ( measurement_pred_size , activation = 'relu' ) ( concat_feat ) prediction_list = [ ] for i in range ( action_size ) : prediction_list . append ( merge ( [ Subtract ( ) ( [ action_stream [ i ] , avg ] ) , expectation_stream ] , mode = 'sum' ) ) model = Model ( input = [ state_input , measurement_input , goal_input ] , output = prediction_list ) adam = Adam ( lr = learning_rate ) model . compile ( loss = 'mse' , optimizer = adam ) model . summary ( ) return model
Neural Network for Direct Future Predition (DFP)
Neural Network for Direct Future Predition ( DFP )
"""
        Neural Network for Direct Future Predition (DFP)
        """ # Perception Feature # Measurement Feature # Goal Feature # 3 measurements, 6 timesteps
input_shape
measurement_size
goal_size
action_size
num_timesteps
learning_rate