void
RockPhysicsInversion4D::SolveGEVProblem(NRLib::Matrix sigma_prior,
                                        NRLib::Matrix sigma_posterior,
                                        NRLib::Matrix & vOut){
  //Compute transforms v1, v2, v3 and v4  ----------------------------------------

  // computing filter
  NRLib::SymmetricMatrix  sigma_priorInv(6);
  for(int i=0;i<6;i++)
    for(int j=0;j<=i;j++)
      sigma_priorInv(j,i)=sigma_prior(i,j);

  NRLib::CholeskyInvert(sigma_priorInv);
  NRLib::Matrix eye = NRLib::IdentityMatrix(6);
  NRLib::Matrix filter = eye- sigma_priorInv*sigma_posterior;
  // computing components
  NRLib::Vector eigen_values(6);
  NRLib::Matrix eigen_vectors(6,6);
  NRLib::ComputeEigenVectors( filter ,eigen_values,eigen_vectors);

  // extracting four best components
  std::vector<int> current_index(6);
  current_index[0] = 0;current_index[1] = 1;
  current_index[2] = 2;current_index[3] = 3;
  current_index[4] = 4;current_index[5] = 5;

  std::vector<int> best_index(4);
  std::vector<int> keep_index(6);
  keep_index = current_index;

  NRLib::Vector current_value(6);
  NRLib::Vector keep_value(6);
  keep_value  = eigen_values;

  for(int i=0;i<4;i++){
    current_index=keep_index;
    current_value =keep_value;
    double maxVal=-999; // (the theoretical max value is less than 1 and larger than zero)
    for(int j=0;j<6-i;j++){
      if(current_value(j) > maxVal){
        maxVal=current_value(j);
        best_index[i]=current_index[j];
      }
    }
    int counter=0;
    for(int j=0;j<6-i;j++){
      if(current_value(j) != maxVal){
        keep_value(counter)=current_value(j);
        keep_index[counter]=current_index[j];
        counter++;
      }
    }
  }
  vOut.resize(6,4);
  for(int i=0;i<4;i++)
    for(int j=0;j<6;j++)
      vOut(j,i)=eigen_vectors(j,best_index[i]);
}
int GridSampleHolder::GetNeighbors(const Sample & query, const float radius, vector<const Sample *> & neighbors) const
{
    neighbors.clear();

    const int dimension = Dimension();

    vector<int> cell_index(dimension);
    if(! LocateCell(query, cell_index))
    {
        // outside the grid
        return 0;
    }

    const float radius_in_cells = (radius/_domain_spec.cell_size + 1);

    NBallSliceCounter counter(dimension, radius_in_cells*radius_in_cells);

    vector<int> offset_index(dimension);
    vector<int> current_index(dimension);
    vector<int> corrected_index(dimension);
    
    counter.Reset();
    do
    {
        counter.Get(offset_index);

        for(unsigned int i = 0; i < current_index.size(); i++)
        {
            current_index[i] = cell_index[i] + offset_index[i];

            if(_domain.Boundary() == Domain::BOUNDARY_TOROIDAL)
            {
                corrected_index[i] = (((current_index[i]%_cells.Size(i))+_cells.Size(i))%_cells.Size(i));
            }
            else
            {
                corrected_index[i] = current_index[i];
            }
        }

        Cell current_cell;
        if(_cells.Get(corrected_index, current_cell))
        {
            for(unsigned int j = 0; j < current_cell.samples.size(); j++)
            {
                neighbors.push_back(current_cell.samples[j]);
            }
        }
    }
    while(counter.Next());

    // done
    return 1;
}
Ejemplo n.º 3
0
void ui_menu_mess_tape_control::populate()
{
	astring timepos;
	cassette_state state;
	UINT32 flags = 0;

	if (count() > 0)
	{
		int index = current_index();

		if( index == (count()-1) )
			flags |= MENU_FLAG_LEFT_ARROW;
		else
			flags |= MENU_FLAG_RIGHT_ARROW;
	}

	if ((current_device() != NULL) && (current_device()->exists()))
	{
		double t0, t1;
		UINT32 tapeflags = 0;

		t0 = current_device()->get_position();
		t1 = current_device()->get_length();

		if (t1 > 0)
		{
			if (t0 > 0)
				tapeflags |= MENU_FLAG_LEFT_ARROW;
			if (t0 < t1)
				tapeflags |= MENU_FLAG_RIGHT_ARROW;
		}

		// name of tape
		item_append(current_device()->device().name(), current_device()->filename(), flags, TAPECMD_SELECT);

		// state
		get_time_string(timepos, current_device(), NULL, NULL);
		state = current_device()->get_state();
		item_append(
			(state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
				?   "stopped"
				:   ((state & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY
					? ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "playing" : "(playing)")
					: ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "recording" : "(recording)")
					),
			timepos,
			tapeflags,
			TAPECMD_SLIDER);

		// pause or stop
		item_append("Pause/Stop", NULL, 0, TAPECMD_STOP);

		// play
		item_append("Play", NULL, 0, TAPECMD_PLAY);

		// record
		item_append("Record", NULL, 0, TAPECMD_RECORD);

		// rewind
		item_append("Rewind", NULL, 0, TAPECMD_REWIND);

		// fast forward
		item_append("Fast Forward", NULL, 0, TAPECMD_FAST_FORWARD);
	}
	else
	{
		// no tape loaded
		item_append("No Tape Image loaded", NULL, flags, NULL);
	}
}