Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ANN.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 /* */
3 /* ---- TALOS C++ verison ---- */
4 /* TALOS: Torsion Angle Likeness Optimized By Shifts. */
5 /* Yang Shen, Gabriel Cornilescu, Frank Delaglio, and Ad Bax */
6 /* NIH Laboratory of Chemical Physics */
7 /* veriosn, 2009.05.31.1551 */
8 /* */
9 /* for any problem, please contact */
10 /* shenyang@niddk.nih.gov */
11 /* */
12 /******************************************************************************/
13 
14 /* ANN.cpp: class for a simple Artificial Neural Network
15 // a simple two-level ANN model with one hidden layer, each level with three different runs
16 */
17 
18 
19 #ifndef ANN_H
20 #define ANN_H
21 
22 #include <boost/unordered_map.hpp>
23 // AUTO-REMOVED #include <protocols/sparta/GDB.hh>
24 #include <utility/vector0.hh>
25 
26 #include <utility/vector1.hh>
27 
28 
29 namespace protocols {
30 namespace sparta {
31 
32 class ANN
33 {
34  char buf[30];
36  int input_code; // code for input format
37  // 0 - all CS and AA data, default
38  // 1 - no CS for residue i-1
39  // 2 - no CS for residue i
40  // 3 - no CS for residue i+1
41 
44  int N1_NODE_I, N1_NODE_H, N1_NODE_O; // Number of node in input, hidden and output layers of the 1st level ANN
45  int N2_NODE_I, N2_NODE_H, N2_NODE_O; // Number of node in input, hidden and output layers of the 1st level ANN
46 
47  // 1st level ANN weights and bias
48  boost::unordered_map<int, utility::vector0<float> > WI_1, WI_2, WI_3; // Weighting utility::vector0s for converting input layer, N_I*N_I matrix
49  utility::vector0<float> BI_1, BI_2, BI_3; // Bias utility::vector0s (converting input layer), size of N_I
50  boost::unordered_map<int, utility::vector0<float> > WL1_1, WL1_2, WL1_3; // Weighting utility::vector0s connecting input and hidden layer, N_H*N_I matrix
51  utility::vector0<float> BL1_1, BL1_2, BL1_3; // Bias utility::vector0s (connecting input and hidden layer), size of N_H
52  boost::unordered_map<int, utility::vector0<float> > WL2_1, WL2_2, WL2_3; // Weighting utility::vector0s connecting hidden and output layer, N_O*N_H matrix
53  utility::vector0<float> BL2_1, BL2_2, BL2_3; // Bias utility::vector0s (connecting hidden and output layer), size of N_O
54 
55  // 1st level ANN weights and bias
56  boost::unordered_map<int, utility::vector0<float> > W2I_1, W2I_2, W2I_3; // Weighting utility::vector0s for converting input layer, N_I*N_I matrix
57  utility::vector0<float> B2I_1, B2I_2, B2I_3; // Bias utility::vector0s (converting input layer), size of N_I
58  boost::unordered_map<int, utility::vector0<float> > W2L1_1, W2L1_2, W2L1_3; // Weighting utility::vector0s connecting input and hidden layer, N_H*N_I matrix
59  utility::vector0<float> B2L1_1, B2L1_2, B2L1_3; // Bias utility::vector0s (connecting input and hidden layer), size of N_H
60  boost::unordered_map<int, utility::vector0<float> > W2L2_1, W2L2_2, W2L2_3; // Weighting utility::vector0s connecting hidden and output layer, N_O*N_H matrix
61  utility::vector0<float> B2L2_1, B2L2_2, B2L2_3; // Bias utility::vector0s (connecting hidden and output layer), size of N_O
62 public:
63 
64  boost::unordered_map<int, utility::vector0<float> > ANN_IN_MTX; // input matrix for neural netwrok calculation, indexed by resID and with an input utility::vector0 of size 32
65  // singlet only!!!(6*2 for chemical shifts and 20 for amino acid sequence)
66  boost::unordered_map<int, utility::vector0<float> > ANN_IN_MTX_LEVEL1; // tripet model input matrix for 1st level ANN
67  boost::unordered_map<int, utility::vector0<float> > ANN_IN_MTX_LEVEL2; // tripet modelinput matrix for 2nd level ANN
68 
69  boost::unordered_map<int, utility::vector0<float> > ANN_OUT_MTX_LEVEL1; // output matrix, , indexed by resID and with an utility::vector0 of size 3
70 
71  boost::unordered_map< int, boost::unordered_map< std::string, std::string> >::iterator it;
72 
73  boost::unordered_map<int, utility::vector0<float> > ANN_OUT_MTX_LEVEL2; // output matrix, , indexed by resID and with an utility::vector0 of size 3
74 
75  ANN();
76  ANN( const std::string& dPATH, const std::string& dNAME_PREFIX );
77  ANN( int N1_nodeI, int N1_nodeH, int N1_nodeO, const std::string& dPATH, const std::string& dNAME_PREFIX );
78  ANN( int N1_nodeI, int N1_nodeH, int N1_nodeO, int N2_nodeI, int N2_nodeH, int N2_nodeO, const std::string& dPATH, const std::string& dNAME_PREFIX );
79 
80  void init( int N1_nodeI, int N1_nodeH, int N1_nodeO, int N2_nodeI, int N2_nodeH, int N2_nodeO, const std::string& dPATH, const std::string& dNAME_PREFIX );
81  void getSlashChar();
82 
83  void set_input_code(int c);
84 
85  void loadWeights(); // load all weighting and bias
86  void loadWeightBias3( const std::string& fName, boost::unordered_map<int, utility::vector0<float> > &W1, utility::vector0<float> &B1,
87  boost::unordered_map<int, utility::vector0<float> > &W2, utility::vector0<float> &B2, boost::unordered_map<int, utility::vector0<float> > &W3, utility::vector0<float> &B3,
88  int N_W_row, int N_W_col, int N_B);
89  // load weighting (N_W_row*N_W_col) and bias (N_B) from a given file containing all three sets data
90 
91 
92  void calcLevel1();
93  void calcLevel2();
94  void runSpartaANN( boost::unordered_map<int, utility::vector0<float> > &inMatrix ); // used by SPARTA
95 
97 
99  //calculate 'confidence-averaged' utility::vector0 of three utility::vector0s v1, v2, v3
101  //apply normalization
103 
104  //check the number of atom without CS for a given residue
106 
107  char * ftoa( float n, char *buff, char f='g', int prec=6 );
108  char * itoa( int n, char *buff, int base=10 );
109 
110 };
111 
112 }
113 }
114 #endif