Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.15...3.15)
# Warning. This must be consistent with src/nomad_version.hpp
set(NOMAD_VERSION_MAJOR 4)
set(NOMAD_VERSION_MINOR 5)
set(NOMAD_VERSION_PATCH 0)
set(NOMAD_VERSION_PATCH 1)

set(NOMAD_VERSION ${NOMAD_VERSION_MAJOR}.${NOMAD_VERSION_MINOR}.${NOMAD_VERSION_PATCH})

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Jan Provaznik
Tangi Migot
Edward Hallé-Hannan
Samuel Mendoza

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PyNomad
import sys

# This example of blackbox function is for a single process
# The blackbox output must be put in the EvalPoint passed as argument
def bb(x):
try:
dim = x.size()
f = x.get_coord(4)
g1 = sum([(x.get_coord(i)-1)**2 for i in range(dim)])-25
g2 = 25-sum([(x.get_coord(i)+1)**2 for i in range(dim)])
rawBBO = str(f) + " " + str(g1) + " " + str(g2)
x.setBBO(rawBBO.encode("UTF-8"))
except:
print("Unexpected eval error", sys.exc_info()[0])
return 0
return 1 # 1: success 0: failed evaluation

def surrogate(x):
try:
dim = x.size()
f = x.get_coord(4)
g1 = (x.get_coord(0)-1)**2 + (x.get_coord(1)-1)**2-15
g2 = 15-(x.get_coord(0)+1)**2+(x.get_coord(1)+1)**2
rawBBO = str(f) + " " + str(g1) + " " + str(g2)
x.setBBO(rawBBO.encode("UTF-8"))
except:
print("Unexpected eval error", sys.exc_info()[0])
return 0
return 1 # 1: success 0: failed evaluation

X0 = [0, 0, 0, 0, 0]
params = ["DIMENSION 5","BB_OUTPUT_TYPE OBJ EB EB", "MAX_BB_EVAL 100", "EVAL_QUEUE_SORT SURROGATE", "X0 * 0" , "LOWER_BOUND * -6" , "DISPLAY_DEGREE 2", "DISPLAY_ALL_EVAL false", "DISPLAY_STATS BBE OBJ CONS_H", "VNS_MADS_SEARCH_WITH_SURROGATE true"]

result = PyNomad.optimize(bb, X0, [] , [], params, surrogate)

fmt = ["{} = {}".format(n,v) for (n,v) in result.items()]
output = "\n".join(fmt)
print("\nNOMAD results \n" + output + " \n")
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# PROBLEM PARAMETERS
####################

# Number of variables
DIMENSION 2

# Black box
BB_OUTPUT_TYPE OBJ
BB_EXE ss_bb.exe

# Surrogate
SURROGATE_EXE ss_sgte.exe
EVAL_SURROGATE_COST 3

# Starting point
X0 ( 5.0 5.0 )

# Bounds are useful to avoid extreme values
LOWER_BOUND * -20.0
UPPER_BOUND * 20.0


# ALGORITHM PARAMETERS
######################
# The algorithm terminates after that number surrogate evaluations
MAX_BB_EVAL 400

VNS_MADS_SEARCH_WITH_SURROGATE yes
QUAD_MODEL_SEARCH yes
NM_SEARCH no

# Use surrogate executable to sort points before evaluating them with the blackbox
EVAL_QUEUE_SORT SURROGATE

# Display parameters
####################
DISPLAY_ALL_EVAL true
DISPLAY_STATS SURROGATE_EVAL BBE ( SOL ) OBJ

6 changes: 3 additions & 3 deletions ext/sgtelib/src/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ double SGTELIB::kernel ( const SGTELIB::kernel_t kt ,
case SGTELIB::KERNEL_D4:
// Bi-quadratic
{
double ksr = fabs(ks*r)*16.0/15.0;
double ksr = std::fabs(ks*r)*16.0/15.0;
if (ksr<=1){
double d = (1-ksr*ksr);
return d*d;
Expand All @@ -255,7 +255,7 @@ double SGTELIB::kernel ( const SGTELIB::kernel_t kt ,
case SGTELIB::KERNEL_D5:
// Tri-cubic
{
double ksr = fabs(ks*r)*162.0/140.0;
double ksr = std::fabs(ks*r)*162.0/140.0;
if (ksr<=1.0){
double d = (1-ksr*ksr*ksr);
return d*d*d;
Expand All @@ -268,7 +268,7 @@ double SGTELIB::kernel ( const SGTELIB::kernel_t kt ,
case SGTELIB::KERNEL_D7:
// Epanechnikov
{
double ksr = fabs(ks*r);
double ksr = std::fabs(ks*r);
if (ksr<=3/4) return (1-(16/9)*ksr*ksr);
}
return 0.0;
Expand Down
56 changes: 28 additions & 28 deletions ext/sgtelib/src/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ SGTELIB::Matrix SGTELIB::Matrix::hadamard_sqrt ( const SGTELIB::Matrix & A ) {
int i,j;
for ( i = 0 ; i < nb_rows ; ++i ) {
for ( j = 0 ; j < nb_cols ; ++j ){
C._X[i][j] = sqrt(fabs(A._X[i][j]));
C._X[i][j] = sqrt(std::fabs(A._X[i][j]));
}
}
return C;
Expand Down Expand Up @@ -1242,7 +1242,7 @@ void SGTELIB::Matrix::hadamard_sqrt ( void ) {
int i,j;
for ( i = 0 ; i < _nbRows ; ++i ) {
for ( j = 0 ; j < _nbCols ; ++j ){
_X[i][j] = sqrt(fabs(_X[i][j]));
_X[i][j] = sqrt(std::fabs(_X[i][j]));
}
}
}//
Expand Down Expand Up @@ -1793,19 +1793,19 @@ SGTELIB::Matrix SGTELIB::Matrix::col_norm ( const norm_t nt ) const {
double v = 0;
switch (nt){
case SGTELIB::NORM_0:
for (i=0;i<_nbRows;++i) v += double(fabs(_X[i][j])<EPSILON);
for (i=0;i<_nbRows;++i) v += double(std::fabs(_X[i][j])<EPSILON);
v /= double(_nbCols);
break;
case SGTELIB::NORM_1:
for (i=0;i<_nbRows;++i) v += fabs(_X[i][j]);
for (i=0;i<_nbRows;++i) v += std::fabs(_X[i][j]);
v /= double(_nbCols);
break;
case SGTELIB::NORM_2:
for (i=0;i<_nbRows;++i) v += _X[i][j]*_X[i][j];
v = sqrt(v/double(_nbCols));
break;
case SGTELIB::NORM_INF:
for (i=0;i<_nbRows;++i) v = std::max(v,fabs(_X[i][j]));
for (i=0;i<_nbRows;++i) v = std::max(v,std::fabs(_X[i][j]));
break;
}
N.set(0,j,v);
Expand All @@ -1832,7 +1832,7 @@ double SGTELIB::Matrix::norm_inf ( void ) const{
{
for (int j = 0 ; j < _nbCols ; ++j)
{
norm = std::max(std::abs(_X[i][j]), norm);
norm = std::max(std::fabs(_X[i][j]), norm);
}
}
return norm;
Expand Down Expand Up @@ -1914,7 +1914,7 @@ int SGTELIB::Matrix::count ( void ) const{
const int nb_cols = get_nb_cols();
for ( i = 0 ; i < nb_rows ; ++i ) {
for ( j = 0 ; j < nb_cols ; ++j ){
v += (fabs(_X[i][j])>EPSILON)? 1:0 ;
v += (std::fabs(_X[i][j])>EPSILON)? 1:0 ;
}
}
return v;
Expand Down Expand Up @@ -2225,7 +2225,7 @@ SGTELIB::Matrix SGTELIB::Matrix::SVD_pseudo_inverse ( const double tol_rank ) co
// Inverse diag terms of W.
for (int i=0 ; i<_nbCols ; i++)
{
if (fabs(W.get(i,i)) > tol_rank)
if (std::fabs(W.get(i,i)) > tol_rank)
{
W.set(i,i,1/W.get(i,i));
}
Expand Down Expand Up @@ -2408,14 +2408,14 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
g = s = scale = 0.0;
if ( i < nbRows ) {
for ( k = i ; k < nbRows ; ++k )
scale += fabs ( U[k][i] );
scale += std::fabs ( U[k][i] );
if ( scale != 0.0 ) {
for ( k = i ; k < nbRows ; ++k ) {
U[k][i] /= scale;
s += U[k][i] * U[k][i];
}
f = U[i][i];
g = ( f >= 0.0 ) ? -fabs(sqrt(s)) : fabs(sqrt(s));
g = ( f >= 0.0 ) ? -std::fabs(sqrt(s)) : std::fabs(sqrt(s));
h = f * g - s;
U[i][i] = f - g;
for ( j = l ; j < nbCols ; ++j ) {
Expand All @@ -2433,14 +2433,14 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
g = s = scale = 0.0;
if ( i < nbRows && i != nm1 ) {
for ( k = l ; k < nbCols ; ++k )
scale += fabs ( U[i][k] );
scale += std::fabs ( U[i][k] );
if ( scale != 0.0 ) {
for ( k = l ; k < nbCols ; ++k ) {
U[i][k] /= scale;
s += U[i][k] * U[i][k];
}
f = U[i][l];
g = ( f >= 0.0 ) ? -fabs(sqrt(s)) : fabs(sqrt(s));
g = ( f >= 0.0 ) ? -std::fabs(sqrt(s)) : std::fabs(sqrt(s));
h = f * g - s;
U[i][l] = f - g;
for ( k = l ; k < nbCols ; ++k )
Expand All @@ -2455,7 +2455,7 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
U[i][k] *= scale;
}
}
tmp = fabs ( W[i] ) + fabs ( rv1[i] );
tmp = std::fabs ( W[i] ) + std::fabs ( rv1[i] );
norm = ( norm > tmp ) ? norm : tmp;
}

Expand Down Expand Up @@ -2510,11 +2510,11 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
flag = true;
for ( l = k ; l >= 0 ; l-- ) {
nm = l - 1;
if ( nm < 0 || fabs ( rv1[l]) + norm == norm ) {
if ( nm < 0 || std::fabs ( rv1[l]) + norm == norm ) {
flag = false;
break;
}
if ( fabs ( W[nm] ) + norm == norm )
if ( std::fabs ( W[nm] ) + norm == norm )
break;
}
if ( flag ) {
Expand All @@ -2523,12 +2523,12 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
for ( i = l ; i <= k ; i++ ) {
f = s * rv1[i];
rv1[i] = c * rv1[i];
if ( fabs(f) + norm == norm )
if ( std::fabs(f) + norm == norm )
break;
g = W[i];

absf = fabs(f);
absg = fabs(g);
absf = std::fabs(f);
absg = std::fabs(g);
h = ( absf > absg ) ?
absf * sqrt ( 1.0 + pow ( absg/absf , 2.0 ) ) :
( ( absg==0 ) ? 0.0 : absg * sqrt ( 1.0 + pow ( absf/absg , 2.0 ) ) );
Expand Down Expand Up @@ -2567,13 +2567,13 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
h = rv1[k];
f = ( (y-z) * (y+z) + (g-h) * (g+h) ) / ( 2.0 * h * y );

absf = fabs(f);
absf = std::fabs(f);
g = ( absf > 1.0 ) ?
absf * sqrt ( 1.0 + pow ( 1.0/absf , 2.0 ) ) :
sqrt ( 1.0 + pow ( absf , 2.0 ) );

f = ( (x-z) * (x+z) +
h * ( ( y / ( f + ( (f >= 0)? fabs(g) : -fabs(g) ) ) ) - h ) ) / x;
h * ( ( y / ( f + ( (f >= 0)? std::fabs(g) : -std::fabs(g) ) ) ) - h ) ) / x;
c = s = 1.0;

for ( j = l ; j <= nm ; ++j ) {
Expand All @@ -2583,8 +2583,8 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
h = s * g;
g = c * g;

absf = fabs(f);
absh = fabs(h);
absf = std::fabs(f);
absh = std::fabs(h);
z = ( absf > absh ) ?
absf * sqrt ( 1.0 + pow ( absh/absf , 2.0 ) ) :
( ( absh==0 ) ? 0.0 : absh * sqrt ( 1.0 + pow ( absf/absh , 2.0 ) ) );
Expand All @@ -2603,8 +2603,8 @@ bool SGTELIB::Matrix::SVD_decomposition ( std::string & error_msg ,
V[jj][i] = z * c - x * s;
}

absf = fabs(f);
absh = fabs(h);
absf = std::fabs(f);
absh = std::fabs(h);
z = ( absf > absh ) ?
absf * sqrt ( 1.0 + pow ( absh/absf , 2.0 ) ) :
( ( absh==0 ) ? 0.0 : absh * sqrt ( 1.0 + pow ( absf/absh , 2.0 ) ) );
Expand Down Expand Up @@ -2666,7 +2666,7 @@ SGTELIB::Matrix SGTELIB::Matrix::null_space( const double rank_tol ) const
int rank=0;
for (int i=0; i < nvar; i++)
{
if (fabs(W[i]) > rank_tol)
if (std::fabs(W[i]) > rank_tol)
rank++;
}

Expand Down Expand Up @@ -2948,7 +2948,7 @@ SGTELIB::Matrix SGTELIB::Matrix::get_distances_norm1 ( const SGTELIB::Matrix & A
// Distance between the point ia of the cache and the point ib of the matrix XXs
v = 0;
for (j=0 ; j < n ; j++){
v += fabs(A._X[ia][j]-B._X[ib][j]);
v += std::fabs(A._X[ia][j]-B._X[ib][j]);
}
D._X[ia][ib] = v;
}
Expand Down Expand Up @@ -2977,7 +2977,7 @@ SGTELIB::Matrix SGTELIB::Matrix::get_distances_norminf ( const SGTELIB::Matrix &
// Distance between the point ia of the cache and the point ib of the matrix XXs
v = 0;
for (j=0 ; j < n ; j++){
v = std::max( v , fabs(A._X[ia][j]-B._X[ib][j]) );
v = std::max( v , std::fabs(A._X[ia][j]-B._X[ib][j]) );
}
D._X[ia][ib] = v;
}
Expand Down Expand Up @@ -3111,7 +3111,7 @@ SGTELIB::Matrix SGTELIB::Matrix::get_poll_directions ( const SGTELIB::Matrix& sc

// Find max asb
d = 0;
for (j=0 ; j<N ; j++) d = std::max( d , fabs(D._X[i][j]) );
for (j=0 ; j<N ; j++) d = std::max( d , std::fabs(D._X[i][j]) );

// Scale continuous dimensions
for (j=0 ; j<N ; j++){
Expand Down
10 changes: 5 additions & 5 deletions ext/sgtelib/src/Surrogate_Ensemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void SGTELIB::Surrogate_Ensemble::compute_W_by_select ( void ) {
if (is_ready(k)){
metric = _surrogates.at(k)->get_metric(_param.get_metric_type(),j);
// If the metric is close to metric_best
if ( fabs(metric-metric_best)<EPSILON ){
if ( std::fabs(metric-metric_best)<EPSILON ){
// Give weight to this model
W.set(k,j,1.0);
// Increment k_best (number of surrogates such that metric=metric_best)
Expand Down Expand Up @@ -446,7 +446,7 @@ void SGTELIB::Surrogate_Ensemble::compute_W_by_select_nb ( const int nb_bests )
if (is_ready(k)){
metric = _surrogates.at(k)->get_metric(_param.get_metric_type(),j);
// If the metric is close to metric_best
if ( fabs(metric-metric_best)<EPSILON ){
if ( std::fabs(metric-metric_best)<EPSILON ){
// Give weight to this model
W.set(k,j,1.0);
// Increment k_best (number of surrogates such that metric=metric_best)
Expand Down Expand Up @@ -496,7 +496,7 @@ void SGTELIB::Surrogate_Ensemble::compute_W_by_select_nb ( const int nb_bests )
if (selected[k]){
// If metric of model k is equal to metric_sum
// set weigth to 0.1
if ( fabs(metrics[k]-metric_sum)<EPSILON ){
if ( std::fabs(metrics[k]-metric_sum)<EPSILON ){
W.set(k,j, 0.1);
}
else{
Expand Down Expand Up @@ -811,7 +811,7 @@ void SGTELIB::Surrogate_Ensemble::predict_private ( const SGTELIB::Matrix & XXs,
for (int i=0 ; i<pxx ; i++){
z = ZZ->get(i,j);
s = std->get(i,j) - z*z;
std->set(i,j, sqrt(fabs(s)) );
std->set(i,j, sqrt(std::fabs(s)) );
}// end loop i
}
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ bool SGTELIB::Surrogate_Ensemble::check_weight_vector ( void ) const {
if ( isnan(w) ) return true;
}
s = W.get_col(j).sum();
if (fabs(s-1.0)>_kready*EPSILON) return true;
if (std::fabs(s-1.0)>_kready*EPSILON) return true;
}
}

Expand Down
Loading
Loading