41 bool fpEqual(
double a,
double b,
double tol,
bool check_relative_also) {
59 else if(a == 0 || b == 0 || (
abs(a) +
abs(b)) < DOUBLE_MIN_NORMAL) {
60 return abs(a-b) <= tol * DOUBLE_MIN_NORMAL;
64 else if (
abs(a - b) <= tol) {
68 else if (
abs(a - b) <=
70 check_relative_also) {
83 for(
size_t i=0;
i<
n;
i++) {
84 stream << setprecision(9) <<
v(
i) << (
i<n-1 ?
"; " :
"");
86 stream <<
"];" << endl;
104 if (vec1.size() != vec2.size())
return false;
105 size_t m = vec1.size();
106 for(
size_t i=0;
i<
m;
i++)
107 if(vec1[
i] != vec2[
i])
114 size_t m = vec1.size();
115 for(
size_t i=0;
i<
m;
i++)
116 if(!(vec1[
i] >= vec2[
i]))
123 if (vec1.size()!=vec2.size())
return false;
124 size_t m = vec1.size();
125 for(
size_t i=0;
i<
m; ++
i) {
126 if (!
fpEqual(vec1[
i], vec2[i], tol))
134 if (vec1.size()!=vec2.size())
return false;
135 size_t m = vec1.size();
136 for(
size_t i=0;
i<
m; ++
i) {
137 if (!
fpEqual(vec1[
i], vec2[i], tol))
146 cout <<
"not equal:" << endl;
147 print(expected,
"expected");
148 print(actual,
"actual");
155 cout <<
"Erroneously equal:" << endl;
156 print(expected,
"expected");
157 print(actual,
"actual");
164 cout <<
"not equal:" << endl;
165 print(static_cast<Vector>(expected),
"expected");
166 print(static_cast<Vector>(actual),
"actual");
173 cout <<
"not equal:" << endl;
181 if (vec1.size()!=vec2.size())
return false;
182 bool flag =
false;
double scale = 1.0;
183 size_t m = vec1.size();
184 for(
size_t i=0;
i<
m;
i++) {
187 if(vec1[i] == 0 && vec2[i] == 0)
continue;
189 scale = vec1[
i] / vec2[
i];
192 else if (
std::abs(vec1[i] - vec2[i]*scale) > tol)
return false;
200 assert (b.size()==a.size());
202 for(
size_t i = 0;
i <
n;
i++ ) {
203 const double &ai =
a(
i), &bi =
b(
i);
204 c(
i) = (bi==0.0 && ai==0.0) ? 0.0 : ai/bi;
212 const double x0 =
v(0);
213 const double x02 = x0*
x0;
216 const double sigma = v.squaredNorm() - x02;
223 double mu =
sqrt(x02 + sigma);
227 v(0) = -sigma / (x0 +
mu);
229 const double v02 =
v(0)*
v(0);
231 return 2.0 * v02 / (sigma + v02);
239 return make_pair(beta, v);
248 size_t m = weights.size();
249 static const double inf = std::numeric_limits<double>::infinity();
253 for (
size_t i = 0;
i <
m; ++
i) isZero.push_back(
std::abs(a[
i]) < 1
e-9);
256 for (
size_t i = 0; i <
m; ++
i) {
257 if (weights[i] == inf && !isZero[i]) {
261 pseudo = Vector::Unit(m,i)*(1.0/a[
i]);
269 for (
size_t i = 0; i <
m; i++) {
272 precision += weights[
i] * (ai * ai);
276 if (precision < 1
e-9)
277 for (
size_t i = 0; i <
m; i++)
282 for (
size_t i = 0; i <
m; i++)
283 pseudo[i] = isZero[i] ? 0 : variance * weights[i] * a[i];
294 throw invalid_argument(
"a and weights have different sizes!");
297 return make_pair(pseudo, precision);
303 for (
const Vector&
v : vs) dim +=
v.size();
308 for (
int d = 0;
d <
v.size();
d++) A(
d + index) =
v(
d);
320 va_start(ap, nrVectors);
321 for(
size_t i = 0 ;
i < nrVectors ;
i++) {
bool linear_dependent(const Vector &vec1, const Vector &vec2, double tol)
Vector ediv_(const Vector &a, const Vector &b)
std::ofstream out("Result.txt")
bool assert_equal(const ConstSubVector &expected, const ConstSubVector &actual, double tol)
bool greaterThanOrEqual(const Vector &vec1, const Vector &vec2)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
bool equal_with_abs_tol(const SubVector &vec1, const SubVector &vec2, double tol)
bool assert_inequal(const Vector &expected, const Vector &actual, double tol)
ptrdiff_t DenseIndex
The index type for Eigen objects.
bool fpEqual(double a, double b, double tol, bool check_relative_also)
void print(const Vector &v, const string &s)
void save(const Vector &v, const string &s, const string &filename)
Expression of a fixed-size or dynamic-size sub-vector.
pair< double, Vector > house(const Vector &x)
pair< Vector, double > weightedPseudoinverse(const Vector &a, const Vector &weights)
Array< int, Dynamic, 1 > v
Array< double, 1, 3 > e(1./3., 0.5, 2.)
bool operator==(const Vector &vec1, const Vector &vec2)
Vector concatVectors(size_t nrVectors,...)
typedef and functions to augment Eigen's VectorXd
double houseInPlace(Vector &v)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
static const double sigma
Jet< T, N > sqrt(const Jet< T, N > &f)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector