示例#1
0
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
0
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
0
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
0
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();
}
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+"/implicit_euler@"+material_model+"@"+solver+"/"+to_string(spaceStep)+"tets@"+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
0
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
0
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);
  }
}
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
0
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
0
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
0
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();
}
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
0
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
0
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;
}
  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;
  }
示例#16
0
MatrixXi duplicatematrix(int n){
	MatrixXi D;
	D.setZero(n*n,n*(n-1)/2 + n);
	int k = n;
	int l = n;
	for(int i=0;i<n;i++){
		D(i*n+i,i) = 1;
		for(int j=i+1;j<n;j++){
			D(i*n + j,k++) = 1;
      D(j*n + i,l++) = 1;
		}
	
	}
	return D;
}
示例#17
0
void printMatrix(MatrixXi &mat, string &crypted) {
    int n = mat.rows();
    for(int i = 0; i < n; ++i) {
        char c = (mat(i, 0) % 26) + 65;
        crypted += c;
    }
}
void WeightedSampling(int m, int N, const MatrixXi &resIndex, vector<int> &sample, int h) {
  sample.reserve(m);
  vector<int> seedIndex;
  RandomSampling(1, N, seedIndex);
  sample[0] = seedIndex[0];
  int prevSelected = seedIndex[0];
  ArrayXf w(N);
  w.setConstant(1);
  for (int i = 1; i < m; i++) {
    ArrayXf new_w(N);
    computeIntersection(resIndex.row(prevSelected), resIndex, h, new_w);
    w(prevSelected) = 0;
    w *= new_w;
    if (w.sum() > 0) {
      map<double, int> cumulative;
      typedef std::map<double, int>::iterator it;
      double acc = 0;
      for (int j = 0; j < N; j++) {
        acc += w(j);
        cumulative[acc] = j; 
      }
      double linear = rand()*acc/RAND_MAX;
      prevSelected = cumulative.upper_bound(linear)->second;
      sample[i] = prevSelected;
    } else {
      vector<int> temp_sample;
      RandomSampling(1, N, temp_sample);
      prevSelected = temp_sample[0];
      sample[i] = prevSelected;
    }
  }
}
  static void initCounts(MatrixXi& counts, size_t size) {
    counts = counts.Constant(size, size,
			     1); // prior counts for Laplace smoothing, 0 for MLE
    // No transitions to initial state!
    for (size_t i = 0; i < size; i++)
      counts(0, i) = 0;
  }
示例#20
0
// Read a surface mesh from a {.obj|.off|.mesh} files
// Inputs:
//   mesh_filename  path to {.obj|.off|.mesh} file
// Outputs:
//   V  #V by 3 list of mesh vertex positions
//   F  #F by 3 list of triangle indices
// Returns true only if successfuly able to read file
bool load_mesh_from_file(
  const std::string mesh_filename,
  Eigen::MatrixXd & V,
  Eigen::MatrixXi & F)
{
  using namespace std;
  using namespace igl;
  using namespace Eigen;
  string dirname, basename, extension, filename;
  pathinfo(mesh_filename,dirname,basename,extension,filename);
  transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
  bool success = false;
  if(extension == "obj")
  {
    success = readOBJ(mesh_filename,V,F);
  }else if(extension == "off")
  {
    success = readOFF(mesh_filename,V,F);
  }else if(extension == "mesh")
  {
    // Unused Tets read from .mesh file
    MatrixXi Tets;
    success = readMESH(mesh_filename,V,Tets,F);
    // We're not going to use any input tets. Only the surface
    if(Tets.size() > 0 && F.size() == 0)
    {
      // If Tets read, but no faces then use surface of tet volume
    }else
    {
      // Rearrange vertices so that faces come first
      VectorXi IM;
      faces_first(V,F,IM);
      // Dont' bother reordering Tets, but this is how one would:
      //Tets = 
      //  Tets.unaryExpr(bind1st(mem_fun( static_cast<VectorXi::Scalar&
      //  (VectorXi::*)(VectorXi::Index)>(&VectorXi::operator())),
      //  &IM)).eval();
      // Don't throw away any interior vertices, since user may want weights
      // there
    }
  }else
  {
    cerr<<"Error: Unknown shape file format extension: ."<<extension<<endl;
    return false;
  }
  return success;
}
示例#21
0
void igl::is_boundary_edge(
  const Eigen::PlainObjectBase<DerivedE> & E,
  const Eigen::PlainObjectBase<DerivedF> & F,
  Eigen::PlainObjectBase<DerivedB> & B)
{
  using namespace Eigen;
  using namespace std;
  // Should be triangles
  assert(F.cols() == 3);
  // Should be edges
  assert(E.cols() == 2);
  // number of faces
  const int m = F.rows();
  // Collect all directed edges after E
  MatrixXi EallE(E.rows()+3*m,2);
  EallE.block(0,0,E.rows(),E.cols()) = E;
  for(int e = 0;e<3;e++)
  {
    for(int f = 0;f<m;f++)
    {
      for(int c = 0;c<2;c++)
      {
        // 12 20 01
        EallE(E.rows()+m*e+f,c) = F(f,(c+1+e)%3);
      }
    }
  }
  // sort directed edges into undirected edges
  MatrixXi sorted_EallE,_;
  sort(EallE,2,true,sorted_EallE,_);
  // Determine unique undirected edges E and map to directed edges EMAP
  MatrixXi uE;
  VectorXi EMAP;
  unique_rows(sorted_EallE,uE,_,EMAP);
  // Counts of occurances
  VectorXi N = VectorXi::Zero(uE.rows());
  for(int e = 0;e<EMAP.rows();e++)
  {
    N(EMAP(e))++;
  }
  B.resize(E.rows());
  // Look of occurances of 2: one for original and another for boundary
  for(int e = 0;e<E.rows();e++)
  {
    B(e) = (N(EMAP(e)) == 2);
  }
}
示例#22
0
文件: main.cpp 项目: nixz/libigl
int main(int argc, char *argv[])
{
  using namespace Eigen;
  using namespace std;
  MatrixXd V;
  MatrixXi F;

  // Load a mesh in OFF format
  igl::readOFF("../shared/cheburashka.off", V, F);

  // Read scalar function values from a file, U: #V by 1
  VectorXd U;
  igl::readDMAT("../shared/cheburashka-scalar.dmat",U);

  // Compute gradient operator: #F*3 by #V
  SparseMatrix<double> G;
  igl::grad(V,F,G);

  // Compute gradient of U
  MatrixXd GU = Map<const MatrixXd>((G*U).eval().data(),F.rows(),3);
  // Compute gradient magnitude
  const VectorXd GU_mag = GU.rowwise().norm();

  igl::viewer::Viewer viewer;
  viewer.data.set_mesh(V, F);

  // Compute pseudocolor for original function
  MatrixXd C;
  igl::jet(U,true,C);
  // // Or for gradient magnitude
  //igl::jet(GU_mag,true,C);
  viewer.data.set_colors(C);

  // Average edge length divided by average gradient (for scaling)
  const double max_size = igl::avg_edge_length(V,F) / GU_mag.mean();
  // Draw a black segment in direction of gradient at face barycenters
  MatrixXd BC;
  igl::barycenter(V,F,BC);
  const RowVector3d black(0,0,0);
  viewer.data.add_edges(BC,BC+max_size*GU, black);

  // Hide wireframe
  viewer.core.show_lines = false;

  viewer.launch();
}
  static void countsToProbs(MatrixXd& probs, const MatrixXi counts) {
    // Now form probability matrix from counts
    for (size_t col = 0; col < counts.cols(); col++) {
      double sum = 0;
      for (size_t row = 0; row < counts.rows(); row++) {
	sum += counts(row, col);
      }
      assert(sum > 0);
      for (size_t row = 0; row < counts.rows(); row++) {
	probs(row, col) = counts(row, col) / sum;
	// NaN != NaN, this tests that it's not NaN
	assert(probs(row, col) == probs(row, col));
	assert(probs(row, col) >= 0);
	assert(probs(row, col) <= 1);
      }
    }
  }
示例#24
0
// function used internally, which computes lasso fits for subsets containing a
// small number of observations (typically only 3) and returns the indices of
// the respective h observations with the smallest absolute residuals
MatrixXi sparseSubsets(const MatrixXd& x, const VectorXd& y,
                       const double& lambda, const int& h, const MatrixXi& subsets,
                       const bool& normalize, const bool& useIntercept,
                       const double& eps, const bool& useGram) {
    const int nsamp = subsets.cols();
    MatrixXi indices(h, nsamp);
    for(int k = 0; k < nsamp; k++) {
        // compute lasso fit
        double intercept, crit;
        VectorXd coefficients, residuals;
        fastLasso(x, y, lambda, true, subsets.col(k), normalize, useIntercept,
                  eps, useGram, false, intercept, coefficients, residuals, crit);
        // find h observations with smallest absolute residuals
        indices.col(k) = findSmallest(residuals.cwiseAbs(), h);
    }
    return indices;
}
示例#25
0
parameters::parameters(datafile dat, model nv_mod, model ref_mod,parameters ref_param,int compo,int iter){
	const MatrixXi & omega=nv_mod.Get_model(),ref_omega=ref_mod.Get_model(),mat=dat.Get_mat_datafile();
	const int g=omega.rows(),unique=mat.rows();
	m_proba=ref_param.m_proba;
	m_proba_block.resize(g);
	m_param.resize(g);
	for (int k=0;k<g;k++){
		if (k!=compo){
			m_param[k].resize(omega.rowwise().maxCoeff()(k)+1);
			m_param[k]=ref_param.m_param[k];
			m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1);
			m_proba_block[k]=ref_param.m_proba_block[k];
			for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){
				if ((omega.row(k).array()==b).any()){
					m_param[k][b]=ref_param.m_param[k][b];
				}
			}
		}else{
			m_param[k].resize(omega.rowwise().maxCoeff()(k)+1);
			m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1);
			for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){
				if ((omega.row(k).array()==b).any()){
					if ((((omega.row(k).array()==b)==(ref_omega.row(k).array()==b)).prod())==1){
						m_param[k][b]=ref_param.m_param[k][b];
					}else{
						m_param[k][b]=param_block(k,b,dat,nv_mod,m_proba.col(k).array()/m_proba.rowwise().sum().array(),1);
						if ((omega.row(k).array()==b).count()>1){
							int prem=0;
							while(omega(k,prem)!=b){prem++;}
							if (mat.col(prem).maxCoeff()>5){
									m_param[k][b]=m_param[k][b].Optimise_gamma(k,b,dat,nv_mod,5,m_proba.col(k).array()/m_proba.rowwise().sum().array(),dat.Get_eff_datafile());
							}
						}
					}
				}
			}
		}

	}
	m_propor=uniforme(g);
	Probapost( nv_mod , mat );
	Compte_nbparam(dat,nv_mod);
	Likelihood(dat.Get_eff_datafile());
	Estimation(1,0,iter,dat,nv_mod);
}
示例#26
0
  Density_2(const MatrixXd& X,
            const VectorXd& f,
            const MatrixXi& tri) : gen(clock())
  {
    size_t N = X.rows();
    assert(X.cols() == 2);
    assert(f.cols() == 1);
    assert(f.rows() == N);
    assert(tri.cols() == 3);


    CGAL::Triangulation_incremental_builder_2<T> builder(_t);
    builder.begin_triangulation();

    // add vertices
    std::vector<T::Vertex_handle> vertices(N);
    for (size_t i = 0; i < N; ++i)
      {
	Point p(X(i,0),X(i,1));
	vertices[i] = builder.add_vertex(Point(X(i,0), X(i,1)));
	vertices[i]->info() = i;
      }

    // add faces
    size_t Nt = tri.rows();
    for (size_t i = 0; i < Nt; ++i)
      {
	int a = tri(i,0), b = tri(i,1), c = tri(i,2);
	builder.add_face(vertices[a], vertices[b], vertices[c]);
      }
    builder.end_triangulation();

    // compute functions
    for (T::Finite_faces_iterator it = _t.finite_faces_begin ();
	 it != _t.finite_faces_end(); ++it)
      {
	size_t a = it->vertex(0)->info();
	size_t b = it->vertex(1)->info();
	size_t c = it->vertex(2)->info();
	_functions[it] = Function(vertices[a]->point(), f[a],
				  vertices[b]->point(), f[b],
				  vertices[c]->point(), f[c]);
      }
  }
示例#27
0
void parameters::Probapost(model mod, const MatrixXi & mat){
	const MatrixXi & omega=mod.Get_model();
	m_proba=MatrixXd::Ones(mat.rows(),omega.rows());
	for (int k = 0; k < omega.rows(); ++k) {
		m_proba_block[k]=m_proba_block[k].Ones(mat.rows(),(omega.rowwise().maxCoeff()(k)+1));
		for (int b = 0; b < (omega.rowwise().maxCoeff()(k)+1); ++b){

			if ((omega.row(k).array()==b).any()){
				const VectorXi & who=mod.Get_var_block(k,b);
				if (who.rows()>1){
					m_proba_block[k].col(b)=m_param[k][b].proba_indpt(who,mat)+m_param[k][b].proba_dpt(who,mat);
				}else{
					m_proba_block[k].col(b)=m_param[k][b].proba_indpt(who,mat);
				}
			}
		}
		m_proba.col(k)=m_propor(k)* (m_proba_block[k].rowwise().prod()).array();
	}
}
示例#28
0
bool EventModel::loadEventData(QFile& qFile)
{
    beginResetModel();
    clearModel();

    // Read events
    MatrixXi events;

    if(!MNE::read_events(qFile, events)) {
        qDebug() << "Error while reading events.";
        return false;
    }

    //std::cout << events << endl;

    qDebug() << QString("Events read from %1").arg(qFile.fileName());

    //set loaded fiff event data
    for(int i = 0; i < events.rows(); i++) {
        m_dataSamples.append(events(i,0));
        m_dataTypes.append(events(i,2));
        m_dataIsUserEvent.append(0);
    }

    //Set filtered events to original
    m_dataSamples_Filtered = m_dataSamples;
    m_dataTypes_Filtered = m_dataTypes;
    m_dataIsUserEvent_Filtered = m_dataIsUserEvent;

    //Create type string list
    m_eventTypeList.clear();
    for(int i = 0; i<m_dataTypes.size(); i++)
        if(!m_eventTypeList.contains(QString().number(m_dataTypes[i])))
            m_eventTypeList<<QString().number(m_dataTypes[i]);

    emit updateEventTypes("All");

    endResetModel();

    m_bFileloaded = true;

    return true;
}
示例#29
0
void NeighbourJoining::calcNJ(MatrixXf& D, MatrixXi& rowsID, BuildNJTree& LTM,
		int numOccupiedNodes) {
	MatrixXf currentD(rowsID.rows() + 1, rowsID.rows() + 1);
	configure(D, currentD, rowsID, numOccupiedNodes);

	MatrixXf Q(currentD.rows(), currentD.cols());
	LTM.configure(rowsID, numOccupiedNodes);
	//BuildNJTree* LTM = new BuildNJTree(D.rows() + numOccupiedNodes, rowsID);

	//grows LTM till there are at least two nodes left
	while (numCurrentNodes > 2) {
		calcQ(currentD, Q);
		findMinQ(Q, rowsID, pair);
		updateD(D, currentD, pair,	2 * numObservableNodes - numCurrentNodes + numOccupiedNodes);
		calcNewD(currentD, rowsID, pair);
		LTM.addClosestPair(pair);
		--numCurrentNodes;
	}
	LTM.connectLast2Nodes();
}
示例#30
0
//TODO: Clean up function params size Fixed and size Move are not needed
void Simulation::reIndexTVandTT(
	vector<int> newVertsIndices, 
	int sizeFixed, 
	int sizeMove, 
	MatrixXd& TV, 
	MatrixXi& TT, 
	VectorXd& force, 
	MatrixXd& newTV, 
	MatrixXi& newTT, 
	VectorXd& new_force){
	//apply re-index to TV
	for(unsigned int i=0; i<newVertsIndices.size(); i++){
		newTV.row(i) = TV.row(newVertsIndices[i]);
		new_force.segment<3>(3*i) = force.segment<3>(3*newVertsIndices[i]);
	}
	//create map out of newVertsIndex
	//map keys = newVertsIndex values = old indices in TV
	//map vals = newVertsIndex index = new indices in TV
	map<int, int> oldToNewmap;
	pair<map<int, int>::iterator, bool> err;
	for(unsigned int i=0; i<newVertsIndices.size(); i++){
		err = oldToNewmap.insert(pair<int, int>(newVertsIndices[i], i));
		if(err.second==false){
			cout<<"ERROR::Simulation.cpp::reIndexTVandTT::>>Map already contains this value(";
			cout<< err.first->second <<". Indices should not be repeated"<<endl;
		}
	}

	//Check map, see if its working
	// map<int,int>::iterator it = oldToNewmap.begin();
	// for (it=oldToNewmap.begin(); it!=oldToNewmap.end(); ++it)
	// 	cout << it->first << " => " << it->second << '\n';


	//apply re-index to TT
	for(int i=0; i< TT.rows(); i++){
		for(int j=0; j<4; j++){
			newTT.row(i)[j] = oldToNewmap.find(TT.row(i)[j])->second;
		}
	}
}