singleRankingNet.pm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/perl -w
  2. package singleRankingNet;
  3. require Exporter;
  4. use strict;
  5. use PDBResolution;
  6. use utilities;
  7. {
  8. my $nhidden = 5;
  9. my @bias = (2.849843e+00,2.111072e+00,-1.083691e+01,-4.135554e+00,-4.120570e-01,2.0);
  10. my @weights = ( -3.129355e-04, -1.589077e-02, -2.161848e+00 , 2.226650e-01,
  11. -4.868254e-01, 4.035841e-03, 8.064615e-02, -1.659731e+01,
  12. 8.745763e-01, -1.147158e+00, 4.432926e-03 , 4.485627e-02,
  13. 1.612531e+01, -6.115551e+00, -3.739336e+00 , 8.667732e-02,
  14. 2.469719e-01, 3.679384e+00 ,-8.063131e-01, -4.584766e+00 ,
  15. -8.657036e-01, -3.492344e-01 ,-1.328472e-01 ,-5.744038e-01 , 3.360329e-02,
  16. -7.531151e+00, -9.724150e-01 ,-2.660009e+00, 7.692027e-01,
  17. 1.438417e+00);
  18. sub _get_nhidden() {
  19. $nhidden;
  20. }
  21. sub _get_bias {
  22. my ($self, $i) = @_;
  23. $bias[$i];
  24. }
  25. sub _get_weight {
  26. my ($self, $i) = @_;
  27. $weights[$i];
  28. }
  29. sub _init {
  30. my ($self) = @_;
  31. }
  32. }
  33. sub new {
  34. my ($caller) = @_;
  35. my $caller_is_obj = ref($caller);
  36. my $class = $caller_is_obj || $caller;
  37. no strict "refs";
  38. my $self = bless {}, $class;
  39. return $self;
  40. }
  41. sub read_from_file {
  42. my ($self, $paramFile) = @_;
  43. ## TODO
  44. }
  45. sub predict {
  46. my $self = shift;
  47. my $template = shift;
  48. my $queryLength = shift;
  49. my $TMscore = 0;
  50. my $templateName = $template->get_Hit();
  51. print "templateName=$templateName\n";
  52. print "score=" . $template->get_Score() . "\n";
  53. for (my $unit = 0; $unit<$self->_get_nhidden(); $unit++) {
  54. #calculate input of hidden unit (sum of all inputs * weights)
  55. my $input = ($template->get_Score()) * $self->_get_weight(0 + $unit * 3) +
  56. $template->get_SS()/$queryLength * $self->_get_weight(1 + $unit * 3) +
  57. $template->get_SumProbL() * $self->_get_weight(2 + $unit * 3);
  58. #calculate output of hidden unit
  59. my $output = 1.0 / (1.0 + exp(-($input + $self->_get_bias($unit))));
  60. $TMscore += $output * $self->_get_weight( $self->_get_nhidden()*3 + $unit);
  61. }
  62. $TMscore = sprintf("%.6f", $TMscore);
  63. #$template->set_predTM($TMscore);
  64. print "predict->$TMscore\n";
  65. return $TMscore;
  66. }
  67. sub predict_TMscore {
  68. my $self = shift;
  69. my $template = shift;
  70. my $QNeff = shift;
  71. $self->_init();
  72. my $TMscore = 0;
  73. my $numFeat = 5;
  74. my $templateName = $template->get_Hit();
  75. print "templateName=$templateName\n";
  76. print "score=" . $template->get_Score() . "\n";
  77. print "ssScore=" . $template->get_SS() . "\n";
  78. print "sumProbsL=" . $template->get_SumProbL() . "\n";
  79. print "sim=" . $template->get_Sim() . "\n";
  80. print "col=" . $template->get_Cols() . "\n";
  81. print "QNeff=" . $QNeff . "\n";
  82. my $unit = 0;
  83. for ($unit = 0; $unit<$self->_get_nhidden(); $unit++) {
  84. #calculate input of hidden unit (sum of all inputs * weights)
  85. my $input = ($template->get_Score()) * $self->_get_weight(0 + $unit * $numFeat) +
  86. $template->get_SS() * $self->_get_weight(1 + $unit * $numFeat) +
  87. $template->get_SumProbL() * $self->_get_weight(2 + $unit * $numFeat) +
  88. $template->get_Score()/$template->get_Cols() * $self->_get_weight(3 + $unit * $numFeat) +
  89. $template->get_Sim() * $self->_get_weight(4 + $unit*$numFeat);
  90. #calculate output of hidden unit
  91. my $output = 1.0 / (1.0 + exp(-($input + $self->_get_bias($unit))));
  92. $TMscore += $output * $self->_get_weight( $self->_get_nhidden()*$numFeat + $unit);
  93. }
  94. $TMscore += $self->_get_bias($unit);
  95. $TMscore = &sigmoid($TMscore);
  96. $TMscore = sprintf("%.6f", $TMscore);
  97. print "predict->$TMscore\n";
  98. return $TMscore;
  99. }
  100. 1;