001 package org.jaga.exampleApplications.proteinLocation;
002
003 import org.jaga.individualRepresentation.proteinLocation.*;
004 import org.jaga.masterAlgorithm.ElitistGA;
005 import org.jaga.definitions.*;
006 import org.jaga.fitnessEvaluation.proteinLocation.*;
007 import org.jaga.util.*;
008 import org.jaga.masterAlgorithm.*;
009 import org.jaga.reproduction.*;
010 import org.jaga.reproduction.proteinLocation.*;
011 import org.jaga.hooks.*;
012 import org.jaga.selection.*;
013
014 /**
015 * TODO: Complete these comments.
016 *
017 * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
018 *
019 * <p><u>Company:</u> University College London and JAGA.Org
020 * (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
021 * </p>
022 *
023 * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
024 * This program is free software; you can redistribute it and/or modify
025 * it under the terms of the GNU General Public License as published by
026 * the Free Software Foundation, ONLY if you include a note of the original
027 * author(s) in any redistributed/modified copy.<br/>
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
031 * GNU General Public License for more details.<br/>
032 * You should have received a copy of the GNU General Public License
033 * along with this program; if not, write to the Free Software
034 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
035 * or see http://www.gnu.org/licenses/gpl.html</p>
036 *
037 * @author Greg Paperin (greg@jaga.org)
038 *
039 * @version JAGA public release 1.0 beta
040 */
041
042 public class SubcellularProteinLocation {
043
044 public SubcellularProteinLocation() {}
045
046 public void exec() {
047
048 GAParameterSet params = new DefaultParameterSet();
049
050 SimplifiedFastaFileParser parser = new SimplifiedFastaFileParser();
051 ProteinGroup cytosol = new ProteinGroup("Cytosol", parser, "D:/Courseworks/4C58/cw/data/Cytosol.train.dat");
052 ProteinGroup extracellular = new ProteinGroup("Extracellular", parser, "D:/Courseworks/4C58/cw/data/Extracellular.train.dat");
053 ProteinGroup nucleus = new ProteinGroup("Nucleus", parser, "D:/Courseworks/4C58/cw/data/Nucleus.train.dat");
054 ProteinGroup mitochondrion = new ProteinGroup("Mitochondrion", parser, "D:/Courseworks/4C58/cw/data/Mitochondrion.train.dat");
055
056 ProteinGroup allPositives = new ProteinGroup();
057 allPositives.add(nucleus);
058 ProteinGroup allNegatives = new ProteinGroup();
059 allNegatives.add(mitochondrion);
060 allNegatives.add(extracellular);
061 allNegatives.add(cytosol);
062 ProteinGroup testPositives = new ProteinGroup();
063 ProteinGroup testNegatives = new ProteinGroup();
064 params.setFitnessEvaluationAlgorithm(new ProteinLocationTrainer(testPositives, testNegatives, 3));
065 ProgressiveTestGroupSizeHook progressHook = new ProgressiveTestGroupSizeHook(
066 allPositives, allNegatives, testPositives, testNegatives,
067 30, 2, 0.41, 3., 200, 3, params);
068
069
070 params.setPopulationSize(30);
071
072 CombinedReproductionAlgorithm repAlg = new CombinedReproductionAlgorithm();
073 repAlg.insertReproductionAlgorithm(0, new PolypeptidePatternXOver(1, 0.85));
074 PolypeptidePatternMutation mutation = new PolypeptidePatternMutation(0.1);
075 repAlg.insertReproductionAlgorithm(1, mutation);
076 repAlg.insertReproductionAlgorithm(2, new PolypeptidePatternElongation(0.0005));
077 params.setReproductionAlgorithm(repAlg);
078
079 params.setMaxGenerationNumber(10000);
080
081 params.setSelectionAlgorithm(//new TwoTournamentProbabalisticSelection(0.9));
082 new TournamentSelection(5, 0.9));
083 //new RouletteWheelSelection(-5));
084
085 ProteinLocationClassifierFactory factory = new ProteinLocationClassifierFactory();
086 params.setIndividualsFactory(factory);
087
088 final int attempts = 1;
089
090 //ReusableSimpleGA ga = new ReusableSimpleGA(params);
091 ElitistGA ga = new ElitistGA(params, 0.1, 0.0); // params, elite, bad
092 AnalysisHook analysis = new AnalysisHook();
093 analysis.setLogStream(System.out);
094 analysis.setUpdateDelay(1500);
095 ga.addHook(analysis);
096 ga.addHook(progressHook);
097 progressHook.setAnalysisHookForCooperation(analysis);
098 GAResult [] allResults = new GAResult[attempts];
099
100 for (int i = 0; i < attempts; i++) {
101
102 System.out.println("\n ========== STARTING RUN " + (i+1) + ". ==============================\n");
103 analysis.reset();
104
105 GAResult result = new FittestIndividualResult();
106 try {
107 result = ((ReusableSimpleGA) ga).exec();
108 } catch (OutOfMemoryError e) {
109 e.printStackTrace();
110 }
111
112 System.out.println("\nDONE.\n");
113 System.out.println("Total fitness evaluations: " + analysis.getFitnessCalculations());
114 System.out.println("Result is: " + result);
115 System.out.println("(Fitness: " + ((FittestIndividualResult) result).getBestFitness() + ")");
116 allResults[i] = result;
117 }
118
119 System.out.println("\nALL DONE.\n");
120 for (int i = 0; i < attempts; i++) {
121 System.out.println("Result " + i + " is: " + allResults[i]);
122 System.out.println("(Fitness " + i + " is:" + ((FittestIndividualResult) allResults[i]).getBestFitness() + ")");
123 }
124
125 }
126
127 public static void main(String[] unusedArgs) {
128 SubcellularProteinLocation subcellularProteinLocation = new SubcellularProteinLocation();
129 subcellularProteinLocation.exec();
130 }
131
132 }