Visualize and Model Lévy Flight via Python

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 3

  • @TuemmlerTanne11
    @TuemmlerTanne11 3 місяці тому

    x_steps and y_steps shouldnt be independently sampled. the length and angle should be sampled and then x_step and y_step can be calculated. Thats why the levy flight doesn't travel large distances diagonally in your example

  • @user-ju5en4rv9h
    @user-ju5en4rv9h 5 місяців тому

    thank you that was useful ,,, but could you share the code file

    • @IngridGamedev
      @IngridGamedev 3 місяці тому

      import numpy as np
      import matplotlib.pyplot as plt
      import seaborn as sns
      long_tail_steps = np.random.pareto(a=2, size=100)
      sns.histplot(long_tail_steps, kde=True)
      # number of steps
      n = 300
      # generate steps
      x_steps = np.random.pareto(a = 2, size = n)
      y_steps = np.random.pareto(a = 2, size = n)
      # generate the angle
      angles = 2 * np.pi * np.random.rand(n)
      # define the steps and angle for each dimention
      dx = x_steps * np.cos(angles)
      dy = y_steps * np.sin(angles)
      # turn steps to trajectory
      x = np.cumsum(dx)
      y = np.cumsum(dy)
      # visualize the levy flight
      plt.plot(x, y, marker= 'o', markersize=4)
      plt.grid(True)
      plt.show()