Advertisement
Guest User

Run_MOGB

a guest
Jun 26th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 KB | None | 0 0
  1. package MOEA_GP;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Properties;
  6.  
  7. import org.moeaframework.* ;
  8. import org.moeaframework.Executor;
  9. import org.moeaframework.core.Algorithm;
  10. import org.moeaframework.core.NondominatedPopulation;
  11. import org.moeaframework.core.Solution;
  12. import org.moeaframework.core.spi.AlgorithmFactory;
  13.  
  14. import core.ConfusionMatrix;
  15. import core.DataFrame;
  16.  
  17. public class Run_MOGP extends Thread {
  18.    
  19.     private Thread t;
  20.     public NondominatedPopulation solutions ;
  21.     public HashMap<String,String> run_configs ;
  22.     public DataFrame train_data ;
  23.     public HashMap<String,Integer> features ;
  24.     public String topredict ;
  25.     public String [] objectives ;
  26.     public Object[] true_train_labels ;
  27.    
  28.    
  29.     public Run_MOGP(DataFrame train_data, HashMap<String,Integer> features,String topredict,String algo,String[] objectives,int pop_size,int maxgeneration,Double cross_prob,Double mut_prob) {
  30.        
  31.         //saving run parameters
  32.         this.train_data = train_data ;
  33.         this.run_configs = new HashMap<String,String>() ;
  34.         this.features = features ;
  35.         this.objectives = objectives ;
  36.         this.topredict = topredict ;
  37.         this.true_train_labels = train_data.get_column_data(topredict) ;
  38.                
  39.         this.run_configs.put("algorithm", algo);
  40.         this.run_configs.put("populationsize",  String.valueOf(pop_size));
  41.         this.run_configs.put("mutation_rate",  String.valueOf(mut_prob));
  42.         this.run_configs.put("crossover_rate",  String.valueOf(cross_prob));
  43.         this.run_configs.put("maxgeneration",  String.valueOf(maxgeneration));
  44.         this.run_configs.put("algorithm", algo);
  45.        
  46.        
  47.        
  48.     }
  49.     /*public void run()
  50.     {
  51.         this.solutions = new Executor()
  52.                   .withProblemClass(Train_MOGP.class, train_data,true_train_labels,features,objectives)
  53.                   .withAlgorithm(this.run_configs.get("algorithm"))
  54.                   .withProperty("populationSize", this.run_configs.get("populationsize"))
  55.                   .withProperty("operator", "bx")
  56.                   .withProperty("operator", "ptm")
  57.                   .withProperty("bx.rate",Double.parseDouble(this.run_configs.get("crossover_rate")))
  58.                   .withProperty("ptm.rate", Double.parseDouble(this.run_configs.get("mutation_rate")))
  59.                   //.distributeOnAllCores()
  60.                   .withMaxEvaluations(Integer.parseInt(this.run_configs.get("max_evaluation_number")))
  61.                   .run();  
  62.     }*/
  63.     @Override
  64.     public void run()
  65.     {
  66.         Properties properties = new Properties();
  67.         properties.setProperty("populationSize",this.run_configs.get("populationsize"));
  68.         properties.setProperty("operator","bx");
  69.         properties.setProperty("operator","ptm");
  70.         properties.setProperty("bx.rate",this.run_configs.get("crossover_rate")) ;
  71.         properties.setProperty("ptm.rate",this.run_configs.get("mutation_rate")) ;
  72.         Algorithm algorithm = null;
  73.         System.out.println(this.run_configs.get("maxgeneration"));
  74.         int maxGenerations = Integer.parseInt(this.run_configs.get("maxgeneration"));
  75.         algorithm = AlgorithmFactory.getInstance().getAlgorithm(
  76.                 this.run_configs.get("algorithm"), properties,new Train_MOGP(train_data,true_train_labels,features,objectives));
  77.         for (int igen = 0 ; igen< maxGenerations ; igen++)
  78.         {
  79.             System.out.println("generation : " + (igen+1));
  80.             algorithm.step();
  81.             this.solutions = algorithm.getResult() ;
  82.             /*for (Solution sol : this.solutions )
  83.             {
  84.                 System.out.println(sol.getVariable(0).toString());
  85.                 System.out.println("front tpr:"+sol.getObjective(0));
  86.                 System.out.println("front tnr:"+sol.getObjective(1));
  87.             }*/
  88.         }
  89.     }
  90.    
  91.     /* public void start () {
  92.           System.out.println("Starting " +  this.run_configs.get("algorithm") );
  93.           if (t == null) {
  94.              t = new Thread (this, this.run_configs.get("algorithm"));
  95.              t.start ();
  96.           }
  97.      }*/
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement