### Install GPBoost Dependencies Source: https://github.com/fabsig/gpboost/blob/master/examples/python-guide/README.md Install scikit-learn and matplotlib, which are recommended for running the GPBoost examples. ```bash pip install scikit-learn matplotlib -U ``` -------------------------------- ### Install Dependencies and Build Docs Source: https://github.com/fabsig/gpboost/blob/master/docs/README.rst Install project dependencies and build the HTML documentation locally. Ensure Doxygen is installed and you are in the 'docs' folder. ```sh pip install -r requirements.txt make html ``` -------------------------------- ### Build and Configure Example Executables Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/unsupported/doc/examples/CMakeLists.txt Iterates through each example source file, creates an executable, links libraries, and sets up post-build commands to capture output. It also adds each example to the 'unsupported_examples' custom target. ```cmake foreach(example_src ${examples_SRCS}) get_filename_component(example ${example_src} NAME_WE) add_executable(example_${example} ${example_src}) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) target_link_libraries(example_${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) endif() add_custom_command( TARGET example_${example} POST_BUILD COMMAND example_${example} ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out ) add_dependencies(unsupported_examples example_${example}) endforeach(example_src) ``` -------------------------------- ### C++ Main File Example Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/support/bazel/README.md A simple C++ program demonstrating the use of `fmt::print` to output formatted text. This is used in conjunction with the WORKSPACE system setup. ```cpp #include "fmt/core.h" int main() { fmt::print("The answer is {} ", 42); } ``` -------------------------------- ### Install Documentation Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/CMakeLists.txt Installs the generated HTML documentation to a system-specific directory. The installation is optional and excludes intermediate '.doctrees' files. ```cmake include(GNUInstallDirs) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/fmt OPTIONAL PATTERN ".doctrees" EXCLUDE) ``` -------------------------------- ### GPBoost Regression Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates a basic GPBoost regression model. Ensure GPBoost is installed and data is prepared. ```python import gpboost as gpb import numpy as np # Generate random data np.random.seed(0) X = np.random.rand(100, 3) y = X[:, 0] + 2 * X[:, 1] + np.random.normal(0, 0.1, 100) # Create GPBoost regression model params = { 'objective': 'regression', 'metric': 'rmse', } model = gpb.train(params, gpb.Dataset(X, label=y), num_boost_round=10) # Predict on new data X_new = np.random.rand(10, 3) y_pred = model.predict(X_new) print('Predictions:', y_pred) ``` -------------------------------- ### GPBoost Regression Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates a basic GPBoost regression model. Ensure GPBoost is installed and imported. ```python import gpboost as gpb import numpy as np # Generate random data np.random.seed(0) X = np.random.rand(100, 3) y = X[:, 0] + 2 * X[:, 1] + np.random.normal(0, 0.1, 100) # Create DMatrix data = gpb.Dataset(X, label=y) # Define parameters p = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'num_leaves': 5, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'verbose': -1, 'n_jobs': -1, 'seed': 0 } # Train the model num_round = 100 bst = gpb.train(p, data, num_round) # Predict print(bst.predict(X[:5])) ``` -------------------------------- ### Run Python Example Script Source: https://github.com/fabsig/gpboost/blob/master/examples/python-guide/README.md Execute a GPBoost Python example script from the command line. ```bash python boosting_example.py ``` -------------------------------- ### Install fmt with LHelper Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install fmt using the lhelper dependency manager. This requires activating an environment and then installing the fmt package. ```bash lhelper activate lhelper install fmt ``` -------------------------------- ### Install fmt with Vcpkg Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install fmt using the vcpkg dependency manager. This involves cloning the vcpkg repository, bootstrapping it, integrating it with the system, and then installing the fmt package. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install fmt ``` -------------------------------- ### Install GPBoost from PyPI Source: https://github.com/fabsig/gpboost/blob/master/python-package/README.md Use this command to install GPBoost from PyPI, ensuring it is built from source. ```sh pip install --no-binary :all: gpboost ``` -------------------------------- ### Glob for Example Source Files Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/unsupported/doc/examples/CMakeLists.txt Finds all .cpp files in the current directory to be used as example sources. ```cmake file(GLOB examples_SRCS "*.cpp") ``` -------------------------------- ### GPBoost Parameter Tuning Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Provides an example of how to tune GPBoost parameters using a simple grid search. This helps in finding optimal hyperparameters. ```python import gpboost as gpb import numpy as np from sklearn.model_selection import ParameterGrid # Generate random data np.random.seed(0) X = np.random.rand(100, 3) y = X[:, 0] + 2 * X[:, 1] + np.random.normal(0, 0.1, 100) # Create DMatrix data = gpb.Dataset(X, label=y) # Parameter grid for tuning param_grid = { 'num_leaves': [5, 10, 20], 'learning_rate': [0.01, 0.05, 0.1], 'feature_fraction': [0.7, 0.9] } best_score = float('inf') best_params = {} # Grid search for params in ParameterGrid(param_grid): p = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'verbose': -1, 'n_jobs': -1, 'seed': 0, **params } num_round = 50 bst = gpb.train(p, data, num_round) score = bst.best_score['training']['rmse'] if score < best_score: best_score = score best_params = params print(f'Best score: {best_score}') print(f'Best parameters: {best_params}') ``` -------------------------------- ### Install Library with Scons Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fast_double_parser/benchmarks/dependencies/double-conversion/README.md Install the library using 'scons install'. The DESTDIR option can be used to specify an alternative installation directory. ```bash scons install ``` ```bash scons DESTDIR=alternative_directory install ``` -------------------------------- ### Install GPBoost from PyPI Source: https://github.com/fabsig/gpboost/blob/master/python-package/README.md Install or upgrade the GPBoost package using pip. This command installs precompiled binaries. ```sh pip install gpboost -U ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/CMakeLists.txt Installs the generated configuration, version, and export files to the specified CMake directory. ```cmake install( FILES ${project_config} ${version_config} DESTINATION ${FMT_CMAKE_DIR}) ``` ```cmake install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR} NAMESPACE fmt::) ``` ```cmake install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}") ``` -------------------------------- ### Build Sparse Example with Qt Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/special_examples/CMakeLists.txt Configures and builds a sparse matrix example executable that integrates with Qt. It links necessary Qt libraries and sets up a post-build command to generate a JPEG visualization. ```cmake if(NOT EIGEN_TEST_NOQT) find_package(Qt4) if(QT4_FOUND) include(${QT_USE_FILE}) endif() endif() if(QT4_FOUND) add_executable(Tutorial_sparse_example Tutorial_sparse_example.cpp Tutorial_sparse_example_details.cpp) target_link_libraries(Tutorial_sparse_example ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) add_custom_command( TARGET Tutorial_sparse_example POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/../html/ COMMAND Tutorial_sparse_example ARGS ${CMAKE_CURRENT_BINARY_DIR}/../html/Tutorial_sparse_example.jpeg ) add_dependencies(all_examples Tutorial_sparse_example) endif() ``` -------------------------------- ### Install fmt with Meson Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install the fmt subproject from WrapDB. This command should be run from the root of your project. ```bash meson wrap install fmt ``` -------------------------------- ### Build GPBoost with MinGW-w64 on Windows from GitHub Source: https://github.com/fabsig/gpboost/blob/master/python-package/README.md Install GPBoost from a local GitHub repository using MinGW-w64 on Windows. CMake and MinGW-w64 should be installed first. ```sh python setup.py install --mingw ``` -------------------------------- ### Build and Test with Scons Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fast_double_parser/benchmarks/dependencies/double-conversion/README.md Use 'scons install' to build and install the static and shared libraries. Run 'make test' to execute all tests. ```bash make make test ``` -------------------------------- ### Build GPBoost with MinGW-w64 on Windows Source: https://github.com/fabsig/gpboost/blob/master/python-package/README.md Install GPBoost from PyPI with MinGW-w64 support on Windows. CMake and MinGW-w64 must be installed beforehand. ```sh pip install gpboost --install-option=--mingw ``` -------------------------------- ### Compile and Run LBFGS++ Example Source: https://github.com/fabsig/gpboost/blob/master/external_libs/LBFGSpp/README.md Compile the C++ example using g++ with specified include paths for Eigen and LBFGS++, then run the executable. ```bash $ g++ -I/path/to/eigen -I/path/to/lbfgspp/include -O2 example.cpp $ ./a.out 23 iterations x = 1 1 1 1 1 1 1 1 1 1 f(x) = 1.87948e-19 ``` -------------------------------- ### Abseil Installation Configuration Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fast_double_parser/benchmarks/dependencies/abseil-cpp/CMakeLists.txt Handles the installation of Abseil components if ABSL_ENABLE_INSTALL is set. It configures package files and installs headers, ensuring Abseil can be used as a dependency in other projects. ```cmake if(ABSL_ENABLE_INSTALL) # absl:lts-remove-begin(system installation is supported for LTS releases) # We don't support system-wide installation list(APPEND SYSTEM_INSTALL_DIRS "/usr/local" "/usr" "/opt/" "/opt/local" "c:/Program Files/${PROJECT_NAME}") if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX IN_LIST SYSTEM_INSTALL_DIRS) message(WARNING " The default and system-level install directories are unsupported except in LTS releases of Abseil. Please set CMAKE_INSTALL_PREFIX to install Abseil in your source or build tree directly. ") endif() # absl:lts-remove-end # install as a subdirectory only install(EXPORT ${PROJECT_NAME}Targets NAMESPACE absl:: DESTINATION "${ABSL_INSTALL_CONFIGDIR}" ) configure_package_config_file( CMake/abslConfig.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${ABSL_INSTALL_CONFIGDIR}" ) install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${ABSL_INSTALL_CONFIGDIR}" ) # Abseil only has a version in LTS releases. This mechanism is accomplished # Abseil's internal Copybara (https://github.com/google/copybara) workflows and # isn't visible in the CMake buildsystem itself. if(absl_VERSION) write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY ExactVersion ) install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${ABSL_INSTALL_CONFIGDIR} ) endif() # absl_VERSION install(DIRECTORY absl DESTINATION ${ABSL_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.inc" PATTERN "*.h" ) endif() # ABSL_ENABLE_INSTALL ``` -------------------------------- ### Install fmt with Homebrew Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install fmt on OS X using the Homebrew package manager. ```bash brew install fmt ``` -------------------------------- ### Install GPBoost from GitHub Source: https://github.com/fabsig/gpboost/blob/master/python-package/README.md Clone the GPBoost repository and install from the local source. For macOS users, specify compilers if using gcc. ```sh git clone --recursive https://github.com/fabsig/GPBoost.git cd GPBoost/python-package # export CXX=g++-7 CC=gcc-7 # macOS users, if you decided to compile with gcc, don't forget to specify compilers (replace "7" with version of gcc installed on your machine) python -m pip install . ``` -------------------------------- ### Install gpboost Headers with CMake Source: https://github.com/fabsig/gpboost/blob/master/CMakeLists.txt Installs the LightGBM header directory to the include path of the installation prefix. This makes the library's headers available for external projects. ```cmake install(DIRECTORY ${LightGBM_HEADER_DIR}/LightGBM DESTINATION ${CMAKE_INSTALL_PREFIX}/include) ``` -------------------------------- ### Install FMT Library and Headers Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/CMakeLists.txt Installs the FMT library targets, including runtime destinations for executables and public headers. ```cmake install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name} LIBRARY DESTINATION ${FMT_LIB_DIR} ARCHIVE DESTINATION ${FMT_LIB_DIR} PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### GPBoost Hyperparameter Tuning Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Provides a basic example of hyperparameter tuning for GPBoost. This often involves using libraries like Optuna or GridSearchCV. ```python import gpboost as gpb import numpy as np import optuna # Generate random data X_train = np.random.rand(100, 10) y_train = np.random.rand(100) # Objective function for Optuna def objective(trial): params = { 'objective': 'regression', 'metric': 'rmse', 'n_estimators': trial.suggest_int('n_estimators', 50, 200), 'learning_rate': trial.suggest_float('learning_rate', 0.01, 0.3), 'feature_fraction': trial.suggest_float('feature_fraction', 0.6, 1.0), 'bagging_fraction': trial.suggest_float('bagging_fraction', 0.6, 1.0), 'bagging_freq': trial.suggest_int('bagging_freq', 1, 7), 'verbose': -1 } model = gpb.train(params, gpb.Dataset(X_train, label=y_train), num_boost_round=params['n_estimators']) # In a real scenario, you would evaluate on a validation set # For simplicity, we'll just return a dummy value return 0.5 # Replace with actual validation metric # Create an Optuna study object and run the optimization study = optuna.create_study(direction='minimize') study.optimize(objective, n_trials=20) print('Best parameters found: ', study.best_params) print('Best objective value: ', study.best_value) ``` -------------------------------- ### Install GPBoost from CRAN Source: https://github.com/fabsig/gpboost/blob/master/R-package/README.md Use this command to install the gpboost package from the CRAN repository. ```r install.packages("gpboost", repos = "https://cran.r-project.org") ``` -------------------------------- ### Install GCC on macOS using Homebrew Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Install GCC on macOS using Homebrew. ```bash brew install gcc ``` -------------------------------- ### Build Eigen Examples with CMake Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/examples/CMakeLists.txt This CMake script iterates through all C++ example source files, adds them as executables, links them to Eigen and standard libraries, and sets up post-build commands to run the examples. ```cmake file(GLOB examples_SRCS "*.cpp") foreach(example_src ${examples_SRCS}) get_filename_component(example ${example_src} NAME_WE) add_executable(${example} ${example_src}) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) target_link_libraries(${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) endif() add_custom_command( TARGET ${example} POST_BUILD COMMAND ${example} ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out ) add_dependencies(all_examples ${example}) endforeach() if(EIGEN_COMPILER_SUPPORT_CPP11) ei_add_target_property(nullary_indexing COMPILE_FLAGS "-std=c++11") endif() ``` -------------------------------- ### Install OpenMP on macOS using Homebrew Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Install the OpenMP runtime library on macOS using Homebrew. ```bash brew install libomp ``` -------------------------------- ### GPBoost Classification Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Illustrates how to set up and train a GPBoost classification model. Requires binary or multi-class labels. ```python import gpboost as gpb import numpy as np # Generate random data for binary classification np.random.seed(1) X = np.random.rand(100, 3) y = (X[:, 0] + 2 * X[:, 1] + np.random.normal(0, 0.1, 100) > 1).astype(int) # Create GPBoost classification model params = { 'objective': 'binary', 'metric': 'binary_logloss', } model = gpb.train(params, gpb.Dataset(X, label=y), num_boost_round=10) # Predict probabilities on new data X_new = np.random.rand(10, 3) y_pred_proba = model.predict(X_new) print('Prediction probabilities:', y_pred_proba) ``` -------------------------------- ### GPBoost Regression Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates a basic regression task using GPBoost. Requires importing the GPBoost library. ```python import gpboost as gp from sklearn.model_selection import train_test_split from sklearn.datasets import make_regression # Generate random data for regression X, y = make_regression(n_samples=1000, n_features=10, noise=0.1, random_state=42) # Split data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Initialize GPBoost parameters prms = { 'objective': 'regression_l2', 'metric': 'rmse', 'boosting_type': 'gbdt', 'verbose': -1, 'num_leaves': 31, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'max_depth': -1, 'seed': 42 } # Create GPBoost dataset train_data = gp.Dataset(X_train, label=y_train) # Train the GPBoost model bst = gp.train(prms, train_data, num_boost_round=100) # Make predictions preds = bst.predict(X_test) # Evaluate the model (example using RMSE) from sklearn.metrics import mean_squared_error rmse = mean_squared_error(y_test, preds, squared=False) print(f'RMSE: {rmse}') ``` -------------------------------- ### Write to a file with fmt Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/README.md Example of writing to a file efficiently using fmt::output_file. ```c++ #include int main() { auto out = fmt::output_file("guide.txt"); out.print("Don't {}", "Panic"); } ``` -------------------------------- ### Install gpboost Targets with CMake Source: https://github.com/fabsig/gpboost/blob/master/CMakeLists.txt Installs the gpboost executable and libraries to specified destinations. This ensures the built components are placed in the correct directories for deployment. ```cmake install(TARGETS gpboost _gpboost RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) ``` -------------------------------- ### Install Less and clean-css plugin Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install Less and the clean-css plugin globally using npm. This is necessary for building documentation on systems like Ubuntu. ```bash sudo npm install -g less less-plugin-clean-css. ``` -------------------------------- ### GPBoost Classification Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Illustrates how to use GPBoost for binary classification. Requires data with binary labels. ```python import gpboost as gpb import numpy as np # Generate random data np.random.seed(0) X = np.random.rand(100, 3) y = (X[:, 0] + 2 * X[:, 1] + np.random.normal(0, 0.1, 100) > 0.5).astype(int) # Create DMatrix data = gpb.Dataset(X, label=y) # Define parameters p = { 'objective': 'binary', 'metric': 'binary_logloss', 'boosting_type': 'gbdt', 'num_leaves': 5, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'verbose': -1, 'n_jobs': -1, 'seed': 0 } # Train the model num_round = 100 bst = gpb.train(p, data, num_round) # Predict probabilities print(bst.predict(X[:5])) ``` -------------------------------- ### GPBoost Classification Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates training a GPBoost classification model. Suitable for binary or multi-class problems. ```python import gpboost as gp from sklearn.model_selection import train_test_split from sklearn.datasets import make_classification # Generate synthetic data for classification X, y = make_classification(n_samples=1000, n_features=10, n_classes=2, random_state=42) # Split data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Define GPBoost parameters for classification prms = { 'objective': 'binary', 'metric': 'binary_logloss', 'boosting_type': 'gbdt', 'n_estimators': 100, 'learning_rate': 0.05, 'num_leaves': 31, 'verbose': -1, 'n_jobs': -1, 'seed': 42 } # Initialize and train the GPBoost classifier gbm = gp.train(prms, gp.Dataset(X_train, label=y_train), num_boost_round=100) # Make predictions (probabilities) y_pred_proba = gbm.predict(X_test) # Convert probabilities to class labels y_pred = (y_pred_proba > 0.5).astype(int) print(f"LogLoss: {gp.evals_result()['valid_0']['binary_logloss'][0]}") ``` -------------------------------- ### jQuery Animation Property Setup Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Sets up the start and end values for a CSS property being animated, including handling relative values and ensuring correct units. ```javascript return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]) ``` -------------------------------- ### Build and Run Benchmarks Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fast_double_parser/README.md Instructions for cloning the repository, building the project with benchmarks enabled, and running the benchmarks using cmake and ctest. ```bash git clone https://github.com/lemire/fast_double_parser.git cd fast_double_parser mkdir build cd build cmake .. -DFAST_DOUBLE_BENCHMARKS=ON cmake --build . --config Release ctest . ./benchmark ``` -------------------------------- ### GPBoost Initialization with Booster Parameters Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates initializing GPBoost using Booster parameters, which can be useful for fine-grained control or when integrating with other libraries. ```python import gpboost as gp from sklearn.datasets import make_regression # Generate sample data X, y = make_regression(n_samples=100, n_features=5, random_state=0) # Define parameters for Booster booster_params = { 'objective': 'regression', 'metric': 'rmse', 'verbose': -1, 'seed': 42 } # Create GPBoost dataset data = gp.Dataset(X, label=y) # Initialize Booster with parameters bst = gp.train(booster_params, data, num_boost_round=100) print('Model trained successfully using Booster parameters.') ``` -------------------------------- ### Finding Column with Maximum Sum in Eigen Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/TutorialReductionsVisitorsBroadcasting.dox This example finds the column in a matrix that has the largest sum of its elements. It uses `colwise().sum()` to get the sum of each column and then `maxCoeff()` to find the index of the column with the maximum sum. ```cpp #include #include int main() { Eigen::MatrixXf mat(2, 4); mat << 1, 2, 6, 9, 3, 1, 7, 2; Eigen::RowVectorXf sums = mat.colwise().sum(); int max_sum_col_index = (sums.array() > 0).select(sums, -1).argmax(); std::cout << "Column with max sum index: " << max_sum_col_index << std::endl; return 0; } ``` -------------------------------- ### GPBoost Classification Example Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Illustrates a binary classification task with GPBoost. Ensure the 'objective' is set to a classification type. ```python import gpboost as gp from sklearn.model_selection import train_test_split from sklearn.datasets import make_classification # Generate random data for classification X, y = make_classification(n_samples=1000, n_features=10, n_classes=2, random_state=42) # Split data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Initialize GPBoost parameters for binary classification prms = { 'objective': 'binary', 'metric': 'binary_logloss', 'boosting_type': 'gbdt', 'verbose': -1, 'num_leaves': 31, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'max_depth': -1, 'seed': 42 } # Create GPBoost dataset train_data = gp.Dataset(X_train, label=y_train) # Train the GPBoost model bst = gp.train(prms, train_data, num_boost_round=100) # Make predictions (probabilities) preds_proba = bst.predict(X_test) # Convert probabilities to class labels (e.g., using a threshold of 0.5) preds_labels = (preds_proba > 0.5).astype(int) # Evaluate the model (example using accuracy) from sklearn.metrics import accuracy_score accuracy = accuracy_score(y_test, preds_labels) print(f'Accuracy: {accuracy}') ``` -------------------------------- ### LBFGS++ Minimization Example Source: https://github.com/fabsig/gpboost/blob/master/external_libs/LBFGSpp/README.md Set up LBFGS++ parameters, create a solver instance, provide an initial guess, and run the minimization function. The initial guess vector will be overwritten with the optimal solution. ```cpp int main() { const int n = 10; // Set up parameters LBFGSParam param; param.epsilon = 1e-6; param.max_iterations = 100; // Create solver and function object LBFGSSolver solver(param); Rosenbrock fun(n); // Initial guess VectorXd x = VectorXd::Zero(n); // x will be overwritten to be the best point found double fx; int niter = solver.minimize(fun, x, fx); std::cout << niter << " iterations" << std::endl; std::cout << "x = \n" << x.transpose() << std::endl; std::cout << "f(x) = " << fx << std::endl; return 0; } ``` -------------------------------- ### Install CRAN Package Source: https://github.com/fabsig/gpboost/blob/master/R-package/README.md Install the built GPBoost R package tarball using the R CMD INSTALL command. ```shell R CMD INSTALL gpboost_*.tar.gz ``` -------------------------------- ### Integrate Installed FMT with CMake Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Find and link an installed version of the FMT library in your CMake project. This requires FMT to be installed on the system. ```cmake find_package(fmt) target_link_libraries( fmt::fmt) ``` -------------------------------- ### Build GPBoost with CMake and MinGW-w64 on Windows Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Clone the repository, set up a build directory, configure the build using CMake with the MinGW Makefiles generator, and then compile using mingw32-make. ```bash git clone --recursive https://github.com/fabsig/GPBoost cd GPBoost mkdir build cd build cmake -G "MinGW Makefiles" .. mingw32-make.exe -j4 ``` -------------------------------- ### GPBoost Initialization with Dictionary Parameters Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Shows how to initialize GPBoost parameters using a Python dictionary. This is a common and flexible way to configure the model. ```python import gpboost as gp from sklearn.datasets import make_regression # Generate sample data X, y = make_regression(n_samples=100, n_features=5, random_state=0) # Define parameters using a dictionary params = { 'objective': 'regression', 'metric': 'rmse', 'n_estimators': 100, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'verbose': -1, 'seed': 42 } # Create GPBoost dataset data = gp.Dataset(X, label=y) # Train the model bst = gp.train(params, data) print('Model trained successfully with dictionary parameters.') ``` -------------------------------- ### Build GPBoost with CMake and VS Build Tools on Windows Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Use these commands to clone the repository, create a build directory, configure the build with CMake for a 64-bit architecture, and compile the project in Release mode. ```bash git clone --recursive https://github.com/fabsig/GPBoost cd GPBoost mkdir build cd build cmake -A x64 .. cmake --build . --target ALL_BUILD --config Release ``` -------------------------------- ### Configure Installation Directories Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/CMakeLists.txt Sets cache variables for installation directories, which can be absolute paths or relative to CMAKE_INSTALL_PREFIX. ```cmake set_verbose(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING "Installation directory for cmake files, a relative path that " "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute " "path.") ``` ```cmake set_verbose(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Installation directory for libraries, a relative path that " "will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path.") ``` ```cmake set_verbose(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE STRING "Installation directory for pkgconfig (.pc) files, a relative " "path that will be joined with ${CMAKE_INSTALL_PREFIX} or an " "absolute path.") ``` -------------------------------- ### Get Window or Document Element Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html A utility function to get the window or document element associated with a node. ```javascript function dc(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1} ``` -------------------------------- ### Basic GPBoost Model Training Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates the fundamental steps to train a GPBoost model. Ensure necessary imports are included. ```python import gpboost as gpb import numpy as np # Generate random data X_train = np.random.rand(100, 10) y_train = np.random.rand(100) X_test = np.random.rand(50, 10) # Create a GPBoost model params = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'verbose': -1 } model = gpb.train(params, gpb.Dataset(X_train, label=y_train), num_boost_round=10) # Make predictions y_pred = model.predict(X_test) print(y_pred) ``` -------------------------------- ### Install CMake on macOS using Homebrew Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Use Homebrew to install CMake version 3.16 or higher on macOS. ```bash brew install cmake ``` -------------------------------- ### Build with CMake Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fast_double_parser/benchmarks/dependencies/double-conversion/README.md Configure the build using 'cmake .' in the root directory. Use -DBUILD_TESTING=ON to include tests. ```bash cmake . make test/cctest/cctest --list | tr -d '<' | xargs test/cctest/cctest ``` ```bash cmake . -DBUILD_TESTING=ON make test/cctest/cctest --list | tr -d '<' | xargs test/cctest/cctest ``` -------------------------------- ### Conditional Build for SYCL Examples Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/unsupported/doc/examples/CMakeLists.txt Includes the SYCL subdirectory for building SYCL-specific examples if the EIGEN_TEST_SYCL flag is enabled. ```cmake if(EIGEN_TEST_SYCL) add_subdirectory(SYCL) endif(EIGEN_TEST_SYCL) ``` -------------------------------- ### Add Custom Target for Unsupported Examples Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/unsupported/doc/examples/CMakeLists.txt Creates a custom target named 'unsupported_examples' to group all example builds. ```cmake add_custom_target(unsupported_examples) ``` -------------------------------- ### GPBoost with GPU Training Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Shows how to enable GPU acceleration for training GPBoost models. Requires a compatible GPU and installation. ```python import gpboost as gpb import numpy as np # Generate random data X_train = np.random.rand(1000, 10) y_train = np.random.rand(1000) # Create a GPBoost dataset train_data = gpb.Dataset(X_train, label=y_train) # Define parameters params = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'num_leaves': 31, 'learning_rate': 0.05, 'verbose': -1, 'seed': 42, 'device': 'gpu' # Enable GPU training } # Train the model num_round = 100 bst = gpb.train(params, train_data, num_round) print('Model trained using GPU acceleration.') ``` -------------------------------- ### Clone and Build Format Benchmarks Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/README.md Clone the format-benchmark repository and configure it with CMake to prepare for running benchmarks. ```bash git clone --recursive https://github.com/fmtlib/format-benchmark.git cd format-benchmark cmake . ``` -------------------------------- ### Get Element Dimensions (Height/Width) Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Provides methods to get the height or width of elements, including padding and border. ```javascript m.each(["Height","Width"],function(a,b){m.each({padding:"inner"+a,content:b," ":"outer"+a},function(c,d){m.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||"boolean"!=typeof d&&"margin"||"border";return V(this,function(b,c,d){var e;return m.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?m.css(b,c,g):m.style(b,c,d,g)},b,f?d:void 0,f,null)}})})} ``` -------------------------------- ### GPBoost Parameter Tuning with Optuna Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Example of using Optuna for hyperparameter optimization of a GPBoost model. This helps find optimal model settings. ```python import gpboost as gpb import numpy as np import optuna # Generate random data X_train = np.random.rand(100, 10) y_train = np.random.rand(100) X_val = np.random.rand(50, 10) y_val = np.random.rand(50) # Create GPBoost datasets train_data = gpb.Dataset(X_train, label=y_train) val_data = gpb.Dataset(X_val, label=y_val, reference=train_data) # Objective function for Optuna def objective(trial): params = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'num_leaves': trial.suggest_int('num_leaves', 20, 100), 'learning_rate': trial.suggest_float('learning_rate', 0.01, 0.3), 'feature_fraction': trial.suggest_float('feature_fraction', 0.6, 1.0), 'bagging_fraction': trial.suggest_float('bagging_fraction', 0.6, 1.0), 'bagging_freq': trial.suggest_int('bagging_freq', 1, 7), 'min_child_samples': trial.suggest_int('min_child_samples', 20, 100), 'verbose': -1, 'seed': 42 } num_round = 100 bst = gpb.train(params, train_data, num_round, valid_sets=[val_data], callbacks=[gpb.early_stopping(10, verbose=False)]) return bst.best_score[list(bst.best_score.keys())[0]]['valid_0']['rmse'] # Create an Optuna study object and optimize study = optuna.create_study(direction='minimize') study.optimize(objective, n_trials=50) print('Hyperparameter optimization complete.') print('Best parameters:', study.best_params) print('Best RMSE:', study.best_value) ``` -------------------------------- ### Run Format Benchmarks Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/README.md Execute the speed or bloat tests after setting up the format-benchmark repository. ```bash make speed-test ``` ```bash make bloat-test ``` -------------------------------- ### Set CMAKE_PREFIX_PATH for Eigen Installation Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/TopicCMakeGuide.dox Specify the Eigen installation directory using `CMAKE_PREFIX_PATH` if it's not in a default location or if you need a specific version. ```sh cmake path-to-example-directory -DCMAKE_PREFIX_PATH=$HOME/mypackages ``` -------------------------------- ### Basic GPBoost Model Training Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Demonstrates the fundamental process of training a GPBoost model with standard parameters. Ensure data is preprocessed appropriately. ```python import gpboost as gpb import numpy as np # Generate random data X_train = np.random.rand(100, 10) y_train = np.random.rand(100) X_test = np.random.rand(50, 10) # Create a GPBoost dataset train_data = gpb.Dataset(X_train, label=y_train) # Define parameters params = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'num_leaves': 31, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'verbose': -1, 'n_jobs': -1, 'seed': 42 } # Train the model num_round = 100 bst = gpb.train(params, train_data, num_round) # Predict on test data y_pred = bst.predict(X_test) print('Prediction complete.') ``` -------------------------------- ### Qt Interoperability Test Setup Source: https://github.com/fabsig/gpboost/blob/master/external_libs/compute/test/extra/CMakeLists.txt Sets up tests for Qt (both Qt4 and Qt5) interoperability, including finding Qt components and linking libraries. It also configures the OpenGL interop test which depends on Qt. ```cmake if(${BOOST_COMPUTE_HAVE_QT}) # look for Qt4 in the first place find_package(Qt4 QUIET) if(${QT4_FOUND}) find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui QtOpenGL) include(${QT_USE_FILE}) else() find_package(Qt5Widgets QUIET) # look for Qt5 if(${Qt5Widgets_FOUND}) find_package(Qt5Core REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5OpenGL REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5OpenGL_EXECUTABLE_COMPILE_FLAGS}") set(QT_LIBRARIES ${Qt5OpenGL_LIBRARIES}) else() # no valid Qt framework found message(FATAL_ERROR "Error: Did not find Qt4 or Qt5") endif() endif() add_compute_test("interop.qt" test_interop_qt.cpp) target_link_libraries(test_interop_qt ${QT_LIBRARIES}) # the opengl interop test depends on qt to create the opengl context add_compute_test("interop.opengl" test_interop_opengl.cpp) target_link_libraries(test_interop_opengl ${QT_LIBRARIES}) endif() ``` -------------------------------- ### Install fmt with Conda Source: https://github.com/fabsig/gpboost/blob/master/external_libs/fmt/doc/usage.md Install the fmt package from the conda-forge channel using the Conda package manager. This command is applicable to Linux, macOS, and Windows. ```bash conda install -c conda-forge fmt ``` -------------------------------- ### Identity Matrix Initialization Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/QuickReference.dox Shows how to create identity matrices of specified dimensions. ```C++ x = Dynamic2D::Identity(rows, cols); x.setIdentity(rows, cols); ``` ```C++ MatrixXi M(3,3); M.setIdentity(); ``` -------------------------------- ### Example: Matrix Block Operations Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/TutorialBlockOperations.dox Demonstrates the practical application of matrix block operations. Ensure the necessary Eigen headers are included. ```cpp #include #include int main() { Eigen::MatrixXi matrix(4, 4); matrix << 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15; std::cout << "Original matrix:\n" << matrix << std::endl; // Extracting a 2x2 block from the top-right corner Eigen::MatrixXi topRight = matrix.topRightCorner(2, 2); std::cout << "Top-right 2x2 block:\n" << topRight << std::endl; // Extracting the top 2 rows Eigen::MatrixXi topRows = matrix.topRows(2); std::cout << "Top 2 rows:\n" << topRows << std::endl; // Extracting the left 2 columns Eigen::MatrixXi leftCols = matrix.leftCols(2); std::cout << "Left 2 columns:\n" << leftCols << std::endl; // Extracting a 2x2 block from the bottom-left corner Eigen::MatrixXi bottomLeft = matrix.bottomLeftCorner(2, 2); std::cout << "Bottom-left 2x2 block:\n" << bottomLeft << std::endl; return 0; } ``` -------------------------------- ### GPBoost with External Data (from file) Source: https://github.com/fabsig/gpboost/blob/master/examples/README.html Shows how to load training data directly from a file (e.g., CSV) using GPBoost's data loading capabilities. ```python import gpboost as gpb import numpy as np import pandas as pd # Create a dummy CSV file for demonstration data = { 'feature1': np.random.rand(100), 'feature2': np.random.rand(100), 'target': np.random.rand(100) } df = pd.DataFrame(data) df.to_csv('dummy_data.csv', index=False) # Load data from CSV file data_file = 'dummy_data.csv' label_column = 'target' train_data = gpb.Dataset(data_file, label_column=label_column) # Define parameters params = { 'objective': 'regression', 'metric': 'rmse', 'boosting_type': 'gbdt', 'num_leaves': 31, 'learning_rate': 0.05, 'verbose': -1, 'seed': 42 } # Train the model num_round = 100 bst = gpb.train(params, train_data, num_round) print('Model trained using data loaded from CSV.') # Clean up the dummy file import os os.remove('dummy_data.csv') ``` -------------------------------- ### Add SYCL Example Tests Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/unsupported/doc/examples/SYCL/CMakeLists.txt Iterates through found C++ example source files, adds them as internal tests, and sets dependencies for the 'unsupported_examples' target. ```cmake FOREACH(example_src ${examples_SRCS}) GET_FILENAME_COMPONENT(example ${example_src} NAME_WE) ei_add_test_internal(${example} example_${example}) ADD_DEPENDENCIES(unsupported_examples example_${example}) ENDFOREACH(example_src) set(EIGEN_SYCL OFF) ``` -------------------------------- ### Build GPBoost with CMake and GCC on macOS Source: https://github.com/fabsig/gpboost/blob/master/docs/Installation_guide.rst Clone the repository, set environment variables for GCC, create a build directory, configure with CMake, and compile using make. Ensure the correct GCC version is specified. ```bash git clone --recursive https://github.com/fabsig/GPBoost cd GPBoost export CXX=g++-7 CC=gcc-7 # replace "7" with version of gcc installed on your machine mkdir build cd build cmake .. make -j4 ``` -------------------------------- ### Example: Vector Block Operations Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/TutorialBlockOperations.dox Illustrates how to use block operations on Eigen vectors. This example shows extracting head, tail, and segments from a vector. ```cpp #include #include int main() { Eigen::VectorXi vector(6); vector << 0, 1, 2, 3, 4, 5; std::cout << "Original vector:\n" << vector << std::endl; // Extracting the first 3 elements (head) Eigen::VectorXi head = vector.head(3); std::cout << "Head (first 3 elements):\n" << head << std::endl; // Extracting the last 3 elements (tail) Eigen::VectorXi tail = vector.tail(3); std::cout << "Tail (last 3 elements):\n" << tail << std::endl; // Extracting a segment of 3 elements starting at index 1 Eigen::VectorXi segment = vector.segment(1, 3); std::cout << "Segment (3 elements starting at index 1):\n" << segment << std::endl; return 0; } ``` -------------------------------- ### Eigen Matrix Type Examples Source: https://github.com/fabsig/gpboost/blob/master/external_libs/eigen/doc/QuickReference.dox Examples of declaring Eigen matrices with dynamic or fixed dimensions and different storage orders. Heap allocation is used for dynamic sizes. ```c++ Matrix // Dynamic number of columns (heap allocation) Matrix // Dynamic number of rows (heap allocation) Matrix // Fully dynamic, row major (heap allocation) Matrix // Fully fixed (usually allocated on stack) ```