Ejemplo n.º 1
0
    inline result_type operator()(const T &t) const
    {
//std::cout<<"unary energy\n";
        std::map< std::string,double > dist,hasWindow;
        _lot->dist2borders(t,dist,hasWindow);


        std::map<Var,double> var_value;
        std::map< std::string,double >::iterator it;
        for(it=dist.begin(); it!=dist.end(); ++it)
        {
            if(it->second!=it->second || isinf(it->second))
                return _eRej*3;

            var_value.insert(std::make_pair(Var("d"+it->first),it->second));
        }

        for(it=hasWindow.begin();it!=hasWindow.end();++it)
            var_value.insert(std::make_pair(Var("hasWindow"+it->first),it->second));

        var_value.insert(std::make_pair(Var("h"),t.h()));
        result_type eFront=0,eSide=0,eBack=0;

        if(_lot->hasRule(RuleType::DistFront))
            eFront = (_lot->ruleEnergy(RuleType::DistFront))->energy(var_value);

        if(_lot->hasRule(RuleType::DistSide))
            eSide = (_lot->ruleEnergy(RuleType::DistSide))->energy(var_value);

        if(_lot->hasRule(RuleType::DistBack))
            eBack = (_lot->ruleEnergy(RuleType::DistBack))->energy(var_value);

        return (eFront+eSide+eBack)*_eRej;
    }
Ejemplo n.º 2
0
    inline result_type operator()(double x,double h) const
    {
        std::map<Var,double> var_value;
        std::map< std::string,Border* >::iterator it,bbegin,bend;
        bbegin = _lot->name_borders().begin();
        bend = _lot->name_borders().end();
        for(it=bbegin;it!=bend;++it)
        {
            var_value.insert(std::make_pair(Var("d"+it->first),x));
            var_value.insert(std::make_pair(Var("hasWindow"+it->first),1.));
        }
        var_value.insert(std::make_pair(Var("h"),_lot->ruleGeom()->hMax()));

        double eFront=0,eSide=0,eBack=0;
        if(_lot->hasRule(RuleType::DistFront))
            eFront = (_lot->ruleEnergy(RuleType::DistFront))->energy(var_value);

        if(_lot->hasRule(RuleType::DistSide))
            eSide = (_lot->ruleEnergy(RuleType::DistSide))->energy(var_value);

        if(_lot->hasRule(RuleType::DistBack))
            eBack = (_lot->ruleEnergy(RuleType::DistBack))->energy(var_value);


        return _eRej*std::max(std::max(eFront,eSide),eBack);
    }
Ejemplo n.º 3
0
static void
Relative(struct dataset *ds, struct dataset *rs, int confidx)
{
	double spool, s, d, e, t;
	int i;

	i = ds->n + rs->n - 2;
	if (i > NSTUDENT)
		t = student[0][confidx];
	else
		t = student[i][confidx];
	spool = (ds->n - 1) * Var(ds) + (rs->n - 1) * Var(rs);
	spool /= ds->n + rs->n - 2;
	spool = sqrt(spool);
	s = spool * sqrt(1.0 / ds->n + 1.0 / rs->n);
	d = Avg(ds) - Avg(rs);
	e = t * s;

	if (fabs(d) > e) {
	
		printf("Difference at %.1f%% confidence\n", studentpct[confidx]);
		printf("	%g +/- %g\n", d, e);
		printf("	%g%% +/- %g%%\n", d * 100 / Avg(rs), e * 100 / Avg(rs));
		printf("	(Student's t, pooled s = %g)\n", spool);
	} else {
		printf("No difference proven at %.1f%% confidence\n",
		    studentpct[confidx]);
	}
}
Ejemplo n.º 4
0
func CreateContructionNear(id def, int x, int y, int owner)
{
  Var(0)=x; Var(1)=y;
  if (!FindConstructionSite(def, 0,1)) return 0;
  x=Var(0); y=Var(1);
  return CreateConstruction(def, x,y, owner, 100, true);
}
Ejemplo n.º 5
0
Lua::Var Lua::State :: load_str(std::string &str)
 { int n = lua_gettop(vm);
   if(luaL_dostring(vm, str.c_str()))
    lua_error(vm);
   int t = lua_gettop(vm) - n;
   if (t > 0) return Var(this, n + 1, t);
   else return Var();
 }
Ejemplo n.º 6
0
Lua::Var Lua::State :: load_file(const char* fileName)
 { int n = lua_gettop(vm);
   if(luaL_dofile(vm, fileName))
    lua_error(vm);
   int t = lua_gettop(vm) - n;
   if (t > 0) return Var(this, n + 1, t);
   else return Var();
 }
Ejemplo n.º 7
0
Lua::Var Lua::State :: load_data(Data* data)
 { int n = lua_gettop(vm);
   if(luaL_loadbuffer(vm, (const char*)data -> getPtr(), data ->getLength(),
                           "") || lua_pcall(vm, 0, LUA_MULTRET, 0))
    lua_error(vm);
   int t = lua_gettop(vm) - n;
   if (t > 0) return Var(this, n + 1, t);
   else return Var();
 }
Ejemplo n.º 8
0
      void constraints() {
        OKLIB_MODELS_CONCEPT_TAG(Var, VariablesAsIndex);

        OKLIB_MODELS_CONCEPT_REQUIRES(Var, VariablesWithIndex);
        OKLIB_MODELS_CONCEPT_TAG(Var, VariablesWithIndex);

        dummy_use_v(Var(i));
        dummy_use_v(Var(ic));
      }
Ejemplo n.º 9
0
void CBP::construct() {

	// prepare datastructures for compression
	for (size_t i=0; i<nrVars(); i++) {
		_gndVarToSuperVar[i] = i;
	}

	for (size_t i=0; i<nrFactors(); i++) {
		_gndFacToSuperFac[i] = i;
	}

	// create edge properties
	_edges.clear();
	_edges.reserve( nrVars() );
	for( size_t i = 0; i < nrVars(); ++i ) {
		_edges.push_back( vector<EdgeProp>() );
		_edges[i].reserve( nbV(i).size() );
		foreach( const Neighbor &I, nbV(i) ) {

			EdgeProp newEP;
			size_t edgeCount = factor(I).counts()[I.dual].size();
			newEP.message = vector<Prob>(edgeCount,Prob( var(i).states() ));
			newEP.newMessage = vector<Prob>(edgeCount,Prob( var(i).states() ));
			newEP.count = vector<int>(edgeCount);
			newEP.index = vector<ind_t>(edgeCount);
			newEP.nrPos = edgeCount;

			// simulate orginal varSet with possibly more variables, must ensure that the number of variables is equal to number of ground variables
			VarSet gndVarSet;
			size_t varCount = 0;
			foreach(const Neighbor &tmpVar, nbF(I)) {
				for(map<size_t, int>::const_iterator iter=factor(I).counts()[tmpVar.iter].begin(); iter!=factor(I).counts()[tmpVar.iter].end();iter++) {
					gndVarSet |= Var(varCount, var(tmpVar).states());
					varCount++;
				}
			}

			varCount = 0;
			foreach(const Neighbor &tmpVar, nbF(I)) {
				size_t pos=0;
				for(map<size_t, int>::const_iterator iter=factor(I).counts()[tmpVar.iter].begin(); iter!=factor(I).counts()[tmpVar.iter].end();iter++,pos++) {
					if (tmpVar == i) {
						// assumes that counts are iterated in increases order of positions
						size_t sortedPos = factor(I).sigma()[(*iter).first];
						newEP.count[pos] = (*iter).second;
						newEP.index[pos].reserve( factor(I).states() );
						for( IndexFor k( Var(sortedPos, var(i).states()), gndVarSet ); k >= 0; ++k ) {
							newEP.index[pos].push_back( k );
						}
					}
					varCount++;
				}
			}

			_edges[i].push_back( newEP );
		}
TEST(Util, NormalSampleTest) {
    VReal tmp;
    for (int i = 0; i < 1000000; i++) {
        tmp.push_back(NormalSample() / 100);
    }
    EXPECT_LT(std::abs(0.0 - Mean(tmp)), 0.00001);
    EXPECT_LT(std::abs(0.0001 - Var(tmp)), 0.00001);
    VVVReal tmp2;
    RandomInit(100, 100, 100, &tmp2);
    EXPECT_LT(std::abs(0.0 - Mean(tmp2)), 0.00001);
    EXPECT_LT(std::abs(0.0001 - Var(tmp2)), 0.00001);
}
Ejemplo n.º 11
0
TensorIndex::TensorIndex(std::string name, pe::PathExpression pexpr)
    : content(new Content) {
  content->name = name;
  content->pexpr = pexpr;
  content->kind = PExpr;

  string prefix = (name == "") ? name : name + ".";
  content->coordArray = Var(prefix + "coords",
                            ArrayType::make(ScalarType::Int));
  content->sinkArray  = Var(prefix + "sinks",
                            ArrayType::make(ScalarType::Int));
}
Ejemplo n.º 12
0
global func ExtraLog(szString, a,b,c,d,e,f,g,e,h)
{	
  var obj, i;
  // Alle vorigen Logs speichern und verschieben
  while(obj = FindObject(_LOG, 0-GetX(), 0-GetY(), -1, -1, 0, 0, 0, 0, obj)) Var(i++) = obj;  
  while(--i>=0) SetPosition(GetX(Var(i)), GetY(Var(i))+18, Var(i));
  // Neues Log hinzufügen
  var szText = Format(szString, a,b,c,d,e,f,g,e,h);
  obj = CreateObject(_LOG, -GetX(), 138-GetY(), -1);
  AddEffect("Log", obj, 1, 1, 0, _LOG, szText);
  return(1);
}
TEST(Util, VarTest) {
    VReal tmp;
    tmp.push_back(1);
    tmp.push_back(2);
    tmp.push_back(3);
    EXPECT_DOUBLE_EQ(2.0 / 3, Var(tmp));
    VVReal tmp2;
    tmp2.push_back(tmp);
    tmp2.push_back(tmp);
    EXPECT_DOUBLE_EQ(2.0 / 3, Var(tmp2));
    VVVReal tmp3;
    tmp3.push_back(tmp2);
    tmp3.push_back(tmp2);
    EXPECT_DOUBLE_EQ(2.0 / 3, Var(tmp3));
}
Ejemplo n.º 14
0
Var Interpreter::make_Callable( Vec<Var> lst, Var self ) {
    // remove doubles
    for( int i = 0; i < lst.size(); ++i )
        for( int j = i + 1; j < lst.size(); ++j )
            if ( lst[ i ].expr() == lst[ j ].expr() )
                lst.remove_unordered( j-- );

    //
    Expr surdef_list_data = cst( SI32( lst.size() ) );
    for( int i = 0; i < lst.size(); ++i )
        surdef_list_data = concat( surdef_list_data, pointer_on( lst[ i ].expr() ) );
    Var surdef_list( &type_SurdefList, surdef_list_data );

    //
    Var self_type = type_of( self ); // returns void if self is not defined

    // -> Callable[ surdef_list, self_type, parm_type ]
    Var *parms[ 3 ];
    parms[ 0 ] = &surdef_list;
    parms[ 1 ] = &self_type;
    parms[ 2 ] = &void_var;

    Var *callable_type = type_for( class_info( class_Callable ), parms );
    return Var( callable_type, self ? pointer_on( self.expr() ) : cst() ).add_ref( 0, self );
}
Ejemplo n.º 15
0
Var Interpreter::ext_method( const Var &var ) {
    if ( isa_Def( var ) )
        if ( DefInfo *d = def_info( pointer_on( var.expr() ) ) )
            if ( d->self_as_arg() )
                return var;
    return Var();
}
Ejemplo n.º 16
0
__inline__ bool rebelege_Verz(LIT x)

/* Macht x -> 0 wieder rueckgaengig fuer eine Verzweigungsvariable. */

/* rebelege_Verz = true falls verzweigt werden muss. */

{
  LITV y, z;
  LIT kx;
  VAR v;

  for (y = erstesVork(x); echtesVork(y, x); y = naechstesVork(y))
    {
      bindeLK(y);
      LaengeP1(KlnVk(y));
    }

  for (y = erstesVork(kx = Komp(x)); echtesVork(y, kx); y = naechstesVork(y))
    for (z = naechstesVorkK(y); z != y; z = naechstesVorkK(z))
      bindeLv(z);

  bindeV(v = Var(x));
  setzenbelegt(v, false);

  return enthalten(v);

}
Ejemplo n.º 17
0
void * reduce_phase2(const void * _exp)
{
	if(isA(_exp, Integer()))
		return domainCast(_exp, Real());
	else if(isA(_exp, Real()) || isA(_exp, Var()))
		return copy(_exp);
	else if(isA(_exp, Sum()) || isA(_exp, Product()))
	{
		void * s = copy(_exp);
		size_t i;
		for(i = 0; i < size(s); ++i)
		{
			delete(argv(s, i));
			setArgv(s, i, reduce_phase2(argv(_exp, i)));
		}
		return s;
	}
	else if(isA(_exp, Pow()))
	{
		void * p = copy(_exp);
		delete(base(p));
		delete(power(p));
		setBase(p, reduce_phase2(base(_exp)));
		setPower(p, reduce_phase2(power(_exp)));
		return p;
	}
	else if(isOf(_exp, Apply_1()))
	{
		void * f = copy(_exp);
		delete(arg(f));
		setArg(f, reduce_phase2(arg(_exp)));
		return f;
	}
	assert(0);
}
Ejemplo n.º 18
0
inline
const std::vector<T>
ICR::EnsembleLearning::DeterministicNode<Model,T>::GetVariance() 
{
  std::vector<T> Var(1,0.0);
  return Var;
}
Ejemplo n.º 19
0
CFactorGraph CompressInterface::createCFactorGraph() {

	createVarClustering();
	createFacClustering();

	// create lifted fg here
	vector<CFactor> superFacs;

	// clusterIdx => facIdx
	for (map<size_t,size_t>::iterator facIter = _facRepr.begin(); facIter != _facRepr.end(); facIter++) {
		VarSet superVarSet;

		foreach (const dai::BipartiteGraph::Neighbor &tmpVar, _cfg.nbF(facIter->second)) {
			Var varCluster = _varRepr[_varColorVec[tmpVar]];
			if (!superVarSet.contains(varCluster)) {
				superVarSet |= Var(varCluster);
			}
		}

		CFactor superFac = CFactor(superVarSet, _cfg.factor(facIter->second).p());
		superFac.sigma() = _cfg.factor(facIter->second).sigma();
		superFac.position() = _cfg.factor(facIter->second).position();

		superFac.counts() = createCounts(facIter->second, superVarSet);
		superFacs.push_back(superFac);
	}

	return CFactorGraph(superFacs);
}
Ejemplo n.º 20
0
 Contents(const Type &t, int dims, const std::string &name) :
     t(t), name(name) {
     sizes.resize(dims);
     for (int i = 0; i < dims; i++) {
         sizes[i] = Var(std::string(".") + name + ".dim." + int_to_str(i));  // Connelly: std::ostringstream broken in Python binding, use string + instead
     }
 }
Ejemplo n.º 21
0
void DirectHandler::handleData(const JSONEntity& val)
{
	if (isArray())
	{
		switch(val.type())
		{
		case JSONEntity::JSON_T_STRING:
			_data.push_back(val.toString());
			break;
		case JSONEntity::JSON_T_INTEGER:
			_data.push_back(val.toInteger());
			break;
		case JSONEntity::JSON_T_FLOAT:
			_data.push_back(val.toFloat());
			break;
		case JSONEntity::JSON_T_TRUE:
			_data.push_back(true);
			break;
		case JSONEntity::JSON_T_FALSE:
			_data.push_back(false);
			break;
		case JSONEntity::JSON_T_NULL:
			_data.push_back(Var());
			break;
		default:
			throw Poco::InvalidArgumentException("Unknown type.");
		}
	}
}
Ejemplo n.º 22
0
int WalksatAlgorithm::pickrandom(void)
{
    int tofix;

    tofix = falsified[random()%numfalse];
    return Var(tofix, random()%size[tofix]);
}
Ejemplo n.º 23
0
__inline__ void rebelege(LIT x)

/* Macht x -> 0 wieder rueckgaengig */
/* ("belegt" wird wieder rueckgesetzt). */
/* Ist BAUMRES gesetzt, so wird aktrelV aktualisiert. */

{
  LITV y, z;
  LIT kx;
  VAR v;

  for (y = erstesVork(x); echtesVork(y, x); y = naechstesVork(y))
    {
      bindeLK(y);
      LaengeP1(KlnVk(y));
    }

  for (y = erstesVork(kx = Komp(x)); echtesVork(y, kx); y = naechstesVork(y))
    for (z = naechstesVorkK(y); z != y; z = naechstesVorkK(z))
      bindeLv(z);

  bindeV(v = Var(x));
  setzenbelegt(v, false);

#ifdef BAUMRES
  if (enthalten(v))
    relVhinzufuegen();
#endif

}
Ejemplo n.º 24
0
    Stmt makeLoopNest(Expr tensor) {
      const TensorType *ttype = tensor.type().toTensor();
      std::vector<Var> indices;
      std::vector<Expr> indicesExpr;
      std::vector<IndexSet> domains;
      for (auto &is : ttype->getOuterDimensions()) {
        indices.push_back(Var("index", Int));
        indicesExpr.push_back(indices.back());
        domains.push_back(is);
      }

      Stmt stmt;
      // Recursively build write statement with any inner loops
      if (!isScalar(ttype->getBlockType())) {
        stmt = makeLoopNest(TensorRead::make(tensor, indicesExpr));
      }
      else {
        stmt = TensorWrite::make(tensor, indicesExpr, getZeroVal(ttype));
      }

      // Wrap in current level loops
      for (int i = domains.size()-1; i >= 0; --i) {
        stmt = For::make(indices[i], domains[i], stmt);
      }
      return stmt;
    }
Ejemplo n.º 25
0
int WalksatAlgorithm::picktabu(void)
{
    int numbreak[MAXLENGTH];
    int tofix;
    int clausesize;
    int i;			/* a loop counter */
    int best[MAXLENGTH];	/* best possibility so far */
    int numbest;		/* how many are tied for best */
    int bestvalue;		/* best value so far */
    int noisypick;

    tofix = falsified[random()%numfalse];
    clausesize = size[tofix];
    for(i = 0;i < clausesize;i++)
	numbreak[i] = breakcount[ABS(clause[tofix][i])];

    numbest = 0;
    bestvalue = BIG;

    noisypick = (numerator > 0 && random()%denominator < numerator); 
    for (i=0; i < clausesize; i++) {
	if (numbreak[i] == 0) {
	    if (bestvalue > 0) {
		bestvalue = 0;
		numbest = 0;
	    }
	    best[numbest++] = i;
	}
	else if (tabu_length < numflip - changed[ABS(clause[tofix][i])]) {
	    if (noisypick && bestvalue > 0) { 
		best[numbest++] = i; 
	    }
	    else {
		if (numbreak[i] < bestvalue) {
		    bestvalue = numbreak[i];
		    numbest = 0;
		}
		if (numbreak[i] == bestvalue) {
		    best[numbest++] = i; 
		}
	    }
	}
    }
    if (numbest == 0) return NOVALUE;
    if (numbest == 1) return Var(tofix, best[0]);
    return (Var(tofix, best[random()%numbest]));
}
Ejemplo n.º 26
0
void AusgabeBelegung(FILE* const fp) {
  assert(fp);
  extern enum Ausgabeformat Format;
  const char* Einrueckung = 0;

  if (Format == Dimacs_Format)
    fprintf(fp, "v");
  else {
    assert(Format == XML_Format);
    extern bool Dateiausgabe;
    Einrueckung = (Dateiausgabe) ? "" : " ";
    fprintf(fp, "%s<solution>\n", Einrueckung);
  }

  if (EinerKlausel)
    for (unsigned int i = 0; i < InitEinerRed; ++i) {
      assert(Pfad0[i] > INT_MIN);
      const unsigned int v = abs(Pfad0[i]);
      const VZ e = (Pfad0[i] > 0) ? Pos : Neg;
      if (Format == Dimacs_Format) {
        if (e == Neg)
          fprintf(fp, " %s", Symbol1(v));
        else
          fprintf(fp, " -%s", Symbol1(v));
      }
      else {
        assert(Einrueckung);
        fprintf(fp, "%s  <value var = \"%s\"> %d </value>\n", Einrueckung, Symbol1(v), e);
      }
    }
  {
    const Pfadinfo* const Z = Tiefe;
    for (Tiefe = Pfad; Tiefe < Z; ++Tiefe) {
      const LIT l = PfadLit(); const VAR v = Var(l);
      const VZ e = (l == Literal(v, Pos)) ? Pos : Neg;
      if (Format == Dimacs_Format) {
        if (e == Neg)
          fprintf(fp, " %s", Symbol(v));
        else
          fprintf(fp, " -%s", Symbol(v));
      }
      else {
        assert(Einrueckung);
        fprintf(fp, "%s  <value var = \"%s\"> %d </value>\n", Einrueckung, Symbol(v), e);
      }
    }
    Tiefe = (Pfadinfo*) Z;
  }

  if (Format == Dimacs_Format)
    fprintf(fp, " 0\n");
  else {
    assert(Einrueckung);
    fprintf(fp, "%s</solution>\n", Einrueckung);
    extern bool Dateiausgabe;
    if (! Dateiausgabe)
      fprintf(fp, "</SAT-Solver.output>\n");
  }
}
Ejemplo n.º 27
0
/*!
  \brief In monitoring mode, output branching literal x (with the given
  depth in the search tree).

  Currently output actually only happens if output of a satisfying assignment
  is enabled.
*/
__inline__ static void Verzweigungsliteralausgabe(const LIT x, const unsigned int Tiefe) {
  const VAR v = Var(x);
  const VZ e = (x == Literal(v, Pos)) ? Pos : Neg;
  if (Belegung) {
    fprintf(fpmo, "# %-6d %7s %d\n", Tiefe, Symbol(v), e);
  }
  fflush(NULL);
}
Ejemplo n.º 28
0
bool RefSliceUnk::indirect_set( const Var &src, Scope *set_scope, const Expr &sf, int off, Expr ext_cond ) {
    Expr expr = set_scope->simplified_expr( src, sf, off );

    ASSERT( expr.size_in_bits() == len, "..." );
    Expr res = setval( var.expr(), expr, beg );
    set_scope->set( var, Var( var.type, res ), sf, off, ext_cond );
    return true;
}
Ejemplo n.º 29
0
void split_predicate_test() {
    Expr x = Var("x"), y = Var("y"), z = Var("z"), w = Var("w");

    {
        std::vector<Expr> expected;
        expected.push_back(z < 10);
        check(z < 10, expected);
    }

    {
        std::vector<Expr> expected;
        expected.push_back((x < y) || (x == 10));
        check((x < y) || (x == 10), expected);
    }

    {
        std::vector<Expr> expected;
        expected.push_back(x < y);
        expected.push_back(x == 10);
        check((x < y) && (x == 10), expected);
    }

    {
        std::vector<Expr> expected;
        expected.push_back(x < y);
        expected.push_back(x == 10);
        expected.push_back(y == z);
        check((x < y) && (x == 10) && (y == z), expected);
    }

    {
        std::vector<Expr> expected;
        expected.push_back((w == 1) || ((x == 10) && (y == z)));
        check((w == 1) || ((x == 10) && (y == z)), expected);
    }

    {
        std::vector<Expr> expected;
        expected.push_back(x < y);
        expected.push_back((w == 1) || ((x == 10) && (y == z)));
        check((x < y) && ((w == 1) || ((x == 10) && (y == z))), expected);
    }

    std::cout << "Split predicate test passed" << std::endl;
}
Ejemplo n.º 30
0
//=========================================================
bool Parser::Block () {
    PrintRule rule("Block");
    while (
        Class() ||
        Function() ||
        (Var() && Expect(TokenType::Semicolon))
    );
    return rule.Accept();
}