Ignore:
Timestamp:
05/05/15 16:29:40 (9 years ago)
Author:
ftrautsch
Message:

integrating decent into crosspare

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  
    119119         */ 
    120120        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"; 
    121133         
    122134        /** 
     
    315327        } 
    316328         
     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         
    317345        /* (non-Javadoc) 
    318346         * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 
     
    393421                                final IEvaluationStrategy evaluator = (IEvaluationStrategy) Class.forName("de.ugoe.cs.cpdp.eval." + attributes.getValue("name")).newInstance(); 
    394422                                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"); 
    395429                        } 
    396430                        else if( qName.equals("partialconfig") ) { 
     
    423457         * If the current data path is the empty string (&quot;&quot;), it is override by the datapath of the other configuration. Otherwise, the current data path is kept. 
    424458         * @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 { 
    427462                if( "results".equals(resultsPath) ) { 
    428463                        resultsPath = other.resultsPath; 
     
    441476                trainers.addAll(other.trainers); 
    442477                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 
    443490        } 
    444491         
     
    464511                builder.append("Pointwise trainers: " + trainers.toString() + StringTools.ENDLINE); 
    465512                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                                 
    467516                return builder.toString(); 
    468517        } 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/Runner.java

    r2 r32  
    22 
    33import java.io.File; 
     4import java.lang.reflect.Constructor; 
     5import java.lang.reflect.InvocationTargetException; 
    46import java.util.concurrent.ExecutorService; 
    57import java.util.concurrent.Executors; 
     
    79import java.util.logging.Level; 
    810 
     11import de.ugoe.cs.cpdp.execution.IExecutionStrategy; 
    912import de.ugoe.cs.util.console.Console; 
    1013import de.ugoe.cs.util.console.TextConsole; 
     
    2326        public static void main(String[] args) { 
    2427                new TextConsole(Level.FINE); 
    25                  
    2628                final int concurrentThreads = Runtime.getRuntime().availableProcessors(); 
    2729                final ExecutorService threadPool = Executors.newFixedThreadPool(concurrentThreads); 
     
    4749        } 
    4850         
     51        /** 
     52         * Creates the config and starts the corresponding experiment 
     53         * @param threadPool  
     54         * @param configFile location of the config file 
     55         */ 
    4956        public static void createConfig(ExecutorService threadPool, String configFile) { 
    5057                ExperimentConfiguration config = null; 
     
    5562                        e.printStackTrace(); 
    5663                } 
     64 
    5765                if( config!=null ) { 
    5866                        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                         
    61100                } 
     101                 
    62102        } 
    63103} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/execution/CrossProjectExperiment.java

    r31 r32  
    1 package de.ugoe.cs.cpdp; 
     1package de.ugoe.cs.cpdp.execution; 
    22 
    33import java.io.File; 
     
    1010 
    1111import weka.core.Instances; 
     12import de.ugoe.cs.cpdp.ExperimentConfiguration; 
    1213import de.ugoe.cs.cpdp.dataprocessing.IProcessesingStrategy; 
    1314import de.ugoe.cs.cpdp.dataprocessing.ISetWiseProcessingStrategy; 
     
    5152 * @author Steffen Herbold 
    5253 */ 
    53 public class Experiment implements Runnable { 
     54public class CrossProjectExperiment implements IExecutionStrategy { 
    5455 
    5556        /** 
     
    6263         * @param config configuration of the experiment 
    6364         */ 
    64         public Experiment(ExperimentConfiguration config) { 
     65        public CrossProjectExperiment(ExperimentConfiguration config) { 
    6566                this.config = config; 
    6667        } 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java

    r4 r32  
    2121         * Path of the data. 
    2222         */ 
    23         private String path = ""; 
     23        protected String path = ""; 
    2424 
    2525        /** 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/IVersionLoader.java

    r4 r32  
    2626         */ 
    2727        public List<SoftwareVersion> load(); 
     28 
    2829} 
Note: See TracChangeset for help on using the changeset viewer.