本文整理汇总了C++中MatrixXi类的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXi类的具体用法?C++ MatrixXi怎么用?C++ MatrixXi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MatrixXi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: color_intersections
void color_intersections(
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXd & U,
const Eigen::MatrixXi & G,
Eigen::MatrixXd & C,
Eigen::MatrixXd & D)
{
using namespace igl;
using namespace igl::cgal;
using namespace Eigen;
MatrixXi IF;
const bool first_only = false;
intersect_other(V,F,U,G,first_only,IF);
C.resize(F.rows(),3);
C.col(0).setConstant(0.4);
C.col(1).setConstant(0.8);
C.col(2).setConstant(0.3);
D.resize(G.rows(),3);
D.col(0).setConstant(0.4);
D.col(1).setConstant(0.3);
D.col(2).setConstant(0.8);
for(int f = 0;f<IF.rows();f++)
{
C.row(IF(f,0)) = RowVector3d(1,0.4,0.4);
D.row(IF(f,1)) = RowVector3d(0.8,0.7,0.3);
}
}
示例2: configure
void NeighbourJoining::configure(const MatrixXf& D, MatrixXf& currentD, MatrixXi& rowsID, int numOccupiedNodes) {
numObservableNodes = rowsID.rows();
numCurrentNodes = numObservableNodes;
//allocates memory for the latent nodes
rowsID.conservativeResize((2 * numObservableNodes - 2), 1);
//gives latent nodes IDs
for (int i = numObservableNodes; i < 2 * numObservableNodes - 2; ++i) {
rowsID(i) = i + numOccupiedNodes;
}
sort(rowsID.data(), rowsID.data() + rowsID.size());
//cout << "rowsID after sort:" << rowsID.transpose(); cout << endl;
//copies distances of selected Nodes
int offseti = 0; int offsetj = 0;
for (int i = 0; i < numObservableNodes; ++i) {
while (rowsID(i) != i + offseti)
++offseti;
offsetj = 0;
for (int j = 0; j < numObservableNodes; ++j) {
while (rowsID(j) != j + offsetj)
++offsetj;
currentD(i, j) = D(i + offseti, j + offsetj);
currentD(j, i) = currentD(i, j);
}
}
//cout << "copied matrix: " << endl; printMatrix(currentD);
}
示例3: calcNewD
void NeighbourJoining::calcNewD(MatrixXf& currentD, MatrixXi& rowsID, const Pair& p) {
//calculates distances to new node
int j = 0;
for (int i = 0; i < numCurrentNodes - 1; ++i) {
if (i == p.i)
j++;
currentD(numCurrentNodes, i) = (currentD(p.i, i + j) + currentD(p.j, i + j) - currentD(p.i, p.j)) / 2;
currentD(i, numCurrentNodes) = currentD(numCurrentNodes, i);
}
//cout << "distances to new node: " << currentD.row(numCurrentNodes).head(numCurrentNodes-1) <<endl;
//swaps rows and columns so that the closest pair nodes go right and at the bottom of the matrix
currentD.row(p.i).head(numCurrentNodes - 1).swap(
currentD.row(numCurrentNodes - 1).head(numCurrentNodes - 1));
currentD.col(p.i).head(numCurrentNodes - 1).swap(
currentD.col(numCurrentNodes - 1).head(numCurrentNodes - 1));
currentD.row(p.j).head(numCurrentNodes - 1).swap(
currentD.row(numCurrentNodes).head(numCurrentNodes - 1));
currentD.col(p.j).head(numCurrentNodes - 1).swap(
currentD.col(numCurrentNodes).head(numCurrentNodes - 1));
currentD.diagonal().setZero();
//cout << "new Matrix:" << endl; printMatrix(currentD);
//adjusts node IDs to new matrix indices
int newNode = 2 * numObservableNodes - numCurrentNodes;
rowsID.row(p.i).swap(rowsID.row(numCurrentNodes - 1));
rowsID.row(p.j).swap(rowsID.row(newNode));
//cout << "rowsID: " << rowsID.transpose(); cout << endl;
}
示例4: main
int main(int argc, char *argv[])
{
using namespace Eigen;
using namespace std;
MatrixXd V;
MatrixXi F;
igl::readOFF("../shared/decimated-knight.off",V,F);
// 100 random indicies into rows of F
VectorXi I;
igl::floor((0.5*(VectorXd::Random(100,1).array()+1.)*F.rows()).eval(),I);
// 50 random indicies into rows of I
VectorXi J;
igl::floor((0.5*(VectorXd::Random(50,1).array()+1.)*I.rows()).eval(),J);
// K = I(J);
VectorXi K;
igl::slice(I,J,K);
// default green for all faces
MatrixXd C = RowVector3d(0.4,0.8,0.3).replicate(F.rows(),1);
// Red for each in K
MatrixXd R = RowVector3d(1.0,0.3,0.3).replicate(K.rows(),1);
// C(K,:) = R
igl::slice_into(R,K,1,C);
// Plot the mesh with pseudocolors
igl::viewer::Viewer viewer;
viewer.data.set_mesh(V, F);
viewer.data.set_colors(C);
viewer.launch();
}
示例5: time
void ConsistencyTest::replaceWithMain()
{
cout<<"########START CONSISTENCY TESTS######"<<endl;
cout<<"----Constants for the test"<<endl;
//Const across all tests
printThisOften = 0.1;
printForThisManySeconds = 10;
timeIterations = 1;
gravity = -10;
rayleighCoeff = 0;
material_model = "neo";
solver = "newton";
objectName = "spring";
int spaceStep = 0;
char method = 'i';
string tetmesh_code = "-pRq1.7";
string spaceDescription = tetmesh_code;
double implicitTimestep = 1e-1;
cout<<"----Constants for the test"<<endl;
//Time stuff------
time_t now = time(0);
string dt = ctime(&now);//local time, replace all spaces and new lines
dt.erase('\n');
replace(dt.begin(), dt.end(), ' ', '-');
//-----------------
MatrixXd V;
MatrixXi F;
MatrixXd B;
MatrixXd TV;
MatrixXi TT;
MatrixXi TF;
igl::readOBJ(TUTORIAL_SHARED_PATH "shared/"+objectName+".obj", V, F);
igl::copyleft::tetgen::tetrahedralize(V,F,tetmesh_code, TV, TT, TF);
igl::barycenter(TV, TT, B);
spaceStep =TT.rows();
if(method == 'i'){
string printHere = CONSISTENCY_TEST_SAVE_PATH"TestsResults/ConsistencyTests/objectName:"+objectName+"/[email protected]"+material_model+"@"+solver+"/"+to_string(spaceStep)+"[email protected]"+tetmesh_code+"/timestep:"+to_string(implicitTimestep)+"/";
test(implicitTimestep, method, printHere, TT, TV, B);
}else if(method == 'n'){
cout<<"Not Yet, fill in the same thing for newmark"<<endl;
}else if(method = 'e'){
cout<<"Use an implicit method instead"<<endl;
}else{
cout<<"Lolz"<<endl;
exit(0);
}
return;
}
示例6: set_submatrix
void set_submatrix(MatrixXi& M, const MatrixXi& Msub, const VectorXi& ind)
{
int k = 0;
for(int i=0;i<ind.size();i++){
if(ind(i) == 1){
M.row(i) = Msub.row(k);
k++;
}
}
}
示例7: assert
IGL_INLINE void igl::exterior_edges(
const Eigen::MatrixXi & F,
Eigen::MatrixXi & E)
{
using namespace Eigen;
using namespace std;
assert(F.cols() == 3);
const size_t m = F.rows();
MatrixXi all_E,sall_E,sort_order;
// Sort each edge by index
all_edges(F,all_E);
sort(all_E,2,true,sall_E,sort_order);
// Find unique edges
MatrixXi uE;
VectorXi IA,EMAP;
unique_rows(sall_E,uE,IA,EMAP);
VectorXi counts = VectorXi::Zero(uE.rows());
for(size_t a = 0;a<3*m;a++)
{
counts(EMAP(a)) += (sort_order(a)==0?1:-1);
}
E.resize(all_E.rows(),2);
{
int e = 0;
const size_t nue = uE.rows();
// Append each unique edge with a non-zero amount of signed occurances
for(size_t ue = 0; ue<nue; ue++)
{
const int count = counts(ue);
size_t i,j;
if(count == 0)
{
continue;
}else if(count < 0)
{
i = uE(ue,1);
j = uE(ue,0);
}else if(count > 0)
{
i = uE(ue,0);
j = uE(ue,1);
}
// Append edge for every repeated entry
const int abs_count = abs(count);
for(size_t k = 0;k<abs_count;k++)
{
E(e,0) = i;
E(e,1) = j;
e++;
}
}
E.conservativeResize(e,2);
}
}
示例8: saveImage
void Utils::saveImage(MatrixXi rawData, string outputFile)
{
QImage* img = new QImage(rawData.cols(), rawData.rows(), QImage::Format_RGB16);
for (int y = 0; y < img->height(); y++)
{
VectorXi a = rawData.row(y);
memcpy(img->scanLine(y), (void*)&a, img->bytesPerLine());
}
QString file = QString::fromUtf8(outputFile.c_str());
img->save(file);
}
示例9: get_submatrix
MatrixXi get_submatrix(const MatrixXi& M, const VectorXi& ind)
{
MatrixXi Msub(ind.sum(),M.cols());
int k = 0;
for(int i=0;i<M.rows();i++){
if(ind(i) == 1){
Msub.row(k) = M.row(i);
k++;
}
}
return Msub;
}
示例10: Mstep
void parameters::Mstep(datafile dat, model mod){
const MatrixXi & omega=mod.Get_model(),mat=dat.Get_mat_datafile();
const VectorXd & eff=dat.Get_eff_datafile();
for (int k=0;k<m_proba.cols();k++){
m_propor(k)= (eff.array()*(m_proba.col(k)).array()/m_proba.rowwise().sum().array()).sum() / eff.sum();
for (int b=0;b<mat.cols();b++){
if ((omega.row(k).array()==b).any()){
const VectorXi & who=mod.Get_var_block(k,b);
m_param[k][b].Mstep(who,mat,m_proba_block[k].col(b),m_proba.col(k).array()/m_proba.rowwise().sum().array(),eff);
}
}
}
}
示例11: calculate_from_confusion_matrix
void FScore::calculate_from_confusion_matrix(const MatrixXi &cmat) {
// Sometimes a class is never predicted, leading to a sum that is 0.
// When dividing later, there can be a nan. Avoid setting the value to 1.
// Setting to 1 is correct because the value to divide will be 0.
VectorXi sums = cmat.colwise().sum().unaryExpr(std::ptr_fun(avoid_zero));
recall_ = cmat.cast<double>().diagonal().array() / sums.cast<double>().array();
sums = cmat.rowwise().sum().unaryExpr(std::ptr_fun(avoid_zero));
precision_ = cmat.cast<double>().diagonal().array() / sums.cast<double>().array();
// Apply the same fix to the sum of the recall and precision arrays.
VectorXd s = (recall_ + precision_).unaryExpr(std::ptr_fun(avoid_zero_double));
fscore_ = 2 * recall_.array() * precision_.array() / s.array();
}
示例12: main
int main(int, char**)
{
cout.precision(3);
MatrixXi m = MatrixXi::Random(3,4);
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the reverse of m:" << endl << m.reverse() << endl;
cout << "Here is the coefficient (1,0) in the reverse of m:" << endl
<< m.reverse()(1,0) << endl;
cout << "Let us overwrite this coefficient with the value 4." << endl;
m.reverse()(1,0) = 4;
cout << "Now the matrix m is:" << endl << m << endl;
return 0;
}
示例13: nominal_entropy_gain
double nominal_entropy_gain(const VectorXi &values, const VectorXi &classes) {
MatrixXi T = get_cross_table(values, classes);
MatrixXi total_per_value = T.rowwise().sum();
VectorXd probability_of_value = total_per_value.cast<double>() /values.rows();
MatrixXd fractions_yx = divide_colwise( T.cast<double>(),
total_per_value.cast<double>());
double epsilon = std::numeric_limits<double>::epsilon();
double invlog = 1 / std::log(2);
MatrixXd H = (- invlog) * fractions_yx.array() *
(fractions_yx.array() + epsilon).log().array();
double total_entropy = probability_of_value.transpose() * H.rowwise().sum();
VectorXi counts = T.colwise().sum();
double gain = entropy(counts.cast<double>()) - total_entropy;
return gain;
}
示例14: nominal_gini_gain
double nominal_gini_gain(const VectorXi &values, const VectorXi &classes) {
MatrixXi T = get_cross_table(values, classes);
// total_per_value(k) is the number of times that value k appears
MatrixXi total_per_value = T.rowwise().sum();
VectorXd probability_of_value = total_per_value.cast<double>() /values.rows();
// Fraction of each class per value
MatrixXd fractions_yx = divide_colwise( T.cast<double>(),
total_per_value.cast<double>());
// Gini impurity for each value: sum fractions^2 over the rows
VectorXd G = fractions_yx.array().square().rowwise().sum();
double total_gini = 1 - probability_of_value.transpose() * G;
VectorXi counts = T.colwise().sum();
double gain = gini(counts.cast<double>()) - total_gini;
return gain;
}
示例15: updateSentenceCounts
static void updateSentenceCounts(MatrixXi& counts, const Sentence& sentence) {
int last_tag = -1;
for (const pair<Tag, string>& taggedWord : sentence.words) {
int tag = taggedWord.first;
assert (last_tag+1 < counts.rows());
assert(tag+1 < counts.cols());
counts(tag+1, last_tag+1) += 1;
last_tag = tag;
}
// Now update transition to final state.
counts(counts.cols()-1, last_tag+1) += 1;
}