|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Get[FileNameJoin[{NotebookDirectory[], "ChaosSim.nb"}]]
|
|
|
Get[FileNameJoin[{NotebookDirectory[], "Visualizations.nb"}]]
|
|
|
|
|
|
Print[Style["ChaosSim Examples Loaded", Bold, 16, Blue]]
|
|
|
Print["Run each section to see different chaos simulations in action.\n"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["=== Example 1: Bernoulli Chaos Simulation ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
bernoulliExample = SimulateBernoulliChaos[500, 12];
|
|
|
|
|
|
|
|
|
Print["Statistics:"]
|
|
|
Print[" Mean: ", Mean[bernoulliExample]]
|
|
|
Print[" Standard Deviation: ", StandardDeviation[bernoulliExample]]
|
|
|
Print[" Min: ", Min[bernoulliExample], " | Max: ", Max[bernoulliExample]]
|
|
|
|
|
|
|
|
|
ListPlot[bernoulliExample,
|
|
|
PlotStyle -> {Blue, PointSize[Small]},
|
|
|
PlotLabel -> Style["Example 1: Bernoulli Chaos", Bold, 14],
|
|
|
AxesLabel -> {"Iteration", "State"},
|
|
|
ImageSize -> Large,
|
|
|
GridLines -> Automatic
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 2: Fibonacci Golden Spiral ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
fibonacciSpiralPoints = FibonacciSpiral3D[20, 100];
|
|
|
|
|
|
Print["Generated ", Length[fibonacciSpiralPoints], " points in golden spiral"]
|
|
|
Print["Golden Ratio β ", N[GoldenRatio, 6]]
|
|
|
|
|
|
|
|
|
ListPointPlot3D[fibonacciSpiralPoints,
|
|
|
PlotStyle -> Directive[PointSize[Small]],
|
|
|
ColorFunction -> Function[{x, y, z},
|
|
|
ColorData["SunsetColors"][Norm[{x, y}]]
|
|
|
],
|
|
|
BoxRatios -> {1, 1, 0.6},
|
|
|
ImageSize -> Large,
|
|
|
PlotLabel -> Style["Example 2: Fibonacci Golden Spiral", Bold, 14],
|
|
|
AxesLabel -> {"X", "Y", "Z"},
|
|
|
Background -> GrayLevel[0.95],
|
|
|
ViewPoint -> {2, -2, 1.5}
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 3: Prisoner's Dilemma Nash Equilibrium ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
|
|
|
prisonerPayoff1 = {{-1, -3}, {0, -2}};
|
|
|
prisonerPayoff2 = {{-1, 0}, {-3, -2}};
|
|
|
|
|
|
Print["Player 1 Payoff Matrix (rows: P1 strategy, cols: P2 strategy):"]
|
|
|
Print[MatrixForm[prisonerPayoff1]]
|
|
|
|
|
|
Print["\nPlayer 2 Payoff Matrix:"]
|
|
|
Print[MatrixForm[prisonerPayoff2]]
|
|
|
|
|
|
|
|
|
equilibria = FindNashEquilibrium[prisonerPayoff1, prisonerPayoff2];
|
|
|
|
|
|
Print["\nNash Equilibrium found at: ", equilibria]
|
|
|
Print["Interpretation: Both players choosing Defect (strategy 2, 2)"]
|
|
|
|
|
|
|
|
|
GraphicsRow[{
|
|
|
ArrayPlot[prisonerPayoff1,
|
|
|
ColorFunction -> "Rainbow",
|
|
|
PlotLabel -> "Player 1 Payoffs",
|
|
|
FrameLabel -> {"P2 Strategy", "P1 Strategy"},
|
|
|
PlotLegends -> Automatic
|
|
|
],
|
|
|
ArrayPlot[prisonerPayoff2,
|
|
|
ColorFunction -> "Rainbow",
|
|
|
PlotLabel -> "Player 2 Payoffs",
|
|
|
FrameLabel -> {"P2 Strategy", "P1 Strategy"},
|
|
|
PlotLegends -> Automatic
|
|
|
]
|
|
|
}, ImageSize -> Large]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 4: Chaotic Game Evolution ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
chaosGameHistory = ChaosGameSimulation[100, 2, 0.3];
|
|
|
|
|
|
|
|
|
rounds = chaosGameHistory[[All, 1]];
|
|
|
strategies = chaosGameHistory[[All, 2]];
|
|
|
equilibriaCounts = Length /@ chaosGameHistory[[All, 3]];
|
|
|
|
|
|
Print["Simulation complete: ", Length[rounds], " rounds"]
|
|
|
Print["Average equilibria per round: ", Mean[equilibriaCounts]]
|
|
|
|
|
|
|
|
|
ListLinePlot[
|
|
|
{strategies[[All, 1]], strategies[[All, 2]]},
|
|
|
PlotStyle -> {{Blue, Thick}, {Red, Thick}},
|
|
|
PlotLabel -> Style["Example 4: Strategy Evolution in Chaotic Game", Bold, 14],
|
|
|
AxesLabel -> {"Round", "Strategy Choice"},
|
|
|
PlotLegends -> {"Player 1", "Player 2"},
|
|
|
ImageSize -> Large,
|
|
|
GridLines -> Automatic
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 5: Multi-Agent Chaos Equilibrium ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
multiAgentChaos = MultiAgentChaosEquilibrium[5, 200];
|
|
|
|
|
|
|
|
|
agentStates = multiAgentChaos[[All, 2]];
|
|
|
|
|
|
Print["Number of agents: 5"]
|
|
|
Print["Iterations: 200"]
|
|
|
Print["Final agent states: ", agentStates[[-1]]]
|
|
|
Print["State convergence: ", StandardDeviation[agentStates[[-1]]]]
|
|
|
|
|
|
|
|
|
ListLinePlot[
|
|
|
Table[agentStates[[All, i]], {i, 1, 5}],
|
|
|
PlotStyle -> Table[Directive[Thick, ColorData[97][i]], {i, 1, 5}],
|
|
|
PlotLabel -> Style["Example 5: Multi-Agent State Evolution", Bold, 14],
|
|
|
AxesLabel -> {"Iteration", "Agent State"},
|
|
|
PlotLegends -> Table[StringTemplate["Agent ``"][i], {i, 1, 5}],
|
|
|
ImageSize -> Large,
|
|
|
GridLines -> Automatic
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 6: Unified Chaos System ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
unifiedChaos = UnifiedChaosSimulation[400];
|
|
|
|
|
|
|
|
|
correlations = ChaosCorrelationAnalysis[unifiedChaos];
|
|
|
|
|
|
Print["Unified chaos simulation complete"]
|
|
|
Print["Data points: ", Length[unifiedChaos]]
|
|
|
Print["\nCorrelation Analysis:"]
|
|
|
Print[Grid[
|
|
|
Prepend[correlations, {"Component Pair", "Correlation"}],
|
|
|
Frame -> All,
|
|
|
Background -> {None, {LightBlue, White}}
|
|
|
]]
|
|
|
|
|
|
|
|
|
ListPointPlot3D[unifiedChaos,
|
|
|
PlotStyle -> Directive[PointSize[Small]],
|
|
|
ColorFunction -> Function[{x, y, z},
|
|
|
ColorData["Rainbow"][z]
|
|
|
],
|
|
|
BoxRatios -> {1, 1, 1},
|
|
|
ImageSize -> Large,
|
|
|
PlotLabel -> Style["Example 6: Unified Chaos Phase Space", Bold, 14],
|
|
|
AxesLabel -> {"Bernoulli", "Fibonacci", "Nash"},
|
|
|
Background -> Black,
|
|
|
ViewPoint -> {1.5, -2.5, 1.2}
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 7: Bernoulli 3D Attractor ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
attractorPoints = BernoulliAttractor[3000, 3];
|
|
|
|
|
|
Print["Generated ", Length[attractorPoints], " points"]
|
|
|
Print["Attractor bounds:"]
|
|
|
Print[" X: [", Min[attractorPoints[[All, 1]]], ", ", Max[attractorPoints[[All, 1]]], "]"]
|
|
|
Print[" Y: [", Min[attractorPoints[[All, 2]]], ", ", Max[attractorPoints[[All, 2]]], "]"]
|
|
|
Print[" Z: [", Min[attractorPoints[[All, 3]]], ", ", Max[attractorPoints[[All, 3]]], "]"]
|
|
|
|
|
|
|
|
|
ListPointPlot3D[attractorPoints,
|
|
|
PlotStyle -> Directive[PointSize[Tiny]],
|
|
|
ColorFunction -> Function[{x, y, z},
|
|
|
ColorData["DarkRainbow"][Norm[{x, y, z}]/2]
|
|
|
],
|
|
|
BoxRatios -> {1, 1, 1},
|
|
|
ImageSize -> Large,
|
|
|
PlotLabel -> Style["Example 7: Bernoulli Attractor", Bold, 14],
|
|
|
AxesLabel -> {"X", "Y", "Z"},
|
|
|
Background -> Black,
|
|
|
Boxed -> False,
|
|
|
ViewPoint -> {2, -2, 1}
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 8: Fibonacci Chaos Map ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
fibChaosMap = FibonacciChaosMap[800];
|
|
|
|
|
|
Print["Generated ", Length[fibChaosMap], " iterations"]
|
|
|
Print["Mean value: ", Mean[fibChaosMap]]
|
|
|
Print["Chaos entropy: ", ChaosEntropy[fibChaosMap]]
|
|
|
|
|
|
|
|
|
GraphicsRow[{
|
|
|
ListPlot[fibChaosMap,
|
|
|
PlotStyle -> {Orange, PointSize[Small]},
|
|
|
PlotLabel -> "Time Series",
|
|
|
AxesLabel -> {"Iteration", "Value"},
|
|
|
ImageSize -> Medium
|
|
|
],
|
|
|
ListPlot[Partition[fibChaosMap, 2, 1],
|
|
|
PlotStyle -> {Red, PointSize[Tiny]},
|
|
|
PlotLabel -> "Phase Space",
|
|
|
AxesLabel -> {"x(t)", "x(t+1)"},
|
|
|
ImageSize -> Medium,
|
|
|
AspectRatio -> 1
|
|
|
]
|
|
|
}, ImageSize -> Large,
|
|
|
PlotLabel -> Style["Example 8: Fibonacci Chaos Map Analysis", Bold, 14]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 9: Comparative Chaos Analysis ===", Bold, 14, Purple]]
|
|
|
|
|
|
|
|
|
iterations = 400;
|
|
|
bernoulliChaos = SimulateBernoulliChaos[iterations, 12];
|
|
|
fibonacciChaos = FibonacciChaosMap[iterations];
|
|
|
nashChaos = MultiAgentChaosEquilibrium[5, iterations][[All, 2, 1]];
|
|
|
|
|
|
|
|
|
Print["Chaos Type Statistics:"]
|
|
|
Print[Grid[{
|
|
|
{"Type", "Mean", "Std Dev", "Entropy"},
|
|
|
{"Bernoulli", Mean[bernoulliChaos], StandardDeviation[bernoulliChaos],
|
|
|
ChaosEntropy[bernoulliChaos]},
|
|
|
{"Fibonacci", Mean[fibonacciChaos], StandardDeviation[fibonacciChaos],
|
|
|
ChaosEntropy[fibonacciChaos]},
|
|
|
{"Nash", Mean[nashChaos], StandardDeviation[nashChaos],
|
|
|
ChaosEntropy[nashChaos]}
|
|
|
}, Frame -> All, Background -> {None, {LightYellow, White}}]]
|
|
|
|
|
|
|
|
|
ListLinePlot[
|
|
|
{bernoulliChaos, fibonacciChaos, nashChaos},
|
|
|
PlotStyle -> {
|
|
|
{Blue, Thick, Opacity[0.7]},
|
|
|
{Orange, Thick, Opacity[0.7]},
|
|
|
{Green, Thick, Opacity[0.7]}
|
|
|
},
|
|
|
PlotLabel -> Style["Example 9: Chaos Type Comparison", Bold, 14],
|
|
|
AxesLabel -> {"Iteration", "State Value"},
|
|
|
PlotLegends -> {"Bernoulli", "Fibonacci", "Nash Equilibrium"},
|
|
|
ImageSize -> Large,
|
|
|
GridLines -> Automatic
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n=== Example 10: Chaotic Market Simulation ===", Bold, 14, Purple]]
|
|
|
|
|
|
SimulateChaoticMarket[days_Integer, initialPrice_Real: 100.0] := Module[
|
|
|
{chaos, prices, returns},
|
|
|
|
|
|
|
|
|
chaos = SimulateBernoulliChaos[days, 10];
|
|
|
|
|
|
|
|
|
returns = (chaos - 0.5) * 0.1;
|
|
|
|
|
|
|
|
|
prices = FoldList[
|
|
|
#1 * (1 + #2) &,
|
|
|
initialPrice,
|
|
|
returns
|
|
|
];
|
|
|
|
|
|
prices
|
|
|
]
|
|
|
|
|
|
|
|
|
marketPrices = SimulateChaoticMarket[250, 100.0];
|
|
|
|
|
|
Print["Market simulation: 250 trading days"]
|
|
|
Print["Initial price: $100.00"]
|
|
|
Print["Final price: $", marketPrices[[-1]]]
|
|
|
Print["Max price: $", Max[marketPrices]]
|
|
|
Print["Min price: $", Min[marketPrices]]
|
|
|
Print["Total return: ", (marketPrices[[-1]] - 100.0), "%"]
|
|
|
|
|
|
|
|
|
ListLinePlot[marketPrices,
|
|
|
PlotStyle -> {Darker[Green], Thick},
|
|
|
PlotLabel -> Style["Example 10: Chaotic Market Prices", Bold, 14],
|
|
|
AxesLabel -> {"Trading Day", "Price ($)"},
|
|
|
ImageSize -> Large,
|
|
|
Filling -> Axis,
|
|
|
FillingStyle -> Opacity[0.2, Green],
|
|
|
GridLines -> Automatic
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Print[Style["\n\n" <> StringRepeat["=", 60], Bold, Blue]]
|
|
|
Print[Style["ChaosSim Examples Complete!", Bold, 18, Blue]]
|
|
|
Print[Style[StringRepeat["=", 60] <> "\n", Bold, Blue]]
|
|
|
|
|
|
Print["You have explored:"]
|
|
|
Print[" β Bernoulli number-based chaos generation"]
|
|
|
Print[" β Fibonacci sequence chaotic patterns"]
|
|
|
Print[" β Nash equilibrium in game theory"]
|
|
|
Print[" β Multi-agent chaos systems"]
|
|
|
Print[" β Unified chaos simulations"]
|
|
|
Print[" β 3D attractors and visualizations"]
|
|
|
Print[" β Practical applications (market simulation)"]
|
|
|
|
|
|
Print["\nNext steps:"]
|
|
|
Print[" β’ Modify parameters in any example to explore variations"]
|
|
|
Print[" β’ Create your own chaos combinations"]
|
|
|
Print[" β’ Use Visualizations.nb for advanced plotting"]
|
|
|
Print[" β’ Refer to README.md for detailed documentation"]
|
|
|
|
|
|
Print[Style["\nHappy chaos simulation! π", Bold, 16, Purple]]
|
|
|
|