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]);
}
Exemplo n.º 2
0
vector<entry> Matrix::get_values()
{
    vector<entry> res;
    for (uint index=0; index<entries.size(); index++) {
        entry e = current_value(index);
        res.push_back(e);
    }
    return res;
}
Exemplo n.º 3
0
uint Matrix::find_uncovered_zero() {
    //res.pos.i = -1; res.pos.j = -1; res.cost = -1;
    for (uint index=0; index<entries.size(); index++) {
        entry e = current_value(index);
        if (e.cost < EPS && e.cost > -EPS && !covered_rows[e.pos.i] && !covered_columns[e.pos.j]) {
            return index;
        }
    }
    return NOTFOUND;
}
Exemplo n.º 4
0
vector<uint> Matrix::zeros() {
    vector<uint> res;
    for (uint index=0; index<entries.size(); index++) {
        entry e = current_value(index);
        if (e.cost < EPS && e.cost > -EPS) {
            res.push_back(index);
        }
    }
    return res;
}
Exemplo n.º 5
0
vector<entry> Matrix::row(uint rowindex)
{
    vector<entry> res;
    for (uint index=0; index<entries.size(); index++) {
        entry e = current_value(index);
        if (e.pos.i == rowindex) {
            res.push_back(e);
        }
    }
    return res;
}
Exemplo n.º 6
0
double Matrix::min_uncovered_cost() {
    double minval = INF;
    for (uint index = 0; index < entries.size(); index++) {
        entry e = current_value(index);
        bool covered = covered_rows[e.pos.i] || covered_columns[e.pos.j];
        if (!covered && minval > e.cost) {
            minval = e.cost;
        }
    }
    assert(EPS < minval && minval < INF);
    return minval;
}
Exemplo n.º 7
0
void osd_common_t::update_option(const char * key, std::vector<const char *> &values)
{
	std::string current_value(m_options.description(key));
	std::string new_option_value("");
	for (unsigned int index = 0; index < values.size(); index++)
	{
		std::string t(values[index]);
		if (new_option_value.length() > 0)
		{
			if( index != (values.size()-1))
				new_option_value.append(", ");
			else
				new_option_value.append(" or ");
		}
		new_option_value.append(t);
	}
	// TODO: core_strdup() is leaked
	m_options.set_description(key, core_strdup(current_value.append(new_option_value).c_str()));
}
Exemplo n.º 8
0
void osd_interface::update_option(osd_options &options, const char * key, dynamic_array<const char *> &values)
{
	astring current_value(options.description(key));
	astring new_option_value("");
	for (int index = 0; index < values.count(); index++)
	{
		astring t(values[index]);
		if (new_option_value.len() > 0)
		{
			if( index != (values.count()-1))
				new_option_value.cat(", ");
			else
				new_option_value.cat(" or ");
		}
		new_option_value.cat(t);
	}
	// TODO: core_strdup() is leaked
	options.set_description(key, core_strdup(current_value.cat(new_option_value).cstr()));
}
Exemplo n.º 9
0
 void on_code_unit(char_type c) {
     current_value() += c;
 }
Exemplo n.º 10
0
 void on_code_units(Range code_units) {
     current_value().append(code_units.begin(), code_units.end());
 }
Exemplo n.º 11
0
 void on_digit(char_type d) {
     current_value() += d;
 }
Exemplo n.º 12
0
void update_value(UBYTE mode, UBYTE line, UWORD value)
{
  if(mode == 0) {
    switch(line)
      {
      case 0: /* global_On_Off */
	soundReg->control.global_On_Off = value;
	NR52_REG = ((UBYTE *)soundReg)[0x16];
	break;
      case 1: /* Vin_SO1 */
	soundReg->control.Vin_SO1 = value;
	NR50_REG = ((UBYTE *)soundReg)[0x14];
	break;
      case 2: /* Vin_SO2 */
	soundReg->control.Vin_SO2 = value;
	NR50_REG = ((UBYTE *)soundReg)[0x14];
	break;
      case 3: /* SO1_OutputLevel */
	soundReg->control.SO1_OutputLevel = value;
	NR50_REG = ((UBYTE *)soundReg)[0x14];
	break;
      case 4: /* SO2_OutputLevel */
	soundReg->control.SO2_OutputLevel = value;
	NR50_REG = ((UBYTE *)soundReg)[0x14];
	break;
      case FREQUENCY:
	update_value(1, FREQUENCY, value);
	update_value(2, FREQUENCY, value);
	update_value(3, FREQUENCY, value);
	break;
      case PLAY: /* restart */
	update_value(1, FREQUENCY, current_value(1, FREQUENCY));
	update_value(2, FREQUENCY, current_value(2, FREQUENCY));
	update_value(3, FREQUENCY, current_value(3, FREQUENCY));
	soundReg->mode1.restart = value;
	soundReg->mode2.restart = value;
	soundReg->mode3.restart = value;
	soundReg->mode4.restart = value;
	NR14_REG = ((UBYTE *)soundReg)[0x04];
	NR24_REG = ((UBYTE *)soundReg)[0x09];
	NR34_REG = ((UBYTE *)soundReg)[0x0E];
	NR44_REG = ((UBYTE *)soundReg)[0x13];
	soundReg->mode1.restart = 0;
	soundReg->mode2.restart = 0;
	soundReg->mode3.restart = 0;
	soundReg->mode4.restart = 0;
	break;
      }
  } else if(mode == 1) {
    switch(line)
      {
      case 0: /* sweepTime */
	soundReg->mode1.sweepTime = value;
	NR10_REG = ((UBYTE *)soundReg)[0x00];
	break;
      case 1: /* sweepMode */
	soundReg->mode1.sweepMode = value;
	NR10_REG = ((UBYTE *)soundReg)[0x00];
	break;
      case 2: /* sweepShifts */
	soundReg->mode1.sweepShifts = value;
	NR10_REG = ((UBYTE *)soundReg)[0x00];
	break;
      case 3: /* patternDuty */
	soundReg->mode1.patternDuty = value;
	NR11_REG = ((UBYTE *)soundReg)[0x01];
	break;
      case 4: /* soundLength */
	soundReg->mode1.soundLength = value;
	NR11_REG = ((UBYTE *)soundReg)[0x01];
	break;
      case 5: /* envInitialValue */
	soundReg->mode1.envInitialValue = value;
	NR12_REG = ((UBYTE *)soundReg)[0x02];
	break;
      case 6: /* envMode */
	soundReg->mode1.envMode = value;
	NR12_REG = ((UBYTE *)soundReg)[0x02];
	break;
      case 7: /* envNbSweep */
	soundReg->mode1.envNbSweep = value;
	NR12_REG = ((UBYTE *)soundReg)[0x02];
	break;
      case 8: /* frequency */
      case FREQUENCY:
	soundReg->mode1.frequencyHigh = value >> 8;
	soundReg->mode1.frequencyLow  = value;
	NR13_REG = ((UBYTE *)soundReg)[0x03];
	NR14_REG = ((UBYTE *)soundReg)[0x04];
	break;
      case 9: /* counter_ConsSel */
	soundReg->mode1.counter_ConsSel = value;
	NR14_REG = ((UBYTE *)soundReg)[0x04];
	break;
      case 10: /* Sound1_To_SO1 */
	soundReg->control.Sound1_To_SO1 = value;
	NR51_REG = ((UBYTE *)soundReg)[0x15];
	break;
      case 11: /* Sound1_To_SO2 */
	soundReg->control.Sound1_To_SO2 = value;
	NR51_REG = ((UBYTE *)soundReg)[0x15];
	break;
      case 12: /* Sound1_On_Off */
	soundReg->control.Sound1_On_Off = value;
	NR52_REG = ((UBYTE *)soundReg)[0x16];
	break;
      case PLAY: /* restart */
	update_value(mode, FREQUENCY, current_value(mode, FREQUENCY));
	soundReg->mode1.restart = value;
	NR14_REG = ((UBYTE *)soundReg)[0x04];
	soundReg->mode1.restart = 0;
	break;
      }
  } else if(mode == 2) {