Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MOEA_GP;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Properties;
- import org.moeaframework.* ;
- import org.moeaframework.Executor;
- import org.moeaframework.core.Algorithm;
- import org.moeaframework.core.NondominatedPopulation;
- import org.moeaframework.core.Solution;
- import org.moeaframework.core.spi.AlgorithmFactory;
- import core.ConfusionMatrix;
- import core.DataFrame;
- public class Run_MOGP extends Thread {
- private Thread t;
- public NondominatedPopulation solutions ;
- public HashMap<String,String> run_configs ;
- public DataFrame train_data ;
- public HashMap<String,Integer> features ;
- public String topredict ;
- public String [] objectives ;
- public Object[] true_train_labels ;
- 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) {
- //saving run parameters
- this.train_data = train_data ;
- this.run_configs = new HashMap<String,String>() ;
- this.features = features ;
- this.objectives = objectives ;
- this.topredict = topredict ;
- this.true_train_labels = train_data.get_column_data(topredict) ;
- this.run_configs.put("algorithm", algo);
- this.run_configs.put("populationsize", String.valueOf(pop_size));
- this.run_configs.put("mutation_rate", String.valueOf(mut_prob));
- this.run_configs.put("crossover_rate", String.valueOf(cross_prob));
- this.run_configs.put("maxgeneration", String.valueOf(maxgeneration));
- this.run_configs.put("algorithm", algo);
- }
- /*public void run()
- {
- this.solutions = new Executor()
- .withProblemClass(Train_MOGP.class, train_data,true_train_labels,features,objectives)
- .withAlgorithm(this.run_configs.get("algorithm"))
- .withProperty("populationSize", this.run_configs.get("populationsize"))
- .withProperty("operator", "bx")
- .withProperty("operator", "ptm")
- .withProperty("bx.rate",Double.parseDouble(this.run_configs.get("crossover_rate")))
- .withProperty("ptm.rate", Double.parseDouble(this.run_configs.get("mutation_rate")))
- //.distributeOnAllCores()
- .withMaxEvaluations(Integer.parseInt(this.run_configs.get("max_evaluation_number")))
- .run();
- }*/
- @Override
- public void run()
- {
- Properties properties = new Properties();
- properties.setProperty("populationSize",this.run_configs.get("populationsize"));
- properties.setProperty("operator","bx");
- properties.setProperty("operator","ptm");
- properties.setProperty("bx.rate",this.run_configs.get("crossover_rate")) ;
- properties.setProperty("ptm.rate",this.run_configs.get("mutation_rate")) ;
- Algorithm algorithm = null;
- System.out.println(this.run_configs.get("maxgeneration"));
- int maxGenerations = Integer.parseInt(this.run_configs.get("maxgeneration"));
- algorithm = AlgorithmFactory.getInstance().getAlgorithm(
- this.run_configs.get("algorithm"), properties,new Train_MOGP(train_data,true_train_labels,features,objectives));
- for (int igen = 0 ; igen< maxGenerations ; igen++)
- {
- System.out.println("generation : " + (igen+1));
- algorithm.step();
- this.solutions = algorithm.getResult() ;
- /*for (Solution sol : this.solutions )
- {
- System.out.println(sol.getVariable(0).toString());
- System.out.println("front tpr:"+sol.getObjective(0));
- System.out.println("front tnr:"+sol.getObjective(1));
- }*/
- }
- }
- /* public void start () {
- System.out.println("Starting " + this.run_configs.get("algorithm") );
- if (t == null) {
- t = new Thread (this, this.run_configs.get("algorithm"));
- t.start ();
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement