Algorithm parameter keys of MOEA framework - java

Using the withProperty method of the executing routine you can set several parameters of an algorithm i.e. for NSGA-II
NondominatedPopulation result = new Executor()
.withProblem("UF1")
.withAlgorithm("NSGAII")
.withMaxEvaluations(10000)
.withProperty("populationSize", 50)
.withProperty("sbx.rate", 0.9)
.withProperty("sbx.distributionIndex", 15.0)
.run();
The documentation says
Each algorithm defines its own parameters. Refer to the API documentation
for the exact parameter keys. Any parameters not explicitly defined using
the withProperty methods will be set to their default values.
But I can not find these keys within NSGAII class. Can you give me a link to it.
Thanks in advance

I found them here: http://www.moeaframework.org/javadoc/org/moeaframework/algorithm/jmetal/JMetalAlgorithms.html
Man, those are not easy to find!
Your algorithm (NSGAII) in particular uses: NSGAII -> populationSize, maxEvaluations
Also ... totally agree that the NSGAII API documentation would've been a great place to put this information.

Related

Cannot find symbol for makeCopy method in weka java

I am trying to modify cross validation code developed by weka in this page. When I paste the exact code the method .makeCopy(cls) in the line Classifier clsCopy = Classifier.makeCopy(cls); is not exist. Is there any replacement or update for this method?
Classifier has become an interface since Weka 3.7. Use the weka.classifiers.AbstractClassifier.makeCopy(Classifier) instead.
Reference : http://weka.8497.n7.nabble.com/Classifier-td32507.html
You are doing it wrong. Use AbstractClassifier which then takes Classifier as parameter. AbstractClassifier has the method namely makeCopy. Do tell me, if that was the case. Here is the LINK to it

Minimum finding for univariate nonlinear function in Java

I'm looking for a simple way to accomplish in Java what MATLAB's fminsearch() does. I don't need to be as general as fminsearch, in my case I only want to find the minimum (function and parameter values at minimum) of a single-variable nonlinear function. I don't know the analytical expression of the function, but I can evaluate it easily.
Do you know of a library that performs this, or of an easy algorithm I could re-implement?
Note: I saw that apache's common-math seems to have something like this (UnivariateOptimizer), but most of the methods seem to be deprecated and I couldn't find a good explanation how to use it. Any tips related to that are welcome as well.
Thanks!
Apache Commons Math is generally a good place to start for numerical computations in Java. Usage is best learnt by example, looking at the API documentation and the unit test source code for the various classes and methods.
The optimization classes that are referenced in the user guide are, as you have noted, deprecated. They can still be called, but eventually they will of course be phased out from the library. For reasons unknown to me, ongoing optimization development is now taking place in the optim rather than the optimization sub-package.
For univariate function (local optimum) minimization, Apache Commons Math provides an implementation of the Brent method. Usage is outlined in the unit tests of the BrentOptimizer, from which I have copied this excerpt:
#Test
public void testSinMin() {
UnivariateFunction f = new Sin();
UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
Assert.assertEquals(3 * Math.PI / 2,
optimizer.optimize(new MaxEval(200),
new UnivariateObjectiveFunction(f),
GoalType.MINIMIZE,
new SearchInterval(4, 5)).getPoint(), 1e-8);
Assert.assertTrue(optimizer.getEvaluations() <= 50);
Assert.assertEquals(200, optimizer.getMaxEvaluations());
...
}

How to use getAt() function in Java/Groovy?

Recently I encountered the usage of the method getAt() in Java code. It is used to get the data from a URL (which is sent via GET method by form submit). The URL will be like:
http://192.168.27.55/flight/search?n=airchina
The method was used like name=params.getAt("n"). Then the data was passed to another function by search("n",name). Can any one please brief me how it works?
getAt() in Groovy has special meaning for collections. It allows one to access elements of the collection using the subscript operator.
Here's the documentation for Map and List:
Map#getAt(key)
List#getAt(index)
Since it's defined to support some syntactic sugar, you don't really see it ever called directly, since it enables you to instead do something like:
Map foo = [bar: 'baz']
assert foo['bar'] == 'baz'
In your particular case with params, you'd simply use:
params['n']
...to take advantage of getAt(). Alternatively, you could use:
params.n
// or
params.get('n')
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
params.n
documentation for params

Modify code at runtime to log return values in Java?

Is there any way of inserting code at runtime to log return values, for instance, using instrumentation?
So far, I managed to insert code when a method exits, but I would like to log something like "method foo returned HashMap { 1 -> 2, 2 -> 3 }"
I'm looking for a general approach that can also deal with, for instance, java.io.* classes. (So in general I'll have no access to the code).
I tried using a custom classloader too, but lot of difficulties arise as I cannot modify java.* classes.
Thanks for the help!
Sergio
Check out BTrace. It's Java, and I believe it'll do what you want.
Have you considered AOP? (Aspect-oriented programming) - if by "I cannot modify java.* classes" you mean you don't have access to the uncompiled code, and cannot add configuration, etc., then that won't probably work for you. In any other case, check that link for examples using Spring-aop:
http://static.springsource.org/spring/docs/2.5.x/reference/aop.html
If not, you could consider solutions based on remote-debugging, or profiling. But they all involve "some" access to the original code, if only to enable / disable JMX access.
Well, since you're looking for everything, the only thing I can think off is using a machine agent. Machine agents hook into the low levels of the JVM itself and can be used to monitor these things.
I have not used DTrace, but it sounds like it would be able to do what you need. Adam Leventhal wrote a nice blog post about it. The link to DTrace in the blog is broken, but I'm sure a quick search and you'll come up with it.
Take a look at Spring AOP, which is quite powerful, and flexible. To start you off on the method foo, you can apply an AfterReturning advice to it as:
#Aspect
public class AfterReturningExample {
#AfterReturning(
pointcut="package.of.your.choice.YourClassName.foo()",
returning="retVal")
public void logTheFoo( Object retVal ) {
// ... logger.trace( "method 'foo' returned " + retVal ); // might need to convert "retVal" toString representation if needed
}
}
The pointcut syntax is really flexible so you can target all the sub packages, components, methods, return values given the expression.

EasyMock/Guice style api

Is there a name for the style of API that reads like a sentence? For example, in google-guice
bind(TransactionLog.class).to(DatabaseTransactionLog.class);
or in Easymock
expect(mock.voteForRemoval("Document")).andReturn((byte) 42);
I want to program an api that looks similar to what I call the 'google style' api, i.e. I want it to look like:
RowStyle(RED_BACKGROUND).when(PROP_ERROR_MESSAGE).notNull();
and would like to know pros/cons to this type of API, if it has a name, and how you would go about implementing it.
Those APIs are called "fluent API" and in our days some guys call them "internal DSL", but the first term is AFAICT more widely used (and is the older correct term).
For me, this will only work if the sequence of those operations (style(), when(), notNull() ) is strictly defined. If you can call when() after notNull(), this won't make any sence.
Normally, you just define a method with several parameters:
public void rowStyle(String condition, boolean notNull)
, but these additional calls are the good way to specify optional parameters.
So, + if you have optional parameters, - if you don't have them; + if strictly defined call sequence, - if not.

Categories

Resources