Comments (5)
Hello, depending on the optimizer it's possible to set the bounds, see https://ensmallen.org/docs.html#pso for an example. What optimizer are you using?
from ensmallen.
@zoq is right, there are some techniques that specifically support constrained optimization. If you still want to use a differentiable optimizer like SGD or L-BFGS or something that doesn't specifically have supports for constraints, I would suggest a "soft" constraint instead of simply evaluating to DBL_MAX
(or similar); think, e.g., adding some constant multiplied by how far you are from the edge of the bounds. So for a one-dimensional problem, if you want something in [0, 1]
, maybe add, say, 1000 * (std::min(x[0], x[0] - 1))
or something like this if x[0]
is not in [0, 1]
. Just an idea.
from ensmallen.
@zoq Sorry for late reply! I was using DE. PSO for me has a strange bug of not terminating even due to maxIterations
- it just goes on and on; I've looked at the ensmallen code, and it looks like it should work...
@rcurtin thanks for the soft constraint idea, not sure if it is useful for non-differentiable optimizers, my testing for DE seems to yield the same results as with DBL_MAX
:
auto outOfBoundsLoss(const arma::mat& coordinates,
const arma::mat& lower,
const arma::mat& upper) -> std::optional<double> {
constexpr double PENALTY = 1000.0;
std::optional<double> loss{};
for (int i = 0; i < coordinates.size(); ++i) {
if (coordinates[i] < lower[i]) {
loss = PENALTY * (lower[i] - coordinates[i]) + loss.value_or(0.0);
} else if (coordinates[i] > upper[i]) {
loss = PENALTY * (coordinates[i] - upper[i]) + loss.value_or(0.0);
}
}
return loss;
}
auto ObjectiveType::Evaluate(const arma::mat coordinates) -> double {
const auto outOfBounds =
outOfBoundsLoss(aberrations, {-100, -10'000}, {100, 10'000});
if (outOfBounds.has_value()) {
return outOfBounds.value();
}
// In-bounds calculations
}
from ensmallen.
Ok, there is no problem with maxIterations
, I was counting evaluations, not iterations... But bounds for PSO do not work, I still need to use the loss-bounding function. It kinda makes sense, even in documentation it is written that bounds are only for the initial population.
Also, a better approach with the above code would be not to return the out-of-bounds loss, but instead add it as penalty, otherwise algorithm can optimize out-of-bounds and converge to one of the bounds:
auto ObjectiveType::Evaluate(const arma::mat coordinates) -> double {
const auto penalty =
outOfBoundsLoss(aberrations, {-100, -10'000}, {100, 10'000});
// In-bounds calculations
// result = ...
return result + penalty.value_or(0.0);
}
from ensmallen.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍
from ensmallen.
Related Issues (20)
- Compiling errors ensmallen 02.18.02 using VS2019 armadillo.lib 10.08.02 and mlpack.lib 03.04.02 HOT 6
- The example to use the constrained function HOT 4
- AugLagrangian with constraints validation HOT 8
- Multi-objective functions both MOEA/D-DE and NSGA2 - Examples using SchafferFunctionN1 HOT 1
- Implementing Function Type for Partial Derivatives HOT 3
- Does ensmallen work with armadillo >=10.0? HOT 5
- Enable HTTPS on ensmallen.org HOT 1
- Debian build (test) failure on i386 HOT 7
- ProgressBar() does not work with L_BFGS HOT 3
- During AugLagrangian's optimization, L_BFGS sets coordinates to nan HOT 6
- Migrate from Catch v2 to v3 HOT 3
- Using optimizer with integers HOT 6
- Custom early stop callback HOT 12
- SCD isn't stochastic and perhaps should be called CD? HOT 2
- 2.20 documentation + link issues
- Which optimizer should I use? HOT 2
- [PowerPC] Bus error during running tests: `KERN_PROTECTION_FAILURE at address: 0x00000000` HOT 7
- [aarch64] One test failure in Johnson844LovaszThetaFMatSDP HOT 8
- benchmarking framework for single-objective evolutionary optimization algorithms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ensmallen.