Skip to content

Commit 12af778

Browse files
authored
Merge pull request #313 from godardma/adding_peibos
[functions] final patch for parallelepiped_eval
2 parents 37176ca + 8809806 commit 12af778

6 files changed

Lines changed: 20 additions & 62 deletions

File tree

src/core/domains/zonotope/codac2_Parallelepiped.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "codac2_Parallelepiped.h"
1111
#include "codac2_inversion.h"
1212

13-
using namespace std;
1413
using namespace codac2;
1514

1615
Parallelepiped::Parallelepiped(const Vector& z_, const Matrix& A_)
@@ -19,7 +18,7 @@ Parallelepiped::Parallelepiped(const Vector& z_, const Matrix& A_)
1918
assert_release(A.cols() <= z.size() && "too many vectors, you are describing a zonotope");
2019
}
2120

22-
void generate_vertices(Index i, Index n, const Vector& z, const Matrix& A, vector<Vector>& L_v)
21+
void generate_vertices(Index i, Index n, const Vector& z, const Matrix& A, std::vector<Vector>& L_v)
2322
{
2423
if (i == n)
2524
{
@@ -34,7 +33,7 @@ void generate_vertices(Index i, Index n, const Vector& z, const Matrix& A, vecto
3433

3534
std::vector<Vector> Parallelepiped::vertices() const
3635
{
37-
vector<Vector> L_v;
36+
std::vector<Vector> L_v;
3837
generate_vertices(0, z.size(),z,A,L_v);
3938
return L_v;
4039
}

src/core/domains/zonotope/codac2_Zonotope.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "codac2_Zonotope.h"
1111

12-
using namespace std;
1312
using namespace codac2;
1413

1514
Zonotope::Zonotope(const Vector& z_, const Matrix& A_)

src/core/peibos/codac2_peibos.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "codac2_peibos_tools.h"
1212
#include "codac2_OctaSym_operator.h"
1313

14-
using namespace std;
1514
using namespace codac2;
1615

1716
namespace codac2
@@ -34,12 +33,12 @@ namespace codac2
3433
return Parallelepiped(z, A_inf);
3534
}
3635

37-
vector<Parallelepiped> PEIBOS(const AnalyticFunction<VectorType>& f, const AnalyticFunction<VectorType>& psi_0, const vector<OctaSym>& Sigma, double epsilon, bool verbose)
36+
std::vector<Parallelepiped> PEIBOS(const AnalyticFunction<VectorType>& f, const AnalyticFunction<VectorType>& psi_0, const std::vector<OctaSym>& Sigma, double epsilon, bool verbose)
3837
{
3938
return PEIBOS(f, psi_0, Sigma, epsilon, Vector::zero(psi_0.output_size()), verbose);
4039
}
4140

42-
vector<Parallelepiped> PEIBOS(const AnalyticFunction<VectorType>& f, const AnalyticFunction<VectorType>& psi_0, const vector<OctaSym>& Sigma, double epsilon, const Vector& offset, bool verbose)
41+
std::vector<Parallelepiped> PEIBOS(const AnalyticFunction<VectorType>& f, const AnalyticFunction<VectorType>& psi_0, const std::vector<OctaSym>& Sigma, double epsilon, const Vector& offset, bool verbose)
4342
{
4443
Index m = psi_0.input_size();
4544

@@ -50,9 +49,9 @@ namespace codac2
5049

5150
clock_t t_start = clock();
5251

53-
vector<Parallelepiped> output;
52+
std::vector<Parallelepiped> output;
5453

55-
vector<IntervalVector> boxes;
54+
std::vector<IntervalVector> boxes;
5655
double true_eps = split(IntervalVector::constant(m,{-1,1}), epsilon, boxes);
5756

5857
for (const auto& sigma : Sigma)

src/core/peibos/codac2_peibos_tools.cpp

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
*/
99

1010
#include "codac2_peibos_tools.h"
11+
#include "codac2_template_tools.h"
1112
#include "codac2_inversion.h"
1213
#include "codac2_IntvFullPivLU.h"
1314

14-
#include <iostream>
15-
16-
using namespace std;
1715
using namespace codac2;
1816

1917
namespace codac2
2018
{
21-
double split (const IntervalVector& X, double eps, vector<IntervalVector>& boxes)
19+
double split (const IntervalVector& X, double eps, std::vector<IntervalVector>& boxes)
2220
{
2321
if (X.max_diam()<=eps)
2422
{
@@ -58,25 +56,24 @@ namespace codac2
5856
Index m = A.cols();
5957
Index n = A.rows();
6058

61-
IntervalMatrix A_int (A);
62-
63-
IntvFullPivLU LUdec((IntervalMatrix) A_int.transpose());
59+
IntvFullPivLU LUdec((Matrix) A.transpose());
6460
IntervalMatrix N = LUdec.kernel();
6561

66-
vector<int> col_indices;
62+
std::vector<int> col_indices;
6763

6864
for (int i = 0; i < m; i++)
6965
if (! (A.col(i).isZero()) )
7066
col_indices.push_back(i);
7167

72-
// A_reduced is composed of the non empty vectors of A_int
73-
IntervalMatrix A_reduced (n, col_indices.size());
68+
// A_reduced is composed of the non empty vectors of A
69+
70+
Matrix A_reduced (n, col_indices.size());
7471
for (int i = 0; i < (int) col_indices.size(); i++)
75-
A_reduced.col(i) = A_int.col(col_indices[i]);
72+
A_reduced.col(i) = A.col(col_indices[i]);
7673

7774
// Construct the new matrix A_tild = [A_reduced | N]
78-
IntervalMatrix A_tild (n,n);
79-
A_tild << A_reduced,N;
75+
Matrix A_tild (n,n);
76+
A_tild << A_reduced,N.mid();
8077

8178
IntervalMatrix Q = inverse_enclosure(A_tild.transpose() * A_tild);
8279

@@ -87,42 +84,7 @@ namespace codac2
8784
for (int i = 0; i < m; i++)
8885
mult(i,i) += e_vec(i);
8986

90-
// From here we have an IntervalMatrix A_inf, meaning that each generator is an interval vector
91-
IntervalMatrix A_inf = A_tild * mult;
92-
93-
// The initial parallelepiped is <y> = Y*[-1,1]^n
94-
Matrix Y = A_inf.smig();
95-
96-
// The following is similar to the previous operations. The difference is that here the Matrix Y is square and not interval
97-
98-
// rho2 is the sum of the radiuses of the circle enclosing each interval generator
99-
Interval rho2 (0.);
100-
101-
for (int i = 0; i < n; i++)
102-
rho2 += A_inf.col(i).rad().norm();
103-
104-
IntervalMatrix M = Y.transpose() * Y;
105-
106-
double eps = 1e-10 * M.norm().ub();
107-
double cond_Y = condition_number(Y);
108-
109-
if (cond_Y>1e10)
110-
{
111-
cerr << "Warning: ill-conditioned matrix in the inflate process. The result may not be guaranteed " << endl;
112-
M += IntervalMatrix::Identity(n,n)*eps; // if Y is ill-conditioned, we add a small term to M to make it invertible
113-
}
114-
115-
IntervalMatrix Q2 = inverse_enclosure(M);
116-
117-
IntervalMatrix Y2 = IntervalMatrix::zero(n,n);
118-
119-
Interval factor = sqrt(1.0 + eps * cond_Y);
120-
for (int i = 0; i < n; i++)
121-
if (cond_Y>1e10)
122-
Y2.col(i) = Y.col(i)*(1+rho2*sqrt(Q2(i,i))*factor); // sufficient to keep the guarantee ?
123-
else
124-
Y2.col(i) = Y.col(i)*(1+rho2*sqrt(Q2(i,i)));
125-
126-
return Y2.smag();
87+
return ((A_tild.template cast<Interval>()) * mult).smag();
12788
}
89+
12890
}

tests/core/domains/zonotope/codac2_tests_Parallelepiped_eval.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ TEST_CASE("Parallelepiped_eval")
3636
auto pa = f2.parallelepiped_eval(Interval(-0.1,0.1), Interval(-0.1,0.1));
3737
auto pb = f2.parallelepiped_eval(1.0, Interval(-1,1));
3838

39-
4039
CHECK(Approx(pa.z,1e-6) == Vector({0,0,0}));
4140
CHECK(Approx(pa.A,1e-6) == Matrix({{0.14,0,0},{0,0.14,0},{0,0,0.04}}));
4241
CHECK(Approx(pb.z,1e-6) == Vector({1,0,1}));
43-
CHECK(Approx(pb.A,1e-5) == Matrix({{0.894428,0,1.78886},{0,3.00001,0},{1.78886,0,-0.894427}}));
42+
CHECK(Approx(pb.A,1e-5) == Matrix({{0.894428,0,1.78886},{0,3,0},{1.78886,0,-0.894427}}));
4443

4544

4645
double dx = 0.4;

tests/core/domains/zonotope/codac2_tests_Parallelepiped_eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_parallelepiped_eval(self):
3838
self.assertTrue(Approx(pa.z,1e-6)==Vector([0,0,0]))
3939
self.assertTrue(Approx(pa.A,1e-6)==Matrix([[0.14,0,0],[0,0.14,0],[0,0,0.04]]))
4040
self.assertTrue(Approx(pb.z,1e-6)==Vector([1,0,1]))
41-
self.assertTrue(Approx(pb.A,1e-5)==Matrix([[0.894428,0,1.78886],[0,3.00001,0],[1.78886,0,-0.894427]]))
41+
self.assertTrue(Approx(pb.A,1e-5)==Matrix([[0.894428,0,1.78886],[0,3,0],[1.78886,0,-0.894427]]))
4242

4343

4444
dx = 0.4

0 commit comments

Comments
 (0)