List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration()
XMLConfiguration
. From source file:io.datalayer.conf.XmlConfigurationTest.java
@Before public void setUp() throws Exception { conf = new XMLConfiguration(); conf.setFile(new File(testProperties)); conf.load();/*w w w . j ava2 s . com*/ removeTestFile(); }
From source file:keel.Algorithms.Neural_Networks.IRPropPlus_Regr.KEELIRPropPlusWrapperRegr.java
/** * <p>/*from ww w . ja va 2 s . c o m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the * execution * </p> */ @SuppressWarnings("unchecked") private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); // Configure schema byte[] schema = null; try { schema = readSchema(trainFile); } catch (IOException e) { e.printStackTrace(); } catch (DatasetException e) { e.printStackTrace(); } // Auxiliar configuration file XMLConfiguration conf = new XMLConfiguration(); conf.setRootElementName("algorithm"); // Configure randGenFactory randGenFactory = new RanNnepFactory(); conf.addProperty("rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); if (randGenFactory instanceof IConfigure) ((IConfigure) randGenFactory).configure(conf.subset("rand-gen-factory")); // Configure species NeuralNetIndividualSpecies nnspecies = new NeuralNetIndividualSpecies(); species = (ISpecies) nnspecies; if (props.getProperty("Transfer").equals("Product_Unit")) { conf.addProperty("species.neural-net-type", "keel.Algorithms.Neural_Networks.IRPropPlus_Regr.MSEOptimizablePUNeuralNetRegressor"); conf.addProperty("species.hidden-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.ExpLayer"); conf.addProperty("species.hidden-layer[@biased]", false); } else { conf.addProperty("species.neural-net-type", "keel.Algorithms.Neural_Networks.IRPropPlus_Regr.MSEOptimizableSigmNeuralNetRegressor"); conf.addProperty("species.hidden-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.SigmLayer"); conf.addProperty("species.hidden-layer[@biased]", true); } int neurons = Integer.parseInt(props.getProperty("Hidden_nodes")); conf.addProperty("species.hidden-layer.minimum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.initial-maximum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.maximum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.initiator-of-links", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator"); conf.addProperty("species.hidden-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval"); conf.addProperty("species.hidden-layer.weight-range[@closure]", "closed-closed"); if (props.getProperty("Transfer").equals("Product_Unit")) { conf.addProperty("species.hidden-layer.weight-range[@left]", -0.1); conf.addProperty("species.hidden-layer.weight-range[@right]", 0.1); } else { conf.addProperty("species.hidden-layer.weight-range[@left]", -5.0); conf.addProperty("species.hidden-layer.weight-range[@right]", 5.0); } conf.addProperty("species.output-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.LinearLayer"); conf.addProperty("species.output-layer[@biased]", true); conf.addProperty("species.output-layer.initiator-of-links", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator"); conf.addProperty("species.output-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval"); conf.addProperty("species.output-layer.weight-range[@closure]", "closed-closed"); conf.addProperty("species.output-layer.weight-range[@left]", -5.0); conf.addProperty("species.output-layer.weight-range[@right]", 5.0); if (species instanceof IConfigure) ((IConfigure) species).configure(conf.subset("species")); // Configure evaluator evaluator = (IEvaluator) new RegressionProblemEvaluator(); if (props.getProperty("Transfer").equals("Product_Unit")) conf.addProperty("evaluator[@log-input-data]", true); conf.addProperty("evaluator[@normalize-data]", true); conf.addProperty("evaluator.error-function", "keel.Algorithms.Neural_Networks.NNEP_Regr.problem.errorfunctions.MSEErrorFunction"); conf.addProperty("evaluator.input-interval[@closure]", "closed-closed"); conf.addProperty("evaluator.input-interval[@left]", 0.1); conf.addProperty("evaluator.input-interval[@right]", 0.9); conf.addProperty("evaluator.output-interval[@closure]", "closed-closed"); conf.addProperty("evaluator.output-interval[@left]", 1.0); conf.addProperty("evaluator.output-interval[@right]", 2.0); if (evaluator instanceof IConfigure) ((IConfigure) evaluator).configure(conf.subset("evaluator")); // Configure provider provider = new NeuralNetCreator(); KEELIRPropPlusWrapperRegr system = new KEELIRPropPlusWrapperRegr(); provider.contextualize(system); // Configure iRProp+ algorithm algorithm = new IRPropPlus(); conf.addProperty("algorithm.initial-step-size[@value]", 0.0125); conf.addProperty("algorithm.minimum-delta[@value]", 0.0); conf.addProperty("algorithm.maximum-delta[@value]", 50.0); conf.addProperty("algorithm.positive-eta[@value]", 1.2); conf.addProperty("algorithm.negative-eta[@value]", 0.2); conf.addProperty("algorithm.cycles[@value]", Integer.parseInt(props.getProperty("Epochs"))); if (algorithm instanceof IConfigure) ((IConfigure) algorithm).configure(conf.subset("algorithm")); // Read data ProblemEvaluator<AbstractIndividual<INeuralNet>> evaluator2 = (ProblemEvaluator<AbstractIndividual<INeuralNet>>) evaluator; evaluator2.readData(schema, new KeelDataSet(trainFile), new KeelDataSet(testFile)); nnspecies.setNOfInputs(evaluator2.getTrainData().getNofinputs()); nnspecies.setNOfOutputs(evaluator2.getTrainData().getNofoutputs()); algorithm.setTrainingData(evaluator2.getTrainData()); // Read output files tokenizer = new StringTokenizer(props.getProperty("outputData")); String trainResultFile = tokenizer.nextToken(); trainResultFile = trainResultFile.substring(1, trainResultFile.length() - 1); consoleReporter.setTrainResultFile(trainResultFile); String testResultFile = tokenizer.nextToken(); testResultFile = testResultFile.substring(1, testResultFile.length() - 1); consoleReporter.setTestResultFile(testResultFile); String bestModelResultFile = tokenizer.nextToken(); bestModelResultFile = bestModelResultFile.substring(1, bestModelResultFile.length() - 1); consoleReporter.setBestModelResultFile(bestModelResultFile); }
From source file:de.nec.nle.siafu.control.Controller.java
/** * Create a config file with default values. This is used when the config * file doesn't exist in the first place. * /* w w w. j a v a 2 s .c o m*/ * @return the newly created configuration file. */ private XMLConfiguration createDefaultConfigFile() { System.out.println("Creating a default configuration file at " + DEFAULT_CONFIG_FILE); XMLConfiguration newConfig = new XMLConfiguration(); newConfig.setRootElementName("configuration"); newConfig.setProperty("commandlistener.enable", true); newConfig.setProperty("commandlistener.tcpport", DEFAULT_PORT); newConfig.setProperty("ui.usegui", true); newConfig.setProperty("ui.speed", DEFAULT_UI_SPEED); newConfig.setProperty("ui.gradientcache.prefill", true); newConfig.setProperty("ui.gradientcache.size", DEFAULT_CACHE_SIZE); newConfig.setProperty("output.type", "null"); newConfig.setProperty("output.csv.path", System.getProperty("user.home") + File.separator + "SiafuContext.csv"); newConfig.setProperty("output.csv.interval", DEFAULT_CSV_INTERVAL); newConfig.setProperty("output.csv.keephistory", true); try { newConfig.setFileName(DEFAULT_CONFIG_FILE); newConfig.save(); } catch (ConfigurationException e) { throw new RuntimeException("Can not create a default config file at " + DEFAULT_CONFIG_FILE, e); } return newConfig; }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that attempting to return a connection that has been closed throws no error. * @throws ConfigurationException if there is a problem setting up the default test connection * @throws RserveException if there is a problem with the connection to the Rserve process */// ww w .j ava 2 s.c o m @Test public void returnClosedConnection() throws ConfigurationException, RserveException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); assertNotNull("Connection pool should never be null", pool); assertFalse("Everybody in - the pool should be open!", pool.isClosed()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get a connection from the pool final RConnection connection = pool.borrowConnection(); assertNotNull("Connection should not be null", connection); assertTrue("The connection should be connected to the server", connection.isConnected()); connection.close(); assertFalse("The connection should not be connected to the server anymore", connection.isConnected()); // return the connection to the pool pool.returnConnection(connection); // and the connection should remain closed assertFalse("The connection should not be connected to the server anymore", connection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get another connection from the pool final RConnection connection2 = pool.borrowConnection(); assertNotNull("Connection should not be null", connection2); assertTrue("The connection should be connected to the server", connection2.isConnected()); }
From source file:de.nec.nle.siafu.model.SimulationData.java
/** * Get an InputSream linked to the simulation configuration file. * /*w w w . j a va2s. c om*/ * @return the inputstream with the configuration */ public XMLConfiguration getConfigFile() { if (simulationConfig == null) { simulationConfig = new XMLConfiguration(); try { simulationConfig.load(getFile(CONFIG_FILE)); } catch (ConfigurationException e) { throw new RuntimeException("Error reading the simulation config file", e); } } return simulationConfig; }
From source file:de.uni_hannover.dcsec.siafu.model.SimulationData.java
/** * Get an InputSream linked to the simulation configuration file. * //w w w . ja va 2 s .co m * @return the inputstream with the configuration */ public XMLConfiguration getConfigFile() { if (simulationConfig == null) { simulationConfig = new XMLConfiguration(); try { simulationConfig.load(getFile(CONFIG_FILE)); // simulationConfig.load(classLoader.getResource(CONFIG_FILE)); } catch (ConfigurationException e) { throw new RuntimeException("Error reading the simulation config file", e); } } return simulationConfig; }
From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java
/** * Run the XMLConfiguration getConfig() method test. * //from www . j a v a 2s .co m * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testGetConfig_1() throws Exception { MailMessageConfig fixture = new MailMessageConfig(); fixture.config = new XMLConfiguration(); fixture.configFile = new File(""); XMLConfiguration result = fixture.getConfig(); // An unexpected exception was thrown in user code while executing this test: // java.lang.SecurityException: Cannot write to files while generating test cases // at // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76) // at java.io.FileOutputStream.<init>(FileOutputStream.java:209) // at java.io.FileOutputStream.<init>(FileOutputStream.java:171) // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490) // at // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204) // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63) // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71) assertNotNull(result); }
From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java
private HierarchicalConfiguration getConfig(FileObject checkoutFolder) { XMLConfiguration config;//from w w w.j a v a2 s .c o m try { config = new XMLConfiguration(); config.load(getEnvFileToRead(checkoutFolder).getURLDa()); return config; } catch (ConfigurationException exc) { throw new DeployerRuntimeException(exc); } }
From source file:net.continuumsecurity.Config.java
public void loadConfig(String file) { try {//from w w w. j a v a 2 s .c o m xml = new XMLConfiguration(); xml.load(file); } catch (ConfigurationException cex) { cex.printStackTrace(); } catch (org.apache.commons.configuration.ConfigurationException e) { e.printStackTrace(); } }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that an attempt to return an invalid connection to the pool throws an error. * @throws ConfigurationException if there is a problem setting up the default test connection *///from ww w. j a v a 2s . co m @Test(expected = NullPointerException.class) public void returnNullConnection() throws ConfigurationException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); pool.returnConnection(null); }