Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
network-lego.h
00001 /**************************************************************************
00002  * Copyright (c) 2005-2011 T. M. Murali                                   *
00003  * Copyright (c) 2009-2011 Christopher L. Poirel                          *
00004  * Copyright (c) 2011 Christopher D. Lasher                               *
00005  * Copyright (c) 2010 Jacqueline Addesa                                   *
00006  * Copyright (c) 2003-2005 Deept Kumar                                    *
00007  *                                                                        *
00008  * This file is part of Biorithm.                                         *
00009  *                                                                        *
00010  * Biorithm is free software: you can redistribute it and/or modify       *
00011  * it under the terms of the GNU General Public License as published by   *
00012  * the Free Software Foundation, either version 3 of the License, or      *
00013  * (at your option) any later version.                                    *
00014  *                                                                        *
00015  * Biorithm is distributed in the hope that it will be useful,            *
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00018  * GNU General Public License for more details.                           *
00019  *                                                                        *
00020  * You should have received a copy of the GNU General Public License      *
00021  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00022  *                                                                        *
00023  **************************************************************************/
00024 
00031 #ifndef _NETWORK_LEGO_H
00032 #define _NETWORK_LEGO_H
00033 
00034 #include "active-networks.h"
00035 #include "apriori.h"
00036 #include "dag.h"
00037 
00038 class NetworkLego : public ActiveNetwork
00039 {
00040 private:
00041   // the set of leaves associated with this lego.
00042   set< NetworkLego > _leaves;
00043 
00044   // for inmf, the set of conditions the NL contributes to. the map
00045   // associates each condition with a weight.
00046   map< string, MyNT > _conditionsContributeTo;
00047 
00048 public:
00049 };
00050 
00051 enum NLOperator { NL_INTERSECTION, NL_DIFFERENCE };
00052 
00053 class SDAGNode : DAGNode< NetworkLego >
00054 {
00055 private:
00056   NLOperator _operator;
00057 public:
00058 };
00059 
00060 class SDAG : public DAG< SDAGNode >
00061 {
00062 private:
00063 
00064 public:
00065 
00066   void addLeaf(const NetworkLego &lego);
00067 
00068   void addLeaves(const vector< NetworkLego > &leaves);
00069 
00070   void compute();
00071 
00072 };
00073 
00074 
00075 class SetOfNetworkLegos: public SetOfActiveNetworks
00076 {
00077 private:
00078 
00079   // the main algo used to compute the itemsets.
00080   AprioriWithComplement _aprioriAlgo;
00081 
00082 
00083   // the leaves of the lattice.
00084   SetOfActiveNetworks _leaves;
00085 
00086   // the legos themselves, including the leaves.
00087   SetOfActiveNetworks _legos;
00088 
00089   // the statistically significant legos.
00090   SetOfActiveNetworks _significantLegos;
00091 
00092   // the leaves of the  statistically significant legos.
00093   SetOfActiveNetworks _significantLegosLeaves;
00094 
00095   // the roots of the statistically significant legos.
00096   SetOfActiveNetworks _significantLegosRoots;
00097 
00098   // the lattice that holds the legos together.
00099   ItemsetLattice _lattice;
00100 
00101   // the closure of the lattice that holds the legos together.
00102   ItemsetLattice _closedLattice;
00103 
00104   // the lattice that contains only statistically significant itemsets.
00105   ItemsetLattice _significantLattice;
00106   // the closure of the lattice that holds the significant legos together.
00107   ItemsetLattice _closedSignificantLattice;
00108 
00109   // a binary matrix representing the leaves.
00110   vector< vector < unsigned int > > _binaryMatrix;
00111   // the set of rows corresponding to the complements.
00112   set< unsigned int > _complementRows;
00113   // the row names _binaryMatrix.
00114   map< unsigned int, string > _binaryMatrixRowNames;
00115   // the column names in _binaryMatrix.
00116   map< unsigned int, string > _binaryMatrixColumnNames;
00117 
00118   // for inmf, the set of conditions the NL contributes to, stored as a graph.
00119   MyGraph _mapFromNetworkLegosToActiveNetworks;
00120 
00121 
00122 public:
00123   SetOfNetworkLegos()
00124     {}
00125   SetOfNetworkLegos(SetOfActiveNetworks &anetSet)
00126       : _leaves(anetSet)
00127     {}
00128 
00129   virtual ~SetOfNetworkLegos()
00130     {}
00131 
00138   virtual void compute(ostream &logStream, unsigned int minNumberConditions = 1,
00139                        unsigned int minNumberInteractions = 1);
00140 
00165   void computeMaximallySignificantItemsets(
00166     const vector< Itemset > &allSignificantItemsets,
00167     vector< Itemset > &maximallySignificantItemsets,
00168     vector< Itemset > &significantLatticeRoots,
00169     vector< Itemset > &significantLatticeLeaves);
00170 
00185   virtual void compareNetworkLegosToActiveNetworks();
00186   
00190   virtual void computeTrivialLegos(ostream &logStream);
00191 
00192 
00193   virtual void computeRecoverability(ostream &logStream);
00194 
00196   virtual void computeSignificantLegos(ostream &logStream, unsigned int numRandomTrials = 100000,
00197                                        MyNT pvalueThreshold = 0.01);
00198 
00200   virtual void computeStability(ostream &logStream);
00201 
00203   virtual void getSignificantLegos(SetOfActiveNetworks &legos)
00204     {
00205       legos = _significantLegos;
00206     }
00207 
00208 
00209 #ifdef CTEMPLATE
00210 
00211   virtual void layout();
00212 #endif
00213 
00214 
00215   // various methods to print stuff.
00216 
00220   void printBinaryMatrix(ostream &ostr, bool transposed = false) const;
00221 
00223   void printClosedLattice(ostream &ostr) const
00224     {
00225       _closedSignificantLattice.print(ostr);
00226     }
00227 
00229   void printLattice(ostream &ostr) const
00230     {
00231       _significantLattice.print(ostr);
00232     }
00233 
00250   virtual void readMappingFromNetworkLegosToActiveNetworks(string nlsToRNsFile);
00251 };
00252 
00253 
00254 
00255 #endif // _NETWORK_LEGO_H
 All Classes Functions Variables Typedefs Friends