-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension-vector-2.h
148 lines (116 loc) · 3.62 KB
/
extension-vector-2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iRRAM/core.h>
namespace iRRAM {
template <typename... P>
FUNCTION<std::vector<REAL>,P...> lipschitzify(
const FUNCTION<FUNCTION<std::vector<REAL>,P...>,std::vector<REAL>> &f,
const FUNCTION<REAL,std::vector<REAL>,P...> &lip_f,
const FUNCTION<LAZY_BOOLEAN,std::vector<REAL>> &on_domain,
const std::vector<REAL> &x
) {
single_valued code_1;
if (!on_domain(x))
iRRAM_REITERATE(0);
std::vector<REAL> x_new(x.size());
sizetype arg_error;
{
sizetype_exact(arg_error);
for (unsigned int i=0;i<x.size();i++) {
sizetype x_error;
DYADIC x_center;
x[i].to_formal_ball(x_center,x_error);
x_new[i]=x_center;
sizetype_max(arg_error,x_error,arg_error);
}
}
cerr << "starting function lipschitz_maxnorm\n";
FUNCTION<std::vector<REAL>,P...> fl;
{
// stiff code_2;
fl = f(x_new);
}
return from_algorithm(
std::function<std::vector<REAL>(const P &...)>(
[fl,lip_f,arg_error,x](const P &... p)
{
single_valued code_1;
REAL lip_bound = lip_f(x,p...);
std::vector<REAL> lip_result;
{
// stiff code_2;
lip_result = fl(p...);
}
sizetype lip_error,lip_size;
lip_bound.getsize(lip_size);
sizetype_mult(lip_error,lip_size,arg_error);
for (unsigned int i=0;i<lip_result.size();i++) {
lip_result[i].adderror(lip_error);
}
return lip_result;
}
)
);
}
std::vector<REAL> lipschitz_maxnorm (
const FUNCTION<std::vector<REAL>,std::vector<REAL> >& f,
const FUNCTION<REAL,std::vector<REAL>>& lip_f,
const FUNCTION<LAZY_BOOLEAN,std::vector<REAL>>& on_domain,
const std::vector<REAL>& x)
/*
* lipschitz_maxnorm(f,lip_f,on_domain,x) computes f(x) with an optimized algorithm,
* with reduced error propagation
* lip_f: Lipschitz-bound valid for f whereever on_domain(x)=true,
* based on the maximum norm
* on_domain: total, multi-valued with property: on_domain(x)=TRUE => x \in domain(f)
*/
{
single_valued code_1;
if (!on_domain(x))
iRRAM_REITERATE(0);
REAL lip_bound=lip_f(x);
stiff code_2;
std::vector<REAL> x_new(x.size());
sizetype arg_error;
sizetype_exact(arg_error);
{
sizetype x_error;
DYADIC x_center;
for (unsigned int i=0;i<x.size();i++){
x[i].to_formal_ball(x_center,x_error);
x_new[i]=x_center;
sizetype_max(arg_error,x_error,arg_error);
}
}
cerr << "starting function lipschitz_maxnorm\n";
std::vector<REAL> lip_result = f(x_new);
sizetype lip_error,lip_size;
lip_bound.getsize(lip_size);
sizetype_mult(lip_error,lip_size,arg_error);
for (unsigned int i=0;i<lip_result.size();i++){
lip_result[i].adderror(lip_error);
}
// {
// lip_result.geterror(lip_error);
// fprintf(stderr,"end of lipschitz_new with error %d*2^(%d)\n",
// lip_error.mantissa,lip_error.exponent);
// fprintf(stderr," for argument with error %d*2^(%d)\n",
// x_error.mantissa,x_error.exponent);
// }
return lip_result;
}
std::vector<REAL> lipschitz_maxnorm (
const FUNCTION<std::vector<REAL>,std::vector<REAL> >& f,
const REAL& lip_c,
const FUNCTION<LAZY_BOOLEAN,std::vector<REAL>>& on_domain,
const std::vector<REAL>& x){
return lipschitz_maxnorm(f,from_value<REAL,std::vector<REAL>>(lip_c),on_domain,x);
//return lipschitzify(f,from_value<REAL,std::vector<REAL>>(lip_c),on_domain,x)();
}
// FUNCTION<vector<REAL>, vector<REAL> > lipschitz_maxnorm (
// const FUNCTION<vector<REAL>,vector<REAL> >& f,
// const FUNCTION<vector<REAL>,REAL>& lip_f,
// const FUNCTION<vector<REAL>,LAZY_BOOLEAN>& on_domain){
//
// FUNCTION<vector<REAL>, vector<REAL> > g;
// return g;
// }
} /* ! namespace iRRAM */