优化算法代码部分

1、mini-bacth:

在一个简单的神经网络上的对比:

(Batch)Gradient Descent:

X = data_input
Y = labels
parameters = initialize_parameters(layers_dims)
for i in range(0, num_iterations):
    # Forward propagation
    a, caches = forward_propagation(X, parameters)
    # Compute cost.
    cost = compute_cost(a, Y)
    # Backward propagation.
    grads = backward_propagation(a, caches, parameters)
    # Update parameters.
    parameters = update_parameters(parameters, grads)

Stochastic Gradient Descent(SGD),即每次只将m个的一个样本放入网络中训练:

X = data_input
Y = labels
parameters = initialize_parameters(layers_dims)
for i in range(0, num_iterations):
    for j in range(0, m):
        # Forward propagation
        a, caches = forward_propagation(X[:,j], parameters)
        # Compute cost
        cost = compute_cost(a, Y[:,j])
        # Backward propagation
        grads = backward_propagation(a, caches, parameters)
        # Update parameters.
        parameters = update_parameters(parameters, grads)

 

 

mini-batch:

mini-batch的两部分:

- Shuffling and Partitioning are the two steps required to build mini-batches 
- Powers of two are often chosen to be the mini-batch size, e.g., 16, 32, 64, 128.

def random_mini_batches(X, Y, mini_batch_size=64, seed=0):
    """
    Creates a list of random minibatches from (X, Y)

    Arguments:
    X -- input data, of shape (input size, number of examples)
    Y -- true "label" vector (1 for blue dot / 0 for red dot), of shape (1, number of examples)
    mini_batch_size -- size of the mini-batches, integer

    Returns:
    mini_batches -- list of synchronous (mini_batch_X, mini_batch_Y)
    """

    np.random.seed(seed)  # To make your "random" minibatches the same as ours
    m = X.shape[1]  # number of training examples
    mini_batches = []

    # Step 1: Shuffle (X, Y),将m个样本的顺序随机化
    permutation = list(np.random.permutation(m))
    shuffled_X = X[:, permutation]
    shuffled_Y = Y[:, permutation].reshape((1, m))

    # Step 2: Partition (shuffled_X, shuffled_Y). Minus the end case.
    num_complete_minibatches = math.floor(m / mini_batch_size)  # number of mini batches of size mini_batch_size in your partitionning
    for k in range(0, num_complete_minibatches):
        mini_batch_X = shuf
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Apollo是Apollo自动驾驶平台中的一个重要组成部分,它包含了一系列的路径规划和优化算法。关于路径优化,通常涉及实时路径调整以适应复杂的驾驶环境,如避开障碍物、最小化行驶时间和保持舒适性等。 在Apollo的路径优化算法代码中,可能会使用以下技术: 1. **A*搜索**:这是一种启发式搜索算法,用于寻找两点之间的最短路径。在路径规划中,A*可能被用来计算从起点到目标的最优路径,同时考虑了实时传感器数据和地图信息。 2. **Dijkstra算法**或**Floyd-Warshall算法**:用于查找两点之间的最短路径,可能在预处理阶段被用来生成一个静态的路径图,然后在实时路径规划中查询。 3. **动态窗口路线追踪(Dynamic Window Approach, DWA)**:一种常用的车辆路径跟踪算法,根据车辆的运动模型和感知信息,动态调整车辆的行驶速度和方向。 4. **避障优化**:使用局部路径规划(Local Path Planning, LPP)方法,比如RRT(快速树)、PRM(概率 roadmap)等,结合传感器数据来避免碰撞。 5. **多目标优化**:可能包括最小化时间、距离、能源消耗以及舒适性等目标,通过多目标粒子群优化(Multi-Objective Particle Swarm Optimization, MOSPSO)或其他优化算法来平衡这些因素。 6. **实时调度和预测**:考虑到其他交通参与者的行为和预测,进行路径优化以确保安全和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值