ランダムリストのK番目に大きいアイテムを使用して、シンプレックスリストのK番目に大きいアイテムを置き換えます。これは、少なくともピークとトラフの配置が進む限り、結果の形状が元の形状と一致することを保証するはずです。
はそれを行うには、私がしたい:
- ソートシンプレックスリストを、
- ソートにそのリスト内のランダムなリスト
- 結果リストを作成し、各項目の元のインデックスのトラックを維持しながら、ソートされたランダムリストから各アイテムを順番に取り出し、ソートされたシンプレックスリスト内の対応するアイテムの元のインデックスの結果リスト内に配置することによって行われる。
厄介な部分は、ソートされたシンプレックス値の元のインデックスを含むリスト。元のシンプレックス値とそのインデックスを含む各項目を使って拡張リストを作成し、そのリストをシンプレックス値でソートすることが簡単な方法です。
もう1つのやり方では、インデックスを昇順[0,1,2,3、...]で含むリストから開始し、次にリストによってリストされるjava.util.Collections.sort compare()メソッドが元のsimplex_listからの適切な値を比較したjava.util.Comparatorを適用します。
simplex_list = [ 8, 10, 3, 2, 6, 20 ]
# Pair each simplex value with its index
augmented_simplex_list = [ [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] ]
# Sort the [email protected] items according to value
sorted_augmented_simplex_list = [ [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] ]
# Discard the value part of each item, leaving only the original
# list index
#
sorted_simplex_index_list = [ 3, 2, 4, 0, 1, 5 ]
# Sort the random list
random_list = [ 5, 7, 1, 8, 9, 4 ]
sorted_random_list = [ 1, 4, 5, 7, 8, 9 ]
# Take each item of sorted_random_list and place it at the index
# in the result list indicated by the corresponding item in
# the sorted_simplex_index_list. That is,
# sorted_random_list[0] goes to result_list[sorted_simplex_index_list[0]],
# sorted_random_list[1] goes to result_list[sorted_simplex_index_list[1]],
# and so on, giving:
#
result_list = [ 7, 8, 4, 1, 5, 9 ]
元シンプレックスリストの形状をしている:アプローチ「インデックスで増補シンプレックス値」を使用して、例えば
public in compare(Integer indexA, Integer indexB) {
return simplex_list.get(indexA).compareTo(simplex_list.get(indexB));
}
:それは次のようになります。
もちろん、拡張されたシンプレックスリストアプローチを使用すると、明示的にsorted_simple_index_listを作成することはできませんが、sorted_augmented_simplex_listからアイテムのインデックス部分を取得するだけです。
'Math.random()'を使って生成されたデータを含む配列をソートし、最も近いものをバイナリ検索すると、アルゴリズムの計算量がO(n^2)からO * log(n))。 – Palle
あなたは 'Math.abs(list [j] - simplexList [i])'ではないと確信していますか? –