All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Protected Member Functions | Static Protected Attributes
DinverCore::Parameter Class Reference

Represents an inversion parameter (range, scaling, conditions) More...

#include <Parameter.h>

Inheritance diagram for DinverCore::Parameter:
QGpCoreTools::XMLClass DinverDCCore::GroundParameter

List of all members.

Public Member Functions

void addCondition (AbstractCondition *c)
uint checksum () const
void conditionDiagnostic () const
void getGridLimits (int &min, int &max) const
void getGridLimits (double &min, double &max) const
void getLimits (double &min, double &max) const
void getRectangularLimits (double &min, double &max) const
int gridCount () const
int gridValue () const
int gridValue (double val) const
void humanInfo () const
bool initGrid ()
bool isFixed () const
bool isFussy () const
bool isOk () const
bool isOkDebug () const
bool isOkDebugVerbose () const
double maximum () const
double minimum () const
const QString & name () const
 Parameter ()
double realValue () const
double realValue (int val) const
double realValue (double val) const
void setFussy (bool f)
void setGridValue (int val)
void setGridValue (double val)
void setMaximum (double m)
void setMinimum (double m)
void setName (QString name)
void setPrecision (double p)
void setRealValue (double val)
bool setRealValue (QDataStream &s)
void setScale (ParameterGrid::Scale s)
void setUnit (QString unit)
const QString & unit () const
virtual ~Parameter ()

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual const QString & xml_tagName () const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Static Protected Attributes

static const QString xmlParamTag = "Param"

Detailed Description

Represents an inversion parameter (range, scaling, conditions)

A parameter may be qualified as 'fussy'. If so, each time the value of the parameter is changed, a validation of the model can be achieved by re-implementing NaModel::isCurrentModelOk() which returns true by default. If NaModel::isCurrentModelOk() returns false, a new value is randomly generated.


Constructor & Destructor Documentation

  {
    _value=0.5;
    _fussy=false;
  }
  {
  }

Member Function Documentation

Do not call this function directly, use the general RealSpace::addCondition() instead. This function is called by RealSpace::addCondition() to initialize the list of condition that include this parameter.

See also:
RealSpace::addCondition().

References DinverCore::AbstractCondition::indexOf(), and TRACE.

Referenced by DinverCore::RealSpace::addCondition().

  {
    TRACE;
    int index=c->indexOf(this);
    if(index>-1) {
      _conditions.append(ParamCondition( c, index) );
    }
  }

Return a number that uniquely identify this parameter and the attached conditions

References DinverCore::qHash(), and TRACE.

  {
    TRACE;
    uint sum=0;
    sum += qHash(_name);
    sum += qHash(_unit);
    for(QVector<ParamCondition>::const_iterator it=_conditions.begin(); it!=_conditions.end(); ++it) {
      sum+=it->checksum();
    }
    return sum;
  }

Print a diagnostic of this parameter: does it fit will all conditions?

References QGpCoreTools::endl(), getLimits(), getRectangularLimits(), isFixed(), and TRACE.

Referenced by DinverCore::RealSpace::conditionDiagnostic().

  {
    TRACE;
    double min, max;
    getRectangularLimits(min, max);
    getLimits(min, max);
    if(isFixed()) {
      App::stream() << " " << _name << ": " << _value  << "=" << min << endl;
    } else {
      App::stream() << " " << _name << ": " << min << " < " << _value  << " < " << max << endl;
      if(_value<=min || _value>=max) {
        App::stream() << "   ---> BAD CONDITION!" << endl;
      }
    }
  }
void DinverCore::Parameter::getGridLimits ( int &  min,
int &  max 
) const [inline]
void DinverCore::Parameter::getGridLimits ( double &  min,
double &  max 
) const [inline]

References getLimits(), DinverCore::ParameterGrid::getLimits(), and getRectangularLimits().

{
  double dmin, dmax;
  getRectangularLimits(dmin, dmax);
  getLimits(dmin, dmax);
  _grid.getLimits(min, max, dmin, dmax);
}
void DinverCore::Parameter::getLimits ( double &  min,
double &  max 
) const [inline]

All values of other parameters are assumed to be set correctly. This function returns the admissible range for this parameter given the current value of all the other parameters.

Referenced by conditionDiagnostic(), getGridLimits(), isOk(), and isOkDebug().

{
  for(QVector<ParamCondition>::const_iterator it=_conditions.begin(); it!=_conditions.end(); ++it) {
    it->getLimits(min, max);
  }
}
void DinverCore::Parameter::getRectangularLimits ( double &  min,
double &  max 
) const [inline]
int DinverCore::Parameter::gridCount ( ) const [inline]
int DinverCore::Parameter::gridValue ( ) const [inline]
int DinverCore::Parameter::gridValue ( double  val) const [inline]
{return _grid.gridValue(val);}

Stream out information about parameter and its condition in a human readable format

References DinverCore::ParameterGrid::count(), QGpCoreTools::endl(), isFixed(), maximum(), minimum(), and TRACE.

Referenced by DinverCore::RealSpace::humanInfo().

  {
    TRACE;
    if(isFixed()) {
      App::stream() << " " << _name << "=" << minimum() << " " << _unit << endl;
    } else {
      App::stream() << " " << minimum() << " < " << _name << " < " << maximum() << " " << _unit << "(" << _grid.count() << " bins)" << endl;
    }
    for(QVector<ParamCondition>::const_iterator it=_conditions.begin(); it!=_conditions.end(); ++it) {
      it->humanInfo();
    }
  }
bool DinverCore::Parameter::isFixed ( ) const [inline]
bool DinverCore::Parameter::isFussy ( ) const [inline]

Referenced by DinverCore::ImportanceSampling::generate().

{return _fussy;}
bool DinverCore::Parameter::isOk ( ) const [inline]

References getLimits(), getRectangularLimits(), and isFixed().

Referenced by DinverCore::RealSpace::isOk().

{
  double min, max;
  getRectangularLimits(min, max);
  getLimits(min, max);
  if(isFixed()) {
    return (_value>=min && _value<=max);
  } else {
    return (_value>min && _value<max);
  }
}
bool DinverCore::Parameter::isOkDebug ( ) const [inline]

References getLimits(), getRectangularLimits(), and isFixed().

Referenced by DinverCore::RealSpace::isOkDebug().

{
  double min, max;
  getRectangularLimits(min, max);
  getLimits(min, max);
  if(isFixed()) {
    if(_value>=min && _value<=max) return true;
    printf("    %lg <= %lg <= %lg ? oh nooo!\n",min,_value,max);
  } else {
    if(_value>min && _value<max) return true;
    printf("    %lg < %lg < %lg ? oh nooo!\n",min,_value,max);
  }
  return false;
}

References getRectangularLimits(), and isFixed().

  {
    double min, max;
    getRectangularLimits(min, max);
    printf("rectangular limits: %10lg %10lg\n", min, max);
    // Get limits
    for(int i=0; i<_conditions.count(); i++) {
      _conditions.at(i).getLimits(min, max);
      printf("condition %3i     : %10lg %10lg\n", i, min, max);
    }
    if(isFixed()) {
      if(_value>=min && _value<=max) return true;
      printf("    %lg <= %lg <= %lg ? oh nooo!\n",min,_value,max);
    } else {
      if(_value>min && _value<max) return true;
      printf("    %lg < %lg < %lg ? oh nooo!\n",min,_value,max);
    }
    return false;
  }
double DinverCore::Parameter::maximum ( ) const [inline]
double DinverCore::Parameter::minimum ( ) const [inline]
const QString& DinverCore::Parameter::name ( ) const [inline]
double DinverCore::Parameter::realValue ( ) const [inline]
double DinverCore::Parameter::realValue ( int  val) const [inline]
{return _grid.realValue(val);}
double DinverCore::Parameter::realValue ( double  val) const [inline]
{return _grid.realValue(val);}
void DinverCore::Parameter::setFussy ( bool  f) [inline]

Referenced by DinverDCCore::ParamLayer::depthToParam().

{_fussy=f;}
void DinverCore::Parameter::setGridValue ( int  val) [inline]
void DinverCore::Parameter::setGridValue ( double  val) [inline]
{_value=realValue(val);}
void DinverCore::Parameter::setMaximum ( double  m) [inline]
void DinverCore::Parameter::setMinimum ( double  m) [inline]
void DinverCore::Parameter::setName ( QString  name) [inline]
void DinverCore::Parameter::setPrecision ( double  p) [inline]
DinverCore::Parameter::setRealValue ( double  val) [inline]
bool DinverCore::Parameter::setRealValue ( QDataStream &  s)

Set the real value of the parameter from a binary stream(report). Returns true if the value can set properly. Failure may occur for fixed parameters when the constant value is not the same as the one of the stream.

References QGpCoreTools::endl(), isFixed(), name(), realValue(), setRealValue(), and QGpCoreTools::tr().

  {
    double v;
    s >> v;
    if(isFixed()) {
      if(realValue()!=v) {
        App::stream() << tr("Fixed parameter %1 does not have the correct value (%2 must be %3)").arg(name()).arg(v).arg(realValue()) << endl;
        return false;
      }
    } else {
      setRealValue(v);
    }
    return true;
  }
void DinverCore::Parameter::setUnit ( QString  unit) [inline]
const QString& DinverCore::Parameter::unit ( ) const [inline]

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

  {
    TRACE;
    Q_UNUSED(attributes);
    Q_UNUSED(context);
    if(tag=="min" )
      return XMLMember(0);
    else if(tag=="max" )
      return XMLMember(1);
    else if(tag=="name" )
      return XMLMember(2);
    else if(tag=="unit" )
      return XMLMember(3);
    else
      return XMLMember(XMLMember::Unknown);
  }

Re-implement this function to offer XML restore properties support to your class.

From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).

For a general case:

  Q_UNUSED(attributes);
  double val=content.toDouble();
  switch (memberID) {
  case 0:
    _x1=val;
    return true;
  case 1:
    _y1=val;
    return true;
  case 2:
    _x2=val;
    return true;
  case 3:
    _y2=val;
    return true;
  default:
    return false;
  }

For classes inheriting other classes (see also xml_member())

  switch (memberID) {
  case 0:
    _anInteger=content.toString();
    return true;
  case 1:
    _aString=content.toInt();
    return true;
  case 2:
    _aDouble=content.toDouble();
    return true;
  default:
    return AbstractLine::xml_setProperty(memberID-3, map, content);

For the arguments of this function use Macro XML_SETPROPERTY_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References setMaximum(), setMinimum(), and TRACE.

  {
    TRACE;
    Q_UNUSED(tag);
    Q_UNUSED(attributes);
    Q_UNUSED(context);
    switch (memberID) {
    case 0:
      setMinimum(content.toDouble());
      return true;
    case 1:
      setMaximum(content.toDouble());
      return true;
    case 2:
      _name=content.toString();
      return true;
    case 3:
      _unit=content.toString();
      return true;
    default:
      return false;
    }
  }
virtual const QString& DinverCore::Parameter::xml_tagName ( ) const [inline, protected, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlParamTag;}

Reimplemented from QGpCoreTools::XMLClass.

References maximum(), minimum(), TRACE, and QGpCoreTools::XMLClass::writeProperty().

  {
    TRACE;
    Q_UNUSED(context);
    writeProperty(s, "name", _name);
    writeProperty(s, "unit", _unit);
    writeProperty(s, "min", minimum());
    writeProperty(s, "max", maximum());
  }

Member Data Documentation

const QString DinverCore::Parameter::xmlParamTag = "Param" [static, protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines