本文整理汇总了Java中edacc.parameterspace.ParameterConfiguration.setParameterValue方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterConfiguration.setParameterValue方法的具体用法?Java ParameterConfiguration.setParameterValue怎么用?Java ParameterConfiguration.setParameterValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edacc.parameterspace.ParameterConfiguration
的用法示例。
在下文中一共展示了ParameterConfiguration.setParameterValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEqualsObject
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testEqualsObject() throws Exception {
APIImpl api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/complex.xml");
ParameterConfiguration config = new ParameterConfiguration(pspace.getParameterSet());
config.setParameterValue("c1", 5);
config.setParameterValue("ps", 0.1);
config.setParameterValue("flag", FlagDomain.FLAGS.OFF);
assertTrue("c1: 5 flag: OFF ps: 0.1 ".equals(config.toString()));
ParameterConfiguration config2 = new ParameterConfiguration(pspace.getParameterSet());
config2.setParameterValue("c1", 5);
config2.setParameterValue("ps", 0.1);
config2.unsetParameter("flag"); // set flag to null, should be equal to a configuration with flag = FlagDomain.FLAGS.OFF
assertTrue(config.equals(config2));
}
示例2: testCrossover
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testCrossover() throws Exception {
Random rng = new MersenneTwister();
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/sparrow_parameterspace.xml");
ParameterConfiguration config1 = new ParameterConfiguration(pspace.getParameterSet());
config1.setParameterValue("ps", 0.1);
config1.setParameterValue("c1", 1);
config1.setParameterValue("c2", 1);
config1.setParameterValue("c3", 11);
ParameterConfiguration config2 = new ParameterConfiguration(pspace.getParameterSet());
config2.setParameterValue("ps", 0.2);
config2.setParameterValue("c1", 2);
config2.setParameterValue("c2", 2);
config2.setParameterValue("c3", 22);
Pair<ParameterConfiguration, ParameterConfiguration> cross = pspace.crossover(config1, config2, rng);
for (Parameter p: pspace.parameters) {
Object p_val1 = cross.getFirst().getParameterValue(p);
Object p_val2 = cross.getSecond().getParameterValue(p);
assertTrue(config1.getParameterValue(p).equals(p_val1) || config2.getParameterValue(p).equals(p_val1));
assertTrue(config1.getParameterValue(p).equals(p_val2) || config2.getParameterValue(p).equals(p_val2));
}
}
示例3: testGetConstrainedNeighbourhood
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testGetConstrainedNeighbourhood() throws Exception {
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/sparrow_parameterspace.xml");
ParameterConfiguration config = new ParameterConfiguration(pspace.getParameterSet());
config.setParameterValue("ps", 0.2);
config.setParameterValue("c1", 10);
config.setParameterValue("c2", 20);
config.setParameterValue("c3", 20);
List<ParameterConfiguration> nbh = pspace.getConstrainedNeighbourhood(config);
ParameterConfiguration neighbour1 = new ParameterConfiguration(config);
neighbour1.setParameterValue("c1", 11);
ParameterConfiguration neighbour2 = new ParameterConfiguration(config);
neighbour2.setParameterValue("c1", 50);
ParameterConfiguration neighbour3 = new ParameterConfiguration(config);
neighbour3.setParameterValue("ps", 0.5);
ParameterConfiguration nonneighbour1 = new ParameterConfiguration(config);
nonneighbour1.setParameterValue("c1", 11);
nonneighbour1.setParameterValue("c2", 19);
assertTrue(nbh.contains(neighbour1));
assertTrue(nbh.contains(neighbour2));
assertTrue(nbh.contains(neighbour3));
assertFalse(nbh.contains(nonneighbour1));
assertTrue(nbh.size() == 100 + 51 + 51 + 21 - 4); // 100 ps, 51 c1, 51 c2, 21 c3 values, minus 4 fixed values from config
assertFalse(nbh.contains(config));
}
示例4: testGetFullNeighbourhood
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testGetFullNeighbourhood() throws Exception {
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/complex.xml");
ParameterConfiguration config = new ParameterConfiguration(pspace.getParameterSet());
config.setParameterValue("c1", 5);
config.setParameterValue("ps", 0.1);
config.setParameterValue("flag", FlagDomain.FLAGS.ON);
config.setParameterValue("method", "hybrid");
config.setParameterValue("cat", "1");
assertTrue("c1: 5 cat: 1 method: hybrid flag: ON ps: 0.1 ".equals(config.toString()));
List<ParameterConfiguration> nbh = pspace.getNeighbourhood(config);
ParameterConfiguration nb1 = new ParameterConfiguration(config);
nb1.setParameterValue("method", "atom");
assertTrue(nbh.contains(nb1));
ParameterConfiguration nb2 = new ParameterConfiguration(config);
nb2.setParameterValue("flag", FlagDomain.FLAGS.OFF);
assertFalse(nbh.contains(nb2)); // flag -> off should lead to method and cat being removed
nb2.unsetParameter("cat");
nb2.unsetParameter("method");
assertTrue(nbh.contains(nb2));
ParameterConfiguration nb3 = new ParameterConfiguration(config);
nb3.setParameterValue("c1", 6);
assertTrue(nbh.contains(nb3));
nb3.setParameterValue("c1", 5); // same config
assertFalse(nbh.contains(nb3));
}
示例5: testGetRandomNeighbour
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testGetRandomNeighbour() throws Exception {
Random rng = new MersenneTwister();
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/sparrow_parameterspace.xml");
ParameterConfiguration config = new ParameterConfiguration(pspace.getParameterSet());
config.setParameterValue("ps", 0.2);
config.setParameterValue("c1", 1);
config.setParameterValue("c2", 2);
config.setParameterValue("c3", 15);
List<ParameterConfiguration> nbh = pspace.getConstrainedNeighbourhood(config);
for (int i = 0; i < 100; i++) assertTrue(nbh.contains(pspace.getRandomNeighbour(config, rng)));
}
示例6: testCrossover2Point
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testCrossover2Point() throws Exception {
Random rng = new MersenneTwister();
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/sparrow_parameterspace.xml");
ParameterConfiguration config1 = new ParameterConfiguration(pspace.getParameterSet());
config1.setParameterValue("ps", 0.1);
config1.setParameterValue("c1", 1);
config1.setParameterValue("c2", 1);
config1.setParameterValue("c3", 11);
ParameterConfiguration config2 = new ParameterConfiguration(pspace.getParameterSet());
config2.setParameterValue("ps", 0.2);
config2.setParameterValue("c1", 2);
config2.setParameterValue("c2", 2);
config2.setParameterValue("c3", 22);
Pair<ParameterConfiguration, ParameterConfiguration> cross = pspace.crossover2Point(config1, config2, rng);
ParameterConfiguration c1 = cross.getFirst();
ParameterConfiguration c2 = cross.getSecond();
for (Parameter p: pspace.parameters) {
Object p_val1 = c1.getParameterValue(p);
Object p_val2 = c2.getParameterValue(p);
assertTrue(config1.getParameterValue(p).equals(p_val1) || config2.getParameterValue(p).equals(p_val1));
assertTrue(config1.getParameterValue(p).equals(p_val2) || config2.getParameterValue(p).equals(p_val2));
}
}
示例7: testValidateParameterConfiguration
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
@Test
public void testValidateParameterConfiguration() throws Exception {
API api = new APIImpl();
ParameterGraph pspace = api.loadParameterGraphFromFile("src/edacc/parameterspace/test/complex.xml");
ParameterConfiguration config = new ParameterConfiguration(pspace.getParameterSet());
config.setParameterValue("c1", 5);
config.setParameterValue("ps", 0.1);
config.setParameterValue("flag", FlagDomain.FLAGS.ON);
config.setParameterValue("method", "hybrid");
config.setParameterValue("cat", "1");
assertTrue(pspace.validateParameterConfiguration(config));
List<ParameterConfiguration> nbh = pspace.getNeighbourhood(config);
ParameterConfiguration nb1 = new ParameterConfiguration(config);
nb1.setParameterValue("method", "atom");
assertTrue(nbh.contains(nb1));
assertTrue(pspace.validateParameterConfiguration(nb1));
ParameterConfiguration nb2 = new ParameterConfiguration(config);
nb2.setParameterValue("flag", FlagDomain.FLAGS.OFF);
assertFalse(nbh.contains(nb2)); // flag -> off should lead to method and cat being removed
assertFalse(pspace.validateParameterConfiguration(nb2));
nb2.unsetParameter("cat");
nb2.unsetParameter("method");
assertTrue(nbh.contains(nb2));
assertTrue(pspace.validateParameterConfiguration(nb2));
ParameterConfiguration nb3 = new ParameterConfiguration(config);
nb3.setParameterValue("c1", 6);
assertTrue(nbh.contains(nb3));
nb3.setParameterValue("c1", 5); // same config
assertFalse(nbh.contains(nb3));
assertTrue(pspace.validateParameterConfiguration(nb3));
}
示例8: getConstrainedNeighbourhood
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
/**
* Returns all parameter configurations that are considered neighbours of the given configuration.
* This neighbourhood is constrained to values that are located in the same AND-nodes as the values
* of the given configuration.
* @param config
* @return (constrained) list of all neighbouring configurations
*/
public List<ParameterConfiguration> getConstrainedNeighbourhood(ParameterConfiguration config) {
Set<OrNode> assigned_or_nodes = new HashSet<OrNode>();
Set<AndNode> assigned_and_nodes = new HashSet<AndNode>();
for (Parameter p: config.getParameter_instances().keySet()) {
for (AndNode n: getAndNodes()) {
if (n == startNode) continue;
if (n.getParameter().equals(p) && n.getDomain().contains(config.getParameterValue(p))) {
assigned_or_nodes.add(preceedingNode(n));
assigned_and_nodes.add(n);
}
}
}
List<ParameterConfiguration> nbh = new LinkedList<ParameterConfiguration>();
for (AndNode node: assigned_and_nodes) {
if (fixedParameters.containsKey(node.getParameter())) continue;
for (Object value: preceedingNode(node).getParameter().getDomain().getDiscreteValues()) {
if (node.getDomain().contains(value)) { // same subdomain, different value
if (valuesEqual(value, config.getParameterValue(node.getParameter()))) continue;
ParameterConfiguration neighbour = new ParameterConfiguration(config);
neighbour.setParameterValue(node.getParameter(), value);
if (calculateChecksums) neighbour.updateChecksum();
nbh.add(neighbour);
}
}
}
return nbh;
}
示例9: crossover2Point
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
/**
* Two point crossover operator
* @param config1
* @param config2
* @param rng
* @return
*/
public Pair<ParameterConfiguration, ParameterConfiguration> crossover2Point(ParameterConfiguration config1, ParameterConfiguration config2, Random rng) {
Map<Node, Integer> colors = new HashMap<Node, Integer>();
int currentColor = 1;
for (Node node: adjacentNodes(startNode)) {
int c = colorDFS(node, currentColor, colors);
if (c == currentColor) currentColor++;
}
ParameterConfiguration c1 = new ParameterConfiguration(parameters);
ParameterConfiguration c2 = new ParameterConfiguration(parameters);
int crossoverFirstColor = rng.nextInt(currentColor / 2) + 1;
int crossoverSecondColor = rng.nextInt(currentColor / 2 + 1) + 1 + currentColor / 2;
for (int col = 1; col < currentColor; col++) {
for (Node n: colors.keySet()) {
if (colors.get(n) == col) {
if (col <= crossoverFirstColor) { // first section (unchanged)
c1.setParameterValue(n.getParameter(), config1.getParameterValue(n.getParameter()));
c2.setParameterValue(n.getParameter(), config2.getParameterValue(n.getParameter()));
} else if (col <= crossoverSecondColor) { // second section (swap)
c1.setParameterValue(n.getParameter(), config2.getParameterValue(n.getParameter()));
c2.setParameterValue(n.getParameter(), config1.getParameterValue(n.getParameter()));
} else { // third section (unchanged)
c1.setParameterValue(n.getParameter(), config1.getParameterValue(n.getParameter()));
c2.setParameterValue(n.getParameter(), config2.getParameterValue(n.getParameter()));
}
}
}
}
if (calculateChecksums) c1.updateChecksum();
if (calculateChecksums) c2.updateChecksum();
return new Pair<ParameterConfiguration, ParameterConfiguration>(c1, c2);
}
示例10: queryTree
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
public static void queryTree(API api, ParameterGraph graph, int expid, List<Pair<ParameterConfiguration, List<ExperimentResult>>> trainData, List<Parameter> params, ArrayList<String> instancePropertyNames) throws Exception {
System.err.println("Generating random tree..");
DecisionTree rt = new DecisionTree(new Random(), new Average(Experiment.Cost.resultTime, true), 2.5, 8, trainData, params, instancePropertyNames, true);
System.err.println("Done.");
//rt.printDot();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
while (true) {
ParameterConfiguration config = graph.getRandomConfiguration(new Random());
for (Parameter p : api.getConfigurableParameters(expid)) {
System.out.println("Value for " + p.getName());
line = br.readLine();
if (line == null)
break;
if (p.getDomain() instanceof IntegerDomain) {
config.setParameterValue(p, Integer.valueOf(line));
} else if (p.getDomain() instanceof RealDomain) {
config.setParameterValue(p, Double.valueOf(line));
} else {
config.setParameterValue(p, line);
}
}
System.out.println("Instance id");
line = br.readLine();
if (line == null)
break;
int instanceId = Integer.valueOf(line);
List<ExperimentResult> results = rt.getResults(config, instanceId);
//for (ExperimentResult result : results) {
// System.out.println("" + result.getResultTime());
//}
System.out.println("" + results.size() + " results with cost (avg): " + new Average(Experiment.Cost.resultTime, true).calculateCost(results));
}
}
示例11: getNeighbourhood
import edacc.parameterspace.ParameterConfiguration; //导入方法依赖的package包/类
/**
* Returns all parameter configurations that are considered neighbours of the given configuration.
* TODO: use generalized algorithm instead of the "same-AND-node" constrained neighbourhood.
* @param config The configuration of which the neighbourhood should be generated.
* @return list of all neighbouring configurations
*/
public List<ParameterConfiguration> getNeighbourhood(ParameterConfiguration config) {
Set<OrNode> assigned_or_nodes = new HashSet<OrNode>();
Set<AndNode> assigned_and_nodes = new HashSet<AndNode>();
for (Parameter p: config.getParameter_instances().keySet()) {
for (AndNode n: getAndNodes()) {
if (n == startNode) continue;
if (n.getParameter().equals(p) && n.getDomain().contains(config.getParameterValue(p))) {
assigned_or_nodes.add(preceedingNode(n));
assigned_and_nodes.add(n);
}
}
}
List<ParameterConfiguration> nbh = new LinkedList<ParameterConfiguration>();
for (AndNode node: assigned_and_nodes) {
for (Object value: preceedingNode(node).getParameter().getDomain().getDiscreteValues()) {
if (node.getDomain().contains(value)) { // same subdomain, different value
if (valuesEqual(value, config.getParameterValue(node.getParameter()))) continue;
ParameterConfiguration neighbour = new ParameterConfiguration(config);
neighbour.setParameterValue(node.getParameter(), value);
neighbour.updateChecksum();
nbh.add(neighbour);
}
}
}
return nbh;
}