def aggregate(global_params, running_aggregate, aggregation_result):
    """
    add an aggregation result into a running total aggregate
    aggregation must be associative
    :global_params: global parameters object
    :running_aggregate: running top level AggregationResult
    :aggregation_result: new aggregation result to add
    :returns: running aggregate
    """
    running_centroids_ref = running_aggregate.get_ref('centroid_updates')
    agg_res_centroids_ref = aggregation_result.get_ref('centroid_updates')
    for i in range(global_params.num_centroids):
        for j in range(global_params.dims):
            running_centroids_ref[i][j] += agg_res_centroids_ref[i][j]
    running_count_ref = running_aggregate.get_ref('update_counts')
    agg_res_count_ref = aggregation_result.get_ref('update_counts')
    for i in range(global_params.num_centroids):
        running_count_ref[i] += agg_res_count_ref[i]
    return running_aggregate