4

分割表であると私が信じているものを構築しようとすると、次のことを考慮してください。

dist = Parallelize[Table[RandomVariate[NormalDistribution[]], {100000}]];

dist2 = Rest@FoldList[0.95 # + #2 &, 0, dist];

dist3 = Rest@FoldList[0.95 # + Abs[#2] &, 0, dist];

dist4 = {dist2, dist3}\[Transpose]

q1 = Flatten[{Quantile[dist2, {1/3, 2/3}], Quantile[dist3, {1/3, 2/3}]}]

{-1.39001, 1.33851, 15.0327, 16.6757}

ここに画像の説明を入力

私がする必要があること:dist4の各要素について、それが属する下の9つのボックスで見る必要があります:

for example : {1.55191, 15.7189} belongs to 2   
                            1.55 belongs to 1 and 
                           15.71 belongs to 8  
So the intersection is 2.  

If や Switch を試しましたが、書くには長すぎます。これを自動的に行う方法はありますか?

4

4 に答える 4

3

私が質問を理解していれば、これでうまくいくと思います:

{a, b, c, d} = q1;
tbl = Range@9 ~Partition~ 3;

f[{x_, y_}] := tbl[[
  Which[x > b, 1, x > a, 2, x <= a, 3],
  Which[y < c, 1, y < d, 2, y >= d, 3]
  ]]

f /@ dist4 // Short
于 2011-10-22T23:40:10.897 に答える
2
y[t_] := Piecewise[{{7, t <  q1[[1]]}, {4, t <= q1[[2]]}}, 1];
x[t_] := Piecewise[{{0, t <  q1[[3]]}, {1, t <= q1[[4]]}}, 2];
{{##}, x[#1] + y[#2]} & @@@ dist4

または、おそらくBinLists! を使用して:

k = BinLists[dist4,
   {Join[{Min[dist4[[All, 1]]]}, q1[[1 ;; 2]], {Max[dist4[[All, 1]]]}]},
   {Join[{Min[dist4[[All, 2]]]}, q1[[3 ;; 4]], {Max[dist4[[All, 2]]]}]}
   ];

Flatten[Replace[
        Flatten[MapIndexed[{#1, #2} &, k, {2}], 1], {{x__}, t_} :>
           (Join[{#}, {9 - 3 First@t + Last@t}] & /@ {x}), {1}], 1]
于 2011-10-22T23:42:27.260 に答える
1

ステップ関数の使用を検討しましたか? スロット 8 の場合に出力を {3,2} にするか、実際には 8 にするかによって、実装が異なる場合があります。

g1[x_] := 
 Piecewise[{{1, x > 1.33851}, {2, 1.33851 >= x > -1.39001}, 3}]

g2[x_] := Piecewise[{{1, x < 15.0327}, {2, 15.0327 <= x < 16.6757}}, 3]

slotfn[{a_, b_}] := {g2[b], g1[a]}

slotnumber[{a_, b_}] := 3 g2[b] + g1[a]

ベリサリウスの実装が本当に同じなら削除します。私の非機能的な no-# バージョンでは、または のいずれかに 2 つの引数のみを渡すことが保証されていることに注意してslotfnくださいslotnumber

于 2011-10-22T23:49:11.670 に答える
1

別の制限仕様:

limits =
  {
   {.1, .15, .5, \[Infinity]},
   {1, 2, 3, \[Infinity]}
   };

cell[l_List] :=
 Table[
  Position[
    limits[[i]], _?(# > l[[i]] &), 1, 1
    ][[1, 1]], {i, 1, Length@l}]

cell[{.4, 1.5}]その後、降伏し{3, 2}ます。次の方法で変換できます。

(cell[{.4, 1.5}] - {0, 1})*{1, Length[limits[[1]]]} // Plus @@ # &

が得られ7ます。

于 2011-10-23T00:00:44.947 に答える