#include <MathAlgo/LeastSquares.hh>
#include <Base/Math/Random.hh>
#include <Base/Debug/TimeMeasure.hh>
using namespace BIAS;
using namespace std;
double sigma=5.0;
{
for (unsigned i=0; i<solsize; i++){
}
for (unsigned i=0; i<solsize*numeq; i++){
}
b=A*sol;
for (unsigned i=0; i<numeq; i++){
}
for (unsigned i=0; i<numeq; i++){
}
}
{
double sum=0.0;
for (unsigned i=0; i<solsize; i++){
sum+=sol[i]*sol[i];
}
sum=sqrt(sum);
for (unsigned i=0; i<solsize; i++){
sol[i]/=sum;
}
for (unsigned r=0; r<numeq; r++){
sum=0.0;
for (unsigned c=0; c<solsize-1; c++){
sum+=A[r][c]*sol[c];
}
A[r][solsize-1]=-sum/sol[solsize-1];
}
for (unsigned r=0; r<numeq; r++){
for (unsigned c=0; c<solsize-1; c++){
}
}
for (unsigned i=0; i<numeq; i++){
}
}
{
cout << "solution: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<<sol[i] << " "; }
cout << endl;
if (lsla.
Solve(A, b, x)==0){
cout << "lapack sol: ";
for (unsigned i=0; i<solsize; i++) { cout<<setw(15)<<x[i]<<" "; }
cout <<endl;
}
if (lssvd.
Solve(A, b, x)==0){
cout << "svd sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
}
{
cout << "solution: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< sol[i] << " "; }
cout << endl;
cout << "lapack sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
cout << "svd sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
}
{
cout << "solution: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<<sol[i] << " "; }
cout << endl;
if (lsla.
Solve(A, x)==0){
cout << "lapack sol: ";
for (unsigned i=0; i<solsize; i++) { cout<<setw(15)<<x[i]<<" "; }
cout <<endl;
}
if (lssvd.
Solve(A, x)==0){
cout << "svd sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
}
{
cout << "solution: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< sol[i] << " "; }
cout << endl;
cout << "lapack sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
cout << "svd sol: ";
for (unsigned i=0; i<solsize; i++) { cout <<setw(15)<< x[i] << " "; }
cout <<endl;
}
}
int main()
{
unsigned solsize=5, numeq=10;
GetSystem(A, b, weight, sol, solsize, numeq);
lsla.
Init(solsize,
true);
lssvd.
Init(solsize,
true);
cout << "\nno weights, reduction to ATA, Ax=b\n";
TestNoWeightAxb(A, b, sol, solsize, lsla, lssvd);
cout << "\nweights, reduction to ATA, Ax=b\n";
TestWeightAxb(A, b, weight, sol, solsize, lsla, lssvd);
lsla.
Init(solsize,
false);
lssvd.
Init(solsize,
false);
cout << "\nno weights, no reduction to ATA, Ax=b\n";
TestNoWeightAxb(A, b, sol, solsize, lsla, lssvd);
cout << "\nweights, no reduction to ATA, Ax=b\n";
TestWeightAxb(A, b, weight, sol, solsize, lsla, lssvd);
GetSystem(A, weight, sol, solsize, numeq);
lsla.
Init(solsize,
true);
lssvd.
Init(solsize,
true);
cout << "\nno weights, reduction to ATA, Ax=0\n";
TestNoWeightAx(A, sol, solsize, lsla, lssvd);
cout << "\nweights, reduction to ATA, Ax=0\n";
TestWeightAx(A, weight, sol, solsize, lsla, lssvd);
lsla.
Init(solsize,
false);
lssvd.
Init(solsize,
false);
cout << "\nno weights, no reduction to ATA, Ax=0\n";
TestNoWeightAx(A, sol, solsize, lsla, lssvd);
cout << "\nweights, no reduction to ATA, Ax=0\n";
TestWeightAx(A, weight, sol, solsize, lsla, lssvd);
return 0;
}