void Interface::search() //Allows user to search by name or check wich scientist were alice wich year { int userChoice,year; string name; cout << "Search options" << endl; cout << "Choose one of the following numbers:" << endl; cout << "------------------------------------" << endl; cout << "1 to search by name" << endl; cout << "2 to check which of the computer scientists were alive the chosen year" << endl; cin >> userChoice; switch (userChoice) { case 1: cout << "What name would you like to search?" << endl; cin >> name; sl.findByName(name); break; case 2: cout << "What year would you like to search?" << endl; cin >> year; displayVector(sl.findByYear(year)); //Displays the vector with whom were alive that year default: break; } }
void simulator::displayInfo() { coutline(40); cout<<" === SIMULATOR INFO ==="<<endl; cout << "Population size: "<<_indiv.size()<<endl; cout << "# E compartments: " << _nE <<endl; cout << "# I compartments: " << _nI <<endl; cout << "sigma rates:"; displayVector(_sigma); cout << "gamma rates:"; displayVector(_gamma); double R0 = _beta/_gamma[0]*_nI; cout << "R0 = "<<R0<<endl; cout << "Number of events: "<<_time.size()<<endl; cout << "Last date: "<<_time[_time.size()-1]<<endl; cout << "Cumul incidence: "<<_cumIncidence[_cumIncidence.size()-1]<<endl; coutline(40); }
int main(int argc, char **argv) { std::fstream fp; std::vector<int> numbers; int number; fp.open(argv[1], std::ios::in ); std::ofstream myfile; myfile.open (argv[2]); if(fp.is_open()){ while(fp >> number){ numbers.push_back(number); fp.get(); } } fp.close(); // before sort std::cout << "Numbers:\n"; displayVector(numbers); // Sort the values sortVector(numbers); //after sort displayVector(numbers); if (std::binary_search (numbers.begin(), numbers.end(), 5)) std::cout << "The number 5 was found!\n"; else std::cout << "not found.\n"; //myfile << displayVector(numbers); myfile.close(); return 0; }
void computeConsistentRotations_L1(double const sigma, int const nIterations, int const nViews, std::vector<Matrix3x3d> const& relativeRotations, std::vector<std::pair<int, int> > const& viewPairs, std::vector<Matrix3x3d>& rotations) { double const gamma = 1.0; int const nRelPoses = relativeRotations.size(); rotations.resize(nViews); Matrix3x3d zero3x3d; makeZeroMatrix(zero3x3d); Matrix4x4d zeroQuat; makeZeroMatrix(zeroQuat); zeroQuat[0][0] = 1; vector<double> denomQ(nViews, 1.0); // from the psd constraint for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; denomQ[i] += 1; denomQ[j] += 1; } for (int i = 0; i < nViews; ++i) denomQ[i] = 1.0 / denomQ[i]; vector<double> T(nRelPoses, 0.0); vector<double> T1(nRelPoses); vector<double> ZT1(nRelPoses, 0.0); vector<double> T2(nRelPoses); vector<double> ZT2(nRelPoses, 0.0); vector<Matrix4x4d> Q(nViews, zeroQuat); vector<Matrix4x4d> Q1(nViews, zeroQuat); vector<Matrix4x4d> ZQ1(nViews, zeroQuat); vector<Matrix4x4d> Q2i(nRelPoses, zeroQuat); vector<Matrix4x4d> Q2j(nRelPoses, zeroQuat); vector<Matrix4x4d> ZQ2i(nRelPoses, zeroQuat); vector<Matrix4x4d> ZQ2j(nRelPoses, zeroQuat); vector<Matrix3x3d> A(nRelPoses, zero3x3d); vector<Matrix3x3d> A1(nRelPoses, zero3x3d); vector<Matrix3x3d> A2(nRelPoses, zero3x3d); vector<Matrix3x3d> ZA1(nRelPoses, zero3x3d); vector<Matrix3x3d> ZA2(nRelPoses, zero3x3d); for (int iter = 0; iter < nIterations; ++iter) { // Convex hull of rotation matrices for (int i = 0; i < nViews; ++i) { Matrix4x4d q = Q[i] + ZQ1[i]; projectConvHull_SO3(q); Q1[i] = q; addMatricesIP(Q[i] - q, ZQ1[i]); } // end for (i) // Shrinkage of T (we want to minimize T) for (int k = 0; k < nRelPoses; ++k) { T2[k] = std::max(0.0, T[k] + ZT2[k] - gamma); ZT2[k] += T[k] - T2[k]; } // end for (k) // Cone constraint for (int k = 0; k < nRelPoses; ++k) { double t = T1[k] + ZT1[k]; Matrix3x3d a = A[k] + ZA1[k]; proxDataResidual_Frobenius(sigma, t, a); T1[k] = t; ZT1[k] += T[k] - t; A1[k] = a; addMatricesIP(A[k] - a, ZA1[k]); } // end for (k) // Enforce linear consistency for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; Matrix4x4d qi = Q[i] + ZQ2i[k]; Matrix4x4d qj = Q[j] + ZQ2j[k]; Matrix3x3d a = A[k] + ZA2[k]; proxConsistency(relativeRotations[k], qi, qj, a); Q2i[k] = qi; Q2j[k] = qj; A2[k] = a; addMatricesIP(Q[i] - qi, ZQ2i[k]); addMatricesIP(Q[j] - qj, ZQ2j[k]); addMatricesIP(A[k] - a, ZA2[k]); } // end for (k) // Averaging of the solutions for (int i = 0; i < nViews; ++i) Q[i] = Q1[i] - ZQ1[i]; for (int k = 0; k < nRelPoses; ++k) T[k] = std::max(0.0, 0.5 * (T1[k] - ZT1[k] + T2[k] - ZT2[k])); for (int k = 0; k < nRelPoses; ++k) A[k] = A1[k] - ZA1[k]; for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; addMatricesIP(Q2i[k] - ZQ2i[k], Q[i]); addMatricesIP(Q2j[k] - ZQ2j[k], Q[j]); addMatricesIP(A2[k] - ZA2[k], A[k]); } // end for (k) for (int i = 0; i < nViews; ++i) scaleMatrixIP(denomQ[i], Q[i]); for (int k = 0; k < nRelPoses; ++k) scaleMatrixIP(0.5, A[k]); if ((iter % 500) == 0) { cout << "iter: " << iter << endl; cout << " T = "; displayVector(T); } } // end for (iter) rotations.resize(nViews); for (int i = 0; i < nViews; ++i) rotations[i] = getRotationFromQuat(Q[i]); } // end computeConsistentRotations_L1()
void computeConsistentRotations_Linf(double const sigma, int const nIterations, int const nViews, std::vector<Matrix3x3d> const& relativeRotations, std::vector<std::pair<int, int> > const& viewPairs, std::vector<Matrix3x3d>& rotations, std::vector<double>& zs) { double const gamma = 1.0; int const nRelPoses = relativeRotations.size(); rotations.resize(nViews); Matrix3x3d zero3x3d; makeZeroMatrix(zero3x3d); Matrix4x4d zeroQuat; makeZeroMatrix(zeroQuat); zeroQuat[0][0] = 1; double const denomT = 1.0 / (1.0 + nRelPoses); vector<double> denomQ(nViews, 1.0); // from the psd constraint for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; denomQ[i] += 1; denomQ[j] += 1; } for (int i = 0; i < nViews; ++i) denomQ[i] = 1.0 / denomQ[i]; double T = 0.0; vector<double> T1(nRelPoses); vector<double> ZT1(nRelPoses, 0.0); double T2; double ZT2 = 0; vector<Matrix4x4d> Q(nViews, zeroQuat); vector<Matrix4x4d> Q1(nViews, zeroQuat); vector<Matrix4x4d> ZQ1(nViews, zeroQuat); vector<Matrix4x4d> Q2i(nRelPoses, zeroQuat); vector<Matrix4x4d> Q2j(nRelPoses, zeroQuat); vector<Matrix4x4d> ZQ2i(nRelPoses, zeroQuat); vector<Matrix4x4d> ZQ2j(nRelPoses, zeroQuat); vector<Matrix3x3d> A(nRelPoses, zero3x3d); vector<Matrix3x3d> A1(nRelPoses, zero3x3d); vector<Matrix3x3d> A2(nRelPoses, zero3x3d); vector<Matrix3x3d> ZA1(nRelPoses, zero3x3d); vector<Matrix3x3d> ZA2(nRelPoses, zero3x3d); for (int iter = 0; iter < nIterations; ++iter) { // Convex hull of rotation matrices for (int i = 0; i < nViews; ++i) { Matrix4x4d q = Q[i] + ZQ1[i]; if (i > 0) projectConvHull_SO3(q); else { makeZeroMatrix(q); q[0][0] = 1; } Q1[i] = q; addMatricesIP(Q[i] - q, ZQ1[i]); } // end for (i) // Shrinkage of T (we want to minimize T) T2 = std::max(0.0, T + ZT2 - gamma); ZT2 += T - T2; // Cone constraint for (int k = 0; k < nRelPoses; ++k) { double t = T + ZT1[k]; Matrix3x3d a = A[k] + ZA1[k]; proxDataResidual_Frobenius(sigma, t, a); T1[k] = t; ZT1[k] += T - t; A1[k] = a; addMatricesIP(A[k] - a, ZA1[k]); } // end for (k) // Enforce linear consistency for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; Matrix4x4d qi = Q[i] + ZQ2i[k]; Matrix4x4d qj = Q[j] + ZQ2j[k]; Matrix3x3d a = A[k] + ZA2[k]; proxConsistency(relativeRotations[k], qi, qj, a); Q2i[k] = qi; Q2j[k] = qj; A2[k] = a; addMatricesIP(Q[i] - qi, ZQ2i[k]); addMatricesIP(Q[j] - qj, ZQ2j[k]); addMatricesIP(A[k] - a, ZA2[k]); } // end for (k) // Averaging of the solutions for (int i = 0; i < nViews; ++i) Q[i] = Q1[i] - ZQ1[i]; T = T2 - ZT2; for (int k = 0; k < nRelPoses; ++k) T += T1[k] - ZT1[k]; T *= denomT; T = std::max(0.0, T); for (int k = 0; k < nRelPoses; ++k) A[k] = A1[k] - ZA1[k]; for (int k = 0; k < nRelPoses; ++k) { int const i = viewPairs[k].first; int const j = viewPairs[k].second; addMatricesIP(Q2i[k] - ZQ2i[k], Q[i]); addMatricesIP(Q2j[k] - ZQ2j[k], Q[j]); addMatricesIP(A2[k] - ZA2[k], A[k]); } // end for (k) for (int i = 0; i < nViews; ++i) scaleMatrixIP(denomQ[i], Q[i]); for (int k = 0; k < nRelPoses; ++k) scaleMatrixIP(0.5, A[k]); if ((iter % 500) == 0) { cout << "iter: " << iter << " t = " << T << endl; cout << "T1 = "; displayVector(T1); cout << "ZT1 = "; displayVector(ZT1); cout << "T2 = " << T2 << " ZT2 = " << ZT2 << endl; Matrix<double> ZZ(4, 4); for (int i = 0; i < nViews; ++i) { copyMatrix(Q[i], ZZ); SVD<double> svd(ZZ); cout << "Q = "; displayMatrix(ZZ); cout << "SV = "; displayVector(svd.getSingularValues()); //Matrix3x3d R = getRotationFromQuat(Q[i]); //cout << "R = "; displayMatrix(R); } // end for (i) } } // end for (iter) rotations.resize(nViews); for (int i = 0; i < nViews; ++i) rotations[i] = getRotationFromQuat(Q[i]); zs = ZT1; } // end computeConsistentRotations_Linf()