Changeset 32 for trunk/CrossPare/src/de/ugoe/cs
- Timestamp:
- 05/05/15 16:29:40 (10 years ago)
- Location:
- trunk/CrossPare/src/de/ugoe/cs/cpdp
- Files:
-
- 15 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/ExperimentConfiguration.java
r2 r32 119 119 */ 120 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"; 121 133 122 134 /** … … 315 327 } 316 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 317 345 /* (non-Javadoc) 318 346 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) … … 393 421 final IEvaluationStrategy evaluator = (IEvaluationStrategy) Class.forName("de.ugoe.cs.cpdp.eval." + attributes.getValue("name")).newInstance(); 394 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"); 395 429 } 396 430 else if( qName.equals("partialconfig") ) { … … 423 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. 424 458 * @param other experiment whose information is added 425 */ 426 private void addConfigurations(ExperimentConfiguration other) { 459 * @throws ExperimentConfigurationException 460 */ 461 private void addConfigurations(ExperimentConfiguration other) throws ExperimentConfigurationException { 427 462 if( "results".equals(resultsPath) ) { 428 463 resultsPath = other.resultsPath; … … 441 476 trainers.addAll(other.trainers); 442 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 443 490 } 444 491 … … 464 511 builder.append("Pointwise trainers: " + trainers.toString() + StringTools.ENDLINE); 465 512 builder.append("Evaluators: " + evaluators.toString() + StringTools.ENDLINE); 466 513 builder.append("Save Classifier?: " + saveClassifier + StringTools.ENDLINE); 514 builder.append("Execution Strategy: " + executionStrategy + StringTools.ENDLINE); 515 467 516 return builder.toString(); 468 517 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/Runner.java
r2 r32 2 2 3 3 import java.io.File; 4 import java.lang.reflect.Constructor; 5 import java.lang.reflect.InvocationTargetException; 4 6 import java.util.concurrent.ExecutorService; 5 7 import java.util.concurrent.Executors; … … 7 9 import java.util.logging.Level; 8 10 11 import de.ugoe.cs.cpdp.execution.IExecutionStrategy; 9 12 import de.ugoe.cs.util.console.Console; 10 13 import de.ugoe.cs.util.console.TextConsole; … … 23 26 public static void main(String[] args) { 24 27 new TextConsole(Level.FINE); 25 26 28 final int concurrentThreads = Runtime.getRuntime().availableProcessors(); 27 29 final ExecutorService threadPool = Executors.newFixedThreadPool(concurrentThreads); … … 47 49 } 48 50 51 /** 52 * Creates the config and starts the corresponding experiment 53 * @param threadPool 54 * @param configFile location of the config file 55 */ 49 56 public static void createConfig(ExecutorService threadPool, String configFile) { 50 57 ExperimentConfiguration config = null; … … 55 62 e.printStackTrace(); 56 63 } 64 57 65 if( config!=null ) { 58 66 Console.trace(Level.FINE, config.toString()); 59 Experiment experiment = new Experiment(config); 60 threadPool.execute(experiment); 67 // Instantiate the class like it was given as parameter in the config file and cast it to the interface 68 try { 69 // Because we need to pass a parameter, a normal new Instance call is not possible 70 Class<?> executionStrategyClass = Class.forName("de.ugoe.cs.cpdp.execution."+config.getExecutionStrategy()); 71 Constructor<?> executionStrategyConstructor = 72 executionStrategyClass.getConstructor(ExperimentConfiguration.class); 73 74 IExecutionStrategy experiment = (IExecutionStrategy) executionStrategyConstructor.newInstance(config); 75 threadPool.execute(experiment); 76 } catch (NoSuchMethodException e) { 77 Console.printerrln("Class \"" + config.getExecutionStrategy()+ "\" does not have the right Constructor"); 78 e.printStackTrace(); 79 } catch (SecurityException e) { 80 Console.printerrln("Security manager prevents reflection"); 81 e.printStackTrace(); 82 } catch (IllegalArgumentException e) { 83 Console.printerrln("Class \"" + config.getExecutionStrategy()+ "\" does not have a Constructor, which" 84 + "matches the given arguments"); 85 e.printStackTrace(); 86 } catch (InvocationTargetException e) { 87 Console.printerrln("Constructor in Class \"" + config.getExecutionStrategy()+ "\" is not public"); 88 e.printStackTrace(); 89 } catch (InstantiationException e) { 90 Console.printerrln("Cannot instantiate Class \"" + config.getExecutionStrategy()+"\""); 91 e.printStackTrace(); 92 } catch (IllegalAccessException e) { 93 Console.printerrln("Cannot access Class \"" + config.getExecutionStrategy()+"\""); 94 e.printStackTrace(); 95 } catch (ClassNotFoundException e) { 96 Console.printerrln("Class \"" + config.getExecutionStrategy()+ "\" was not found"); 97 e.printStackTrace(); 98 } 99 61 100 } 101 62 102 } 63 103 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/execution/CrossProjectExperiment.java
r31 r32 1 package de.ugoe.cs.cpdp ;1 package de.ugoe.cs.cpdp.execution; 2 2 3 3 import java.io.File; … … 10 10 11 11 import weka.core.Instances; 12 import de.ugoe.cs.cpdp.ExperimentConfiguration; 12 13 import de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy; 13 14 import de.ugoe.cs.cpdp.dataprocessing.ISetWiseProcessingStrategy; … … 51 52 * @author Steffen Herbold 52 53 */ 53 public class Experiment implements Runnable{54 public class CrossProjectExperiment implements IExecutionStrategy { 54 55 55 56 /** … … 62 63 * @param config configuration of the experiment 63 64 */ 64 public Experiment(ExperimentConfiguration config) {65 public CrossProjectExperiment(ExperimentConfiguration config) { 65 66 this.config = config; 66 67 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java
r4 r32 21 21 * Path of the data. 22 22 */ 23 pr ivateString path = "";23 protected String path = ""; 24 24 25 25 /** -
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/IVersionLoader.java
r4 r32 26 26 */ 27 27 public List<SoftwareVersion> load(); 28 28 29 }
Note: See TracChangeset
for help on using the changeset viewer.