Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- # from scipy import stats as st
- # import math
- # import pandas as pd
- # from statistics import variance #podpravlennoe
- import matplotlib.pyplot as plt
- from scipy.integrate import odeint
- from skimage.measure import block_reduce
- # Определяем систему Лоренца
- def lorenz_system(state, t, sigma, ksi, r, epsilon, rho):
- x, y, z = state
- dxdt = y - rho * x + sigma * y * z
- dydt = r * y - x * z + z
- dzdt = ksi * x * y - epsilon * z
- return dxdt, dydt, dzdt
- # Вычислите фрактальную размерность, используя метод подсчета ящиков
- def box_counting(state, grid_size):
- # Reshape the state array into a 3D grid
- grid = np.zeros((grid_size, grid_size, grid_size))
- state_min = np.min(state, axis=0)
- state_max = np.max(state, axis=0)
- state_range = state_max - state_min
- state_scaled = (state - state_min) / state_range
- grid_indices = (state_scaled * (grid_size - 1)).astype(int)
- for i in range(len(state)):
- x, y, z = grid_indices[i]
- grid[x, y, z] = 1
- box_counts = []
- scales = []
- for scale in range(1, grid_size):
- scales.append(scale)
- box_size = (grid_size // scale)
- block_size = (scale, scale, scale)
- block_counts = block_reduce(grid, block_size=block_size, func=np.sum)
- box_count = np.sum(block_counts > 0)
- box_counts.append(box_count)
- # Рассчитываем наклон логарифмического графика подсчета ящиков по сравнению с масштабами
- log_box_counts = np.log(box_counts)
- log_scales = np.log(scales)
- slope, intercept = np.polyfit(log_scales, log_box_counts, 1)
- return slope
- if __name__ == '__main__':
- # Задаем начальные условия и вектор времени
- state0 = [1, 2, 3]
- t = np.arange(0, 100, 0.01)
- sigma = 2.7
- r = 1.7
- epsilon = 9
- rho = 3
- ksi = 2
- # Решаем дифференциальное уравнение
- state = odeint(lorenz_system, state0, t, args=(sigma, ksi, r, epsilon, rho))
- # Строим аттрактор Лоренца
- # fig = plt.figure()
- # ax = fig.gca(projection='3d')
- fig = plt.figure(figsize=(16, 12.5))
- ax = fig.add_subplot(2, 2, 1, projection="3d")
- ax.plot(state[:, 0], state[:, 1], state[:, 2])
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_zlabel('z')
- ax.set_title('Lorenz Attractor')
- plt.show()
- # Используем сокращение блоков для расчета количества блоков для разных размеров сетки
- # Вычисляем поточечную фрактальную размерность
- pointwise_fractal_dimension = box_counting(state, grid_size=100)
- # Вычисляем корреляционную фрактальную размерность
- correlation_fractal_dimension = box_counting(np.diff(state, axis=0), grid_size=100) # Рассчитать информационную фрактальную размерность
- X = state.T
- X_d = np.diff(X, axis=1)
- info_fractal_dimension = np.sum(np.log(np.abs(X_d))) / np.sum(np.log(1.0 / np.abs(np.diff(t))))
- # Вывод фрактальных размерностей
- print(f"The pointwise fractal dimension of the Lorenz attractor is approximately {pointwise_fractal_dimension:.2f}")
- print(
- f"The correlation fractal dimension of the Lorenz attractor is approximately {correlation_fractal_dimension:.2f}")
- print(f"The informational fractal dimension of the Lorenz attractor is approximately {info_fractal_dimension:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement