SET(CMAKE_VERBOSE_MAKEFILE OFF)
-ADD_DEFINITIONS(-Wall -pedantic -g -D_GLIBCXX_DEBUG)
+#ADD_DEFINITIONS(-Wall -O2)
+
+#ADD_DEFINITIONS(-Wall -pedantic -g -D_GLIBCXX_DEBUG)
+ADD_DEFINITIONS(-Wall -pedantic -g)
#INCLUDE(CheckCXXSourceCompiles)
#CheckCXXSourceCompiles(test HAVE_TR1)
INCLUDE_DIRECTORIES(.)
-ADD_LIBRARY(GeneSort geneorder genealgorithms modelidentifier genesorter)
+ADD_LIBRARY(GeneSort geneorder genealgorithms modelidentifier genesorter model
+ models)
ADD_EXECUTABLE(genesort main.cpp)
SET(GENELIBS doublefann GeneSort)
#include "modelidentifier.h"
#include "genesorter.h"
#include "sortaction.h"
-
-typedef pair<ModelIdentifier::Model,double> modelpair;
-
-struct ScoreCmp {
- template<typename T>
- bool operator()(T s1, T s2){
- return s1.first < s2.first;
- }
-};
+#include "model.h"
int main(int argc, char** argv){
//TODO: Identify
ModelIdentifier mi(ann);
- map<ModelIdentifier::Model,double> scores = mi.identify(go);
- priority_queue<pair<double,ModelIdentifier::Model>,vector<pair<double,ModelIdentifier::Model> >, ScoreCmp > pq;
- for (map<ModelIdentifier::Model,double>::iterator m = scores.begin();
- m != scores.end(); ++m){
- if (m->second > 0){
- pq.push(pair<double,ModelIdentifier::Model>(m->second,m->first));
- }
- }
+ priority_queue<pair<double,Model> > pq = mi.identify(go);
while (pq.size() > 0){
- cout << "Model: " << mi.modelName(pq.top().second) << " score: " << pq.top().first << endl;
+ cout << "Model: " << pq.top().second.name() << " score: " << pq.top().first << endl;
pq.pop();
}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michael Andreen *
+ * andreen@student.chalmers.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
+ ***************************************************************************/
+
+#include "model.h"
+#include "models.h"
+
+Model::Model(Models::ModelImpl* model): _impl(model){
+}
+
+double Model::score(const SortAction& sa) const{
+ return _impl->score(sa);
+}
+
+std::string Model::name() const{
+ return _impl->name();
+}
+
+bool operator<(const Model& lh,const Model& rh){
+ return &lh < &rh;
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michael Andreen *
+ * andreen@student.chalmers.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
+ ***************************************************************************/
+
+#ifndef __MODEL_H__
+#define __MODEL_H__
+
+#include <tr1/memory>
+#include <string>
+
+class SortAction;
+namespace Models {
+ class ModelImpl;
+}
+
+class Model{
+ public:
+ typedef std::tr1::shared_ptr<Models::ModelImpl> ModelPointer;
+
+ Model(Models::ModelImpl* model);
+
+ double score(const SortAction& sa) const;
+
+ std::string name() const;
+
+ private:
+ ModelPointer _impl;
+
+};
+
+bool operator<(const Model& lh,const Model& rh);
+
+#endif
#include "genealgorithms.h"
#include <doublefann.h>
+#include "models.h"
+#include "model.h"
using namespace std;
fann_destroy(_ann);
}
-std::map<ModelIdentifier::Model,double> ModelIdentifier::identify(const GeneOrder& go){
+priority_queue<pair<double,Model> > ModelIdentifier::identify(const GeneOrder& go){
int pos = 0;
int neg = 0;
for (GeneOrder::iterator g = go.begin(); g != go.end(); ++g){
double *output = fann_run(_ann,&input[0]);
- map<Model,double> scores;
- scores[X] = output[0];
- scores[Zipper] = output[1];
- scores[Whirl] = output[2];
- scores[FatX] = output[3];
- scores[Cloud] = output[4];
+ priority_queue<pair<double,Model> > scores;
+ scores.push(pair<double,Model>(output[0],Model(new Models::X)));
+ scores.push(pair<double,Model>(output[1],Model(new Models::Zipper)));
+ scores.push(pair<double,Model>(output[2],Model(new Models::ModelImpl)));
+ scores.push(pair<double,Model>(output[3],Model(new Models::FatX)));
+ scores.push(pair<double,Model>(output[4],Model(new Models::Cloud)));
return scores;
}
-
-string ModelIdentifier::modelName(Model m){
- switch (m){
- case Whirl : return "Whirl";
- case X : return "X";
- case FatX : return "FatX";
- case Zipper : return "Zipper";
- case Cloud : return "Cloud";
- }
- return "Unknown model";
-}
#include "geneorder.h"
-#include <map>
+#include <queue>
#include <string>
#include <stdexcept>
struct fann;
+class Model;
+
/**
* Identifies the model this gene order belongs to
*/
class ModelIdentifier{
public:
- //TODO: Make a Model class with functions for scoring SortActions
- //one subclass for each model. Possibly storing name as string too.
- enum Model{Whirl,X,FatX,Zipper,Cloud};
/**
* Creates a new identifier given an artificial neural network
*
* \returns a map with the model as key and the score between -1 and 1
*/
- std::map<Model,double> identify(const GeneOrder& go);
-
- static std::string modelName(Model m);
+ std::priority_queue<std::pair<double,Model> > identify(const GeneOrder& go);
~ModelIdentifier();
private:
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michael Andreen *
+ * andreen@student.chalmers.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
+ ***************************************************************************/
+
+#include "models.h"
+
+using namespace std;
+
+namespace Models{
+
+ModelImpl::~ModelImpl(){}
+
+double ModelImpl::score(const SortAction& sa){
+ return 1;
+}
+string ModelImpl::name(){
+ return "Standard";
+}
+
+
+
+double X::score(const SortAction& sa){
+ return 1;
+}
+string X::name(){
+ return "X";
+}
+
+double Zipper::score(const SortAction& sa){
+ return 1;
+}
+string Zipper::name(){
+ return "Zipper";
+}
+
+double Cloud::score(const SortAction& sa){
+ return 1;
+}
+string Cloud::name(){
+ return "Cloud";
+}
+
+double FatX::score(const SortAction& sa){
+ return 1;
+}
+string FatX::name(){
+ return "FatX";
+}
+
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2006 by Michael Andreen *
+ * andreen@student.chalmers.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
+ ***************************************************************************/
+
+#ifndef __MODELS_H__
+#define __MODELS_H__
+
+#include <string>
+
+class SortAction;
+
+namespace Models {
+
+class ModelImpl {
+ public:
+ virtual ~ModelImpl();
+
+ virtual double score(const SortAction& sa);
+
+ virtual std::string name();
+};
+
+
+class X : public ModelImpl {
+ public:
+ double score(const SortAction& sa);
+
+ std::string name();
+};
+
+class Zipper : public ModelImpl {
+ public:
+ double score(const SortAction& sa);
+
+ std::string name();
+};
+
+class Cloud : public ModelImpl {
+ public:
+ double score(const SortAction& sa);
+
+ std::string name();
+};
+
+class FatX : public ModelImpl {
+ public:
+ double score(const SortAction& sa);
+
+ std::string name();
+};
+
+}
+
+#endif
SET(CMAKE_VERBOSE_MAKEFILE OFF)
-ADD_DEFINITIONS(-Wall -O2)
+#ADD_DEFINITIONS(-Wall -O2)
+
+#ADD_DEFINITIONS(-Wall -pedantic -g -D_GLIBCXX_DEBUG)
+
SET(TESTSRC geneordertest genealgorithmstest modelidentifiertest
#include <geneorder.h>
#include <genealgorithms.h>
#include <modelidentifier.h>
+#include <model.h>
#include <algorithm>
#include <queue>
#include <iterator>
+
using namespace std;
/*
#define TESTNAME ModelIdentifierTest
-typedef pair<ModelIdentifier::Model,double> modelpair;
+typedef pair<double, Model> modelpair;
-struct ModelCmp {
- bool operator()(modelpair m1, modelpair m2){
- return m1.second < m2.second;
- }
-};
class TESTNAME : public CPPUNIT_NS::TestFixture
{
ModelIdentifier mi("default.ann");
GeneOrder axis(_1axis.begin(),_1axis.end());
- map<ModelIdentifier::Model,double> scores = mi.identify(axis);
- priority_queue<modelpair, vector<modelpair>, ModelCmp > pq(scores.begin(),scores.end());
- CPPUNIT_ASSERT_EQUAL(ModelIdentifier::X,pq.top().first);
+ priority_queue<modelpair> pq = mi.identify(axis);
+ CPPUNIT_ASSERT_EQUAL(string("X"),pq.top().second.name());
GeneOrder uniform(_uniform.begin(),_uniform.end());
- scores = mi.identify(uniform);
- pq = priority_queue<modelpair, vector<modelpair>, ModelCmp >(scores.begin(),scores.end());
- CPPUNIT_ASSERT_EQUAL(ModelIdentifier::Whirl,pq.top().first);
+ pq = mi.identify(uniform);
+ CPPUNIT_ASSERT_EQUAL(string("Standard"),pq.top().second.name());
GeneOrder zipper(_zipper.begin(),_zipper.end());
- scores = mi.identify(zipper);
- pq = priority_queue<modelpair, vector<modelpair>, ModelCmp >(scores.begin(),scores.end());
- CPPUNIT_ASSERT_EQUAL(ModelIdentifier::Zipper,pq.top().first);
+ pq = mi.identify(zipper);
+ CPPUNIT_ASSERT_EQUAL(string("Zipper"),pq.top().second.name());
GeneOrder transpos(_transpos.begin(),_transpos.end());
- scores = mi.identify(transpos);
- pq = priority_queue<modelpair, vector<modelpair>, ModelCmp >(scores.begin(),scores.end());
- CPPUNIT_ASSERT_EQUAL(ModelIdentifier::Cloud,pq.top().first);
+ pq = mi.identify(transpos);
+ CPPUNIT_ASSERT_EQUAL(string("Cloud"),pq.top().second.name());
}
};