Python code for data-driven localization region detection, segmentation and localized wave directionality estimation within the detected regions in numerical simulations of a two-dimensional (2D) hexagonal crystal lattice model. Using the code and developed methodology, please cite the preprint F. Kozirevs, J. Bajārs, Localization region detection with directionality estimation in a two-dimensional hexagonal crystal lattice model. arXiv:2606.24923 (2026). Available at: https://arxiv.org/abs/2606.24923.
![]()
|
|
The figures above show 2D hexagonal and quasi-one-dimensional (quasi-1D) data collection regions (on the left), as well as localization regions with their estimated directions (on the right) detected in a simulation of three stationary and three traveling discrete breathers (DBs) using the classifiers trained on data which was collected from the 2D hexagonal and quasi-1D regions.
This research is funded by the Latvian Council of Science, project "Development of structure- and data-driven methods for analysis and control of complex dynamical systems", project No. lzp-2024/1-0207.
- The code was developed on Apple Silicon Mac in
Condaosx-64environment. All the requiredPythonpackages are listed inenvironment.yml. The repository includes shared libraries (.so) together with the correspondingCsource code. To recompile theCcode on other platforms, aCcompiler withOpenMPsupport is required. - All the generated figures are saved to the folder
figures. The legends for Figures 2 and 3, as well as the explanations of all the figures, can be found in the preprint. - All the functions used for performing numerical simulations, generating DBs, collecting lattice wave data from different regions, applying the trained classifiers together with the sliding window method and aggregating the obtained predictions, as well as for segmenting the detected localization regions and estimating localized wave directionality, are defined in the folder
functions. - In the code:
-
data_collection_regiondescribes the type of data collection regions used: its values2D,1D, andq1Dencode 2D hexagonal, one-dimensional, and quasi-1D regions, respectively; -
aggregationdescribes if the summation (valuesummation) or product (valueproduct) prediction aggregation approach is used; -
DB_typedescribes if the considered DB is stationary (value0) or traveling (value1); -
DB_direction(ordirection) describes the direction of the considered DB: its values0,1, and2encode the directions correpsonding to$\alpha=0$ ,$\alpha=\pi/3$ and$\alpha=2\pi/3$ , respectively; -
Nsimis used to specify the number of crystal lattice numerical simulations performed to create a lattice wave dataset; -
Tsimis used to specify the final computational time of a crystal lattice numerical simulation; -
dimis used to specify the dimension number of a low-dimensional dataset which is obtained after applying Principal Component Analysis (PCA).
-
- All the parameter and variable values that are not defined directly in the script files are set and saved in dictionaries using
parameter_values.pyandvariable_values.py, respectively. - To perform numerical simulations of the crystal lattice particle dynamics, run
main.py. - To collect crystal lattice wave data, run
collect_wave_data.py. The obtained datasets can be found in the folderdata/training_and_test_data. - To reduce the dataset dimensionality using PCA and train the wave-data Support Vector Machine classifiers, run
classification.py. The trained classifiers, as well as the fitted PCA models and scalers, can be found in the folderclassifiers. - To analyze the trained classifier performance, run
classification_precision_recall.py. The obtained performance measure values are saved to the folderclassification_precision_recall_valuesas.txtfiles. The precision and recall values are also saved to the folderdata/classification_precision_recall_dataas.csvfiles. - To plot Figures 1 and 2 from the preprint, perform the three stationary DB numerical simulation running
loc_regions_simulation.pyand then executedata_collection_regions_fig1a.py,data_collection_regions_fig1b.py,data_collection_regions_fig1c.py, andloc_regions_fig2.py. The simulation data is saved to the folderdata/loc_regions_sim_data. - To analyze performance of the directionality estimation algorithm, run
directionality_estimation_accuracy.py. The simulation and accuracy data is saved to the folderdata/directionality_estimation_acc_data. In the code,datacontains the directionality estimation accuracy, anddata_loc_regionscontains the localization region detection accuracy (the proportion of simulation time instants at which one localization region was detected) for different shapes of the sliding windows and different values of$N_d$ . To plot Figure 3 from the preprint, rundirectionality_estimation_accuracy_fig3.py. - To perform a numerical simulation of six DB interactions, run
numerical_study_six_DBs.py. The simulation data is saved to the folderdata/numerical_study_data/six_DBs. To simulate two DB head-to-head and head-to-adjacent-head collisions, runnumerical_study_H2H_collision.pyandnumerical_study_H2aH_collision.py, respectively. The data is saved to the folderdata/numerical_study_data/H2H_collisionin the former case and to the folderdata/numerical_study_data/H2aH_collisionin the latter case. To plot Figures 4-7 from the preprint, runnumerical_study_fig4.py,numerical_study_fig5.py, andnumerical_study_fig6_7.py. In the code,coldescribes the considered collision type: its valuesH2HandH2aHencode head-to-head and head-to-adjacent-head collisions, respectively.


