### Configure Target and Installation Prefix Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Includes configuration for the target and sets the installation prefix if DIPTEST_MBUILD is enabled. This affects where the library will be installed. ```cmake include(ConfigureTarget) if(DIPTEST_MBUILD) set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/src") endif() install(TARGETS _diptest_core LIBRARY DESTINATION "${PROJECT_NAME}/lib") ``` -------------------------------- ### Install diptest from PyPI Source: https://github.com/rurlus/diptest/blob/stable/README.md Standard installation of the diptest library using pip. This command installs the package with pre-compiled wheels for common platforms. ```bash pip install diptest ``` -------------------------------- ### Install diptest with 64-bit index support Source: https://github.com/rurlus/diptest/blob/stable/README.md Builds diptest from source with support for 64-bit indexes, recommended for very large sample sizes. Requires a C/C++ compiler. ```bash CMAKE_ARGS="-DDIPTEST_64BIT_index=ON" pip install diptest --no-binary diptest ``` -------------------------------- ### Install diptest with debug build Source: https://github.com/rurlus/diptest/blob/stable/README.md Installs a debug version of diptest from source. This enables additional debugging information during compilation and runtime. ```bash CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug" pip install diptest --no-binary diptest ``` -------------------------------- ### Install specific diptest wheel for MacOS ARM Source: https://github.com/rurlus/diptest/blob/stable/README.md Installs a specific diptest wheel file for CPython 3.11 on MacOS ARM. This is an alternative to installing from source or using the default bundled wheels. ```bash pip install diptest-0.8.0-cp311-cp311-macosx_11_0_arm64.whl ``` -------------------------------- ### Install diptest with debug printing enabled Source: https://github.com/rurlus/diptest/blob/stable/README.md Builds diptest from source with debug printing enabled. This allows for verbose output during the dip test calculation when the debug argument is set. ```bash CMAKE_ARGS="-DDIPTEST_ENABLE_DEBUG=ON" pip install diptest --no-binary diptest ``` -------------------------------- ### Compute Dip Statistic and P-value in Python Source: https://github.com/rurlus/diptest/blob/stable/README.md Demonstrates how to generate bimodal data and then compute both the dip statistic and its p-value using the diptest library. Ensure numpy and diptest are installed. ```python import numpy as np import diptest # generate some bimodal random draws N = 1000 hN = N // 2 x = np.empty(N, dtype=np.float64) x[:hN] = np.random.normal(0.4, 1.0, hN) x[hN:] = np.random.normal(-0.4, 1.0, hN) # only the dip statistic dip = diptest.dipstat(x) # both the dip statistic and p-value dip, pval = diptest.diptest(x) ``` -------------------------------- ### Install diptest with OpenMP disabled Source: https://github.com/rurlus/diptest/blob/stable/README.md Builds diptest from source with OpenMP explicitly disabled. This can be useful for debugging or if OpenMP is not desired. ```bash CMAKE_ARGS="-DDIPTEST_DISABLE_OPENMP=ON" pip install diptest --no-binary diptest ``` -------------------------------- ### Install diptest without bundled OpenMP Source: https://github.com/rurlus/diptest/blob/stable/README.md Installs the diptest library from source, disabling the bundled OpenMP. This is useful if you encounter issues with multiple OpenMP versions or want to use your system's OpenMP. ```bash pip install diptest --no-binary diptest ``` -------------------------------- ### Get Full Output from dipstat Source: https://context7.com/rurlus/diptest/llms.txt Use `dipstat` with `full_output=True` to obtain detailed diagnostic information, including modal interval boundaries, GCM, LCM, and the dip location index. This is useful for visualization and understanding the multimodality. ```python import numpy as np import diptest # Generate sample data with clear bimodality np.random.seed(123) sample = np.concatenate([ np.random.normal(-3.0, 1.0, 500), np.random.normal(3.0, 1.0, 500) ]) # Get full output with diagnostic information dip, details = diptest.dipstat(sample, full_output=True) print(f"Dip statistic: {dip:.6f}") print(f"Modal interval indices: lo={details['lo']}, hi={details['hi']}") print(f"Modal interval values: xl={details['xl']:.4f}, xu={details['xu']:.4f}") print(f"Dip location index: {details['dipidx']}") print(f"GCM indices (first 5): {details['gcm'][:5]}") print(f"LCM indices (first 5): {details['lcm'][:5]}") # Use details for visualization of the modal interval sorted_sample = np.sort(sample) modal_interval_data = sorted_sample[details['lo']:details['hi']+1] print(f"Modal interval contains {len(modal_interval_data)} points") ``` -------------------------------- ### Set Project Version and Name Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Extracts the version from SKBUILD_PROJECT_VERSION and sets the project name and version. Ensure SKBUILD_PROJECT_VERSION is defined. ```cmake cmake_minimum_required(VERSION 3.16...3.25) set(STRIPPED_VERSION "") string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" STRIPPED_VERSION ${SKBUILD_PROJECT_VERSION}) project( ${SKBUILD_PROJECT_NAME} VERSION ${STRIPPED_VERSION} LANGUAGES CXX) ``` -------------------------------- ### Configure Module Path and Include Directories Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Manages the CMake module path and sets include directories for the project. The module path is temporarily modified to include local CMake modules. ```cmake set(CMAKE_MODULE_PATH_SAVED ${CMAKE_MODULE_PATH}) list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/src/diptest-core/cmake") include(GNUInstallDirs) # Set build type to Release if not specified include(BuildType) set(CMAKE_CXX_STANDARD ${DIPTEST_CPP_STANDARD}) set(DIPTEST_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/diptest-core/include") set(DIPTEST_PCG_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/external/pcg-cpp/include") set(DIPTEST_SRC_DIR "${PROJECT_SOURCE_DIR}/src/diptest-core/src/") ``` -------------------------------- ### Perform Dip Test with Full Output Details Source: https://context7.com/rurlus/diptest/llms.txt Performs the dip test and returns comprehensive diagnostic details, including modal interval and convex hull components. This is useful for in-depth analysis and visualization of multimodality detection. Requires numpy and diptest libraries. ```python import numpy as np import diptest # Generate sample with clear bimodality np.random.seed(42) sample = np.concatenate([ np.random.normal(-2.5, 0.7, 600), np.random.normal(2.5, 0.7, 400) ]) # Get full output with table-based p-value dip, pval, details = diptest.diptest(sample, full_output=True) print(f"Dip statistic: {dip:.6f}") print(f"P-value: {pval:.6f}") print(f"Null hypothesis (unimodality) rejected: {pval < 0.05}") print(f"\nDiagnostic details:") print(f" Modal interval lower index: {details['lo']}") print(f" Modal interval upper index: {details['hi']}") print(f" Modal interval lower value: {details['xl']:.4f}") print(f" Modal interval upper value: {details['xu']:.4f}") print(f" Dip location index: {details['dipidx']}") print(f" GCM size: {len(details['gcm'])} indices") print(f" LCM size: {len(details['lcm'])} indices") # Output: # Dip statistic: 0.039874 # P-value: 0.000156 # Null hypothesis (unimodality) rejected: True # # Diagnostic details: # Modal interval lower index: 298 # Modal interval upper index: 701 # Modal interval lower value: -0.8456 # Modal interval upper value: 0.9234 ``` -------------------------------- ### Conditional Parallel Processing with Dip Test Source: https://context7.com/rurlus/diptest/llms.txt Demonstrates conditional execution of dip test based on OpenMP availability. Uses parallel bootstrap if OpenMP is supported, otherwise falls back to table interpolation. ```python import diptest import numpy as np np.random.seed(42) sample = np.random.normal(0, 1, 1000) if diptest._has_openmp_support: # Use parallel bootstrap dip, pval = diptest.diptest(sample, boot_pval=True, n_threads=4, seed=42) print(f"Parallel bootstrap p-value: {pval:.4f}") else: # Fall back to table interpolation dip, pval = diptest.diptest(sample, boot_pval=False) print(f"Table interpolation p-value: {pval:.4f}") ``` -------------------------------- ### Check OpenMP Support and Package Version Source: https://context7.com/rurlus/diptest/llms.txt Verifies if the diptest package was compiled with OpenMP support for parallel processing and retrieves the package version. This helps in understanding performance capabilities. ```python import diptest # Check if OpenMP is available has_openmp = diptest._has_openmp_support print(f"OpenMP support available: {has_openmp}") # Get package version print(f"diptest version: {diptest.__version__}") ``` -------------------------------- ### Create Python Module with pybind11 Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Generates a Python extension module named _diptest_core using pybind11. It specifies public and private include directories and links against the pybind11 library. ```cmake include(FindDependencies) pybind11_add_module(_diptest_core MODULE ${DIPTEST_SRC_FILES}) target_include_directories(_diptest_core PUBLIC ${DIPTEST_INCLUDE_DIR}) target_include_directories(_diptest_core PRIVATE ${DIPTEST_PCG_INCLUDE_DIR}) target_link_libraries(_diptest_core PRIVATE pybind11::pybind11) target_compile_definitions(_diptest_core PRIVATE DIPTEST_VERSION_INFO=${PROJECT_VERSION}) ``` -------------------------------- ### Batch Processing with Bootstrap P-values Source: https://context7.com/rurlus/diptest/llms.txt Performs batch processing of multiple samples using bootstrap p-values for more robust multimodality testing. Allows specifying bootstrap iterations, threads, and seeds. ```python import numpy as np import diptest def batch_diptest_bootstrap(samples_list, n_boot=10000, n_threads=4, seed=42): """Test multiple samples using bootstrap p-values.""" results = [] for i, sample in enumerate(samples_list): dip, pval = diptest.diptest( sample, boot_pval=True, n_boot=n_boot, n_threads=n_threads, seed=seed + i # Different seed per sample for independence ) results.append({'sample_id': i, 'dip': dip, 'pval': pval}) return results ``` -------------------------------- ### Define Source Files and Conditional Compilation Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Defines the core source files for the Diptest library. Additional test files are included conditionally based on build flags. ```cmake set(DIPTEST_SRC_FILES bindings.cpp bootstrap.cpp dipstat.cpp) if(DIPTEST_ENABLE_EXT_TESTS OR DIPTEST_DEV_MODE) add_definitions(-DDIPTEST_BUILD_CPP_TESTS=TRUE) list(APPEND DIPTEST_SRC_FILES test_pcg.cpp) endif() list(TRANSFORM DIPTEST_SRC_FILES PREPEND ${DIPTEST_SRC_DIR}) ``` -------------------------------- ### Handle MSVC Specific Definitions Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Adds a definition for HAVE_SNPRINTF when using the MSVC compiler to resolve potential compilation errors. ```cmake if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # error C2039: '_snprintf': is not a member of 'std' add_definitions(-DHAVE_SNPRINTF) endif() ``` -------------------------------- ### Perform Dip Test with Full Output and Bootstrap P-value Source: https://context7.com/rurlus/diptest/llms.txt Performs a dip test on a sample with full output and bootstrap p-value calculation. Useful for detailed analysis and hypothesis testing. ```python import diptest # Full output with bootstrap p-value dip_b, pval_b, details_b = diptest.diptest( sample, full_output=True, boot_pval=True, n_boot=10000, seed=42 ) print(f"\nBootstrap p-value: {pval_b:.6f}") ``` -------------------------------- ### Perform Dip Test with Bootstrap P-value Source: https://context7.com/rurlus/diptest/llms.txt Computes the p-value for the dip test using bootstrap resampling for higher accuracy, especially with unusual sample sizes. Supports parallel execution via OpenMP for performance. Requires numpy and diptest libraries. ```python import numpy as np import diptest # Generate sample data np.random.seed(42) sample = np.concatenate([ np.random.normal(-1.5, 0.6, 500), np.random.normal(1.5, 0.6, 500) ]) # Bootstrap p-value with single thread (reproducible with seed) dip, pval = diptest.diptest( sample, boot_pval=True, n_boot=10000, n_threads=1, seed=42 ) print(f"Bootstrap (single-thread) - Dip: {dip:.6f}, P-value: {pval:.4f}") # Output: Bootstrap (single-thread) - Dip: 0.028934, P-value: 0.0012 # Bootstrap with multiple threads for faster computation dip, pval_mt = diptest.diptest( sample, boot_pval=True, n_boot=50000, n_threads=4, seed=42 ) print(f"Bootstrap (multi-thread, 50k samples) - Dip: {dip:.6f}, P-value: {pval_mt:.4f}") # Output: Bootstrap (multi-thread, 50k samples) - Dip: 0.028934, P-value: 0.0010 # Use all available cores dip, pval_all = diptest.diptest( sample, boot_pval=True, n_boot=100000, n_threads=-1, # Use all cores seed=123 ) print(f"Bootstrap (all cores, 100k samples) - Dip: {dip:.6f}, P-value: {pval_all:.4f}") # Output: Bootstrap (all cores, 100k samples) - Dip: 0.028934, P-value: 0.0009 # Stream parameter for reproducible parallel simulations dip1, pval1 = diptest.diptest(sample, boot_pval=True, n_boot=10000, n_threads=1, seed=42, stream=0) dip2, pval2 = diptest.diptest(sample, boot_pval=True, n_boot=10000, n_threads=1, seed=42, stream=1) print(f"Stream 0 p-value: {pval1:.4f}, Stream 1 p-value: {pval2:.4f}") # Output: Stream 0 p-value: 0.0012, Stream 1 p-value: 0.0014 ``` -------------------------------- ### Restore Module Path Source: https://github.com/rurlus/diptest/blob/stable/CMakeLists.txt Restores the original CMake module path after configuration is complete. This prevents interference with other CMake modules. ```cmake set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH_SAVED}) ``` -------------------------------- ### Compute Dip Statistic using dipstat Source: https://context7.com/rurlus/diptest/llms.txt Use the `dipstat` function to compute only Hartigan's dip statistic. This is faster than computing the p-value and useful for large datasets or custom significance testing. Set `sort_x=False` if the input data is already sorted. The `allow_zero` parameter handles cases with identical values. ```python import numpy as np import diptest # Generate bimodal sample data np.random.seed(42) N = 1000 bimodal_sample = np.concatenate([ np.random.normal(-2.0, 0.8, N // 2), np.random.normal(2.0, 0.8, N // 2) ]) # Compute dip statistic only dip = diptest.dipstat(bimodal_sample) print(f"Dip statistic: {dip:.6f}") # Generate unimodal sample for comparison unimodal_sample = np.random.normal(0.0, 1.0, N) dip_unimodal = diptest.dipstat(unimodal_sample) print(f"Unimodal dip statistic: {dip_unimodal:.6f}") # With pre-sorted data (skip internal sorting for efficiency) sorted_sample = np.sort(bimodal_sample) dip_presorted = diptest.dipstat(sorted_sample, sort_x=False) print(f"Pre-sorted dip statistic: {dip_presorted:.6f}") # Handle edge cases with allow_zero parameter identical_values = np.ones(100) dip_zero = diptest.dipstat(identical_values, allow_zero=True) dip_nonzero = diptest.dipstat(identical_values, allow_zero=False) print(f"Identical values - allow_zero=True: {dip_zero:.6f}") print(f"Identical values - allow_zero=False: {dip_nonzero:.6f}") ``` -------------------------------- ### Batch Processing Multiple Samples for Unimodality Source: https://context7.com/rurlus/diptest/llms.txt Tests multiple samples for unimodality using a batch processing function. This is useful for analyzing multiple groups or performing simulation studies. ```python import numpy as np import diptest def batch_diptest(samples_list, alpha=0.05): """Test multiple samples for unimodality.""" results = [] for i, sample in enumerate(samples_list): dip, pval = diptest.diptest(sample) results.append({ 'sample_id': i, 'n': len(sample), 'dip': dip, 'pval': pval, 'multimodal': pval < alpha }) return results # Generate test samples np.random.seed(42) samples = [ np.random.normal(0, 1, 500), # Unimodal np.concatenate([np.random.normal(-2, 0.5, 250), np.random.normal(2, 0.5, 250)]), # Bimodal np.random.exponential(2, 500), # Skewed unimodal np.concatenate([np.random.normal(-3, 0.3, 200), np.random.normal(0, 0.3, 200), np.random.normal(3, 0.3, 200)]), # Trimodal ] # Process all samples results = batch_diptest(samples) for r in results: status = "MULTIMODAL" if r['multimodal'] else "UNIMODAL" print(f"Sample {r['sample_id']}: dip={r['dip']:.4f}, p={r['pval']:.4f} -> {status}") ``` -------------------------------- ### Perform Dip Test with Table-Based P-value Source: https://context7.com/rurlus/diptest/llms.txt Performs the Hartigan dip test for unimodality using default table-based p-value interpolation for speed. This is suitable for general use when high precision for p-values is not critical. Requires numpy and diptest libraries. ```python import numpy as np import diptest # Generate bimodal data np.random.seed(42) N = 1000 bimodal_data = np.concatenate([ np.random.normal(-2.0, 0.5, N // 2), np.random.normal(2.0, 0.5, N // 2) ]) # Perform dip test with table-based p-value (default, fast) dip, pval = diptest.diptest(bimodal_data) print(f"Bimodal data - Dip: {dip:.6f}, P-value: {pval:.6f}") print(f"Reject unimodality at alpha=0.05: {pval < 0.05}") # Output: Bimodal data - Dip: 0.042315, P-value: 0.000023 # Output: Reject unimodality at alpha=0.05: True # Test unimodal data unimodal_data = np.random.normal(0.0, 1.0, N) dip_uni, pval_uni = diptest.diptest(unimodal_data) print(f"Unimodal data - Dip: {dip_uni:.6f}, P-value: {pval_uni:.6f}") print(f"Reject unimodality at alpha=0.05: {pval_uni < 0.05}") # Output: Unimodal data - Dip: 0.011234, P-value: 0.523451 # Output: Reject unimodality at alpha=0.05: False # Test trimodal data trimodal_data = np.concatenate([ np.random.normal(-4.0, 0.5, N // 3), np.random.normal(0.0, 0.5, N // 3), np.random.normal(4.0, 0.5, N // 3) ]) dip_tri, pval_tri = diptest.diptest(trimodal_data) print(f"Trimodal data - Dip: {dip_tri:.6f}, P-value: {pval_tri:.6f}") # Output: Trimodal data - Dip: 0.038456, P-value: 0.000089 ``` -------------------------------- ### Enable debug printing in diptest Source: https://github.com/rurlus/diptest/blob/stable/README.md Activates debug print statements within the diptest function. Requires a debug build and setting the debug level when calling the function. ```python diptest(x, debug=1) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.