<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_out_of_sample_mds(boot_collection, ref_collection, ref_distance_matrix, index, dimensions, task=_fast_geo, rooted=False, **kwargs):
 """ index = index of the locus the bootstrap sample corresponds to - only important if using recalc=True in kwargs """

    fit = np.empty((len(boot_collection), dimensions))
    if ISPY3:
        query_trees = [PhyloTree(tree.encode(), rooted) for tree in boot_collection.trees]
        ref_trees = [PhyloTree(tree.encode(), rooted) for tree in ref_collection.trees]
    else:
        query_trees = [PhyloTree(tree, rooted) for tree in boot_collection.trees]
        ref_trees = [PhyloTree(tree, rooted) for tree in ref_collection.trees]
    for i, tree in enumerate(query_trees):
        distvec = np.array([task(tree, ref_tree, False) for ref_tree in ref_trees])
        oos = OutOfSampleMDS(ref_distance_matrix)
        fit[i] = oos.fit(index, distvec, dimensions=dimensions, **kwargs)
    return fit