Пример #1
0
void IISource::get(Variable& x) {
  int type = getType();
  if(type==GBInputNumbers::s_IOSYMBOL) {
    symbolGB y;
    ((ISource *)this)->get(y);
    x.assign(y.value().chars());
  } else if(type==GBInputNumbers::s_IOFUNCTION) {
    StringAccumulator acc; 
    getAnything(acc);
    x.assign(acc.chars());
  } else DBG();
};
Пример #2
0
void OptimizableFunction::checkGradient( const FactorPtrVec & facs,
		const PartialGradient & g, const Numeric h ) const {

//	const Numeric h = 1e-8;
	Numeric origeval = 0.0, ferr = 0.0;
	PartialGradient fd;
	fd.reserve( g.size() );

	Variable * v = NULL;

//	for ( Variable * v : variables ) {
	for ( const auto & pgv : g ) {
		v = variables[pgv.first];

		origeval = v->eval();

		v->assign( v->eval() - h / 2.0 );
		onVarAssigned( v->getID(), v->eval() );
		Numeric fl = evalFactors( facs, ferr, false );

		v->assign( v->eval() + h );
		onVarAssigned( v->getID(), v->eval() );
		Numeric fh = evalFactors( facs, ferr, false );

		// restore v
		v->assign( origeval );
		onVarAssigned( v->getID(), v->eval() );

		fd[v->getID()] = ( fh - fl ) / h;
//		std::cout << "fd for " << v->getID() << ": " << fh << " - " << fl <<
//				" / " << h << " = " << fd[v->getID()] << std::endl;
	}

	assert( fd.size() == g.size() );

//	for ( Variable * v : variables ) {
	for ( const auto & pgv : g ) {
		v = variables[pgv.first];

		assert( g.find( v->getID() ) != g.end() );
		const Numeric fdv = fd.at( v->getID() );

		Numeric fdg = fdv - g.at( v->getID() );
		fdg = ( fdv == 0 ? fdg : fdg / fdv );

		if ( !approxeq( fdg, 0.0, 1e-3 ) ) {
			std::cout << "func grad -- var " << v->getID() << ": df/dv = " <<
					g.at( v->getID() ) << ", fd = " << fd.at( v->getID() ) <<
					" -- diff = " << fd.at( v->getID() ) - g.at( v->getID() ) <<
					", fdg = " << fdg << std::endl;
		}
	}
}
Пример #3
0
void GrbSource::get(Variable& x) {
  char s[2];
  s[1]='\0';
  d_so.getCharacter(s[0]);
  x.assign(s);
  d_eoi = d_so.eof();
};
Пример #4
0
void GrbSource::get(Monomial& x) {
  x.setToOne();
  Variable v;
  char s[2];
  s[1]='\0';
  d_so.getCharacter(s[0],"\n *");
  while(('a'<=*s && *s<='z') || ('A'<=*s&& *s<='Z')) {
    v.assign(s);
    x *= v;
    d_so.getCharacter(s[0]);
  };
  d_so.unGetCharacter(s[0]);
  d_eoi = d_so.eof();
};
Пример #5
0
Value AssignmentOperator::execute(Variable& variable, const Value& rightOperand) const
{
	return variable.assign(rightOperand);
}