- Timestamp:
- 09/24/15 10:59:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/ExperimentConfiguration.java
r32 r41 1 // Copyright 2015 Georg-August-Universität Göttingen, Germany 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 1 15 package de.ugoe.cs.cpdp; 2 16 … … 33 47 34 48 /** 35 * Class that contains all meta information about an experiment, i.e., its configuration. The configuration is loaded from an XML file. 36 * <br><br> 37 * In the current implementation, the experiment configuration can only be created using an XML file. Programmatic creation of experiment configurations is currently not possibly. 49 * Class that contains all meta information about an experiment, i.e., its configuration. The 50 * configuration is loaded from an XML file. <br> 51 * <br> 52 * In the current implementation, the experiment configuration can only be created using an XML 53 * file. Programmatic creation of experiment configurations is currently not possibly. 54 * 38 55 * @author Steffen Herbold 39 56 */ 40 public class ExperimentConfiguration extends DefaultHandler { 41 42 /** 43 * handle of the file that contains the configuration 44 */ 45 private final File configFile; 46 47 /** 48 * name of the experiment (automatically set to the file name without the .xml ending) 49 */ 50 private String experimentName = "exp"; 51 52 /** 53 * loads instances 54 */ 55 private List<IVersionLoader> loaders; 56 57 /** 58 * path were the results of the experiments are stored 59 */ 60 private String resultsPath = "results"; 61 62 /** 63 * data set filters applied to all data 64 */ 65 private List<IVersionFilter> versionFilters; 66 67 /** 68 * data set filters that decide if a data set is used as test data 69 */ 70 private List<IVersionFilter> testVersionFilters; 71 72 /** 73 * data set filters that decide if a data is used as candidate training data 74 */ 75 private List<IVersionFilter> trainingVersionFilters; 76 77 /** 78 * setwise data processors that are applied before the setwise data selection 79 */ 80 private List<ISetWiseProcessingStrategy> setwisepreprocessors; 81 82 /** 83 * setwise data selection strategies 84 */ 85 private List<ISetWiseDataselectionStrategy> setwiseselectors; 86 87 /** 88 * setwise data processors that are applied after the setwise data selection 89 */ 90 private List<ISetWiseProcessingStrategy> setwisepostprocessors; 91 92 /** 93 * setwise trainers, i.e., trainers that require the selected training data to be separate from each other 94 */ 95 private List<ISetWiseTrainingStrategy> setwiseTrainers; 96 97 /** 98 * data processors that are applied before the pointwise data selection 99 */ 100 private List<IProcessesingStrategy> preprocessors; 101 102 /** 103 * pointwise data selection strategies 104 */ 105 private List<IPointWiseDataselectionStrategy> pointwiseselectors; 106 107 /** 108 * data processors that are applied before the pointwise data selection 109 */ 110 private List<IProcessesingStrategy> postprocessors; 111 112 /** 113 * normal trainers, i.e., trainers that require the selected training data in a single data set 114 */ 115 private List<ITrainingStrategy> trainers; 116 117 /** 118 * evaluators used for the the experiment results 119 */ 120 private List<IEvaluationStrategy> evaluators; 121 122 /** 123 * indicates, if the classifier should be saved 124 */ 125 private Boolean saveClassifier = null; 126 127 /** 128 * indicates, which execution strategy to choose 129 * (e.g. CrossProjectExperiment, ClassifierCreationExecution). 130 * Default is CrossProjectExperiment. 131 */ 132 private String executionStrategy = "CrossProjectExperiment"; 133 134 /** 135 * Constructor. Creates a new configuration from a given file. 136 * @param filename name of the file from the configuration is loaded. 137 * @throws ExperimentConfigurationException thrown if there is an error creating the configuration 138 */ 139 public ExperimentConfiguration(String filename) throws ExperimentConfigurationException { 140 this(new File(filename)); 141 } 142 143 /** 144 * Constructor. Creates a new configuration from a given file. 145 * @param filename handle of the file from the configuration is loaded. 146 * @throws ExperimentConfigurationException thrown if there is an error creating the configuration 147 */ 148 public ExperimentConfiguration(File file) throws ExperimentConfigurationException { 149 loaders = new LinkedList<>(); 150 versionFilters = new LinkedList<>(); 151 testVersionFilters = new LinkedList<>(); 152 trainingVersionFilters = new LinkedList<>(); 153 setwisepreprocessors = new LinkedList<>(); 154 setwiseselectors = new LinkedList<>(); 155 setwisepostprocessors = new LinkedList<>(); 156 setwiseTrainers = new LinkedList<>(); 157 preprocessors = new LinkedList<>(); 158 pointwiseselectors = new LinkedList<>(); 159 postprocessors = new LinkedList<>(); 160 trainers = new LinkedList<>(); 161 evaluators = new LinkedList<>(); 162 163 if (file == null) { 57 public class ExperimentConfiguration extends DefaultHandler { 58 59 /** 60 * handle of the file that contains the configuration 61 */ 62 private final File configFile; 63 64 /** 65 * name of the experiment (automatically set to the file name without the .xml ending) 66 */ 67 private String experimentName = "exp"; 68 69 /** 70 * loads instances 71 */ 72 private List<IVersionLoader> loaders; 73 74 /** 75 * path were the results of the experiments are stored 76 */ 77 private String resultsPath = "results"; 78 79 /** 80 * data set filters applied to all data 81 */ 82 private List<IVersionFilter> versionFilters; 83 84 /** 85 * data set filters that decide if a data set is used as test data 86 */ 87 private List<IVersionFilter> testVersionFilters; 88 89 /** 90 * data set filters that decide if a data is used as candidate training data 91 */ 92 private List<IVersionFilter> trainingVersionFilters; 93 94 /** 95 * setwise data processors that are applied before the setwise data selection 96 */ 97 private List<ISetWiseProcessingStrategy> setwisepreprocessors; 98 99 /** 100 * setwise data selection strategies 101 */ 102 private List<ISetWiseDataselectionStrategy> setwiseselectors; 103 104 /** 105 * setwise data processors that are applied after the setwise data selection 106 */ 107 private List<ISetWiseProcessingStrategy> setwisepostprocessors; 108 109 /** 110 * setwise trainers, i.e., trainers that require the selected training data to be separate from 111 * each other 112 */ 113 private List<ISetWiseTrainingStrategy> setwiseTrainers; 114 115 /** 116 * data processors that are applied before the pointwise data selection 117 */ 118 private List<IProcessesingStrategy> preprocessors; 119 120 /** 121 * pointwise data selection strategies 122 */ 123 private List<IPointWiseDataselectionStrategy> pointwiseselectors; 124 125 /** 126 * data processors that are applied before the pointwise data selection 127 */ 128 private List<IProcessesingStrategy> postprocessors; 129 130 /** 131 * normal trainers, i.e., trainers that require the selected training data in a single data set 132 */ 133 private List<ITrainingStrategy> trainers; 134 135 /** 136 * evaluators used for the the experiment results 137 */ 138 private List<IEvaluationStrategy> evaluators; 139 140 /** 141 * indicates, if the classifier should be saved 142 */ 143 private Boolean saveClassifier = null; 144 145 /** 146 * indicates, which execution strategy to choose (e.g. CrossProjectExperiment, 147 * ClassifierCreationExecution). Default is CrossProjectExperiment. 148 */ 149 private String executionStrategy = "CrossProjectExperiment"; 150 151 /** 152 * Constructor. Creates a new configuration from a given file. 153 * 154 * @param filename 155 * name of the file from the configuration is loaded. 156 * @throws ExperimentConfigurationException 157 * thrown if there is an error creating the configuration 158 */ 159 public ExperimentConfiguration(String filename) throws ExperimentConfigurationException { 160 this(new File(filename)); 161 } 162 163 /** 164 * Constructor. Creates a new configuration from a given file. 165 * 166 * @param filename 167 * handle of the file from the configuration is loaded. 168 * @throws ExperimentConfigurationException 169 * thrown if there is an error creating the configuration 170 */ 171 public ExperimentConfiguration(File file) throws ExperimentConfigurationException { 172 loaders = new LinkedList<>(); 173 versionFilters = new LinkedList<>(); 174 testVersionFilters = new LinkedList<>(); 175 trainingVersionFilters = new LinkedList<>(); 176 setwisepreprocessors = new LinkedList<>(); 177 setwiseselectors = new LinkedList<>(); 178 setwisepostprocessors = new LinkedList<>(); 179 setwiseTrainers = new LinkedList<>(); 180 preprocessors = new LinkedList<>(); 181 pointwiseselectors = new LinkedList<>(); 182 postprocessors = new LinkedList<>(); 183 trainers = new LinkedList<>(); 184 evaluators = new LinkedList<>(); 185 186 if (file == null) { 164 187 throw new IllegalArgumentException("file must not be null"); 165 188 } 166 167 168 169 170 171 189 if (file.isDirectory()) { 190 throw new IllegalArgumentException("file must not be a directory"); 191 } 192 configFile = file; 193 194 experimentName = file.getName().split("\\.")[0]; 172 195 173 196 final SAXParserFactory spf = SAXParserFactory.newInstance(); … … 177 200 InputSource inputSource = null; 178 201 try { 179 saxParser = spf.newSAXParser(); 180 } catch (ParserConfigurationException | SAXException e) { 181 throw new ExperimentConfigurationException(e); 182 } 183 202 saxParser = spf.newSAXParser(); 203 } 204 catch (ParserConfigurationException | SAXException e) { 205 throw new ExperimentConfigurationException(e); 206 } 207 184 208 InputStreamReader reader = null; 185 try { 186 reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); 187 inputSource = new InputSource(reader); 188 } catch (UnsupportedEncodingException | FileNotFoundException e) { 189 throw new ExperimentConfigurationException("Could not open configuration file.", e); 190 } 191 209 try { 210 reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); 211 inputSource = new InputSource(reader); 212 } 213 catch (UnsupportedEncodingException | FileNotFoundException e) { 214 throw new ExperimentConfigurationException("Could not open configuration file.", e); 215 } 216 192 217 if (inputSource != null) { 193 218 inputSource.setSystemId("file://" + file.getAbsolutePath()); 194 try { 195 saxParser.parse(inputSource, this); 196 } catch (SAXException | IOException e) { 197 throw new ExperimentConfigurationException("Error parsing configuration.", e); 198 } 199 } 200 if( reader!=null ) { 201 try { 202 reader.close(); 203 } catch (IOException e) { 204 throw new ExperimentConfigurationException("Error closing reader.", e); 205 } 206 } 207 } 208 209 /** 210 * returns the name of the experiment 211 * @return name of the experiment 212 */ 213 public String getExperimentName() { 214 return experimentName; 215 } 216 217 /** 218 * returns the loaders for instances 219 * @return data loaders 220 */ 221 public List<IVersionLoader> getLoaders() { 222 return loaders; 223 } 224 225 /** 226 * returns the results path 227 * @return results path 228 */ 229 public String getResultsPath() { 230 return resultsPath; 231 } 232 233 /** 234 * returns the data set filters of the experiment 235 * @return data set filters of the experiment 236 */ 237 public List<IVersionFilter> getVersionFilters() { 238 return versionFilters; 239 } 240 241 /** 242 * returns the test set filters of the experiment 243 * @return test set filters of the experiment 244 */ 245 public List<IVersionFilter> getTestVersionFilters() { 246 return testVersionFilters; 247 } 248 249 /** 250 * returns the candidate training version filters of the experiment 251 * @return candidate training version filters of the experiment 252 */ 253 public List<IVersionFilter> getTrainingVersionFilters() { 254 return trainingVersionFilters; 255 } 256 257 /** 258 * returns the setwise processors applied before the setwise data selection 259 * @return setwise processors applied before the setwise data selection 260 */ 261 public List<ISetWiseProcessingStrategy> getSetWisePreprocessors() { 262 return setwisepreprocessors; 263 } 264 265 /** 266 * returns the setwise data selection strategies 267 * @return setwise data selection strategies 268 */ 269 public List<ISetWiseDataselectionStrategy> getSetWiseSelectors() { 270 return setwiseselectors; 271 } 272 273 /** 274 * returns the setwise processors applied after the setwise data selection 275 * @return setwise processors applied after the setwise data selection 276 */ 277 public List<ISetWiseProcessingStrategy> getSetWisePostprocessors() { 278 return setwisepostprocessors; 279 } 280 281 /** 282 * returns the setwise training algorithms 283 * @return setwise training algorithms 284 */ 285 public List<ISetWiseTrainingStrategy> getSetWiseTrainers() { 286 return setwiseTrainers; 287 } 288 289 /** 290 * returns the processors applied before the pointwise data selection 291 * @return processors applied before the pointwise data selection 292 */ 293 public List<IProcessesingStrategy> getPreProcessors() { 294 return preprocessors; 295 } 296 297 /** 298 * returns the pointwise data selection strategies 299 * @return pointwise data selection strategies 300 */ 301 public List<IPointWiseDataselectionStrategy> getPointWiseSelectors() { 302 return pointwiseselectors; 303 } 304 305 /** 306 * returns the processors applied after the pointwise data selection 307 * @return processors applied after the pointwise data selection 308 */ 309 public List<IProcessesingStrategy> getPostProcessors() { 310 return postprocessors; 311 } 312 313 /** 314 * returns the normal training algorithm 315 * @return normal training algorithms 316 */ 317 public List<ITrainingStrategy> getTrainers() { 318 return trainers; 319 } 320 321 /** 322 * returns the evaluation strategies 323 * @return evaluation strategies 324 */ 325 public List<IEvaluationStrategy> getEvaluators() { 326 return evaluators; 327 } 328 329 /** 330 * returns boolean, if classifier should be saved 331 * @return boolean 332 */ 333 public boolean getSaveClassifier() { 334 return saveClassifier; 335 } 336 337 /** 338 * returns the execution strategy 339 * @return String execution strategy 340 */ 341 public String getExecutionStrategy() { 342 return executionStrategy; 343 } 344 345 /* (non-Javadoc) 346 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 347 */ 348 @Override 349 public void startElement(String uri, String localName, String qName, 350 Attributes attributes) throws SAXException { 351 try { 352 if( qName.equals("config") ) { 353 // ingore 354 } 355 else if( qName.equals("loader") ) { 356 final IVersionLoader loader = (IVersionLoader) Class.forName("de.ugoe.cs.cpdp.loader." + attributes.getValue("name")).newInstance(); 357 loader.setLocation(attributes.getValue("datalocation")); 358 loaders.add(loader); 359 360 // TODO location as relative 361 } 362 else if( qName.equals("resultspath") ) { 363 resultsPath = attributes.getValue("path"); 364 } 365 else if( qName.equals("versionfilter") ) { 366 final IVersionFilter filter = (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name")).newInstance(); 367 filter.setParameter(attributes.getValue("param")); 368 versionFilters.add(filter); 369 } 370 else if( qName.equals("testVersionfilter") ) { 371 final IVersionFilter filter = (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name")).newInstance(); 372 filter.setParameter(attributes.getValue("param")); 373 testVersionFilters.add(filter); 374 } 375 else if( qName.equals("trainVersionfilter") ) { 376 final IVersionFilter filter = (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name")).newInstance(); 377 filter.setParameter(attributes.getValue("param")); 378 trainingVersionFilters.add(filter); 379 } 380 else if( qName.equals("setwisepreprocessor") ) { 381 final ISetWiseProcessingStrategy processor = (ISetWiseProcessingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name")).newInstance(); 382 processor.setParameter(attributes.getValue("param")); 383 setwisepreprocessors.add(processor); 384 } 385 else if( qName.equals("setwiseselector") ) { 386 final ISetWiseDataselectionStrategy selection = (ISetWiseDataselectionStrategy) Class.forName("de.ugoe.cs.cpdp.dataselection." + attributes.getValue("name")).newInstance(); 387 selection.setParameter(attributes.getValue("param")); 388 setwiseselectors.add(selection); 389 } 390 else if( qName.equals("setwisepostprocessor") ) { 391 final ISetWiseProcessingStrategy processor = (ISetWiseProcessingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name")).newInstance(); 392 processor.setParameter(attributes.getValue("param")); 393 setwisepostprocessors.add(processor); 394 } 395 else if( qName.equals("setwisetrainer") ) { 396 final ISetWiseTrainingStrategy trainer = (ISetWiseTrainingStrategy) Class.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name")).newInstance(); 397 trainer.setParameter(attributes.getValue("param")); 398 setwiseTrainers.add(trainer); 399 } 400 else if( qName.equals("preprocessor") ) { 401 final IProcessesingStrategy processor = (IProcessesingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name")).newInstance(); 402 processor.setParameter( attributes.getValue("param")); 403 preprocessors.add(processor); 404 } 405 else if( qName.equals("pointwiseselector") ) { 406 final IPointWiseDataselectionStrategy selection = (IPointWiseDataselectionStrategy) Class.forName("de.ugoe.cs.cpdp.dataselection." + attributes.getValue("name")).newInstance(); 407 selection.setParameter( attributes.getValue("param")); 408 pointwiseselectors.add(selection); 409 } 410 else if( qName.equals("postprocessor") ) { 411 final IProcessesingStrategy processor = (IProcessesingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name")).newInstance(); 412 processor.setParameter( attributes.getValue("param")); 413 postprocessors.add(processor); 414 } 415 else if( qName.equals("trainer") ) { 416 final ITrainingStrategy trainer = (ITrainingStrategy) Class.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name")).newInstance(); 417 trainer.setParameter(attributes.getValue("param")); 418 trainers.add(trainer); 419 } 420 else if( qName.equals("eval") ) { 421 final IEvaluationStrategy evaluator = (IEvaluationStrategy) Class.forName("de.ugoe.cs.cpdp.eval." + attributes.getValue("name")).newInstance(); 422 evaluators.add(evaluator); 423 } 424 else if( qName.equals("saveClassifier")) { 425 saveClassifier = true; 426 } 427 else if( qName.equals("executionStrategy")) { 428 executionStrategy = attributes.getValue("name"); 429 } 430 else if( qName.equals("partialconfig") ) { 431 String path = attributes.getValue("path"); 432 try { 433 boolean relative = true; 434 if( attributes.getValue("relative")!=null ) { 435 relative = Boolean.parseBoolean(attributes.getValue("relative")); 436 } 437 438 if( relative ) { 439 path = configFile.getParentFile().getPath() + "/" + path; 440 } 441 addConfigurations(new ExperimentConfiguration(path)); 442 } catch (ExperimentConfigurationException e) { 443 throw new SAXException("Could not load partial configuration: " + path, e); 444 } 445 } else { 446 Console.traceln(Level.WARNING, "element in config-file " + configFile.getName() + " ignored: " + qName); 447 } 448 } 449 catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException | InstantiationException | ClassCastException e) { 450 throw new SAXException("Could not initialize class correctly", (Exception) e); 451 } 452 } 453 454 /** 455 * Adds the information of another experiment configuration to this configuration. This mechanism allows the usage of partial configuration files. The name of the other configuration is lost. 456 * <br><br> 457 * If the current data path is the empty string (""), it is override by the datapath of the other configuration. Otherwise, the current data path is kept. 458 * @param other experiment whose information is added 459 * @throws ExperimentConfigurationException 460 */ 461 private void addConfigurations(ExperimentConfiguration other) throws ExperimentConfigurationException { 462 if( "results".equals(resultsPath) ) { 463 resultsPath = other.resultsPath; 464 } 465 loaders.addAll(other.loaders); 466 versionFilters.addAll(other.versionFilters); 467 testVersionFilters.addAll(other.testVersionFilters); 468 trainingVersionFilters.addAll(other.trainingVersionFilters); 469 setwisepreprocessors.addAll(other.setwisepreprocessors); 470 setwiseselectors.addAll(other.setwiseselectors); 471 setwisepostprocessors.addAll(other.setwisepostprocessors); 472 setwiseTrainers.addAll(other.setwiseTrainers); 473 preprocessors.addAll(other.preprocessors); 474 pointwiseselectors.addAll(other.pointwiseselectors); 475 postprocessors.addAll(other.postprocessors); 476 trainers.addAll(other.trainers); 477 evaluators.addAll(other.evaluators); 478 479 if(!executionStrategy.equals(other.executionStrategy)) { 480 throw new ExperimentConfigurationException("Executionstrategies must be the same, if config files should be added."); 481 } 482 483 /* Only if saveClassifier is not set in the main config and 484 * the other configs saveClassifier is true, it must be set. 485 */ 486 if(saveClassifier == null && other.saveClassifier == true) { 487 saveClassifier = other.saveClassifier; 488 } 489 490 } 491 492 /* (non-Javadoc) 493 * @see java.lang.Object#toString() 494 */ 495 @Override 496 public String toString() { 497 final StringBuilder builder = new StringBuilder(); 498 builder.append("Experiment name: " + experimentName + StringTools.ENDLINE); 499 builder.append("Loaders: " + loaders + StringTools.ENDLINE); 500 builder.append("Results path: " + resultsPath + StringTools.ENDLINE); 501 builder.append("Version filters: " + versionFilters.toString() + StringTools.ENDLINE); 502 builder.append("Test version filters: " + testVersionFilters.toString() + StringTools.ENDLINE); 503 builder.append("Training version filters: " + trainingVersionFilters.toString() + StringTools.ENDLINE); 504 builder.append("Setwise preprocessors: " + setwisepreprocessors.toString() + StringTools.ENDLINE); 505 builder.append("Setwise selectors: " + setwiseselectors.toString() + StringTools.ENDLINE); 506 builder.append("Setwise postprocessors: " + setwisepostprocessors.toString() + StringTools.ENDLINE); 507 builder.append("Setwise trainers: " + setwiseTrainers.toString() + StringTools.ENDLINE); 508 builder.append("Pointwise preprocessors: " + preprocessors.toString() + StringTools.ENDLINE); 509 builder.append("Pointwise selectors: " + pointwiseselectors.toString() + StringTools.ENDLINE); 510 builder.append("Pointwise postprocessors: " + postprocessors.toString() + StringTools.ENDLINE); 511 builder.append("Pointwise trainers: " + trainers.toString() + StringTools.ENDLINE); 512 builder.append("Evaluators: " + evaluators.toString() + StringTools.ENDLINE); 513 builder.append("Save Classifier?: " + saveClassifier + StringTools.ENDLINE); 514 builder.append("Execution Strategy: " + executionStrategy + StringTools.ENDLINE); 515 516 return builder.toString(); 517 } 219 try { 220 saxParser.parse(inputSource, this); 221 } 222 catch (SAXException | IOException e) { 223 throw new ExperimentConfigurationException("Error parsing configuration.", e); 224 } 225 } 226 if (reader != null) { 227 try { 228 reader.close(); 229 } 230 catch (IOException e) { 231 throw new ExperimentConfigurationException("Error closing reader.", e); 232 } 233 } 234 } 235 236 /** 237 * returns the name of the experiment 238 * 239 * @return name of the experiment 240 */ 241 public String getExperimentName() { 242 return experimentName; 243 } 244 245 /** 246 * returns the loaders for instances 247 * 248 * @return data loaders 249 */ 250 public List<IVersionLoader> getLoaders() { 251 return loaders; 252 } 253 254 /** 255 * returns the results path 256 * 257 * @return results path 258 */ 259 public String getResultsPath() { 260 return resultsPath; 261 } 262 263 /** 264 * returns the data set filters of the experiment 265 * 266 * @return data set filters of the experiment 267 */ 268 public List<IVersionFilter> getVersionFilters() { 269 return versionFilters; 270 } 271 272 /** 273 * returns the test set filters of the experiment 274 * 275 * @return test set filters of the experiment 276 */ 277 public List<IVersionFilter> getTestVersionFilters() { 278 return testVersionFilters; 279 } 280 281 /** 282 * returns the candidate training version filters of the experiment 283 * 284 * @return candidate training version filters of the experiment 285 */ 286 public List<IVersionFilter> getTrainingVersionFilters() { 287 return trainingVersionFilters; 288 } 289 290 /** 291 * returns the setwise processors applied before the setwise data selection 292 * 293 * @return setwise processors applied before the setwise data selection 294 */ 295 public List<ISetWiseProcessingStrategy> getSetWisePreprocessors() { 296 return setwisepreprocessors; 297 } 298 299 /** 300 * returns the setwise data selection strategies 301 * 302 * @return setwise data selection strategies 303 */ 304 public List<ISetWiseDataselectionStrategy> getSetWiseSelectors() { 305 return setwiseselectors; 306 } 307 308 /** 309 * returns the setwise processors applied after the setwise data selection 310 * 311 * @return setwise processors applied after the setwise data selection 312 */ 313 public List<ISetWiseProcessingStrategy> getSetWisePostprocessors() { 314 return setwisepostprocessors; 315 } 316 317 /** 318 * returns the setwise training algorithms 319 * 320 * @return setwise training algorithms 321 */ 322 public List<ISetWiseTrainingStrategy> getSetWiseTrainers() { 323 return setwiseTrainers; 324 } 325 326 /** 327 * returns the processors applied before the pointwise data selection 328 * 329 * @return processors applied before the pointwise data selection 330 */ 331 public List<IProcessesingStrategy> getPreProcessors() { 332 return preprocessors; 333 } 334 335 /** 336 * returns the pointwise data selection strategies 337 * 338 * @return pointwise data selection strategies 339 */ 340 public List<IPointWiseDataselectionStrategy> getPointWiseSelectors() { 341 return pointwiseselectors; 342 } 343 344 /** 345 * returns the processors applied after the pointwise data selection 346 * 347 * @return processors applied after the pointwise data selection 348 */ 349 public List<IProcessesingStrategy> getPostProcessors() { 350 return postprocessors; 351 } 352 353 /** 354 * returns the normal training algorithm 355 * 356 * @return normal training algorithms 357 */ 358 public List<ITrainingStrategy> getTrainers() { 359 return trainers; 360 } 361 362 /** 363 * returns the evaluation strategies 364 * 365 * @return evaluation strategies 366 */ 367 public List<IEvaluationStrategy> getEvaluators() { 368 return evaluators; 369 } 370 371 /** 372 * returns boolean, if classifier should be saved 373 * 374 * @return boolean 375 */ 376 public boolean getSaveClassifier() { 377 return saveClassifier; 378 } 379 380 /** 381 * returns the execution strategy 382 * 383 * @return String execution strategy 384 */ 385 public String getExecutionStrategy() { 386 return executionStrategy; 387 } 388 389 /* 390 * (non-Javadoc) 391 * 392 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, 393 * java.lang.String, org.xml.sax.Attributes) 394 */ 395 @Override 396 public void startElement(String uri, String localName, String qName, Attributes attributes) 397 throws SAXException 398 { 399 try { 400 if (qName.equals("config")) { 401 // ingore 402 } 403 else if (qName.equals("loader")) { 404 final IVersionLoader loader = 405 (IVersionLoader) Class.forName("de.ugoe.cs.cpdp.loader." + 406 attributes.getValue("name")).newInstance(); 407 loader.setLocation(attributes.getValue("datalocation")); 408 loaders.add(loader); 409 410 // TODO location as relative 411 } 412 else if (qName.equals("resultspath")) { 413 resultsPath = attributes.getValue("path"); 414 } 415 else if (qName.equals("versionfilter")) { 416 final IVersionFilter filter = 417 (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + 418 attributes.getValue("name")).newInstance(); 419 filter.setParameter(attributes.getValue("param")); 420 versionFilters.add(filter); 421 } 422 else if (qName.equals("testVersionfilter")) { 423 final IVersionFilter filter = 424 (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + 425 attributes.getValue("name")).newInstance(); 426 filter.setParameter(attributes.getValue("param")); 427 testVersionFilters.add(filter); 428 } 429 else if (qName.equals("trainVersionfilter")) { 430 final IVersionFilter filter = 431 (IVersionFilter) Class.forName("de.ugoe.cs.cpdp.versions." + 432 attributes.getValue("name")).newInstance(); 433 filter.setParameter(attributes.getValue("param")); 434 trainingVersionFilters.add(filter); 435 } 436 else if (qName.equals("setwisepreprocessor")) { 437 final ISetWiseProcessingStrategy processor = 438 (ISetWiseProcessingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + 439 attributes.getValue("name")) 440 .newInstance(); 441 processor.setParameter(attributes.getValue("param")); 442 setwisepreprocessors.add(processor); 443 } 444 else if (qName.equals("setwiseselector")) { 445 final ISetWiseDataselectionStrategy selection = 446 (ISetWiseDataselectionStrategy) Class.forName("de.ugoe.cs.cpdp.dataselection." + 447 attributes.getValue("name")) 448 .newInstance(); 449 selection.setParameter(attributes.getValue("param")); 450 setwiseselectors.add(selection); 451 } 452 else if (qName.equals("setwisepostprocessor")) { 453 final ISetWiseProcessingStrategy processor = 454 (ISetWiseProcessingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + 455 attributes.getValue("name")) 456 .newInstance(); 457 processor.setParameter(attributes.getValue("param")); 458 setwisepostprocessors.add(processor); 459 } 460 else if (qName.equals("setwisetrainer")) { 461 final ISetWiseTrainingStrategy trainer = 462 (ISetWiseTrainingStrategy) Class.forName("de.ugoe.cs.cpdp.training." + 463 attributes.getValue("name")) 464 .newInstance(); 465 trainer.setParameter(attributes.getValue("param")); 466 setwiseTrainers.add(trainer); 467 } 468 else if (qName.equals("preprocessor")) { 469 final IProcessesingStrategy processor = 470 (IProcessesingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + 471 attributes.getValue("name")) 472 .newInstance(); 473 processor.setParameter(attributes.getValue("param")); 474 preprocessors.add(processor); 475 } 476 else if (qName.equals("pointwiseselector")) { 477 final IPointWiseDataselectionStrategy selection = 478 (IPointWiseDataselectionStrategy) Class 479 .forName("de.ugoe.cs.cpdp.dataselection." + attributes.getValue("name")) 480 .newInstance(); 481 selection.setParameter(attributes.getValue("param")); 482 pointwiseselectors.add(selection); 483 } 484 else if (qName.equals("postprocessor")) { 485 final IProcessesingStrategy processor = 486 (IProcessesingStrategy) Class.forName("de.ugoe.cs.cpdp.dataprocessing." + 487 attributes.getValue("name")) 488 .newInstance(); 489 processor.setParameter(attributes.getValue("param")); 490 postprocessors.add(processor); 491 } 492 else if (qName.equals("trainer")) { 493 final ITrainingStrategy trainer = 494 (ITrainingStrategy) Class.forName("de.ugoe.cs.cpdp.training." + 495 attributes.getValue("name")) 496 .newInstance(); 497 trainer.setParameter(attributes.getValue("param")); 498 trainers.add(trainer); 499 } 500 else if (qName.equals("eval")) { 501 final IEvaluationStrategy evaluator = 502 (IEvaluationStrategy) Class.forName("de.ugoe.cs.cpdp.eval." + 503 attributes.getValue("name")) 504 .newInstance(); 505 evaluators.add(evaluator); 506 } 507 else if (qName.equals("saveClassifier")) { 508 saveClassifier = true; 509 } 510 else if (qName.equals("executionStrategy")) { 511 executionStrategy = attributes.getValue("name"); 512 } 513 else if (qName.equals("partialconfig")) { 514 String path = attributes.getValue("path"); 515 try { 516 boolean relative = true; 517 if (attributes.getValue("relative") != null) { 518 relative = Boolean.parseBoolean(attributes.getValue("relative")); 519 } 520 521 if (relative) { 522 path = configFile.getParentFile().getPath() + "/" + path; 523 } 524 addConfigurations(new ExperimentConfiguration(path)); 525 } 526 catch (ExperimentConfigurationException e) { 527 throw new SAXException("Could not load partial configuration: " + path, e); 528 } 529 } 530 else { 531 Console.traceln(Level.WARNING, "element in config-file " + configFile.getName() + 532 " ignored: " + qName); 533 } 534 } 535 catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException 536 | InstantiationException | ClassCastException e) 537 { 538 throw new SAXException("Could not initialize class correctly", (Exception) e); 539 } 540 } 541 542 /** 543 * Adds the information of another experiment configuration to this configuration. This 544 * mechanism allows the usage of partial configuration files. The name of the other 545 * configuration is lost. <br> 546 * <br> 547 * If the current data path is the empty string (""), it is override by the datapath 548 * of the other configuration. Otherwise, the current data path is kept. 549 * 550 * @param other 551 * experiment whose information is added 552 * @throws ExperimentConfigurationException 553 */ 554 private void addConfigurations(ExperimentConfiguration other) 555 throws ExperimentConfigurationException 556 { 557 if ("results".equals(resultsPath)) { 558 resultsPath = other.resultsPath; 559 } 560 loaders.addAll(other.loaders); 561 versionFilters.addAll(other.versionFilters); 562 testVersionFilters.addAll(other.testVersionFilters); 563 trainingVersionFilters.addAll(other.trainingVersionFilters); 564 setwisepreprocessors.addAll(other.setwisepreprocessors); 565 setwiseselectors.addAll(other.setwiseselectors); 566 setwisepostprocessors.addAll(other.setwisepostprocessors); 567 setwiseTrainers.addAll(other.setwiseTrainers); 568 preprocessors.addAll(other.preprocessors); 569 pointwiseselectors.addAll(other.pointwiseselectors); 570 postprocessors.addAll(other.postprocessors); 571 trainers.addAll(other.trainers); 572 evaluators.addAll(other.evaluators); 573 574 if (!executionStrategy.equals(other.executionStrategy)) { 575 throw new ExperimentConfigurationException( 576 "Executionstrategies must be the same, if config files should be added."); 577 } 578 579 /* 580 * Only if saveClassifier is not set in the main config and the other configs saveClassifier 581 * is true, it must be set. 582 */ 583 if (saveClassifier == null && other.saveClassifier == true) { 584 saveClassifier = other.saveClassifier; 585 } 586 587 } 588 589 /* 590 * (non-Javadoc) 591 * 592 * @see java.lang.Object#toString() 593 */ 594 @Override 595 public String toString() { 596 final StringBuilder builder = new StringBuilder(); 597 builder.append("Experiment name: " + experimentName + StringTools.ENDLINE); 598 builder.append("Loaders: " + loaders + StringTools.ENDLINE); 599 builder.append("Results path: " + resultsPath + StringTools.ENDLINE); 600 builder.append("Version filters: " + versionFilters.toString() + StringTools.ENDLINE); 601 builder.append("Test version filters: " + testVersionFilters.toString() + 602 StringTools.ENDLINE); 603 builder.append("Training version filters: " + trainingVersionFilters.toString() + 604 StringTools.ENDLINE); 605 builder.append("Setwise preprocessors: " + setwisepreprocessors.toString() + 606 StringTools.ENDLINE); 607 builder.append("Setwise selectors: " + setwiseselectors.toString() + StringTools.ENDLINE); 608 builder.append("Setwise postprocessors: " + setwisepostprocessors.toString() + 609 StringTools.ENDLINE); 610 builder.append("Setwise trainers: " + setwiseTrainers.toString() + StringTools.ENDLINE); 611 builder 612 .append("Pointwise preprocessors: " + preprocessors.toString() + StringTools.ENDLINE); 613 builder.append("Pointwise selectors: " + pointwiseselectors.toString() + 614 StringTools.ENDLINE); 615 builder.append("Pointwise postprocessors: " + postprocessors.toString() + 616 StringTools.ENDLINE); 617 builder.append("Pointwise trainers: " + trainers.toString() + StringTools.ENDLINE); 618 builder.append("Evaluators: " + evaluators.toString() + StringTools.ENDLINE); 619 builder.append("Save Classifier?: " + saveClassifier + StringTools.ENDLINE); 620 builder.append("Execution Strategy: " + executionStrategy + StringTools.ENDLINE); 621 622 return builder.toString(); 623 } 518 624 }
Note: See TracChangeset
for help on using the changeset viewer.