Compare commits

...
8 Commits
Author SHA1 Message Date
Ryan Curtin f65354c042 Adapt mlpack CI workflow to ensmallen (#461)
Build and Test / CPU (push) Waiting to run
Build and Test / CUDA (push) Waiting to run
Build and Test / OpenCL (push) Waiting to run
Continuous Integration / macOS (Debug) (push) Waiting to run
Continuous Integration / Linux (Debug) (push) Waiting to run
Continuous Integration / macOS (Release) (push) Waiting to run
Continuous Integration / Linux (Release) (push) Waiting to run
Continuous Integration / Windows build: VS2022 (push) Waiting to run
* Adapt mlpack CI workflow to ensmallen.

* Explicitly build the tests.

* Try to figure out what is going on with Bandicoot search on macOS.

* Remove unnecessary CMake options that aren't used by ensmallen.

* Turn on verbose build for debugging.

* Make sure OpenMP is found before compiling with it.

* We have to find the threads library before compiling with it.

* Maybe this is the safer approach?

* A little extra safety.

* Reorganization and get some more output.

* Only use OpenMP for the tests if it was totally found.

* Hopefully fix names of CMake variables for Windows.

* Clean up debugging output.

* Try to debug the one failing test; I can't reproduce locally.

* Oops, order the test running correctly to prevent early exits.

* Improve output of NSGA-2.

* See what it does on the regular matrix type too.

* Try and get some more output.

* Oops, fix the ordering.

* More stuff in the wrong order.

* Another small error.

* Fix incorrect child calculation in NSGA-2 (thanks @zoq for finding this).

* Clean up after debugging.

* Update to action version v1.2.23 to avoid Node version warning.

* Merge adjacent blocks.

* Update changelog.

* Let's just try three cores and see what happens... maybe it's different for ensmallen...

* One more entry in the changelog.

* Enable ccache if it's found.

* Use more concise notation.
2026-08-12 15:04:50 -04:00
Ryan Curtin e04a32e7a8 Add new block for next release to HISTORY.md. 2026-07-29 14:19:04 -04:00
Ryan Curtin 0565cd8ae5 Update and release version 3.11.1.
Build and Test / CPU (push) Waiting to run
Build and Test / CUDA (push) Waiting to run
Build and Test / OpenCL (push) Waiting to run
2026-07-29 14:19:04 -04:00
Ryan Curtin 7490265381 Update HISTORY. 2026-07-29 14:19:04 -04:00
Ryan Curtin 3967e5b752 Initialize the gradient constraint matrix instead of expecting the user to. (#458) 2026-07-25 09:51:17 -04:00
Ryan Curtin 69b2e9fa6b Allow multiple trials for Lookahead logistic regression test (#456)
* Allow a couple trials for LookaheadAdam_LogisticRegressionFunction test (it fails ~1 out of 1k times).

* Update changelog.
2026-05-01 13:32:58 -04:00
Ryan Curtin 4ecf7267c8 Fix ParallelSGD test step sizes and enable OpenMP for tests when found (#454)
* If we find OpenMP, use it.

* Fix unused typedef warning.

* Adjust step sizes so that tests converge for ParallelSGD.

* Include OpenMP explicitly if ENS_USE_OPENMP is defined.

* Use target_compile_definitions() instead.
2026-04-18 13:53:48 -04:00
conradsnicta 5984c2b360 Policy on code generated via LLMs (#450)
* add note on code generated via LLMs

* rework LLM section as per mlpack
2026-02-02 14:34:05 -05:00
17 changed files with 324 additions and 141 deletions
-59
View File
@@ -1,59 +0,0 @@
environment:
ARMADILLO_DOWNLOAD: "https://sourceforge.net/projects/arma/files/armadillo-10.8.2.tar.xz"
BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll"
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
VSVER: Visual Studio 15 2017 Win64
MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
VSVER: Visual Studio 16 2019
MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
VSVER: Visual Studio 17 2022
MSBUILD: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
configuration: Release
install:
- ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}"
build_script:
# First, download and build Armadillo.
- cd ..
- appveyor DownloadFile %ARMADILLO_DOWNLOAD% -FileName armadillo.tar.xz
- 7z x armadillo.tar.xz -so -txz | 7z x -si -ttar > nul
- cd armadillo-10.8.2 && mkdir build && cd build
- >
cmake -G "%VSVER%"
-DBLAS_LIBRARY:FILEPATH=%BLAS_LIBRARY%
-DLAPACK_LIBRARY:FILEPATH=%BLAS_LIBRARY%
-DCMAKE_PREFIX:FILEPATH="%APPVEYOR_BUILD_FOLDER%/armadillo"
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DCMAKE_BUILD_TYPE=Release ..
- >
"%MSBUILD%" "armadillo.sln"
/m /verbosity:quiet /p:Configuration=Release;Platform=x64
- cd ../..
# Now build ensmallen.
- cd ensmallen && mkdir build && cd build
- >
cmake -G "%VSVER%"
-DARMADILLO_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%/../armadillo-10.8.2/include/
-DARMADILLO_LIBRARIES=%BLAS_LIBRARY%
-DLAPACK_LIBRARY=%BLAS_LIBRARY%
-DBLAS_LIBRARY=%BLAS_LIBRARY%
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DCMAKE_BUILD_TYPE=Release ..
- >
"%MSBUILD%" "ensmallen.sln"
/m /verbosity:minimal /nologo /p:BuildInParallel=false
# Run tests after copying libraries.
- ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\
- ctest -C Release -V --output-on-failure .
+230
View File
@@ -0,0 +1,230 @@
# ci.yml: defines all the CI jobs run for each commit and pull request.
name: Continuous Integration
on:
workflow_dispatch:
push:
branches: [master, main]
pull_request:
branches: [master, main]
release:
types: [published, created, edited]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
###
### Linux and macOS test matrix for all binding types.
###
ci_matrix:
strategy:
fail-fast: false # Run all configurations even if one fails.
matrix:
config: [
{
runner: ubuntu-latest,
os: 'Linux',
name: 'Debug',
cmakeVars: '-DCMAKE_BUILD_TYPE=Debug',
cores: 4
},
{
runner: ubuntu-latest,
os: 'Linux',
name: 'Release',
cmakeVars: '-DCMAKE_BUILD_TYPE=Release',
cores: 4
},
{
runner: macOS-latest,
os: 'macOS',
name: 'Debug',
cmakeVars: '-DCMAKE_BUILD_TYPE=Debug',
cores: 3
},
{
runner: macOS-latest,
os: 'macOS',
name: 'Release',
cmakeVars: '-DCMAKE_BUILD_TYPE=Release',
cores: 3
}
]
name: '${{ matrix.config.os }} (${{ matrix.config.name }})'
if: ${{ github.repository == 'mlpack/ensmallen' }}
runs-on: ${{ matrix.config.runner }}
steps:
- uses: actions/checkout@v6
# Set up ccache.
- name: Get ccache
uses: hendrikmuhs/ccache-action@v1.2.23
with:
key: ${{ matrix.config.os }}-${{ matrix.config.name }}
append-timestamp: false
variant: ccache
max-size: 2G # Github has a 10GB repo cache limit, so we use 2GB/job.
- name: Configure ccache
shell: bash
run: |
ccache --set-config "sloppiness=include_file_ctime"
ccache --set-config "hash_dir=false"
ccache --zero-stats
# Install build dependencies via apt.
- name: Install build dependencies (Linux)
if: matrix.config.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --yes --allow-unauthenticated libopenblas-dev
# Install the oldest Armadillo version that we support.
curl -k -L https://sourceforge.net/projects/arma/files/armadillo-10.8.2.tar.xz | tar -xvJ
cd armadillo*
# Armadillo 10.8.2 requests CMake 2.8.12+ compatibility, but that has
# been dropped from newer CMake versions. However, with Armadillo's
# CMake configuration, it works just fine to specify
# CMAKE_POLICY_VERSION_MINIMUM to ignore the missing reverse
# compatibility.
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .
make
sudo make install
cd ..
- name: Install build dependencies (macOS)
if: matrix.config.os == 'macOS'
run: |
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
brew install libomp openblas armadillo ccache
- name: Configure ensmallen with CMake
run: |
mkdir build && cd build
cmake ${{ matrix.config.cmakeVars }} ../
- name: Build ensmallen tests
run: cd build && make -j${{ matrix.config.cores }} ensmallen_tests
# Run the tests manually so that we can get JUnit output.
- name: Run ensmallen_tests
run: |
cd build
# The use of only one thread is to prevent thrashing on older versions
# of OpenBLAS (0.3.26 and older) where OpenMP and pthreads aren't
# playing together well.
OMP_NUM_THREADS=1 ./ensmallen_tests -r junit -o ensmallen_tests.junit.xml
- name: Parse test output
uses: rcurtin/test-summary-action@dist
if: success() || failure()
with:
paths: "build/*.junit.xml"
show: "fail, skip"
fail_job: true
print_output: true
###
### Windows CI testing.
###
ci_windows:
name: 'Windows build: VS2022'
if: ${{ github.repository == 'mlpack/ensmallen' }}
runs-on: windows-2022
steps:
- uses: actions/checkout@v6
# Set up ccache.
- name: Get ccache
uses: hendrikmuhs/ccache-action@v1.2.23
with:
key: ${{ runner.os }}
append-timestamp: false
variant: ccache
max-size: 2G
# Set up Visual Studio.
- name: Set up Visual Studio
uses: microsoft/setup-msbuild@v2
# Set up paths for MS build tools.
- name: Set up devcmd
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
# Install build dependencies.
- name: Install build dependencies (Windows)
shell: powershell
run: |
nuget install OpenBLAS -o deps
# Install the oldest supported version of Armadillo and install cereal.
- name: Install some dependencies manually
shell: bash
run: |
cd deps/
curl -L https://sourceforge.net/projects/arma/files/armadillo-10.8.2.tar.xz -o armadillo-10.8.2.tar.xz
tar -xf armadillo-10.8.2.tar.xz
cd armadillo-10.8.2/
cmake -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_C_COMPILER=cl \
-DCMAKE_CXX_COMPILER=cl \
-DBLAS_LIBRARY:FILEPATH=${{ github.workspace }}/deps/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a \
-DLAPACK_LIBRARY:FILEPATH=${{ github.workspace }}/deps/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a \
-DBUILD_SHARED_LIBS=OFF .
# Disable the wrapper because transitive linking doesn't work on
# Windows anyway.
cp tmp/include/armadillo_bits/config.hpp tmp/include/armadillo_bits/config.hpp.tmp
cat tmp/include/armadillo_bits/config.hpp.tmp | sed 's|#define ARMA_USE_WRAPPER|// #define ARMA_USE_WRAPPER|' \
> tmp/include/armadillo_bits/config.hpp
- name: Configure ensmallen with CMake
shell: bash
run: |
mkdir build && cd build
cmake -G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=cl \
-DCMAKE_CXX_COMPILER=cl \
-DARMADILLO_INCLUDE_DIR=../deps/armadillo-10.8.2/tmp/include/ \
-DBLAS_LIBRARY='${{ github.workspace }}'/deps/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a \
-DLAPACK_LIBRARY='${{ github.workspace }}'/deps/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a \
-DCMAKE_VERBOSE_MAKEFILE=ON \
../
- name: Build mlpack
run: cd build && cmake --build . --config Release --target ensmallen_tests
# Run the tests manually so that we can get JUnit output.
- name: Run ensmallen_tests
shell: bash
run: |
# The .dlls are stored in the bin/ directory, and those are the ones
# we need to run with.
cp -v '${{ github.workspace }}'/deps/OpenBLAS.0.2.14.1/lib/native/bin/x64/* build/
./ensmallen_tests.exe -r junit > ensmallen_tests.junit.xml || true
# Remove version numbers and other non-xml from the output.
cat ensmallen_tests.junit.xml | sed '/<?xml/,$!d' > ensmallen_tests.junit.xml.tmp
rm ensmallen_tests.junit.xml
mv ensmallen_tests.junit.xml.tmp ensmallen_tests.junit.xml
- name: Parse test output
uses: rcurtin/test-summary-action@dist
if: success() || failure()
with:
paths: "build/*.junit.xml"
show: "fail, skip"
fail_job: true
print_output: true
-39
View File
@@ -1,39 +0,0 @@
os: linux
dist: focal
language: cpp
env:
- ARMADILLO=latest SANITY_HISTORY=perform
- ARMADILLO=minimum
stages:
- test
- name: sanity
if: type = pull_request AND env(SANITY_HISTORY) = "perform"
jobs:
include:
- stage: sanity
name: "HISTORY.md Check"
script: sh ./scripts/history-update-check.sh
script:
- sudo apt-get update
- sudo apt-get install -y --allow-unauthenticated libopenblas-dev liblapack-dev g++ xz-utils
- if [ $ARMADILLO == "latest" ]; then
curl https://ftp.fau.de/macports/distfiles/armadillo/`curl https://ftp.fau.de/macports/distfiles/armadillo/ -- | grep '.tar.xz' | sed 's/^.*<a href="\(armadillo-[0-9]*.[0-9]*.[0-9]*.tar.xz\)".*$/\1/' | tail -1` | tar xvJ && cd armadillo*;
else
curl -L https://sourceforge.net/projects/arma/files/armadillo-10.8.2.tar.xz | tar -xvJ && cd armadillo*;
fi
- cmake . && make && sudo make install && cd ..
- mkdir build && cd build && cmake .. && make ensmallen_tests -j2
- CTEST_OUTPUT_ON_FAILURE=1 travis_wait 30 ctest -j2
notifications:
email:
- mlpack-git@lists.mlpack.org
irc:
channels:
- "chat.freenode.net#mlpack"
on_success: change
on_failure: always
+7 -7
View File
@@ -142,10 +142,10 @@ if(EXISTS "${BANDICOOT_INCLUDE_DIR}/bandicoot_bits/config.hpp")
find_package(CUDAToolkit REQUIRED)
if (CUDAToolkit_FOUND)
message(STATUS "CUDA includes: ${CUDAToolkit_INCLUDE_DIRS}")
message(STATUS "CUDA libraries: ${CUDAToolkit_LIBRARY_DIR}")
message(STATUS "CUDA includes: ${CUDAToolkit_INCLUDE_DIRS}")
message(STATUS "CUDA libraries: ${CUDAToolkit_LIBRARY_DIR}")
set(CUDA_LIBRARIES CUDA::cudart CUDA::cuda_driver)
set(CUDA_LIBRARIES CUDA::cudart CUDA::cuda_driver)
set(CUDA_CUBLAS_LIBRARIES CUDA::cublas)
set(CUDA_curand_LIBRARY CUDA::curand)
set(CUDA_cusolver_LIBRARY CUDA::cusolver)
@@ -155,10 +155,10 @@ if(EXISTS "${BANDICOOT_INCLUDE_DIR}/bandicoot_bits/config.hpp")
"${CUDAToolkit_INCLUDE_DIRS}")
set(SUPPORT_LIBRARIES "${SUPPORT_LIBRARIES}"
CUDA_LIBRARIES
CUDA_CUBLAS_LIBRARIES
CUDA_curand_LIBRARY
CUDA_cusolver_LIBRARY
CUDA_nvrtc_LIBRARY)
CUDA_CUBLAS_LIBRARIES
CUDA_curand_LIBRARY
CUDA_cusolver_LIBRARY
CUDA_nvrtc_LIBRARY)
set(HAVE_CUDA true)
endif()
endif ()
+25 -10
View File
@@ -43,6 +43,12 @@ target_include_directories(ensmallen INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Use ccache if we find it.
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
# Set warning flags for target.
if(MSVC)
target_compile_options(ensmallen INTERFACE $<BUILD_INTERFACE:/Wall>)
@@ -52,16 +58,25 @@ endif()
# Find OpenMP and link it.
if(USE_OPENMP)
if(NOT TARGET OpenMP::OpenMP_CXX)
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang).
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
target_link_libraries(ensmallen INTERFACE OpenMP::OpenMP_CXX)
find_package(OpenMP)
if (OpenMP_FOUND)
if(NOT TARGET OpenMP::OpenMP_CXX)
find_package(Threads REQUIRED)
if (Threads_FOUND)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang).
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif ()
endif ()
if (TARGET OpenMP::OpenMP_CXX)
target_compile_definitions(ensmallen INTERFACE -DENS_USE_OPENMP)
target_link_libraries(ensmallen INTERFACE OpenMP::OpenMP_CXX)
endif ()
endif ()
endif()
if(USE_BANDICOOT)
+19 -2
View File
@@ -13,6 +13,23 @@ can happen either here on Github or in the `#mlpack:matrix.org` channel on
[here](https://www.mlpack.org/doc/developer/community.html) for more
information.
## Usage of LLMs / Coding Assistants
Each contributor needs to understand the content they are proposing for ensmallen,
and how the proposed content changes and/or expands functionality in ensmallen.
Content includes source code, documentation, and other material such as images
and datasets. The pull request must justify the proposed content in the
description. Using coding assistants or tools like Large Language Models (LLMs)
does not grant additional privileges or reduce our expectations.
Each contributor is responsible for the proposed content, regardless of where
the content came from. The responsibility includes ensuring that the content
can be submitted to ensmallen and does not violate intellectual property rights
such as copyright(s). Source code in ensmallen is licensed under the BSD license;
see `LICENSE.txt` for details.
## Pull request process
Once a pull request is submitted, it must be reviewed and approved before a
merge, to ensure that:
@@ -109,8 +126,8 @@ $ cd ensmallen
# - or -
$ wget http://ensmallen.org/files/ensmallen-3.11.0.tar.gz
$ tar -xvzpf ensmallen-3.11.0.tar.gz
$ wget http://ensmallen.org/files/ensmallen-3.11.1.tar.gz
$ tar -xvzpf ensmallen-3.11.1.tar.gz
$ cd ensmallen-latest
```
+13
View File
@@ -1,5 +1,18 @@
### ensmallen ?.??.?: "???"
###### ????-??-??
* Fix incorrect child generation computation for NSGA-II
([#461](https://github.com/mlpack/ensmallen/pull/461)).
* Better handling of OpenMP/pthreads linking for non-Linux systems
([#461](https://github.com/mlpack/ensmallen/pull/461)).
### ensmallen 3.11.1: "Sunny Day"
###### 2026-07-25
* Loosen tolerance for Lookahead tests to prevent spurious failures
([#456](https://github.com/mlpack/ensmallen/pull/456)).
* Fix uninitialized gradient constraint matrix for `AugLagrangian`
([#458](https://github.com/mlpack/ensmallen/pull/458)).
### ensmallen 3.11.0: "Sunny Day"
###### 2025-12-15
@@ -73,7 +73,8 @@ void AugLagrangianFunction<LagrangianFunction, VecType>::Gradient(
gradient.zeros();
function.Gradient(coordinates, gradient);
GradType constraintGradient; // Temporary for constraint gradients.
// Temporary for constraint gradients.
GradType constraintGradient(gradient.n_rows, gradient.n_cols);
for (size_t i = 0; i < function.NumConstraints(); i++)
{
function.GradientConstraint(i, coordinates, constraintGradient);
+1
View File
@@ -48,6 +48,7 @@
#define ENS_PRAGMA_OMP_ATOMIC _Pragma("omp atomic")
#define ENS_PRAGMA_OMP_CRITICAL _Pragma("omp critical")
#define ENS_PRAGMA_OMP_CRITICAL_NAMED _Pragma("omp critical(section)")
#include <omp.h>
#else
#define ENS_PRAGMA_OMP_PARALLEL
#define ENS_PRAGMA_OMP_ATOMIC
+4 -4
View File
@@ -16,16 +16,16 @@
// The minor version is two digits so regular numerical comparisons of versions
// work right. The first minor version of a release is always 10.
#define ENS_VERSION_MINOR 11
#define ENS_VERSION_PATCH 0
#define ENS_VERSION_PATCH 1
// If this is a release candidate, it will be reflected in the version name
// (i.e. the version name will be "RC1", "RC2", etc.). Otherwise the version
// name will typically be a seemingly arbitrary set of words that does not
// contain the capitalized string "RC".
#define ENS_VERSION_NAME "Sunny Day"
// Incorporate the date the version was released.
#define ENS_VERSION_YEAR "2025"
#define ENS_VERSION_MONTH "12"
#define ENS_VERSION_DAY "15"
#define ENS_VERSION_YEAR "2026"
#define ENS_VERSION_MONTH "07"
#define ENS_VERSION_DAY "25"
namespace ens {
+9 -2
View File
@@ -168,7 +168,14 @@ typename MatType::elem_type NSGA2::Optimize(
for (size_t generation = 1; generation <= maxGenerations && !terminate;
generation++)
{
Info << "NSGA2: iteration " << generation << "." << std::endl;
Info << "NSGA2: iteration " << generation << "; objectives [";
if (numObjectives > 0)
{
Info << calculatedObjectives[0];
for (size_t i = 0; i < calculatedObjectives.size(); ++i)
Info << ", " << calculatedObjectives[i] << ", ";
}
Info << "]." << std::endl;
// Create new population of candidate from the present elite population.
// Have P_t, generate G_t using P_t.
@@ -347,7 +354,7 @@ void NSGA2::Crossover(
// Use traits from parentA for indices where idx is 1 and parentB otherwise.
childA = parentA % idx + parentB % (1 - idx);
// Use traits from parentB for indices where idx is 1 and parentA otherwise.
childB = parentA % (1 - idx) + parentA % idx;
childB = parentA % (1 - idx) + parentB % idx;
}
//! Perform mutation of the candidates weights with some noise.
@@ -54,8 +54,6 @@ inline void AugLagrangianTestFunction<MatType>::Gradient(
{
// f'_x1(x) = 12 x_1 + 4 x_2
// f'_x2(x) = 4 x_1 + 6 x_2
gradient.set_size(2, 1);
gradient[0] = 12 * coordinates[0] + 4 * coordinates[1];
gradient[1] = 4 * coordinates[0] + 6 * coordinates[1];
}
@@ -127,8 +125,6 @@ inline void GockenbachFunction::Gradient(const MatType& coordinates,
// f'_x1(x) = 2 (x_1 - 1)
// f'_x2(x) = 4 (x_2 + 2)
// f'_x3(x) = 6 (x_3 + 3)
gradient.set_size(3, 1);
gradient[0] = 2 * (coordinates[0] - 1);
gradient[1] = 4 * (coordinates[1] + 2);
gradient[2] = 6 * (coordinates[2] + 3);
@@ -166,8 +162,6 @@ inline void GockenbachFunction::GradientConstraint(const size_t index,
const MatType& coordinates,
GradType& gradient)
{
gradient.zeros(3, 1);
switch (index)
{
case 0:
@@ -184,6 +178,7 @@ inline void GockenbachFunction::GradientConstraint(const size_t index,
// h'_x2(x) = 0
// h'_x3(x) = 1
gradient[0] = -2 * coordinates[0];
gradient[1] = 0;
gradient[2] = 1;
break;
}
+3
View File
@@ -65,6 +65,9 @@ set(ENSMALLEN_TESTS_SOURCES
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_executable(ensmallen_tests EXCLUDE_FROM_ALL ${ENSMALLEN_TESTS_SOURCES})
target_link_libraries(ensmallen_tests PRIVATE ensmallen)
if (USE_OPENMP AND TARGET OpenMP::OpenMP_CXX)
target_link_libraries(ensmallen_tests PRIVATE OpenMP::OpenMP_CXX)
endif ()
# Copy test data into place.
add_custom_command(TARGET ensmallen_tests
+2 -1
View File
@@ -60,5 +60,6 @@ TEMPLATE_TEST_CASE("LookaheadAdam_LogisticRegressionFunction", "[Lookahead]",
LogisticRegressionFunctionTest<TestType>(
optimizer,
Tolerances<TestType>::LRTrainAcc,
Tolerances<TestType>::LRTestAcc);
Tolerances<TestType>::LRTestAcc,
3 /* allow a couple trials */);
}
+1 -3
View File
@@ -560,8 +560,6 @@ TEMPLATE_TEST_CASE("DefaultMOEAD_ZDT1Function", "[MOEAD]", ENS_TEST_TYPES)
*/
TEMPLATE_TEST_CASE("DirichletMOEAD_ZDT3Function", "[MOEAD]", ENS_TEST_TYPES)
{
typedef typename TestType::elem_type ElemType;
//! Parameters taken from original ZDT Paper.
ZDT3<TestType> zdt3(300);
const double lowerBound = 0;
@@ -591,4 +589,4 @@ TEMPLATE_TEST_CASE("DirichletMOEAD_ZDT3Function", "[MOEAD]", ENS_TEST_TYPES)
opt.Optimize(objectives, coords, finalPopulation, finalFront);
REQUIRE(VariableBoundsCheck(finalPopulation));
}
}
+1 -1
View File
@@ -275,4 +275,4 @@ TEMPLATE_TEST_CASE("NSGA2_ZDTONEFunction", "[NSGA2]", ENS_ALL_CPU_TEST_TYPES)
double g = 1. + 9. * sum / (static_cast<double>(numVariables - 1));
REQUIRE(g == Approx(1.0).margin(0.99));
}
}
+6 -6
View File
@@ -45,8 +45,8 @@ TEMPLATE_TEST_CASE("ParallelSGDTest_SparseFunction", "[ParallelSGD]",
size_t batchSize = std::ceil((float) f.NumFunctions() / i);
ConstantStep decayPolicy(0.4 * batchSize);
ParallelSGD<ConstantStep> s(10000, batchSize, 1e-5, true, decayPolicy);
ConstantStep decayPolicy(0.02 * batchSize);
ParallelSGD<ConstantStep> s(10000, batchSize, 1e-7, true, decayPolicy);
FunctionTest<SparseTestFunction>(s,
Tolerances<TestType>::LargeObj,
Tolerances<TestType>::LargeCoord);
@@ -62,10 +62,10 @@ TEMPLATE_TEST_CASE("ParallelSGD_GeneralizedRosenbrockFunction",
// Create the generalized Rosenbrock function.
GeneralizedRosenbrockFunction f(i);
ConstantStep decayPolicy(0.001 * f.NumFunctions());
ConstantStep decayPolicy(0.00005 * f.NumFunctions());
ParallelSGD<ConstantStep> s(
100000, f.NumFunctions(), Tolerances<TestType>::Obj / 100, true,
1000000, f.NumFunctions(), Tolerances<TestType>::Obj / 100, true,
decayPolicy);
TestType coordinates = f.GetInitialPoint<TestType>();
@@ -73,11 +73,11 @@ TEMPLATE_TEST_CASE("ParallelSGD_GeneralizedRosenbrockFunction",
omp_set_num_threads(1);
double result = s.Optimize(f, coordinates);
REQUIRE(result == Approx(0.0).margin(Tolerances<TestType>::Obj));
REQUIRE(result == Approx(0.0).margin(100 * Tolerances<TestType>::Obj));
for (size_t j = 0; j < i; ++j)
{
REQUIRE(coordinates(j) ==
Approx(1.0).epsilon(Tolerances<TestType>::Coord));
Approx(1.0).epsilon(100 * Tolerances<TestType>::Coord));
}
}
}