Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
USOGFunc.cc
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 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/scoring/constraints/USOGFunc.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Package headers
17 
18 // Project headers
19 #include <core/types.hh>
20 
21 // Utility headers
22 #include <utility/exit.hh>
23 #include <utility/vector1.hh>
24 
25 // C/C++ headers
26 #include <algorithm>
27 #include <cmath>
28 #include <iostream>
29 
30 namespace core {
31 namespace scoring {
32 namespace constraints {
33 
36 
38  const utility::vector1<core::Real>& std_devs,
39  const utility::vector1<core::Real>& weights)
40  : means_(means), std_devs_(std_devs), weights_(weights) {
41  if (means_.size() != std_devs_.size() || means_.size() != weights_.size()) {
42  utility_exit_with_message("Unequal number of means, std_devs, weights");
43  }
44 }
45 
47  return new USOGFunc(*this);
48 }
49 
51  return -std::log(gaussianScore(x));
52 }
53 
56  return (func(x + w) - func(x - w)) / (2 * w);
57 }
58 
60  core::Real sum = 0;
61  for (core::Size i = 1; i <= numGaussians(); ++i) {
62  sum += dgaussian(x, means_[i], std_devs_[i], weights_[i]);
63  }
64 
65  return std::max(sum, kMinGaussianScore);
66 }
67 
69  return means_.size();
70 }
71 
72 void USOGFunc::show_definition(std::ostream& out) const {
73  out << "USOGFUNC " << numGaussians();
74  for (core::Size i = 1; i <= numGaussians(); ++i) {
75  out << " " << means_[i] << " " << std_devs_[i] << " " << weights_[i];
76  }
77 }
78 
80  means_.clear();
81  weights_.clear();
82  std_devs_.clear();
83 }
84 
85 // Format: USOGFunc <num_gaussians> <mean_1> <std_dev1> <weight_1> ... <mean_n> <std_dev_n> <weight_n>
86 void USOGFunc::read_data(std::istream& in) {
87  resetInstance();
88 
89  core::Size num_gaussians = 0;
90  in >> num_gaussians;
91 
92  for (core::Size i = 1; i <= num_gaussians; ++i) {
93  core::Real m = readValueOrDie(in);
94  core::Real s = readValueOrDie(in);
95  core::Real w = readValueOrDie(in);
96 
97  assert(s > 0);
98  assert(w > 0);
99 
100  means_.push_back(m);
101  weights_.push_back(w);
102  std_devs_.push_back(s);
103  }
104 }
105 
106 // Utility functions
107 core::Real readValueOrDie(std::istream& in) {
108  core::Real x;
109  in >> x;
110 
111  if (in.fail()) {
112  utility_exit_with_message("Failed to read floating point value ");
113  }
114 
115  return x;
116 }
117 
118 } // namespace constraints
119 } // namespace scoring
120 } // namespace core