Index: kernel/include/IMP/unary_functions/Linear.h =================================================================== --- kernel/include/IMP/unary_functions/Linear.h (revision 512) +++ kernel/include/IMP/unary_functions/Linear.h (working copy) @@ -14,16 +14,17 @@ //! Linear function /** \ingroup unaryf - \note there is no offset since that is not meaningful for optimization + \note The offset is not meaningful for optimization, but does + make the displayed energies nicer. */ class Linear : public UnaryFunction { public: - Linear(Float slope) : slope_(slope) {} + Linear(Float slope, Float offset=0) : slope_(slope), offset_(offset) {} virtual ~Linear() {} - virtual Float evaluate(Float feature) { return feature*slope_; } + virtual Float evaluate(Float feature) { return (feature-offset_)*slope_; } virtual Float evaluate_deriv(Float feature, Float& deriv) { deriv= slope_; @@ -31,11 +32,11 @@ } void show(std::ostream &out=std::cout) const { - out << "Linear: " << slope_ << std::endl; + out << "Linear: " << slope_ << ", " << offset_ << std::endl; } protected: - Float slope_; + Float slope_, offset_; }; } // namespace IMP Index: kernel/test/unary_functions/test_linear.py =================================================================== --- kernel/test/unary_functions/test_linear.py (revision 512) +++ kernel/test/unary_functions/test_linear.py (working copy) @@ -9,13 +9,16 @@ """Test that linear values are correct""" for slope in (0.0, -5.0, 3.5): func = IMP.Linear(slope) + func2 = IMP.Linear(slope, -1) for i in range(15): val = -10.0 + 3.5 * i scoreonly = func.evaluate(val) score, deriv = func.evaluate_deriv(val) + score2 = func2.evaluate(val) self.assertEqual(score, scoreonly) self.assertInTolerance(score, val * slope, 0.001) self.assertInTolerance(deriv, slope, 0.001) + self.assertInTolerance(score-1, score2, 0.001) def test_show(self): """Check Linear::show() method"""