ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
algorithm
ROL_LinearRegression.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_LINEARREGRESSION_H
11
#define ROL_LINEARREGRESSION_H
12
13
#include "
ROL_RegressionError.hpp
"
14
#include "
ROL_SampleGenerator.hpp
"
15
#include "
ROL_StochasticObjective.hpp
"
16
#include "
ROL_ErrorMeasureFactory.hpp
"
17
#include "
ROL_OptimizationProblem.hpp
"
18
#include "ROL_Problem.hpp"
19
#include "
ROL_StdBoundConstraint.hpp
"
20
#include "
ROL_RiskBoundConstraint.hpp
"
21
28
29
30
namespace
ROL
{
31
32
template
<
class
Real>
33
class
LinearRegression
{
34
private
:
35
const
Ptr<RegressionError<Real>>
error_
;
36
const
Ptr<SampleGenerator<Real>>
data_
;
37
38
Ptr<RandVarFunctional<Real>>
em_
;
39
Ptr<StochasticObjective<Real>>
obj_
;
40
Ptr<std::vector<Real>>
cdata_
;
41
Ptr<RiskVector<Real>>
c_
;
42
43
Ptr<std::vector<Real>>
lower_
;
44
Ptr<std::vector<Real>>
upper_
;
45
Ptr<BoundConstraint<Real>>
bnd_
;
46
Ptr<RiskBoundConstraint<Real>>
rbnd_
;
47
48
bool
initialized_
;
49
50
public
:
51
LinearRegression
(
const
Ptr<
SampleGenerator<Real>
> &data)
52
:
error_
(makePtr<
RegressionError
<Real>>()),
data_
(data),
53
lower_
(nullPtr),
upper_
(nullPtr),
bnd_
(nullPtr),
rbnd_
(nullPtr),
54
initialized_
(false) {
55
int
dim
=
data_
->getMyPoint(0).size();
56
cdata_
= makePtr<std::vector<Real>>(
dim
,0);
57
c_
= makePtr<RiskVector<Real>>(makePtr<StdVector<Real>>(
cdata_
));
58
}
59
60
void
setErrorMeasure
(ROL::ParameterList &parlist,
bool
reset
=
false
) {
61
if
(!
initialized_
||
reset
) {
62
em_
=
ErrorMeasureFactory<Real>
(parlist);
63
obj_
= makePtr<StochasticObjective<Real>>(
error_
,
em_
,
data_
);
64
initialized_
=
true
;
65
}
66
}
67
68
void
setLowerBound
(
const
std::vector<Real> &lower) {
69
lower_
= makePtr<std::vector<Real>>(lower);
70
}
71
72
void
setUpperBound
(
const
std::vector<Real> &upper) {
73
upper_
= makePtr<std::vector<Real>>(upper);
74
}
75
76
void
reset
(
void
) {
77
c_
->zero();
78
initialized_
=
false
;
79
}
80
81
const
Ptr<OptimizationProblem<Real>>
getOptimizationProblem
(
void
) {
82
if
(!
initialized_
) {
83
throw
Exception::NotImplemented
(
"ROL::LinearRegression::getOptimizationProblem : setErrorMeasure was not called!"
);
84
}
85
if
(
lower_
!= nullPtr &&
upper_
== nullPtr) {
86
bnd_
= makePtr<StdBoundConstraint<Real>>(*
lower_
,
true
);
87
}
88
if
(
lower_
== nullPtr &&
upper_
!= nullPtr) {
89
bnd_
= makePtr<StdBoundConstraint<Real>>(*
upper_
,
false
);
90
}
91
if
(
lower_
!= nullPtr &&
upper_
!= nullPtr) {
92
bnd_
= makePtr<StdBoundConstraint<Real>>(*
lower_
,*
upper_
);
93
}
94
if
(
bnd_
!= nullPtr) {
95
rbnd_
= makePtr<RiskBoundConstraint<Real>>(
bnd_
);
96
return
makePtr<OptimizationProblem<Real>>(
obj_
,
c_
,
rbnd_
);
97
}
98
return
makePtr<OptimizationProblem<Real>>(
obj_
,
c_
);
99
}
100
101
const
Ptr<Problem<Real>>
getProblem
(
void
) {
102
if
(!
initialized_
) {
103
throw
Exception::NotImplemented
(
"ROL::LinearRegression::getProblem : setErrorMeasure was not called!"
);
104
}
105
Ptr<Problem<Real>> prob
106
= makePtr<Problem<Real>>(
obj_
,
c_
);
107
if
(
lower_
!= nullPtr &&
upper_
== nullPtr) {
108
bnd_
= makePtr<StdBoundConstraint<Real>>(*
lower_
,
true
);
109
}
110
if
(
lower_
== nullPtr &&
upper_
!= nullPtr) {
111
bnd_
= makePtr<StdBoundConstraint<Real>>(*
upper_
,
false
);
112
}
113
if
(
lower_
!= nullPtr &&
upper_
!= nullPtr) {
114
bnd_
= makePtr<StdBoundConstraint<Real>>(*
lower_
,*
upper_
);
115
}
116
if
(
bnd_
!= nullPtr) {
117
rbnd_
= makePtr<RiskBoundConstraint<Real>>(
bnd_
);
118
prob->addBoundConstraint(
rbnd_
);
119
}
120
return
prob;
121
}
122
123
const
Ptr<std::vector<Real>>
getCoefficients
(
void
)
const
{
124
return
cdata_
;
125
}
126
127
void
print
(std::ostream &out = std::cout,
const
std::string delim =
" "
)
const
{
128
int
dim
=
cdata_
->size();
129
out << std::endl;
130
for
(
int
i = 0; i <
dim
; ++i) {
131
out << delim << (*cdata_)[i];
132
}
133
out << std::endl << std::endl;
134
}
135
};
// class LinearRegression
136
137
}
// namespace ROL
138
139
#endif
ROL_ErrorMeasureFactory.hpp
ROL_OptimizationProblem.hpp
ROL_RegressionError.hpp
ROL_RiskBoundConstraint.hpp
ROL_SampleGenerator.hpp
ROL_StdBoundConstraint.hpp
Contains definitions for std::vector bound constraints.
ROL_StochasticObjective.hpp
ROL::Exception::NotImplemented
Definition
ROL_Types.hpp:884
ROL::LinearRegression::print
void print(std::ostream &out=std::cout, const std::string delim=" ") const
Definition
ROL_LinearRegression.hpp:127
ROL::LinearRegression::setUpperBound
void setUpperBound(const std::vector< Real > &upper)
Definition
ROL_LinearRegression.hpp:72
ROL::LinearRegression::setErrorMeasure
void setErrorMeasure(ROL::ParameterList &parlist, bool reset=false)
Definition
ROL_LinearRegression.hpp:60
ROL::LinearRegression::upper_
Ptr< std::vector< Real > > upper_
Definition
ROL_LinearRegression.hpp:44
ROL::LinearRegression::bnd_
Ptr< BoundConstraint< Real > > bnd_
Definition
ROL_LinearRegression.hpp:45
ROL::LinearRegression::data_
const Ptr< SampleGenerator< Real > > data_
Definition
ROL_LinearRegression.hpp:36
ROL::LinearRegression::rbnd_
Ptr< RiskBoundConstraint< Real > > rbnd_
Definition
ROL_LinearRegression.hpp:46
ROL::LinearRegression::c_
Ptr< RiskVector< Real > > c_
Definition
ROL_LinearRegression.hpp:41
ROL::LinearRegression::cdata_
Ptr< std::vector< Real > > cdata_
Definition
ROL_LinearRegression.hpp:40
ROL::LinearRegression::reset
void reset(void)
Definition
ROL_LinearRegression.hpp:76
ROL::LinearRegression::getOptimizationProblem
const Ptr< OptimizationProblem< Real > > getOptimizationProblem(void)
Definition
ROL_LinearRegression.hpp:81
ROL::LinearRegression::initialized_
bool initialized_
Definition
ROL_LinearRegression.hpp:48
ROL::LinearRegression::em_
Ptr< RandVarFunctional< Real > > em_
Definition
ROL_LinearRegression.hpp:38
ROL::LinearRegression::setLowerBound
void setLowerBound(const std::vector< Real > &lower)
Definition
ROL_LinearRegression.hpp:68
ROL::LinearRegression::error_
const Ptr< RegressionError< Real > > error_
Definition
ROL_LinearRegression.hpp:35
ROL::LinearRegression::getProblem
const Ptr< Problem< Real > > getProblem(void)
Definition
ROL_LinearRegression.hpp:101
ROL::LinearRegression::lower_
Ptr< std::vector< Real > > lower_
Definition
ROL_LinearRegression.hpp:43
ROL::LinearRegression::LinearRegression
LinearRegression(const Ptr< SampleGenerator< Real > > &data)
Definition
ROL_LinearRegression.hpp:51
ROL::LinearRegression::obj_
Ptr< StochasticObjective< Real > > obj_
Definition
ROL_LinearRegression.hpp:39
ROL::LinearRegression::getCoefficients
const Ptr< std::vector< Real > > getCoefficients(void) const
Definition
ROL_LinearRegression.hpp:123
ROL::RegressionError
Provides the interface to evaluate linear regression error.
Definition
ROL_RegressionError.hpp:27
ROL::SampleGenerator
Definition
ROL_SampleGenerator.hpp:20
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ErrorMeasureFactory
Ptr< RandVarFunctional< Real > > ErrorMeasureFactory(ParameterList &parlist)
Definition
ROL_ErrorMeasureFactory.hpp:111
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0