ProteoWizard
ParametrizedFunction.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2006 Louis Warschaw Prostate Cancer Center
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#ifndef _PARAMETRIZEDFUNCTION_HPP_
25#define _PARAMETRIZEDFUNCTION_HPP_
26
27
30
31
32#include "boost/numeric/ublas/vector.hpp"
33#if (BOOST_VERSION/100) >= 1064
34#include "boost/serialization/array_wrapper.hpp" // Workaround for https://stackoverflow.com/questions/44534516/error-make-array-is-not-a-member-of-boostserialization
35#endif
36#include "boost/numeric/ublas/matrix.hpp"
37#include "boost/numeric/ublas/io.hpp"
38#include "boost/numeric/ublas/matrix_proxy.hpp"
39namespace ublas = boost::numeric::ublas;
40
41
42#include <complex>
43
44
45namespace pwiz {
46namespace frequency {
47
48
49template<typename value_type>
51{
52 public:
53 virtual unsigned int parameterCount() const = 0;
54 virtual value_type operator()(double x, const ublas::vector<double>& p) const = 0;
55 virtual ublas::vector<value_type> dp(double x, const ublas::vector<double>& p) const = 0;
56 virtual ublas::matrix<value_type> dp2(double x, const ublas::vector<double>& p) const = 0;
58
59 class ErrorFunction;
60};
61
62
63template<typename value_type>
65{
66 public:
67
69 typedef std::vector<Datum> Data;
70
72 : f_(f), data_(data)
73 {}
74
75 int parameterCount() const {return f_.parameterCount();}
76
77 double operator()(const ublas::vector<double>& p) const
78 {
79 double result = 0;
80 for (typename Data::const_iterator it=data_.begin(); it!=data_.end(); ++it)
81 result += norm(std::complex<double>(f_(it->x,p) - it->y));
82 return result;
83 }
84
85 ublas::vector<double> dp(const ublas::vector<double>& p) const
86 {
87 ublas::vector<double> result(parameterCount());
88 result.clear();
89 for (typename Data::const_iterator it=data_.begin(); it!=data_.end(); ++it)
90 {
91 std::complex<double> diffconj = conj(std::complex<double>(f_(it->x,p) - it->y));
92 result += 2 * real(diffconj*f_.dp(it->x,p));
93 }
94 return result;
95 }
96
97 ublas::matrix<double> dp2(const ublas::vector<double>& p) const
98 {
99 ublas::matrix<double> result(parameterCount(), parameterCount());
100 result.clear();
101 for (typename Data::const_iterator it=data_.begin(); it!=data_.end(); ++it)
102 {
103 std::complex<double> diffconj = conj(std::complex<double>(f_(it->x, p) - it->y));
104 ublas::vector<value_type> dp = f_.dp(it->x,p);
105 ublas::matrix<value_type> dp2 = f_.dp2(it->x,p);
106 result += 2 * real(diffconj*dp2 + outer_prod(conj(dp),dp));
107 }
108 return result;
109 }
110
111 private:
113 const Data& data_;
114};
115
116
117} // namespace frequency
118} // namespace pwiz
119
120
121#endif // _PARAMETRIZEDFUNCTION_HPP_
122
KernelTraitsBase< Kernel >::space_type::abscissa_type x
const ParametrizedFunction< value_type > & f_
ErrorFunction(const ParametrizedFunction< value_type > &f, const Data &data)
double operator()(const ublas::vector< double > &p) const
ublas::vector< double > dp(const ublas::vector< double > &p) const
ublas::matrix< double > dp2(const ublas::vector< double > &p) const
virtual value_type operator()(double x, const ublas::vector< double > &p) const =0
virtual ublas::matrix< value_type > dp2(double x, const ublas::vector< double > &p) const =0
virtual unsigned int parameterCount() const =0
virtual ublas::vector< value_type > dp(double x, const ublas::vector< double > &p) const =0