ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
ROL_RegressionError.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Rapid Optimization Library (ROL) Package
4
//
5
// Copyright 2014 NTESS and the ROL contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef ROL_REGRESSIONERROR_H
11
#define ROL_REGRESSIONERROR_H
12
13
#include "
ROL_StdVector.hpp
"
14
#include "
ROL_StdObjective.hpp
"
15
22
23
24
namespace
ROL
{
25
26
template
<
class
Real>
27
class
RegressionError
:
public
StdObjective
<Real> {
28
private
:
29
void
checkSize
(
const
std::vector<Real> &x) {
30
const
std::vector<Real> data =
Objective<Real>::getParameter
();
31
if
(data.size() != x.size()) {
32
throw
Exception::NotImplemented
(
"ROL::RegressionError : Data dimension does not match input dimension!"
);
33
}
34
}
35
36
public
:
37
RegressionError
(
void
) {}
38
39
Real
value
(
const
std::vector<Real> &x, Real &tol ) {
40
checkSize
(x);
41
const
std::vector<Real> data =
Objective<Real>::getParameter
();
42
const
unsigned
dim
= x.size();
43
Real val = data[0] - x[0];
44
for
(
unsigned
i = 1; i <
dim
; ++i) val -= data[i] * x[i];
45
return
val;
46
}
47
48
void
gradient
( std::vector<Real> &g,
const
std::vector<Real> &x, Real &tol ) {
49
checkSize
(g);
50
const
std::vector<Real> data =
Objective<Real>::getParameter
();
51
const
unsigned
dim
= g.size();
52
g[0] =
static_cast<
Real
>
(-1);
53
for
(
unsigned
i = 1; i <
dim
; ++i) g[i] = -data[i];
54
}
55
56
void
hessVec
( std::vector<Real> &hv,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
57
checkSize
(hv);
58
hv.assign(hv.size(),
static_cast<
Real
>
(0));
59
}
60
};
// class RegressionError
61
62
}
// namespace ROL
63
64
#endif
ROL_StdObjective.hpp
ROL_StdVector.hpp
ROL::Exception::NotImplemented
Definition
ROL_Types.hpp:884
ROL::Objective::getParameter
const std::vector< Real > getParameter(void) const
Definition
ROL_Objective.hpp:504
ROL::RegressionError::gradient
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition
ROL_RegressionError.hpp:48
ROL::RegressionError::hessVec
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_RegressionError.hpp:56
ROL::RegressionError::RegressionError
RegressionError(void)
Definition
ROL_RegressionError.hpp:37
ROL::RegressionError::checkSize
void checkSize(const std::vector< Real > &x)
Definition
ROL_RegressionError.hpp:29
ROL::RegressionError::value
Real value(const std::vector< Real > &x, Real &tol)
Definition
ROL_RegressionError.hpp:39
ROL::StdObjective
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Definition
ROL_StdObjective.hpp:26
ROL
Definition
ROL_ElementwiseVector.hpp:27
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0