Skip to main content
Commonmark migration
Source Link

###Method #1

Method #1

###Method #2

Method #2

###Method #1

###Method #2

Method #1

Method #2

remove superfluous operation noted by the OP
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Unitize[Abs@Differences@s1[[AllSparseArray[Abs @ Differences @ s1[[All, 1]] - 1]]["AdjacencyLists"]1]["AdjacencyLists"]

Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
 
s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Unitize[Abs@Differences@s1[[All, 1]] - 1]]["AdjacencyLists"]

Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
 
s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Abs @ Differences @ s1[[All, 1]] - 1]["AdjacencyLists"]

Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
 
added 923 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

It looks like I'm late to the party but here is my approach. Common functions and data:

###Method #1

s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First
Split[%, @Abs[#[[1]] #- /.#2[[1]]] labels,< Length2 @&]

Join #}@@ &Riffle[%, /@{{"unoccupied s1middle"}}]
n
% =/. Lengthp @: s1;
jumps{x_ =..} SparseArray[Unitize[Abs@Differences@s1[[All,:> 1]]{x -/. 1]]["AdjacencyLists"]
labels, Length@p}
{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, {2}, {0}, {1}, {2}, {0, 0}, {1, 1}}

{{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}}, {{2}}, {{0}, {1}, {2}}, {{0, 0}, {1, 
   1}}}

{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, "unoccupied middle", {2},
  "unoccupied middle", {0}, {1}, {2}, "unoccupied middle", {0, 0}, {1, 1}}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, "unoccupied middle", {"top", 1}, "unoccupied middle", {"bottom", 1}, {"middle", 
  1}, {"top", 1}, "unoccupied middle", {"bottom", 2}, {"middle", 2}}

{6, 7, 10}

###Method #2

s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Unitize[Abs@Differences@s1[[All, 1]] - 1]]["AdjacencyLists"]

Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
 
{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, {2}, {0}, {1}, {2}, {0, 0}, {1, 1}}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, {"top", 1}, {"bottom", 1}, {"middle", 1}, {"top", 1}, {"bottom", 2}, {"middle", 2}}

{6, 7, 10}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, "unoccupied middle", {"top", 1}, "unoccupied middle", {"bottom", 1}, {"middle", 
  1}, {"top", 1}, "unoccupied middle", {"bottom", 2}, {"middle", 2}}

It looks like I'm late to the party but here is my approach.

s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Unitize[Abs@Differences@s1[[All, 1]] - 1]]["AdjacencyLists"]
 
{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, {2}, {0}, {1}, {2}, {0, 0}, {1, 1}}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, {"top", 1}, {"bottom", 1}, {"middle", 1}, {"top", 1}, {"bottom", 2}, {"middle", 2}}

{6, 7, 10}
Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, "unoccupied middle", {"top", 1}, "unoccupied middle", {"bottom", 1}, {"middle", 
  1}, {"top", 1}, "unoccupied middle", {"bottom", 2}, {"middle", 2}}

It looks like I'm late to the party but here is my approach. Common functions and data:

###Method #1

Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)

Split[%, Abs[#[[1]] - #2[[1]]] < 2 &]

Join @@ Riffle[%, {{"unoccupied middle"}}]

% /. p : {x_ ..} :> {x /. labels, Length@p}
{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, {2}, {0}, {1}, {2}, {0, 0}, {1, 1}}

{{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}}, {{2}}, {{0}, {1}, {2}}, {{0, 0}, {1, 
   1}}}

{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, "unoccupied middle", {2},
  "unoccupied middle", {0}, {1}, {2}, "unoccupied middle", {0, 0}, {1, 1}}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, "unoccupied middle", {"top", 1}, "unoccupied middle", {"bottom", 1}, {"middle", 
  1}, {"top", 1}, "unoccupied middle", {"bottom", 2}, {"middle", 2}}

###Method #2

s1 = Split @ trinarize[sampleSimulation, 0.9]  (* 0.9 is γ *)
s2 = {First @ # /. labels, Length @ #} & /@ s1
n = Length @ s1;
jumps = SparseArray[Unitize[Abs@Differences@s1[[All, 1]] - 1]]["AdjacencyLists"]

Clip[Ordering @ Join[Range@n, jumps], {1, n}, {1, n + 1}];
Append[s2, "unoccupied middle"][[%]]
 
{{1}, {0}, {1, 1}, {0, 0, 0}, {1}, {0, 0, 0, 0}, {2}, {0}, {1}, {2}, {0, 0}, {1, 1}}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, {"top", 1}, {"bottom", 1}, {"middle", 1}, {"top", 1}, {"bottom", 2}, {"middle", 2}}

{6, 7, 10}

{{"middle", 1}, {"bottom", 1}, {"middle", 2}, {"bottom", 3}, {"middle", 1}, {"bottom", 
  4}, "unoccupied middle", {"top", 1}, "unoccupied middle", {"bottom", 1}, {"middle", 
  1}, {"top", 1}, "unoccupied middle", {"bottom", 2}, {"middle", 2}}
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading