(*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 0, 0] NotebookDataLength[ 853713, 17297] NotebookOptionsPosition[ 846298, 17076] NotebookOutlinePosition[ 846769, 17095] CellTagsIndexPosition[ 846726, 17092] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Definitions ", Background->RGBColor[1, 0.9, 0.8]]], "Section", InitializationCell->True, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"StartPop", "::", "ussage"}], "\"\\""}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"StartPop", "[", RowBox[{"ngenes_", ",", "nn_", ",", "nd_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"mut", "=", "0.002"}], ",", "rrr"}], "}"}], ",", RowBox[{"StartPop", "[", RowBox[{"ngenes", ",", "nn", ",", "nd", ",", "mut_"}], "]"}]}], "]"}]}], ";", RowBox[{ RowBox[{"StartPop", "[", RowBox[{"ngenes_", ",", "nn_", ",", "nd_", ",", "mut_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "rrr", "}"}], ",", RowBox[{ RowBox[{"rrr", "=", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "/", "2"}], ",", RowBox[{"1", "/", "2"}]}], "}"}], "->", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ",", "ngenes"}], "]"}]}], ";", RowBox[{"Mutate", "[", RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"rrr", ",", RowBox[{"{", RowBox[{"nd", ",", "nn"}], "}"}]}], "]"}], ",", "mut", ",", "nd"}], "]"}]}]}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"StartPop", "[", RowBox[{ "ngenes_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "width_", ",", "\[Delta]_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"pList", ",", "x", ",", "x0"}], "}"}], ",", RowBox[{ RowBox[{"pList", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{ RowBox[{"-", "4"}], "/", "width"}], RowBox[{"(", " ", RowBox[{"x", "-", "x0"}], ")"}]}], "]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}], "/", "2"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"x0", ",", RowBox[{"Max", "[", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"\[Delta]", " ", "/", "2"}], ")"}]}], RowBox[{"(", RowBox[{"ngenes", "-", "1"}], ")"}]}]}], "}"}], "]"}], ",", RowBox[{"Min", "[", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}], "/", "2"}], ",", RowBox[{ RowBox[{"\[Delta]", "/", "2"}], " ", RowBox[{"(", " ", RowBox[{"ngenes", "-", "1"}], ")"}]}]}], "}"}], "]"}], ",", RowBox[{"Min", "[", RowBox[{"{", RowBox[{"\[Delta]", ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}], "/", RowBox[{"Max", "[", RowBox[{"{", RowBox[{"1", ",", RowBox[{"ngenes", "-", "1"}]}], "}"}], "]"}]}]}], "}"}], "]"}]}], "}"}]}], "]"}], "//", "Chop"}]}], ";", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "pList", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "nn"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}]}], "]"}]}], ";", RowBox[{ RowBox[{"StartPop", "[", RowBox[{ "ngenes_", ",", "propAdapt_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "width_", ",", "\[Delta]_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", "pop1", ",", "pop2"}], "}"}], ",", RowBox[{ RowBox[{"pop1", "=", RowBox[{"StartPop", "[", RowBox[{ RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}], ",", "nn", ",", "nd", ",", "mut", ",", "width", ",", "\[Delta]"}], "]"}]}], ";", RowBox[{"pop2", "=", RowBox[{"StartPop", "[", RowBox[{ RowBox[{"ngenes", "-", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], ",", "nn", ",", "nd", ",", "mut"}], "]"}]}], ";", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Join", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop1", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"pop2", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}]}], "]"}]}]}]}], "Code", CellChangeTimes->{{3.564216702778266*^9, 3.5642167069043283`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"StartPopdX", "[", RowBox[{ "ngenes_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "\[Delta]x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "rrr", "}"}], ",", RowBox[{ RowBox[{"rrr", "=", RowBox[{"Join", "[", RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"0", ",", RowBox[{"Floor", "[", RowBox[{"ngenes", "/", "2"}], "]"}]}], "]"}], ",", RowBox[{"ConstantArray", "[", RowBox[{"1", ",", RowBox[{"Ceiling", "[", RowBox[{"ngenes", "/", "2"}], "]"}]}], "]"}]}], "]"}]}], ";", "\n", RowBox[{"Mutate", "[", RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"rrr", ",", RowBox[{"{", RowBox[{ RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}], ",", "nn"}], "}"}]}], "]"}], ",", "mut"}], "]"}]}]}], "]"}]}], ";"}]], "Code", Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"StartPopdX", "[", RowBox[{ "ngenes_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "width_", ",", "\[Delta]_", ",", "\[Delta]x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"pList", ",", "x", ",", "x0"}], "}"}], ",", "\n", RowBox[{ RowBox[{"pList", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{ RowBox[{"-", "4"}], "/", "width"}], RowBox[{"(", " ", RowBox[{"x", "-", "x0"}], ")"}]}], "]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"x0", ",", RowBox[{"-", " ", FractionBox[ RowBox[{"\[Delta]", " ", RowBox[{"(", RowBox[{"ngenes", " ", "-", "\[Delta]x"}], ")"}]}], "2"]}], ",", " ", FractionBox[ RowBox[{"\[Delta]", " ", RowBox[{"(", RowBox[{"ngenes", " ", "-", "\[Delta]x"}], ")"}]}], "2"], ",", "\[Delta]"}], "}"}]}], "]"}], "//", "Chop"}]}], ";", "\n", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "pList", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "nn"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"StartPopdX", "[", RowBox[{ "ngenes_", ",", "propAdapt_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "width_", ",", "\[Delta]_", ",", "\[Delta]x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", "pop1", ",", "pop2"}], "}"}], ",", "\n", RowBox[{ RowBox[{"pop2", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{ RowBox[{"-", "4"}], "/", "width"}], RowBox[{"(", " ", RowBox[{"x", "-", "x0"}], ")"}]}], "]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"x0", ",", RowBox[{ RowBox[{"-", "propAdapt"}], FractionBox[ RowBox[{"\[Delta]", " ", RowBox[{"(", RowBox[{"ngenes", " ", "-", "\[Delta]x"}], ")"}]}], "2"]}], ",", RowBox[{"propAdapt", FractionBox[ RowBox[{"\[Delta]", " ", RowBox[{"(", RowBox[{"ngenes", " ", "-", "\[Delta]x"}], ")"}]}], "2"]}], ",", "\[Delta]"}], "}"}]}], "]"}], "//", "Chop"}]}], ";", "\n", RowBox[{"pop1", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "pop2", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "nn"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"ngenes", "-", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], ">", "0"}], ",", RowBox[{ RowBox[{"pop2", "=", RowBox[{"StartPopdX", "[", RowBox[{ RowBox[{"ngenes", "-", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], ",", "nn", ",", "nd", ",", "mut", ",", "\[Delta]x"}], "]"}]}], ";", "\n", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Join", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop1", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"pop2", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ",", "pop1"}], "]"}]}]}], "]"}]}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ RowBox[{"StartPopdXAlphas", "[", RowBox[{ "ngenes_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "widthList_", ",", "\[Delta]List_", ",", "b_", ",", "\[Delta]x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", "pList", ",", RowBox[{"Acc\[Delta]", "=", RowBox[{"Accumulate", "[", "\[Delta]List", "]"}]}]}], "}"}], ",", "\n", RowBox[{ RowBox[{"pList", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{ RowBox[{"-", "4"}], "/", RowBox[{ "widthList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], RowBox[{"(", " ", RowBox[{"x", " ", "-", " ", FractionBox[ RowBox[{ RowBox[{"Acc\[Delta]", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], "-", "\[Delta]x"}], "2"], "+", " ", RowBox[{ "Acc\[Delta]", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ")"}]}], "]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", " ", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", " ", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "ngenes"}], "}"}]}], "]"}], "//", "Chop"}]}], ";", "\n", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "pList", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "nn"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}]}], ";"}], "\n"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"StartPopdXAlphas", "[", RowBox[{ "ngenes_", ",", "propAdapt_", ",", "nn_", ",", "nd_", ",", "mut_", ",", "widthList_", ",", "\[Delta]List_", ",", "b_", ",", "\[Delta]x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", "pop1", ",", "pop2", ",", RowBox[{"Acc\[Delta]", "=", RowBox[{"Accumulate", "[", "\[Delta]List", "]"}]}]}], "}"}], ",", "\n", RowBox[{ RowBox[{"pop2", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{ RowBox[{"-", "4"}], "/", RowBox[{ "widthList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], RowBox[{"(", " ", RowBox[{"x", "-", FractionBox[ RowBox[{ RowBox[{"Acc\[Delta]", "\[LeftDoubleBracket]", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}], "\[RightDoubleBracket]"}], "-", "\[Delta]x"}], "2"], "+", RowBox[{ "Acc\[Delta]", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ")"}]}], "]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", " ", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", " ", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], "}"}]}], "]"}], "//", "Chop"}]}], ";", "\n", RowBox[{"pop1", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{"Transpose", "[", "pop2", "]"}], "[", RowBox[{"[", "i", "]"}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "nn"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"ngenes", "-", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], ">", "0"}], ",", RowBox[{ RowBox[{"pop2", "=", RowBox[{"StartPopdX", "[", RowBox[{ RowBox[{"ngenes", "-", RowBox[{"Ceiling", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}]}], ",", "nn", ",", "nd", ",", "mut", ",", "\[Delta]x"}], "]"}]}], ";", "\n", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Join", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop1", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"pop2", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ",", "pop1"}], "]"}]}]}], "]"}]}], "\n"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"Mutate", "[", RowBox[{"pop_", ",", "mut_", ",", "ng_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", RowBox[{"nnList", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ",", "NR", ",", "mutpos", ",", "i", ",", "AccnnList", ",", RowBox[{"AllGenes", "=", RowBox[{"Length", "[", RowBox[{"pop", "//", "Flatten"}], "]"}]}], ",", "upTo", ",", "InDeme"}], "}"}], ",", "\n", RowBox[{ RowBox[{"AccnnList", "=", RowBox[{"Accumulate", "[", "nnList", "]"}]}], ";", RowBox[{"NR", "=", RowBox[{"RandomSample", "[", RowBox[{ RowBox[{"Range", "[", "AllGenes", "]"}], ",", RowBox[{"Random", "[", RowBox[{"BinomialDistribution", "[", RowBox[{"AllGenes", ",", "mut"}], "]"}], "]"}]}], "]"}]}], ";", "\n", RowBox[{"mutpos", "=", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"upTo", "=", RowBox[{"Select", "[", RowBox[{"AccnnList", ",", RowBox[{ RowBox[{"#", "<", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{ "NR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], " ", "/", RowBox[{"(", "ng", ")"}]}], "]"}]}], "&"}]}], "]"}]}], ";", RowBox[{"InDeme", "=", RowBox[{"(", RowBox[{ RowBox[{ "NR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "-", RowBox[{ RowBox[{"Plus", "@@", RowBox[{ RowBox[{"(", RowBox[{"upTo", "/.", RowBox[{ RowBox[{"{", "}"}], "\[Rule]", " ", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}]}], ")"}], "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], " ", "ng"}]}], ")"}]}], ";", RowBox[{"mutpos", "=", RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"Length", "[", "upTo", "]"}], "+", "1"}], ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{ RowBox[{"InDeme", "-", "1"}], ",", "ng"}], "]"}], "+", "1"}], ",", RowBox[{ RowBox[{"Mod", "[", RowBox[{"InDeme", ",", "ng"}], "]"}], "/.", RowBox[{"(", RowBox[{"0", "\[Rule]", "ng"}], ")"}]}]}], "}"}], "}"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "NR", "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}]}], ";", "\n", RowBox[{"i", "=", "0"}], ";", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ";", RowBox[{"ReplacePart", "[", RowBox[{"#", ",", RowBox[{ RowBox[{"mutpos", "[", RowBox[{"[", "i", "]"}], "]"}], "->", RowBox[{"Abs", "[", RowBox[{"1", "-", RowBox[{"Extract", "[", RowBox[{"#", ",", RowBox[{"mutpos", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}], "]"}]}]}], "]"}]}], ")"}], "&"}], ",", "pop", ",", RowBox[{"Length", "[", "mutpos", "]"}]}], "]"}]}]}], "]"}]}]], "Code", Background->RGBColor[1, 1, 0.85]], Cell[BoxData[ RowBox[{ RowBox[{"Mutate", "[", RowBox[{"pop_", ",", "mut_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", RowBox[{"nnList", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ",", "NR", ",", "mutpos", ",", "i", ",", "AccnnList", ",", RowBox[{"AllGenes", "=", RowBox[{"Length", "[", RowBox[{"pop", "//", "Flatten"}], "]"}]}], ",", "upTo", ",", "InDeme", ",", "ng"}], "}"}], ",", RowBox[{ RowBox[{"i", "=", RowBox[{ RowBox[{"Flatten", "[", RowBox[{"Position", "[", RowBox[{"nnList", ",", RowBox[{"Max", "[", "nnList", "]"}]}], "]"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", "\n", RowBox[{"ng", "=", RowBox[{"Length", "[", RowBox[{"pop", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], "]"}]}], ";", "\n", RowBox[{"AccnnList", "=", RowBox[{"Accumulate", "[", "nnList", "]"}]}], ";", RowBox[{"NR", "=", RowBox[{"RandomSample", "[", RowBox[{ RowBox[{"Range", "[", "AllGenes", "]"}], ",", RowBox[{"Random", "[", RowBox[{"BinomialDistribution", "[", RowBox[{"AllGenes", ",", "mut"}], "]"}], "]"}]}], "]"}]}], ";", "\n", RowBox[{"mutpos", "=", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"upTo", "=", RowBox[{"Select", "[", RowBox[{"AccnnList", ",", RowBox[{ RowBox[{"#", "<", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{ "NR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], " ", "/", RowBox[{"(", "ng", ")"}]}], "]"}]}], "&"}]}], "]"}]}], ";", RowBox[{"InDeme", "=", RowBox[{"(", RowBox[{ RowBox[{ "NR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "-", RowBox[{ RowBox[{"Plus", "@@", RowBox[{ RowBox[{"(", RowBox[{"upTo", "/.", RowBox[{ RowBox[{"{", "}"}], "\[Rule]", " ", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}]}], ")"}], "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], " ", "ng"}]}], ")"}]}], ";", RowBox[{"mutpos", "=", RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"Length", "[", "upTo", "]"}], "+", "1"}], ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{ RowBox[{"InDeme", "-", "1"}], ",", "ng"}], "]"}], "+", "1"}], ",", RowBox[{ RowBox[{"Mod", "[", RowBox[{"InDeme", ",", "ng"}], "]"}], "/.", RowBox[{"(", RowBox[{"0", "\[Rule]", "ng"}], ")"}]}]}], "}"}], "}"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "NR", "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}]}], ";", "\n", RowBox[{"i", "=", "0"}], ";", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ";", RowBox[{"ReplacePart", "[", RowBox[{"#", ",", RowBox[{ RowBox[{"mutpos", "[", RowBox[{"[", "i", "]"}], "]"}], "->", RowBox[{"Abs", "[", RowBox[{"1", "-", RowBox[{"Extract", "[", RowBox[{"#", ",", RowBox[{"mutpos", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}], "]"}]}]}], "]"}]}], ")"}], "&"}], ",", "pop", ",", RowBox[{"Length", "[", "mutpos", "]"}]}], "]"}]}]}], "]"}]}]], "Code", Background->RGBColor[1, 1, 0.85]], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"MutateOld", "::", "ussage"}], "\"\\""}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"MutateOld", "[", RowBox[{"pop_", ",", "mut_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], "}"}], ",", RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "-", "mut"}], ",", "mut"}], "}"}], "->", " ", RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}]}], "]"}], "&"}], ",", RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], "]"}]}], ";", RowBox[{ RowBox[{"MutateOld", "[", RowBox[{"pop_", ",", "mut_", ",", "nd_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "-", "mut"}], ",", "mut"}], "}"}], "->", " ", RowBox[{"{", RowBox[{"#", ",", RowBox[{"1", "-", "#"}]}], "}"}]}], "]"}], "&"}], ",", RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], "]"}]}], ";"}]}], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"\[Alpha]List", "[", RowBox[{"\[Alpha]_", ",", "ngenes_"}], "]"}], ":=", RowBox[{"RandomReal", "[", RowBox[{ RowBox[{"ExponentialDistribution", "[", RowBox[{"1", "/", "\[Alpha]"}], "]"}], ",", "ngenes"}], "]"}]}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"\[Alpha]List", "[", "ngenes_", "]"}], ":=", RowBox[{"RandomReal", "[", RowBox[{ RowBox[{"{", RowBox[{ SuperscriptBox["10", RowBox[{"-", "3"}]], ",", ".1"}], "}"}], ",", "ngenes"}], "]"}]}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{ RowBox[{"\[Theta]", "::", "ussage"}], "\"\\""}], ";"}], Background->RGBColor[0.9, 1, 1]], "\n", StyleBox[ RowBox[{ RowBox[{ RowBox[{"\[Theta]", "[", RowBox[{"b_", ",", "nd_", ",", "ngenes_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"ngenes", "/", "2"}], "+", RowBox[{"b", " ", "x"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "1"}], ")"}], "/", "2"}], ",", "1"}], "}"}]}], "]"}]}], ";"}], Background->RGBColor[0.9, 1, 1]], "\n", StyleBox[ RowBox[{ RowBox[{ RowBox[{"\[Theta]", "[", RowBox[{ "b_", ",", "nd_", ",", "ngenes_", ",", "\[Delta]x_", ",", "\[Alpha]_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"\[Alpha]", " ", RowBox[{"ngenes", "/", "2"}]}], "+", RowBox[{"b", " ", "x"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}]}], ";"}], Background->RGBColor[0.9, 1, 1]], "\n", StyleBox[ RowBox[{ RowBox[{ RowBox[{"\[Theta]Alphas", "[", RowBox[{ "b_", ",", "nd_", ",", "ngenes_", ",", "\[Delta]x_", ",", "\[Alpha]\[Alpha]_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{ FractionBox[ RowBox[{"Plus", "@@", "\[Alpha]\[Alpha]"}], "2"], "+", RowBox[{"b", " ", "x"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}]}], ";"}], Background->RGBColor[0.9, 1, 1]], "\n", StyleBox[ RowBox[{ RowBox[{ RowBox[{"\[Theta]Steep", "[", RowBox[{ "b_", ",", "nd_", ",", "ngenes_", ",", "\[Delta]x_", ",", "\[Alpha]_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"k", "=", RowBox[{"b", "/", "2"}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"\[Alpha]", " ", RowBox[{"ngenes", "/", "2"}]}], " ", "+", " ", RowBox[{"Exp", "[", RowBox[{"k", " ", "x"}], "]"}], "-", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "k"}], " ", "x"}], "]"}]}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"nd", "-", "\[Delta]x"}], ")"}], "/", "2"}], ",", "\[Delta]x"}], "}"}]}], "]"}]}], "]"}]}], ";"}], Background->RGBColor[0.9, 1, 1]]}], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"MigrateStSt", "[", "pop_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "rr", ",", "rrL", ",", "rrR", ",", "poploc", ",", "popL", ",", "popR", ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}]}], "}"}], ",", RowBox[{ RowBox[{"rr", "=", RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"1", "/", "4"}], ",", RowBox[{"1", "/", "2"}], ",", RowBox[{"1", "/", "4"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "0", ",", "1"}], "}"}]}], ",", RowBox[{"Length", "[", "#", "]"}]}], "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"rr", "=", RowBox[{"ReplacePart", "[", RowBox[{ RowBox[{"ReplacePart", "[", RowBox[{"rr", ",", RowBox[{"1", "->", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "==", RowBox[{"-", "1"}]}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"rr", "[", RowBox[{"[", "1", "]"}], "]"}]}], ")"}]}]}], "]"}], ",", RowBox[{ RowBox[{"-", "1"}], "->", " ", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "==", "1"}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"rr", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}], ")"}]}]}], "]"}]}], ";", RowBox[{"popL", "=", RowBox[{"Append", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"pop", ",", "1"}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}], "]"}]}], ";", RowBox[{"popR", "=", RowBox[{"Prepend", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"pop", ",", RowBox[{"-", "1"}]}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", "1", "]"}], "]"}]}], "]"}]}], ";", RowBox[{"rrL", "=", RowBox[{"Append", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"rr", ",", "1"}], "]"}], ",", RowBox[{"0", RowBox[{"rr", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}]}], "]"}]}], ";", RowBox[{"rrR", "=", RowBox[{"Prepend", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"rr", ",", RowBox[{"-", "1"}]}], "]"}], ",", RowBox[{"0", RowBox[{"rr", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], "]"}]}], ";", RowBox[{"poploc", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", "0"}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rr", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{"popL", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", RowBox[{"-", "1"}]}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rrL", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popL", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{"popR", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", "1"}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rrR", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popR", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{ RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"Table", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{"poploc", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popL", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popR", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}], ")"}]}]}]}], "]"}]}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"MigrateStSt", "[", RowBox[{"pop_", ",", "m_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "rr", ",", "rrL", ",", "rrR", ",", "poploc", ",", "popL", ",", "popR", ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}]}], "}"}], ",", RowBox[{ RowBox[{"rr", "=", RowBox[{ RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"m", "/", "2"}], ",", RowBox[{"(", RowBox[{"1", "-", "m"}], ")"}], ",", RowBox[{"m", "/", "2"}]}], "}"}], "->", " ", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "0", ",", "1"}], "}"}]}], ",", RowBox[{"Length", "[", "#", "]"}]}], "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"rr", "=", RowBox[{"ReplacePart", "[", RowBox[{ RowBox[{"ReplacePart", "[", RowBox[{"rr", ",", RowBox[{"1", "->", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "==", RowBox[{"-", "1"}]}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"rr", "[", RowBox[{"[", "1", "]"}], "]"}]}], ")"}]}]}], "]"}], ",", RowBox[{ RowBox[{"-", "1"}], "->", " ", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "==", "1"}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"rr", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}], ")"}]}]}], "]"}]}], ";", RowBox[{"popL", "=", RowBox[{"Append", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"pop", ",", "1"}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}], "]"}]}], ";", RowBox[{"popR", "=", RowBox[{"Prepend", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"pop", ",", RowBox[{"-", "1"}]}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", "1", "]"}], "]"}]}], "]"}]}], ";", RowBox[{"rrL", "=", RowBox[{"Append", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"rr", ",", "1"}], "]"}], ",", RowBox[{"0", RowBox[{"rr", "[", RowBox[{"[", RowBox[{"-", "1"}], "]"}], "]"}]}]}], "]"}]}], ";", RowBox[{"rrR", "=", RowBox[{"Prepend", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"rr", ",", RowBox[{"-", "1"}]}], "]"}], ",", RowBox[{"0", RowBox[{"rr", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], "]"}]}], ";", RowBox[{"poploc", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", "0"}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rr", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{"popL", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", RowBox[{"-", "1"}]}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rrL", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popL", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{"popR", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", "==", "1"}], ",", "#2", ",", "0"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"rrR", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popR", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{ RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"Table", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{"poploc", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popL", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"popR", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}], ")"}]}]}]}], "]"}]}]], "Code"], Cell[BoxData[ RowBox[{ StyleBox[ RowBox[{"Migrate", "[", RowBox[{"pop_", ",", "gg_"}], "]"}], Background->RGBColor[1, 0.9, 0.8]], StyleBox[":=", Background->RGBColor[1, 0.9, 0.8]], RowBox[{ StyleBox["Module", Background->RGBColor[1, 0.9, 0.8]], StyleBox["[", Background->RGBColor[1, 0.9, 0.8]], RowBox[{ StyleBox[ RowBox[{"{", RowBox[{ "i", ",", "j", ",", "ij", ",", "nd", ",", "pp", ",", "displ", ",", RowBox[{"nnList", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}]}], "}"}], Background->RGBColor[1, 0.9, 0.8]], StyleBox[",", Background->RGBColor[1, 0.9, 0.8]], StyleBox["\n", Background->RGBColor[1, 0.9, 0.8]], RowBox[{ RowBox[{"i", "=", "1"}], ";", RowBox[{"j", "=", "1"}], ";", RowBox[{"ij", "=", "1"}], ";", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ";", RowBox[{"pp", "=", RowBox[{"ConstantArray", "[", RowBox[{ RowBox[{"{", "}"}], ",", "nd"}], "]"}]}], ";", "\n", RowBox[{"displ", "=", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"gg", "->", " ", RowBox[{"Range", "[", RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Length", "[", "gg", "]"}], "-", "1"}], ")"}], "/", "2"}], ")"}]}], ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Length", "[", "gg", "]"}], "-", "1"}], ")"}], "/", "2"}]}], "]"}]}], ",", RowBox[{"Plus", "@@", "nnList"}]}], "]"}]}], ";", "\n", RowBox[{"For", "[", RowBox[{ RowBox[{"ij", "=", "1"}], ",", RowBox[{"ij", "\[LessEqual]", RowBox[{"Length", "[", "displ", "]"}]}], ",", RowBox[{"ij", "=", RowBox[{"ij", "+", "1"}]}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"j", "\[Equal]", RowBox[{ RowBox[{ "nnList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "+", "1"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{ "nnList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[Equal]", "0"}], ")"}]}], ")"}], ",", RowBox[{ RowBox[{"j", "=", "1"}], ";", RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ";", RowBox[{"ij", "=", RowBox[{"ij", "-", "1"}]}]}], ",", RowBox[{ RowBox[{"pp", "=", RowBox[{"Insert", "[", RowBox[{"pp", ",", RowBox[{"pop", "\[LeftDoubleBracket]", RowBox[{"i", ",", "j"}], "\[RightDoubleBracket]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Min", "[", RowBox[{"{", RowBox[{"nd", ",", RowBox[{"Max", "[", RowBox[{"{", RowBox[{"1", ",", RowBox[{"i", "+", RowBox[{ "displ", "\[LeftDoubleBracket]", "ij", "\[RightDoubleBracket]"}]}]}], "}"}], "]"}]}], "}"}], "]"}], ",", "1"}], "}"}]}], "]"}]}], ";", RowBox[{"j", "=", RowBox[{"j", "+", "1"}]}]}]}], "]"}]}], "]"}], ";", "pp"}]}], "]"}]}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"gaussianList", "::", "usage"}], "=", "\"\\""}], ";"}]], "Input", InitializationCell->True, CellChangeTimes->{{3.565693883588887*^9, 3.565693884068348*^9}, { 3.565694358899431*^9, 3.565694360947091*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"gaussianList", "[", RowBox[{"\[Sigma]_", ",", "\[Epsilon]_"}], "]"}], ":=", RowBox[{"gaussianList", "[", RowBox[{"\[Sigma]", ",", "\[Epsilon]", ",", "3"}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"gaussianList", "[", RowBox[{"\[Sigma]_", ",", "\[Epsilon]_", ",", "k_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "g", ",", "s0", ",", "s2", ",", "s4", ",", "x", ",", "kk", ",", "n"}], "}"}], ",", "\n", RowBox[{ RowBox[{"kk", "=", RowBox[{ RowBox[{"Nearest", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"n", " ", RowBox[{"\[Epsilon]", "/", "\[Sigma]"}]}], ",", RowBox[{"{", RowBox[{"n", ",", "1", ",", RowBox[{ RowBox[{"k", " ", RowBox[{"Ceiling", "[", RowBox[{"\[Sigma]", "/", "\[Epsilon]"}], "]"}]}], "+", "1"}]}], "}"}]}], "]"}], ",", "k"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", RowBox[{"x", "=", RowBox[{"Range", "[", RowBox[{ RowBox[{ RowBox[{"-", "kk"}], " ", "\[Sigma]"}], ",", RowBox[{"kk", " ", "\[Sigma]"}], ",", "\[Epsilon]"}], "]"}]}], ";", RowBox[{"g", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"PDF", "[", RowBox[{ RowBox[{"NormalDistribution", "[", RowBox[{"0", ",", "\[Sigma]"}], "]"}], ",", "#"}], "]"}], "//", "N"}], ")"}], "&"}], "/@", "x"}]}], ";", "\n", RowBox[{"s0", "=", RowBox[{"Plus", "@@", "g"}]}], ";", RowBox[{"s2", "=", RowBox[{"g", ".", RowBox[{"x", "^", "2"}]}]}], ";", RowBox[{"s4", "=", RowBox[{"g", ".", RowBox[{"x", "^", "4"}]}]}], ";", "\n", RowBox[{"Select", "[", RowBox[{ RowBox[{"g", " ", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"s2", " ", RowBox[{"(", RowBox[{ RowBox[{"\[Sigma]", "^", "2"}], "+", RowBox[{"x", "^", "2"}]}], ")"}]}], "-", "s4", "-", RowBox[{ RowBox[{"\[Sigma]", "^", "2"}], " ", RowBox[{"x", "^", "2"}], " ", "s0"}]}], ")"}], "/", RowBox[{"(", RowBox[{ RowBox[{"s2", "^", "2"}], "-", RowBox[{"s0", " ", "s4"}]}], ")"}]}]}], ",", RowBox[{ RowBox[{"#", ">", "0"}], "&"}]}], "]"}]}]}], "]"}], "//", "Chop"}], "//", "N"}]}], ";"}]}], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"SplitSexes", "::", "ussage"}], "\"\\""}], ";"}], "\n", RowBox[{ RowBox[{"SplitSexes", "[", "pop_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"nnList", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"Quotient", "[", RowBox[{ RowBox[{"nnList", "[", RowBox[{"[", "i", "]"}], "]"}], ",", "2"}], "]"}], "+", RowBox[{ RowBox[{"Mod", "[", RowBox[{ RowBox[{"nnList", "[", RowBox[{"[", "i", "]"}], "]"}], ",", "2"}], "]"}], RowBox[{"Random", "[", RowBox[{"Integer", ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "nd"}], "}"}]}], "]"}]}], "]"}]}]}], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Options", "[", "SelectRecombine", "]"}], "=", RowBox[{"{", RowBox[{"Regulation", "->", "\[Infinity]"}], "}"}]}], ";"}]], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["SelectMutateRecombine", Background->RGBColor[1, 0.9, 0.8]], "::", "ussage"}], "\"\ \[Infinity] is Logarithmic. Plant \ model. \nAsigns fitnesses, calculates the expected number of ofspring \ \\!\\(\\*SubscriptBox[\\(N\\), \\(\\(i\\)\\(\\\\\\ \\)\\)]\\)(Poisson dist.) \ for each individual, \nasigns male according to their fitness (including \ *self*) and recombines (Recombine: with free recombination). \n\ \\!\\(\\*SubscriptBox[\\(r\\), \\(\\(m\\)\\(\\\\\\ \\)\\)]\\)in the \ logarithmic model is \\!\\(\\*SuperscriptBox[\\(r\\), \\(*\\)]\\)\>\""}], ";"}], "\n", RowBox[{ RowBox[{"SelectMutateRecombine", "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Theta]list", ",", "i", ",", RowBox[{"rm", "=", RowBox[{"pars", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", RowBox[{"Vs", "=", RowBox[{"pars", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"pars", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"K", "=", RowBox[{"pars", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", RowBox[{"\[Alpha]", "=", RowBox[{ "pars", "\[LeftDoubleBracket]", "8", "\[RightDoubleBracket]"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", "rr", ",", "zz", ",", "reg", ",", "Nfem", ",", "Ndeme", ",", "popfem", ",", "popmale"}], "}"}], ",", "\n", RowBox[{ RowBox[{"reg", "=", RowBox[{ RowBox[{"Regulation", "/.", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SelectRecombine", "]"}]}]}], ";", RowBox[{"\[Theta]list", "=", RowBox[{"\[Theta]", "[", RowBox[{ "b", ",", "nd", ",", "ngenes", ",", "\[Delta]x", ",", "\[Alpha]"}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"zz", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"\[Alpha]", " ", RowBox[{"Plus", "@@", "#"}]}], "&"}], "/@", "#"}], "&"}], "/@", "pop"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "==", "\[Infinity]"}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"-", "rm"}], " ", RowBox[{"Log", "[", RowBox[{"Ndeme", "/", "K"}], "]"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], ")"}], "]"}]}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{ RowBox[{"rm", RowBox[{"(", RowBox[{"1", "-", RowBox[{"Ndeme", "/", "K"}]}], ")"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], "]"}]}]}], "]"}], ";", "\n", RowBox[{"Nfem", "=", RowBox[{"Map", "[", RowBox[{"RIP", ",", "rr", ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "Nfem"}]}], ";", RowBox[{"popmale", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"#1", "!=", RowBox[{"{", "}"}]}], "&&", RowBox[{"#3", "!=", "0"}]}], ",", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"#1", "->", " ", "#2"}], ",", "#3"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"rr", ",", "pop", ",", "Ndeme"}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"popfem", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Nfem", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", " ", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Recombine", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Mutate", "[", RowBox[{"popfem", ",", RowBox[{"pars", "[", RowBox[{"[", "5", "]"}], "]"}]}], "]"}], ",", RowBox[{"Mutate", "[", RowBox[{"popmale", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}]}]}], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["SelectMutateRecombineKList", Background->RGBColor[1, 0.9, 0.8]], "::", "ussage"}], "\"\ \[Infinity] is Logarithmic. Plant \ model. \nAsigns fitnesses, calculates the expected number of ofspring \ \\!\\(\\*SubscriptBox[\\(N\\), \\(\\(i\\)\\(\\\\\\ \\)\\)]\\)(Poisson dist.) \ for each individual, \nasigns male according to their fitness (including \ *self*) and recombines (Recombine: with free recombination). \n\ \\!\\(\\*SubscriptBox[\\(r\\), \\(\\(m\\)\\(\\\\\\ \\)\\)]\\)in the \ logarithmic model is \\!\\(\\*SuperscriptBox[\\(r\\), \\(*\\)]\\)\>\""}], ";"}], "\n", RowBox[{ RowBox[{"SelectMutateRecombineKList", "[", RowBox[{ "pop_", ",", "pars_", ",", "KList_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Theta]list", ",", "i", ",", RowBox[{"rm", "=", RowBox[{"pars", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", RowBox[{"Vs", "=", RowBox[{"pars", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"pars", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"K", "=", RowBox[{"pars", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", RowBox[{"\[Alpha]", "=", RowBox[{ "pars", "\[LeftDoubleBracket]", "8", "\[RightDoubleBracket]"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", "rr", ",", "zz", ",", "reg", ",", "Nfem", ",", "Ndeme", ",", "popfem", ",", "popmale"}], "}"}], ",", "\n", RowBox[{ RowBox[{"reg", "=", RowBox[{ RowBox[{"Regulation", "/.", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SelectRecombine", "]"}]}]}], ";", RowBox[{"\[Theta]list", "=", RowBox[{"\[Theta]", "[", RowBox[{ "b", ",", "nd", ",", "ngenes", ",", "\[Delta]x", ",", "\[Alpha]"}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"zz", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"\[Alpha]", " ", RowBox[{"Plus", "@@", "#"}]}], "&"}], "/@", "#"}], "&"}], "/@", "pop"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "==", "\[Infinity]"}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"-", "rm"}], " ", RowBox[{"Log", "[", RowBox[{"Ndeme", "/", "KList"}], "]"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], ")"}], "]"}]}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{ RowBox[{"rm", RowBox[{"(", RowBox[{"1", "-", RowBox[{"Ndeme", "/", "KList"}]}], ")"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], "]"}]}]}], "]"}], ";", "\n", RowBox[{"Nfem", "=", RowBox[{"Map", "[", RowBox[{"RIP", ",", "rr", ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "Nfem"}]}], ";", RowBox[{"popmale", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"#1", "!=", RowBox[{"{", "}"}]}], "&&", RowBox[{"#3", "!=", "0"}]}], ",", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"#1", "->", " ", "#2"}], ",", "#3"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"rr", ",", "pop", ",", "Ndeme"}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"popfem", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Nfem", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", " ", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Recombine", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Mutate", "[", RowBox[{"popfem", ",", RowBox[{"pars", "[", RowBox[{"[", "5", "]"}], "]"}]}], "]"}], ",", RowBox[{"Mutate", "[", RowBox[{"popmale", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}]}]}], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["SelectMutateRecombineSteep", Background->RGBColor[1, 0.9, 0.8]], "::", "ussage"}], "\"\ \[Infinity] is Logarithmic. Plant \ model. \nAsigns fitnesses, calculates the expected number of ofspring \ \\!\\(\\*SubscriptBox[\\(N\\), \\(\\(i\\)\\(\\\\\\ \\)\\)]\\)(Poisson dist.) \ for each individual, \nasigns male according to their fitness (including \ *self*) and recombines (Recombine: with free recombination). \n\ \\!\\(\\*SubscriptBox[\\(r\\), \\(\\(m\\)\\(\\\\\\ \\)\\)]\\)in the \ logarithmic model is \\!\\(\\*SuperscriptBox[\\(r\\), \\(*\\)]\\)\>\""}], ";"}], "\n", RowBox[{ RowBox[{"SelectMutateRecombineSteep", "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Theta]list", ",", "i", ",", RowBox[{"rm", "=", RowBox[{"pars", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", RowBox[{"Vs", "=", RowBox[{"pars", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"pars", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"K", "=", RowBox[{"pars", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", RowBox[{"\[Alpha]", "=", RowBox[{ "pars", "\[LeftDoubleBracket]", "8", "\[RightDoubleBracket]"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", "rr", ",", "zz", ",", "reg", ",", "Nfem", ",", "Ndeme", ",", "popfem", ",", "popmale"}], "}"}], ",", "\n", RowBox[{ RowBox[{"reg", "=", RowBox[{ RowBox[{"Regulation", "/.", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SelectRecombine", "]"}]}]}], ";", RowBox[{"\[Theta]list", "=", RowBox[{"\[Theta]Steep", "[", RowBox[{ "b", ",", "nd", ",", "ngenes", ",", "\[Delta]x", ",", "\[Alpha]"}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"zz", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"\[Alpha]", " ", RowBox[{"Plus", "@@", "#"}]}], "&"}], "/@", "#"}], "&"}], "/@", "pop"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "==", "\[Infinity]"}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"-", "rm"}], " ", RowBox[{"Log", "[", RowBox[{"Ndeme", "/", "K"}], "]"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], ")"}], "]"}]}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{ RowBox[{"rm", RowBox[{"(", RowBox[{"1", "-", RowBox[{"Ndeme", "/", "K"}]}], ")"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], "]"}]}]}], "]"}], ";", "\n", RowBox[{"Nfem", "=", RowBox[{"Map", "[", RowBox[{"RIP", ",", "rr", ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "Nfem"}]}], ";", RowBox[{"popmale", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"#1", "!=", RowBox[{"{", "}"}]}], "&&", RowBox[{"#3", "!=", "0"}]}], ",", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"#1", "->", " ", "#2"}], ",", "#3"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"rr", ",", "pop", ",", "Ndeme"}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"popfem", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Nfem", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", " ", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", StyleBox[ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Recombine", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Mutate", "[", RowBox[{"popfem", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}], ",", RowBox[{"Mutate", "[", RowBox[{"popmale", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}]}], "}"}]}], "]"}], Background->RGBColor[0.87, 0.94, 1]]}]}], StyleBox["]", Background->RGBColor[0.87, 0.94, 1]]}]}]}], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["SelectMutateRecombineAlphas", Background->RGBColor[1, 0.9, 0.8]], "::", "ussage"}], "\"\ \[Infinity] is Logarithmic. Plant \ model. \nAsigns fitnesses, calculates the expected number of ofspring \ \\!\\(\\*SubscriptBox[\\(N\\), \\(\\(i\\)\\(\\\\\\ \\)\\)]\\)(Poisson dist.) \ for each individual, \nasigns male according to their fitness (including \ *self*) and recombines (Recombine: with free recombination). \n\ \\!\\(\\*SubscriptBox[\\(r\\), \\(\\(m\\)\\(\\\\\\ \\)\\)]\\)in the \ logarithmic model is \\!\\(\\*SuperscriptBox[\\(r\\), \\(*\\)]\\)\>\""}], ";"}], "\n", RowBox[{ RowBox[{"SelectMutateRecombineAlphas", "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Theta]list", ",", "i", ",", RowBox[{"rm", "=", RowBox[{"pars", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", RowBox[{"Vs", "=", RowBox[{"pars", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"pars", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"K", "=", RowBox[{"pars", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", "rr", ",", "zz", ",", "reg", ",", "Nfem", ",", "Ndeme", ",", "popfem", ",", "popmale"}], "}"}], ",", "\n", RowBox[{ RowBox[{"reg", "=", RowBox[{ RowBox[{"Regulation", "/.", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SelectRecombine", "]"}]}]}], ";", RowBox[{"\[Theta]list", "=", RowBox[{"\[Theta]Alphas", "[", RowBox[{ "b", ",", "nd", ",", "ngenes", ",", "\[Delta]x", ",", "\[Alpha]\[Alpha]"}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"zz", "=", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"\[Alpha]\[Alpha]", "#"}], ")"}]}], "&"}], "/@", "#"}], "&"}], "/@", "pop"}], ")"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "==", "\[Infinity]"}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"-", "rm"}], " ", RowBox[{"Log", "[", RowBox[{"Ndeme", "/", "K"}], "]"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], ")"}], "]"}]}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{ RowBox[{"rm", RowBox[{"(", RowBox[{"1", "-", RowBox[{"Ndeme", "/", "K"}]}], ")"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], "]"}]}]}], "]"}], ";", "\n", RowBox[{"Nfem", "=", RowBox[{"Map", "[", RowBox[{"RIP", ",", "rr", ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "Nfem"}]}], ";", RowBox[{"popmale", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"#1", "!=", RowBox[{"{", "}"}]}], "&&", RowBox[{"#3", "!=", "0"}]}], ",", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"#1", "->", " ", "#2"}], ",", "#3"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"rr", ",", "pop", ",", "Ndeme"}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"popfem", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Nfem", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", " ", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", StyleBox[ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Recombine", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Mutate", "[", RowBox[{"popfem", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}], ",", RowBox[{"Mutate", "[", RowBox[{"popmale", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}]}], "}"}]}], "]"}], Background->RGBColor[0.87, 0.94, 1]]}]}], StyleBox["]", Background->RGBColor[0.87, 0.94, 1]]}]}]}], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["SelectMutateRecombineSteepAlpha", Background->RGBColor[1, 0.9, 0.8]], "::", "ussage"}], "\"\ \[Infinity] is Logarithmic. Plant \ model. \nAsigns fitnesses, calculates the expected number of ofspring \ \\!\\(\\*SubscriptBox[\\(N\\), \\(\\(i\\)\\(\\\\\\ \\)\\)]\\)(Poisson dist.) \ for each individual, \nasigns male according to their fitness (including \ *self*) and recombines (Recombine: with free recombination). \n\ \\!\\(\\*SubscriptBox[\\(r\\), \\(\\(m\\)\\(\\\\\\ \\)\\)]\\)in the \ logarithmic model is \\!\\(\\*SuperscriptBox[\\(r\\), \\(*\\)]\\)\>\""}], ";"}], "\n", RowBox[{ RowBox[{"SelectMutateRecombineSteepAlpha", "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"\[Theta]list", ",", "i", ",", RowBox[{"rm", "=", RowBox[{"pars", "[", RowBox[{"[", "3", "]"}], "]"}]}], ",", RowBox[{"Vs", "=", RowBox[{"pars", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"pars", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"K", "=", RowBox[{"pars", "[", RowBox[{"[", "4", "]"}], "]"}]}], ",", RowBox[{"\[Alpha]", "=", RowBox[{"Mean", "[", "\[Alpha]\[Alpha]", "]"}]}], ",", RowBox[{"nd", "=", RowBox[{"Length", "[", "pop", "]"}]}], ",", "rr", ",", "zz", ",", "reg", ",", "Nfem", ",", "Ndeme", ",", "popfem", ",", "popmale"}], "}"}], ",", "\n", RowBox[{ RowBox[{"reg", "=", RowBox[{ RowBox[{"Regulation", "/.", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SelectRecombine", "]"}]}]}], ";", RowBox[{"\[Theta]list", "=", RowBox[{"\[Theta]Steep", "[", RowBox[{ "b", ",", "nd", ",", "ngenes", ",", "\[Delta]x", ",", "\[Alpha]"}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", "pop"}]}], ";", RowBox[{"zz", "=", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"\[Alpha]\[Alpha]", "#"}], ")"}]}], "&"}], "/@", "#"}], "&"}], "/@", "pop"}], ")"}]}], ";", "\n", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "==", "\[Infinity]"}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"-", "rm"}], " ", RowBox[{"Log", "[", RowBox[{"Ndeme", "/", "K"}], "]"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], ")"}], "]"}]}], ",", RowBox[{"rr", "=", RowBox[{"Exp", "[", RowBox[{ RowBox[{"rm", RowBox[{"(", RowBox[{"1", "-", RowBox[{"Ndeme", "/", "K"}]}], ")"}]}], "-", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"zz", "-", "\[Theta]list"}], ")"}], "^", "2"}], "/", RowBox[{"(", RowBox[{"2", " ", "Vs"}], ")"}]}]}], "]"}]}]}], "]"}], ";", "\n", RowBox[{"Nfem", "=", RowBox[{"Map", "[", RowBox[{"RIP", ",", "rr", ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";", RowBox[{"Ndeme", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "Nfem"}]}], ";", RowBox[{"popmale", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"#1", "!=", RowBox[{"{", "}"}]}], "&&", RowBox[{"#3", "!=", "0"}]}], ",", RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"#1", "->", " ", "#2"}], ",", "#3"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"rr", ",", "pop", ",", "Ndeme"}], "}"}]}], "]"}]}], ";", "\n", RowBox[{"popfem", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"pop", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Nfem", "[", RowBox[{"[", "i", "]"}], "]"}]}], "}"}]}], "]"}], ",", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Floor", "[", RowBox[{"nd", " ", "/", "\[Delta]x"}], "]"}]}], "}"}]}], "]"}]}], ";", "\n", StyleBox[ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Recombine", "[", RowBox[{"#1", ",", "#2"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Mutate", "[", RowBox[{"popfem", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}], ",", RowBox[{"Mutate", "[", RowBox[{"popmale", ",", RowBox[{ "pars", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], ",", "ngenes"}], "]"}]}], "}"}]}], "]"}], Background->RGBColor[0.87, 0.94, 1]]}]}], StyleBox["]", Background->RGBColor[0.87, 0.94, 1]]}]}]}], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"RIP", "[", "r_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"r", "//", "N"}], "//", "Chop"}], ")"}], "<=", "0"}], ",", "0", ",", RowBox[{"RandomInteger", "[", RowBox[{"PoissonDistribution", "[", "r", "]"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Recombine", "::", "ussage"}], "\"\\ \""}], ";"}], "\n", RowBox[{ RowBox[{"Recombine", "[", RowBox[{"popfemdeme_", ",", "popmaledeme_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"j", ",", "reclist", ",", RowBox[{"n", "=", RowBox[{"Length", "[", "popfemdeme", "]"}]}], ",", "ngenes"}], "}"}], ",", RowBox[{ RowBox[{"ngenes", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"n", "==", "0"}], ",", "0", ",", RowBox[{"Length", "[", RowBox[{"popfemdeme", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], "]"}]}], ";", "\n", RowBox[{"reclist", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomChoice", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], ",", "ngenes"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", "n"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{"popfemdeme", "*", "reclist"}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "reclist"}], ")"}], "popmaledeme"}]}]}]}], "]"}]}]}], "Code", CellChangeTimes->{3.564482178368561*^9}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"SelectRecombineMigrate", "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectRecombine", "[", RowBox[{ RowBox[{"Mutate", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", RowBox[{"pars", "[", RowBox[{"[", "5", "]"}], "]"}]}], "]"}], ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"SelectRecombineMigrate", "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectRecombine", "[", RowBox[{ RowBox[{"Mutate", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", RowBox[{"pars", "[", RowBox[{"[", "5", "]"}], "]"}]}], "]"}], ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["MigrateSelectMutateRecombine", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectMutateRecombine", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["MigrateSelectMutateRecombineAlphas", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectMutateRecombineAlphas", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["MigrateSelectMutateRecombineSteep", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectMutateRecombineSteep", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["MigrateSelectMutateRecombineSteepAlpha", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectMutateRecombineSteepAlpha", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["MigrateSelectMutateRecombineKList", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "KList_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"gg", "=", RowBox[{"gaussianList", "[", RowBox[{ RowBox[{"pars", "[", RowBox[{"[", "6", "]"}], "]"}], ",", "\[Delta]x", ",", RowBox[{"pars", "[", RowBox[{"[", "7", "]"}], "]"}]}], "]"}]}], "}"}], ",", RowBox[{"SelectMutateRecombineKList", "[", RowBox[{ RowBox[{"Migrate", "[", RowBox[{"pop", ",", "gg"}], "]"}], ",", "pars", ",", "KList", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Iterate", "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"SelectRecombineMigrate", "[", RowBox[{ "#", ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["Iterate", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"MigrateSelectMutateRecombine", "[", RowBox[{ "#", ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["Iterate", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_", ",", "dT_"}], "]"}], ":=", RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"Iterate", "[", RowBox[{ "#", ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts", ",", "dT"}], "]"}], "&"}], ",", "pop", ",", RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateKList", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "KList_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"MigrateSelectMutateRecombineKList", "[", RowBox[{ "#", ",", "pars", ",", "KList", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateKList", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "KList_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_", ",", "dT_"}], "]"}], ":=", RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"IterateKList", "[", RowBox[{ "#", ",", "pars", ",", "KList", ",", "ngenes", ",", "\[Delta]x", ",", "opts", ",", "dT"}], "]"}], "&"}], ",", "pop", ",", RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateAlphas", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"MigrateSelectMutateRecombineAlphas", "[", RowBox[{ "#", ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateAlphas", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_", ",", "dT_"}], "]"}], ":=", RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"IterateAlphas", "[", RowBox[{ "#", ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts", ",", "dT"}], "]"}], "&"}], ",", "pop", ",", RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateSteep", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"MigrateSelectMutateRecombineSteep", "[", RowBox[{ "#", ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateSteep", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_", ",", "dT_"}], "]"}], ":=", RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"IterateSteep", "[", RowBox[{ "#", ",", "pars", ",", "ngenes", ",", "\[Delta]x", ",", "opts", ",", "dT"}], "]"}], "&"}], ",", "pop", ",", RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateSteepAlpha", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_"}], "]"}], ":=", RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"MigrateSelectMutateRecombineSteepAlpha", "[", RowBox[{ "#", ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts"}], "]"}], "&"}], ",", "pop", ",", "T"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ StyleBox["IterateSteepAlpha", Background->RGBColor[1, 0.9, 0.8]], "[", RowBox[{ "pop_", ",", "pars_", ",", "\[Alpha]\[Alpha]_", ",", "ngenes_", ",", "\[Delta]x_", ",", "opts___Rule", ",", "T_", ",", "dT_"}], "]"}], ":=", RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"IterateSteepAlpha", "[", RowBox[{ "#", ",", "pars", ",", "\[Alpha]\[Alpha]", ",", "ngenes", ",", "\[Delta]x", ",", "opts", ",", "dT"}], "]"}], "&"}], ",", "pop", ",", RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}]}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"DarkGreen", "=", RowBox[{"Hue", "[", RowBox[{"{", RowBox[{"0.4", ",", "1", ",", "0.55"}], "}"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"NiceBlue", "=", RowBox[{"Hue", "[", RowBox[{"{", RowBox[{"0.65", ",", "0.7", ",", ".7"}], "}"}], "]"}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"DarkBlue", "=", RowBox[{"Hue", "[", RowBox[{"{", RowBox[{"0.65", ",", "0.7", ",", ".55"}], "}"}], "]"}]}], ";"}]], "Code"] }, Closed]], Cell[CellGroupData[{ Cell["Initialization", "Section", InitializationCell->True], Cell[TextData[StyleBox["This code generates a simulation run with linear \ gradient, uniform carrying capacity and constant allelic effects. The outcome \ is the variable \"popnew\". The rest of the code processes a selection of \ summary statistics. The working code is above (\"Definitions\"). It runs for \ a short time of T = 200 generations (saving every dT = 10 generations) with \ carrying capacity kk = 20. [Evaluation: Evalutate Initialization Cells].\n\n\ Variations: Exponential distribution of allelic effects is obtained with \ \[Alpha]\[Alpha]=\[Alpha]List[\[Alpha],ngenes]. For a steepening gradient in \ the optimum \[Theta]Steep, the iterating function is IterateSteepAlpha. The \ initialization for the Random set (Figure 2) is below in a closed cell.", FontSize->14]], "Text", FontWeight->"Bold"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"run", "=", "\"\\""}], ";"}], " "}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"k", "=", "2"}], ";", RowBox[{"h", "=", "1"}], ";", RowBox[{"\[Delta]x", "=", "1"}], ";", RowBox[{"propAdapt", "=", RowBox[{"1", "/", "2"}]}], ";", RowBox[{"LLAll", "=", RowBox[{"{", "}"}]}], ";"}]], "Input", InitializationCell->True], Cell["\<\ \"k\" gives the standard deviations for the diffusive dispersal.\ \>", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"rstar", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Sigma]", "=", SqrtBox[ RowBox[{"1", "/", "2"}]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", "0.1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Vs", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"kk", "=", "20"}], ";"}]}], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"h", "=", "1"}], ";", RowBox[{"\[Alpha]", "=", SqrtBox[ RowBox[{"1", "/", "100"}]]}], ";", RowBox[{"T", "=", "200"}], ";", RowBox[{"dTi", "=", RowBox[{"1", "dT"}]}], ";", RowBox[{"dT", "=", "10"}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"LLAll", "=", RowBox[{"{", "}"}]}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"bList", "=", RowBox[{"{", "b", "}"}]}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "1"}], ",", RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ",", RowBox[{ RowBox[{"b", "=", RowBox[{ "bList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"rm", " ", "=", RowBox[{"rstar", "-", " ", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"2", " ", SuperscriptBox["h", "2"], SqrtBox["Vs"]}]]}]}], ";", RowBox[{"wpq", "=", RowBox[{"4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]", "2"]]]}]}], ";", RowBox[{"nd", " ", "=", RowBox[{"Ceiling", "[", RowBox[{"10", " ", "4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]", "2"]]]}], "]"}]}], ";", RowBox[{"ngenes", "=", RowBox[{"Ceiling", "[", RowBox[{"nd", " ", RowBox[{"b", "/", "\[Alpha]"}]}], "]"}]}], ";", RowBox[{"nn", "=", RowBox[{"kk", RowBox[{"(", RowBox[{"1", "-", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"2", SuperscriptBox["h", "2"], SqrtBox["Vs"], " ", "rm"}]]}], ")"}]}]}], ";", RowBox[{"mut", "=", SuperscriptBox["10", RowBox[{"-", "5"}]]}], ";", "\[IndentingNewLine]", RowBox[{"LL", "=", RowBox[{"{", RowBox[{ "b", ",", "Vs", ",", "\[Sigma]", ",", "kk", ",", "nn", ",", "rm", ",", "rstar", ",", "\[Alpha]", ",", "mut", ",", "ngenes", ",", "propAdapt", ",", "\[Delta]x", ",", "nd", ",", "T", ",", "dT", ",", "wpq"}], "}"}]}], ";", RowBox[{"\[Alpha]\[Alpha]", "=", RowBox[{"\[Alpha]List", "[", RowBox[{"\[Alpha]", ",", "ngenes"}], "]"}]}], ";", RowBox[{"\[Alpha]\[Alpha]", "=", RowBox[{"ConstantArray", "[", RowBox[{"\[Alpha]", ",", "ngenes"}], "]"}]}], ";", RowBox[{"widthList", "=", RowBox[{"4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]\[Alpha]", "2"]]]}]}], ";", RowBox[{"\[Delta]List", "=", RowBox[{"\[Alpha]\[Alpha]", "/", "b"}]}], ";", "\[IndentingNewLine]", RowBox[{"pop", "=", RowBox[{"StartPopdXAlphas", "[", RowBox[{"ngenes", ",", "propAdapt", ",", RowBox[{"Max", "[", RowBox[{"{", RowBox[{"1", ",", " ", RowBox[{"Ceiling", "[", "nn", "]"}]}], "}"}], "]"}], ",", "nd", ",", "mut", ",", "widthList", ",", "\[Delta]List", ",", "b", ",", "\[Delta]x"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"pop", "=", RowBox[{"IterateAlphas", "[", RowBox[{"pop", ",", RowBox[{"{", RowBox[{ "b", " ", ",", "Vs", " ", ",", "rm", " ", ",", "kk", " ", ",", "mut", " ", ",", "\[Sigma]", " ", ",", "k", ",", "\[Alpha]"}], "}"}], ",", "\[Alpha]\[Alpha]", ",", RowBox[{"Round", "[", "ngenes", "]"}], " ", ",", "\[Delta]x", " ", ",", RowBox[{"Regulation", "\[Rule]", "1"}], ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"popnew", "=", RowBox[{"IterateAlphas", "[", RowBox[{"pop", ",", RowBox[{"{", RowBox[{ "b", " ", ",", "Vs", " ", ",", "rm", " ", ",", "kk", " ", ",", "mut", " ", ",", "\[Sigma]", " ", ",", "k", ",", "\[Alpha]"}], "}"}], ",", "\[Alpha]\[Alpha]", ",", RowBox[{"Round", "[", "ngenes", "]"}], " ", ",", "\[Delta]x", " ", ",", RowBox[{"Regulation", "\[Rule]", "1"}], ",", "T", ",", "dT"}], "]"}]}], ";", RowBox[{"nnList", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", RowBox[{ "popnew", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}], "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"MeanVarN", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Mean", "[", "#", "]"}], ",", RowBox[{"Variance", "[", "#", "]"}]}], "}"}], "&"}], "/@", RowBox[{"{", RowBox[{"Drop", "[", RowBox[{"nnList", ",", "1"}], "]"}], "}"}]}], "//", "N"}], ")"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ";", RowBox[{"MedianOFMeanVarN", "=", RowBox[{ RowBox[{ RowBox[{"Median", "[", RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{"Except", "[", "0.", "]"}]}], "]"}], "]"}], "&"}], "/@", "MeanVarN"}]}], ";", "\[IndentingNewLine]", RowBox[{"MeanFragm", "=", RowBox[{"Median", "[", RowBox[{"Cases", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"Select", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "&"}], "/@", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{ "nnList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{ RowBox[{"#", "==", "0"}], "&"}]}], "]"}]}], ")"}]}], ",", RowBox[{ RowBox[{"#", ">", "2"}], "&"}]}], "]"}], "//", "Length"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}], "+", "1"}]}], "}"}]}], "]"}], ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Alive", "=", RowBox[{"Length", "[", RowBox[{"Cases", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", "nnList"}], ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "]"}]}], ";", RowBox[{"TMax", "=", RowBox[{"Min", "[", RowBox[{"{", RowBox[{"Alive", ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}], "+", "1"}]}], "}"}], "]"}]}], ";", RowBox[{"TMin", "=", RowBox[{"Max", "[", RowBox[{"1", ",", RowBox[{"TMax", "-", StyleBox["9", FontColor->RGBColor[0.5, 0, 0.5]]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"range", "=", RowBox[{ RowBox[{ RowBox[{ FractionBox[ RowBox[{"(", RowBox[{ RowBox[{"Length", "[", "#", "]"}], "-", RowBox[{"Count", "[", RowBox[{"#", ",", "0"}], "]"}]}], ")"}], RowBox[{"Min", "[", RowBox[{"{", RowBox[{"nd", ",", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Plus", "@@", " ", "\[Alpha]\[Alpha]"}], " ", "/", "b"}], "]"}]}], "}"}], "]"}]], "&"}], "/@", "nnList"}], "//", "N"}]}], ";", RowBox[{"rangetillfix", "=", RowBox[{"Select", "[", RowBox[{"range", ",", RowBox[{ RowBox[{"#", ">", "0"}], "&"}]}], "]"}]}], ";", RowBox[{"r2dT", "=", RowBox[{ "rangetillfix", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "rangetillfix", "]"}], "\[LessEqual]", "6"}], ",", RowBox[{ RowBox[{"slope", "=", RowBox[{"-", "1"}]}], ";", RowBox[{"PCI", "=", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "1"}]}], "}"}]}], ";", RowBox[{"meangrad", "=", RowBox[{"-", "1"}]}], ";", RowBox[{"MeanWpq", "=", "0"}], ";", RowBox[{"MeanVarZ", "=", "0"}], ";", RowBox[{"MeanvarLE", "=", "0"}], ";", RowBox[{"nnLast", "=", "0"}]}], ",", RowBox[{ RowBox[{"rangetillfix", "=", RowBox[{"Select", "[", RowBox[{ RowBox[{"Take", "[", RowBox[{"rangetillfix", ",", RowBox[{"{", RowBox[{"5", ",", RowBox[{"Length", "[", "rangetillfix", "]"}]}], "}"}]}], "]"}], ",", RowBox[{ RowBox[{"#", "<", "1.0"}], "&"}]}], "]"}]}], ";", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "rangetillfix", "]"}], ">", "1"}], ",", RowBox[{ RowBox[{"lm", "=", RowBox[{"LinearModelFit", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"i", "-", "1"}], ",", RowBox[{ RowBox[{ "rangetillfix", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "-", "r2dT"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "rangetillfix", "]"}]}], "}"}]}], "]"}], ",", "x", ",", "x", ",", RowBox[{"ConfidenceLevel", "\[Rule]", ".98"}]}], "]"}]}], ";", RowBox[{"PCI", "=", RowBox[{ RowBox[{"lm", "[", "\"\\"", "]"}], "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ";", RowBox[{"slope", "=", RowBox[{"D", "[", RowBox[{ RowBox[{"Normal", "[", "lm", "]"}], ",", "x"}], "]"}]}]}], ",", RowBox[{ RowBox[{"slope", "=", "1"}], ";", RowBox[{"PCI", "=", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", RowBox[{"nnList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], "\[Equal]", "0"}], ",", RowBox[{ RowBox[{"nnLast", "=", "0"}], ";", RowBox[{"ExpFAcrossGenes", "=", "0"}], ";", RowBox[{"meangrad", "=", RowBox[{"-", "1"}]}], ";", RowBox[{"MeanWpq", "=", "0"}], ";", RowBox[{"MeanVarZ", "=", "0"}], ";", RowBox[{"MeanvarLE", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"MeanVZC", "=", "0"}], ";", RowBox[{"MeanVLEC", "=", "0"}], ";", RowBox[{"MeanFluctN", "=", "0"}], ";", RowBox[{"Fragm", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"\[Rho]", "=", "0"}]}], ",", RowBox[{ RowBox[{"nnLast", "=", RowBox[{"Mean", "[", RowBox[{"Cases", "[", RowBox[{ RowBox[{"nnList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "]"}]}], ";", RowBox[{"\[Rho]", "=", FractionBox[ RowBox[{"nnList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], RowBox[{"Plus", "@@", RowBox[{"nnList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}]]}], ";", "\[IndentingNewLine]", RowBox[{"pList", "=", RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", "}"}], ",", RowBox[{"Mean", "[", "#", "]"}]}], "]"}], "&"}], ",", RowBox[{"popnew", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], "]"}]}], ";", RowBox[{"varLELast", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", "}"}], ",", RowBox[{ SuperscriptBox["\[Alpha]\[Alpha]", "2"], "#"}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"#", RowBox[{"(", RowBox[{"1", "-", "#"}], ")"}]}], "&"}], "/@", "pList"}], ")"}], ")"}]}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"MeanvarLE", "=", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"varLELast", " ", "\[Rho]"}], ")"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"pListList", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Map", "[", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", "}"}], ",", RowBox[{"Mean", "[", "#", "]"}]}], "]"}], "&"}], ",", RowBox[{ "popnew", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "TMin", ",", "TMax"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"pNullNull", " ", "=", " ", RowBox[{"ConstantArray", "[", RowBox[{"0", ",", " ", "ngenes"}], "]"}]}], ";", RowBox[{"pListNull", "=", " ", RowBox[{"pListList", " ", "/.", " ", RowBox[{ RowBox[{"{", "}"}], " ", "->", " ", "pNullNull"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"pTrans100", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Take", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{ "pListNull", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Max", "[", RowBox[{"1", ",", RowBox[{ RowBox[{"Round", "[", FractionBox[ RowBox[{"ngenes", " ", "propAdapt"}], "2"], "]"}], "-", "50"}]}], "]"}], ",", RowBox[{"Min", "[", RowBox[{ RowBox[{"Round", "[", RowBox[{"ngenes", " ", "propAdapt"}], "]"}], ",", RowBox[{ RowBox[{"Round", "[", FractionBox[ RowBox[{"ngenes", " ", "propAdapt"}], "2"], "]"}], "+", "50"}]}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"TMax", "-", "TMin", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"MeanDispl", "=", RowBox[{"Round", "[", RowBox[{"Mean", "[", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", RowBox[{"pTrans100", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"SolidRangeFragments", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{ "nnList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{ RowBox[{"#", "\[LessEqual]", StyleBox["4", FontColor->RGBColor[1, 0, 0]]}], "&"}]}], "]"}], ")"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "TMin", ",", "TMax"}], "}"}]}], "]"}]}], ";", RowBox[{"DropZeros", "=", RowBox[{ RowBox[{ RowBox[{"#", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], "&"}], "/@", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{ "SolidRangeFragments", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{ RowBox[{"#", "\[LessEqual]", RowBox[{ RowBox[{"Max", "[", RowBox[{ "SolidRangeFragments", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}], "-", "1"}]}], "&"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"TMax", "-", "TMin", "+", "1"}]}], "}"}]}], "]"}]}]}], ";", RowBox[{"DropZeros", "=", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "\[Equal]", "nd"}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", "DropZeros"}]}], ";", "\[IndentingNewLine]", RowBox[{"DropFirstZeros", "=", RowBox[{ RowBox[{ RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "&"}], "/@", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "#"}], "&"}], "/@", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{ "SolidRangeFragments", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{ RowBox[{"#", "\[LessEqual]", RowBox[{ RowBox[{"Max", "[", RowBox[{ "SolidRangeFragments", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}], "-", "1"}]}], "&"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"TMax", "-", "TMin", "+", "1"}]}], "}"}]}], "]"}]}]}], ";", RowBox[{"DropFirstZeros", "=", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "\[Equal]", "nd"}], ",", "0", ",", "#"}], "]"}], "&"}], "/@", "DropFirstZeros"}]}], ";", "\[IndentingNewLine]", RowBox[{"AlignedTable", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{"ConstantArray", "[", RowBox[{"0", ",", RowBox[{ RowBox[{"Round", "[", RowBox[{"Plus", "@@", "#1"}], "]"}], "+", "#2"}]}], "]"}], ",", RowBox[{"Drop", "[", RowBox[{ RowBox[{"Drop", "[", RowBox[{"#1", ",", RowBox[{"-", "#3"}]}], "]"}], ",", "#2"}], "]"}], ",", RowBox[{"Join", "[", RowBox[{"ConstantArray", "[", RowBox[{"1", ",", RowBox[{"#3", "+", "nd", "-", RowBox[{"Round", "[", RowBox[{"Plus", "@@", "#1"}], "]"}]}]}], "]"}], "]"}]}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{ "pTrans100", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{"ConstantArray", "[", RowBox[{ RowBox[{ "DropFirstZeros", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{"Length", "[", RowBox[{ "pTrans100", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}]}], "]"}], ",", RowBox[{"ConstantArray", "[", RowBox[{ RowBox[{ "DropZeros", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{"Length", "[", RowBox[{ "pTrans100", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}]}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"TMax", "-", "TMin", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"pAlignedList", "=", RowBox[{"Transpose", "[", RowBox[{"Drop", "[", RowBox[{"AlignedTable", ",", "1"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"FluctForAllGenes", "=", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{ RowBox[{"Variance", "[", RowBox[{"Drop", "[", RowBox[{"#", ",", "1"}], "]"}], "]"}], "//", "N"}], ")"}]}], "&"}], "/@", "pAlignedList"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"\[CapitalDelta]nn", "=", RowBox[{ RowBox[{"Take", "[", RowBox[{ RowBox[{ RowBox[{"Drop", "[", RowBox[{"nnList", ",", "1"}], "]"}], "-", RowBox[{"Drop", "[", RowBox[{"nnList", ",", RowBox[{"-", "1"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"Max", "[", RowBox[{"1", ",", RowBox[{"TMin", "-", "1"}]}], "]"}], ",", RowBox[{"TMax", "-", "1"}]}], "}"}]}], "]"}], "//", "N"}]}], ";", "\[IndentingNewLine]", RowBox[{"MeanFluctN", "=", RowBox[{"Median", "[", RowBox[{"Cases", "[", RowBox[{ RowBox[{"Variance", "[", "\[CapitalDelta]nn", "]"}], ",", RowBox[{"Except", "[", "0.", "]"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Fragm", "=", RowBox[{ RowBox[{"Select", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{"Except", "[", "0", "]"}]}], "]"}], "&"}], "/@", RowBox[{"SplitBy", "[", RowBox[{ RowBox[{"nnList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], ",", RowBox[{ RowBox[{"#", "==", "0"}], "&"}]}], "]"}]}], ")"}]}], ",", RowBox[{ RowBox[{"#", ">", "2"}], "&"}]}], "]"}], "//", "Length"}]}], ";", RowBox[{"wList", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"4", " ", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"#", RowBox[{"(", RowBox[{"1", "-", "#"}], ")"}]}], ")"}]}]}], "&"}], "/@", RowBox[{"Transpose", "[", RowBox[{"pList", " ", "/.", " ", RowBox[{ RowBox[{"{", "}"}], " ", "->", " ", "pNullNull"}]}], "]"}]}], "//", "N"}]}], ";", RowBox[{"MeanWpq", "=", RowBox[{ RowBox[{"(", RowBox[{"Mean", "[", RowBox[{"Select", "[", RowBox[{ RowBox[{"Take", "[", RowBox[{"wList", ",", RowBox[{"{", RowBox[{"1", ",", "ngenes"}], "}"}]}], "]"}], ",", RowBox[{ RowBox[{"#", ">", RowBox[{"Mean", "[", FractionBox[ RowBox[{"Cases", "[", RowBox[{ RowBox[{"Take", "[", RowBox[{"wList", ",", RowBox[{"{", RowBox[{"1", ",", "ngenes"}], "}"}]}], "]"}], ",", RowBox[{"Except", "[", "0.", "]"}]}], "]"}], "10"], "]"}]}], "&"}]}], "]"}], "]"}], ")"}], "/.", RowBox[{ RowBox[{"Mean", "[", RowBox[{"{", "}"}], "]"}], "\[Rule]", " ", "0"}]}]}], ";", RowBox[{"If", "[", RowBox[{ RowBox[{"MeanWpq", ">", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"ExpCline", "=", RowBox[{"Table", "[", RowBox[{ FractionBox["1", RowBox[{"1", "+", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "4"}], FractionBox[ RowBox[{"x", "-", "nd"}], "MeanWpq"]}], "]"}]}]], ",", RowBox[{"{", RowBox[{"x", ",", "1", ",", RowBox[{"2", "nd"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ExpFAcrossGenes", "=", RowBox[{"Median", "[", RowBox[{"FluctForAllGenes", "/", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"ExpCline", RowBox[{"(", RowBox[{"1", "-", "ExpCline"}], ")"}]}], ")"}]}]}], "]"}]}]}], ",", RowBox[{"ExpFAcrossGenes", "=", "Null"}]}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"zzAllList", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"\[Alpha]\[Alpha]", "#"}], ")"}]}], "&"}], "/@", "#"}], "&"}], "/@", RowBox[{"(", RowBox[{"popnew", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"varzzList", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], ">", "1"}], ",", RowBox[{"Variance", "[", "#", "]"}], ",", RowBox[{"{", "}"}]}], "]"}], "&"}], "/@", "zzAllList"}], "//", "N"}]}], ";", RowBox[{"MeanVarZ", "=", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"Cases", "[", RowBox[{ RowBox[{"varzzList", " ", "\[Rho]"}], ",", RowBox[{"Except", "[", RowBox[{"{", "}"}], "]"}]}], "]"}], ")"}]}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"varLEP", "=", RowBox[{ RowBox[{"Cases", "[", RowBox[{"varLELast", ",", RowBox[{"Except", "[", "0.", "]"}]}], "]"}], "//", "N"}]}], ";", RowBox[{"MeanVLEC", "=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "varLEP", "]"}], ">", "2"}], ",", RowBox[{"Mean", "[", RowBox[{"Take", "[", RowBox[{"varLEP", ",", RowBox[{"Sort", "[", RowBox[{"{", RowBox[{ RowBox[{"3", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Length", "[", "varLEP", "]"}], "/", "8"}], "]"}]}], ",", RowBox[{"Floor", "[", RowBox[{ FractionBox["5", "8"], RowBox[{"Length", "[", "varLEP", "]"}]}], "]"}]}], "}"}], "]"}]}], "]"}], "]"}], ",", RowBox[{"Mean", "[", "varLEP", "]"}]}], "]"}]}], ";", RowBox[{"varZP", "=", RowBox[{ RowBox[{"Cases", "[", RowBox[{"varzzList", ",", RowBox[{"Except", "[", RowBox[{"0.", "|", RowBox[{"{", "}"}]}], "]"}]}], "]"}], "//", "N"}]}], ";", RowBox[{"MeanVZC", "=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "varZP", "]"}], ">", "2"}], ",", RowBox[{"Mean", "[", RowBox[{"Take", "[", RowBox[{"varZP", ",", RowBox[{"Sort", "[", RowBox[{"{", RowBox[{ RowBox[{"3", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Length", "[", "varZP", "]"}], "/", "8"}], "]"}]}], ",", RowBox[{"Floor", "[", RowBox[{ FractionBox["5", "8"], RowBox[{"Length", "[", "varZP", "]"}]}], "]"}]}], "}"}], "]"}]}], "]"}], "]"}], ",", RowBox[{"Mean", "[", "varZP", "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"zzList", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#", "==", RowBox[{"{", "}"}]}], ",", RowBox[{"{", "}"}], ",", RowBox[{"Mean", "[", "#", "]"}]}], "]"}], "&"}], "/@", "zzAllList"}], "//", "N"}]}], ";", RowBox[{"meangrad", "=", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"Cases", "[", RowBox[{ RowBox[{ RowBox[{"Drop", "[", RowBox[{ RowBox[{ RowBox[{"Append", "[", RowBox[{"zzList", ",", RowBox[{"zzList", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], "]"}], "-", RowBox[{"Prepend", "[", RowBox[{"zzList", ",", RowBox[{ "zzList", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}]}], ",", RowBox[{"-", "1"}]}], "]"}], "\[Rho]"}], ",", RowBox[{"Except", "[", RowBox[{"{", "}"}], "]"}]}], "]"}], ")"}]}]}]}]}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"LL", "=", RowBox[{ RowBox[{"Join", "[", RowBox[{"LL", ",", RowBox[{"{", RowBox[{ "MeanWpq", ",", "MeanVarZ", ",", "MeanvarLE", ",", "MeanVZC", ",", "MeanVLEC", ",", RowBox[{"range", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], ",", "ExpFAcrossGenes", ",", "Null", ",", "MeanFragm", ",", "Null", ",", "MeanFluctN", ",", RowBox[{ "MedianOFMeanVarN", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", "Fragm", ",", RowBox[{"nnLast", "//", "N"}], ",", RowBox[{ "PCI", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", "slope", ",", RowBox[{ "PCI", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", "meangrad"}], "}"}]}], "]"}], "//", "N"}]}], ";", "\[IndentingNewLine]", RowBox[{"LLAll", "=", RowBox[{"Append", "[", RowBox[{"LLAll", ",", "LL"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "popnew"}], "]"}], ";", RowBox[{"popLast", "=", RowBox[{"popnew", "\[LeftDoubleBracket]", RowBox[{"-", "1"}], "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "popLast"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "LL"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "\[Alpha]\[Alpha]"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "FluctForAllGenes"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"DumpSave", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "run", "]"}], "<>", RowBox[{"ToString", "[", "\"\<_\>\"", "]"}], "<>", RowBox[{"ToString", "[", "i", "]"}], "<>", "\"\<.mx\>\""}], ",", "wList"}], "]"}]}]}], "]"}], ";"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"DumpSave", "[", RowBox[{ RowBox[{ "\"\\"", " ", "<>", " ", RowBox[{"ToString", "[", "run", "]"}], " ", "<>", " ", "\"\<.mx\>\""}], ",", " ", "LLAll"}], "]"}], ";"}]], "Input", InitializationCell->True], Cell["Exit[]", "Text", InitializationCell->True], Cell[CellGroupData[{ Cell["\<\ For Random runs, the following rutine was used to generate the paramters :\ \>", "Subsection"], Cell[TextData[StyleBox["10 simulation runs with linear gradient and uniform \ carrying capacity, using a distribution of parameters. ", FontWeight->"Bold"]], "Text", FontSize->14], Cell[BoxData[ RowBox[{ RowBox[{"seed", "=", "999"}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"run", "=", RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "seed", "]"}]}]}], ";"}]], "Code"], Cell[BoxData[ RowBox[{ RowBox[{"SeedRandom", "[", "seed", "]"}], ";"}]], "Code"], Cell[BoxData[ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "10"}], ",", RowBox[{"i", "=", RowBox[{"i", "+", "1"}]}], ",", RowBox[{ RowBox[{"ngenes", "=", "5001"}], ";", RowBox[{"B", "=", "2.1"}], ";", RowBox[{"rm", "=", "2.1"}], ";", RowBox[{"\[Sigma]", "=", ".001"}], ";", RowBox[{"mut", "=", RowBox[{"10", "^", RowBox[{"-", "9"}]}]}], ";", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"ngenes", ">", "4000"}], "||", RowBox[{"B", ">", "1.6"}], "||", RowBox[{"B", "<", "0.01"}], "||", RowBox[{"rm", ">", "2"}], "||", RowBox[{"\[Sigma]", "<", "0.5"}], "||", RowBox[{"mut", "<", RowBox[{"10", "^", RowBox[{"-", "8"}]}]}]}], ",", RowBox[{ RowBox[{"rstar", "=", RowBox[{"Random", "[", RowBox[{"NormalDistribution", "[", RowBox[{"1", ",", RowBox[{"1", "/", "3"}]}], "]"}], "]"}]}], ";", RowBox[{"b", "=", RowBox[{"Random", "[", RowBox[{"Real", ",", RowBox[{"{", RowBox[{"0.01", ",", "2"}], "}"}]}], "]"}]}], ";", RowBox[{"\[Sigma]", "=", RowBox[{"Random", "[", RowBox[{"ExponentialDistribution", "[", RowBox[{ RowBox[{"Log", "[", "2", "]"}], SqrtBox["2"]}], "]"}], "]"}]}], ";", RowBox[{"Vs", "=", RowBox[{"Random", "[", RowBox[{"ExponentialDistribution", "[", "1", "]"}], "]"}]}], ";", RowBox[{"rm", "=", RowBox[{"rstar", " ", "+", " ", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"2", " ", SuperscriptBox["h", "2"], SqrtBox["Vs"]}]]}]}], ";", RowBox[{"nn", "=", RowBox[{"Random", "[", RowBox[{"Integer", ",", RowBox[{"{", RowBox[{"4", ",", "100"}], "}"}]}], "]"}]}], ";", RowBox[{"kk", "=", RowBox[{"nn", "/", RowBox[{"(", RowBox[{"1", "-", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"2", SuperscriptBox["h", "2"], SqrtBox["Vs"], " ", "rm"}]]}], ")"}]}]}], ";", RowBox[{"\[Alpha]", "=", RowBox[{"Random", "[", RowBox[{"ExponentialDistribution", "[", "20", "]"}], "]"}]}], ";", RowBox[{"s", "=", FractionBox[ SuperscriptBox["\[Alpha]", "2"], RowBox[{"2", "Vs"}]]}], ";", RowBox[{"nd", " ", "=", RowBox[{"Ceiling", "[", RowBox[{"10", " ", "4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]", "2"]]]}], "]"}]}], ";", RowBox[{"ngenes", "=", RowBox[{"Ceiling", "[", RowBox[{"nd", " ", RowBox[{"b", "/", "\[Alpha]"}]}], "]"}]}], ";", RowBox[{"B", "=", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"rstar", SqrtBox[ RowBox[{"2", "Vs"}]]}]]}], ";", RowBox[{"mut", "=", FractionBox["1", RowBox[{"nn", " ", "ngenes", " ", "nd", " "}]]}]}]}], "]"}], ";", RowBox[{"wpq", "=", RowBox[{"4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]", "2"]]]}]}], ";", RowBox[{"\[Alpha]\[Alpha]", "=", RowBox[{"ConstantArray", "[", RowBox[{"\[Alpha]", ",", "ngenes"}], "]"}]}], ";", RowBox[{"widthList", "=", RowBox[{"4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]\[Alpha]", "2"]]]}]}], ";", RowBox[{"\[Delta]List", "=", RowBox[{"\[Alpha]\[Alpha]", "/", "b"}]}], ";", "\[IndentingNewLine]", RowBox[{"LL", "=", RowBox[{"{", RowBox[{ "b", ",", "Vs", ",", "\[Sigma]", ",", "kk", ",", "nn", ",", "rm", ",", "rstar", ",", "\[Alpha]", ",", "mut", ",", "ngenes", ",", "propAdapt", ",", "\[Delta]x", ",", "nd", ",", "T", ",", "dT", ",", "wpq"}], "}"}]}], ";"}]}], "]"}]], "Input"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Charts from data", "Section"], Cell[CellGroupData[{ Cell["Loading data", "Subsection"], Cell["\<\ The data can be loaded [path modification is necessary] or used directly. \ [Definitions need to be evaluated].\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"<<", "\"\\""}], ";", "LL"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{ "0.1`", ",", "1.`", ",", "0.7071067811865475`", ",", "20.`", ",", "19.26697693998844`", ",", "0.9646446609406726`", ",", "1.`", ",", "0.1`", ",", "0.00001`", ",", "283.`", ",", "0.5`", ",", "1.`", ",", "283.`", ",", "200.`", ",", "10.`", ",", "28.284271247461902`", ",", "16.05269379886745`", ",", "0.040503019711320774`", ",", "0.03825099327799454`", ",", "0.052973489308113166`", ",", "0.04570301610686745`", ",", "0.6219081272084805`", ",", "0.4015462258648036`", ",", "Null", ",", "1.`", ",", "Null", ",", "40.900000000000006`", ",", "18.6`", ",", "1.`", ",", "17.75`", ",", "0.0002460119631449997`", ",", "0.0009007136423473993`", ",", "0.0015554153215497988`", ",", "0.08802904438494437`"}], "}"}]], "Output", CellChangeTimes->{{3.623585014706839*^9, 3.623585042283228*^9}}] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"<<", "\"\\""}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{ "<<", "\"\\""}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"T", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "14", "\[RightDoubleBracket]"}]}], ";", RowBox[{"dT", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "15", "\[RightDoubleBracket]"}]}], ";", RowBox[{"h", "=", "1"}], ";", RowBox[{"b", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ";", RowBox[{"\[Sigma]", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}], ";", RowBox[{"Vs", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ";", RowBox[{"rm", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "6", "\[RightDoubleBracket]"}]}], ";", RowBox[{"kk", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}]}], ";", RowBox[{"\[Alpha]", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "8", "\[RightDoubleBracket]"}]}], ";", RowBox[{"ngenes", "=", RowBox[{"Round", "[", RowBox[{"LL", "\[LeftDoubleBracket]", "10", "\[RightDoubleBracket]"}], "]"}]}], ";", RowBox[{"nd", "=", RowBox[{"LL", "\[LeftDoubleBracket]", "13", "\[RightDoubleBracket]"}]}], ";", RowBox[{"nn", "=", RowBox[{"kk", RowBox[{"(", RowBox[{"1", "-", FractionBox[ RowBox[{"b", " ", "\[Sigma]"}], RowBox[{"2", SuperscriptBox["h", "2"], SqrtBox["Vs"], " ", "rm"}]]}], ")"}]}]}], ";", RowBox[{"rstar", "=", RowBox[{"rm", "-", FractionBox[ RowBox[{"b", " ", "\[Sigma]", " ", SqrtBox[ RowBox[{"Vs", " "}]]}], RowBox[{"2", "Vs"}]]}]}], ";", RowBox[{"\[Delta]x", "=", "1"}], ";"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Charts", "Subsection"], Cell[BoxData[ RowBox[{"Needs", "[", "\"\\"", "]"}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"Vopt", "=", RowBox[{"b", " ", "\[Sigma]", " ", SqrtBox["Vs"]}]}], ";", RowBox[{"width", "=", RowBox[{"4", SqrtBox[ FractionBox[ RowBox[{ SuperscriptBox["\[Sigma]", "2"], "Vs"}], SuperscriptBox["\[Alpha]", "2"]]]}]}], ";", RowBox[{"s", "=", FractionBox[ SuperscriptBox["\[Alpha]", "2"], RowBox[{"2", "Vs"}]]}], ";"}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Timing", "[", RowBox[{ RowBox[{"nnList", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "#", "]"}], "&"}], "/@", RowBox[{ "popnew", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{ RowBox[{"Quotient", "[", RowBox[{"T", ",", "dT"}], "]"}], "+", "1"}]}], "}"}]}], "]"}]}], ";"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{ "0.00800000000000000016653345369377348106`3.9236899002715675", ",", "Null"}], "}"}]], "Output", CellChangeTimes->{{3.623585015319372*^9, 3.623585042709771*^9}}] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"FullRange", "=", "T"}], ";"}]], "Input"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Show", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Show", "[", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{ RowBox[{"Range", "[", RowBox[{"0", ",", "T", ",", "dT"}], "]"}], ",", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Length", "[", "#", "]"}], "-", RowBox[{"Count", "[", RowBox[{"#", ",", "0"}], "]"}]}], ")"}], "&"}], "/@", "nnList"}], RowBox[{"Min", "[", RowBox[{"{", RowBox[{"nd", ",", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Plus", "@@", " ", "\[Alpha]\[Alpha]"}], "/", "b"}], "]"}]}], "}"}], "]"}]]}], "}"}], "]"}], ",", RowBox[{"Joined", "\[Rule]", " ", "True"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"Thickness", "[", "0.002", "]"}], ",", "Black"}], "}"}]}]}], "]"}], ",", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{ RowBox[{"Range", "[", RowBox[{"0", ",", "T", ",", "dT"}], "]"}], ",", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Length", "[", "#", "]"}], "-", RowBox[{"Count", "[", RowBox[{"#", ",", "0"}], "]"}]}], ")"}], "&"}], "/@", "nnList"}], RowBox[{"Min", "[", RowBox[{"{", RowBox[{"nd", ",", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"Plus", "@@", " ", "\[Alpha]\[Alpha]"}], " ", "/", "b"}], "]"}]}], "}"}], "]"}]]}], "}"}], "]"}], ",", RowBox[{"Joined", "\[Rule]", "False"}], ",", RowBox[{"PlotStyle", "\[Rule]", " ", RowBox[{"{", RowBox[{ RowBox[{"PointSize", "[", "0.007", "]"}], ",", "Black"}], "}"}]}]}], "]"}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"FontSize", "\[Rule]", "14"}], ",", RowBox[{"FontFamily", "\[Rule]", "\"\\""}]}], "}"}]}], ",", RowBox[{"FrameLabel", "\[Rule]", " ", RowBox[{"{", RowBox[{ "\"\