Exemplo n.º 1
0
TokArr Tok::PropagateFload(Tok const &tok)
{
    TokArr retval;
    int i, j;
    TokIdNode *nd;

    if(tok.fload.size() == 0)
    {
        return retval;
    }
    if(tok.IsUnres())
    {
        return tok;
    }
    
    for(i = 0, j = 0; j < tok.node.size(); ++j)
    {
        nd = TokIdNode::GetLeaf(tok.node[j]);
        for(; i < tok.fload.size(); ++i)
        {
            retval &= Tok(nd, tok.fload[i]);
            nd = TokIdNode::GetNextLeaf(nd, tok.node[j]);
            if(nd == 0)
            {
                break;
            }
        }
    }
    return retval;
}
Exemplo n.º 2
0
void TestsPnlHigh::TestConditionalGaussianGetJPD()
{
    printf("TestConditionalGaussianGetJPD\n");

    BayesNet *net = SimpleCGM1();
    
    net->SetPGaussian("Cont0", "1.5 -0.5", "1.0 0.3 0.3 2.0", TokArr(), TokArr());
    net->SetPGaussian("Cont1", "0.0", "2.5", "1.0 3.0", "Tab0^State0");
    net->SetPGaussian("Cont1", "-1.5", "0.75", "0.5 2.5", "Tab0^State1");

    net->SetProperty("Inference", "naive");

    net->EditEvidence("Tab0^State0");
    net->GetJPD("Cont0");
    net->GetJPD("Cont1");
    net->GetJPD("Cont2");

    net->ClearEvid();

    Tok tok0("Cont0^Dim0^0.0");
    Tok tok1("Cont0^Dim1^0.0");

    TokIdNode *id0 = tok0.Node();
    TokIdNode *id1 = tok1.Node();

    bool is_int0 = id0->id[id0->id.size()-1].is_int; 
    bool is_int1 = id1->id[id1->id.size()-1].is_int;

    int int_id0 = id0->id[id0->id.size()-1].int_id;
    int int_id1 = id1->id[id1->id.size()-1].int_id;

    TokIdNode *id = net->Net().Token().Node(Tok("Cont0"))->v_next;
    TokIdNode *id2 = net->Net().Token().Node(Tok("Cont1"))->v_next;
    TokIdNode *id3 = net->Net().Token().Node(Tok("Cont2"))->v_next;
    TokIdNode *id4 = net->Net().Token().Node(Tok("Tab0"))->v_next;

    //TokIdNode *a1 = id->v_next;
    //TokIdNode *a2 = a1->h_next;

    net->EditEvidence("Cont0^Dim0^0.0 Cont0^Dim1^1.0");
    net->EditEvidence("Cont1^Dim0^0.0");
    net->EditEvidence("Cont2^Dim0^0.0");

    net->GetJPD("Tab0");

    delete net;
};  
Exemplo n.º 3
0
int NetworkPNL::GetEvidence(int node)
{
    MarkCallFunction("GetEvidence", true);
    Vector<int> aiNode, aiValue;
    if (m_pWNet->Net().EvidenceBoard()->IsEmpty())
        return -1;
    if (!(m_pWNet->Net().EvidenceBoard()->IsNodeHere(Tok(m_pWNet->Net().Token().Node(node)))) || 
        m_pWNet->Net().EvidenceBoard()->IsHidden(Tok(m_pWNet->Net().Token().Node(node))))
        return -1;
    Net().ExtractTokArr(m_pWNet->Net().EvidenceBoard()->Get(), &aiNode, &aiValue);
    for(int i = aiNode.size(); --i >= 0;)
    {
	if(aiNode[i] == node)
	{
	    return aiValue[i];
	}
    }

    ThrowInternalError("Not found evidence", "GetEvidence");// must be here, but ...
    return -1;
}
Exemplo n.º 4
0
void NetworkPNL::ClearEvidence(int node)
{
    MarkCallFunction("ClearEvidence", true, (String() << "Node #" << node).c_str());
    m_pWNet->Net().EvidenceBoard()->SetVisibility(Tok(m_pWNet->Net().Token().Node(node)),true);
    m_aNodeValueStatus[node] = NetConst::NotUpdated;
}
Exemplo n.º 5
0
void NetworkPNL::SetEvidence(int node, int outcomeIndex)
{
    MarkCallFunction("SetEvidence", true, (String() << "Node #" << node).c_str());
    m_pWNet->EditEvidence(Tok(Graph().NodeName(node))^outcomeIndex);
    m_aNodeValueStatus[node] = NetConst::Updated;
}
Exemplo n.º 6
0
bool NetworkPNL::IsRealEvidence(int node)
{
    MarkCallFunction("IsRealEvidence", true, (String() << "Node #" << node).c_str());
    return (m_pWNet->Net().EvidenceBoard()->IsNodeHere(Tok(m_pWNet->Net().Token().Node(node))) && !m_pWNet->Net().EvidenceBoard()->IsHidden(Tok(m_pWNet->Net().Token().Node(node))));
}
Exemplo n.º 7
0
#ifdef OLD_TOKENS

#pragma warning(push, 2)
#include <queue>
#pragma warning(pop)

#include "pnlTok.hpp"

PNLW_BEGIN

TokIdNode *TokIdNode::root = new(TokIdNode)("");
Vector< TokIdNode * > TokIdNode::cemetery;
Tok Tok::root(TokIdNode::root);
Tok Tok::nil = Tok();

TokId::TokId(String const &s)
{
    Init(s);
}

TokId::TokId(char const s[])
{
    Init(s);
}

void TokId::Init(String const &s)
{
    int i;

    for(i = s.size(); i--;)
    {
Exemplo n.º 8
0
void Mesh::clean() {
  uint i, j, idist=0;
  Vector a, b, c, m;
  double mdist=0.;
  arr Tc(T.d0, 3); //tri centers
  arr Tn(T.d0, 3); //tri normals
  uintA Vt(V.d0);
  intA VT(V.d0, 100); //tri-neighbors to a vertex
  Vt.setZero(); VT=-1;
  
  for(i=0; i<T.d0; i++) {
    a.set(&V(T(i, 0), 0)); b.set(&V(T(i, 1), 0)); c.set(&V(T(i, 2), 0));
    
    //tri center
    m=(a+b+c)/3.;
    Tc(i, 0)=m.x;  Tc(i, 1)=m.y;  Tc(i, 2)=m.z;
    
    //farthest tri
    if(m.length()>mdist) { mdist=m.length(); idist=i; }
    
    //tri normal
    b-=a; c-=a; a=b^c; a.normalize();
    Tn(i, 0)=a.x;  Tn(i, 1)=a.y;  Tn(i, 2)=a.z;
    
    //vertex neighbor count
    j=T(i, 0);  VT(j, Vt(j))=i;  Vt(j)++;
    j=T(i, 1);  VT(j, Vt(j))=i;  Vt(j)++;
    j=T(i, 2);  VT(j, Vt(j))=i;  Vt(j)++;
  }
  
  //step through tri list and flip them if necessary
  boolA Tisok(T.d0); Tisok=false;
  uintA Tok; //contains the list of all tris that are ok oriented
  uintA Tnew(T.d0, T.d1);
  Tok.append(idist);
  Tisok(idist)=true;
  int A=0, B=0, D;
  uint r, k, l;
  intA neighbors;
  for(k=0; k<Tok.N; k++) {
    i=Tok(k);
    Tnew(k, 0)=T(i, 0); Tnew(k, 1)=T(i, 1); Tnew(k, 2)=T(i, 2);
    
    for(r=0; r<3; r++) {
      if(r==0) { A=T(i, 0);  B=T(i, 1);  /*C=T(i, 2);*/ }
      if(r==1) { A=T(i, 1);  B=T(i, 2);  /*C=T(i, 0);*/ }
      if(r==2) { A=T(i, 2);  B=T(i, 0);  /*C=T(i, 1);*/ }
      
      //check all triangles that share A & B
      setSection(neighbors, VT[A], VT[B]);
      neighbors.removeAllValues(-1);
      if(neighbors.N>2) MT_MSG("edge shared by more than 2 triangles " <<neighbors);
      neighbors.removeValue(i);
      //if(!neighbors.N) cout <<"mesh.clean warning: edge has only one triangle that shares it" <<endl;
      
      //orient them correctly
      for(l=0; l<neighbors.N; l++) {
        j=neighbors(l); //j is a neighboring triangle sharing A & B
        D=-1;
        //align the neighboring triangle and let D be its 3rd vertex
        if((int)T(j, 0)==A && (int)T(j, 1)==B) D=T(j, 2);
        if((int)T(j, 0)==A && (int)T(j, 2)==B) D=T(j, 1);
        if((int)T(j, 1)==A && (int)T(j, 2)==B) D=T(j, 0);
        if((int)T(j, 1)==A && (int)T(j, 0)==B) D=T(j, 2);
        if((int)T(j, 2)==A && (int)T(j, 0)==B) D=T(j, 1);
        if((int)T(j, 2)==A && (int)T(j, 1)==B) D=T(j, 0);
        if(D==-1) HALT("dammit");
        //determine orientation
        if(!Tisok(j)) {
          T(j, 0)=B;  T(j, 1)=A;  T(j, 2)=D;
          Tok.append(j);
          Tisok(j)=true;
        } else {
          //check if consistent!
        }
      }
      
#if 0
      //compute their rotation
      if(neighbors.N>1) {
        double phi, phimax;
        int jmax=-1;
        Vector ni, nj;
        for(l=0; l<neighbors.N; l++) {
          j=neighbors(l); //j is a neighboring triangle sharing A & B
          
          a.set(&V(T(i, 0), 0)); b.set(&V(T(i, 1), 0)); c.set(&V(T(i, 2), 0));
          b-=a; c-=a; a=b^c; a.normalize();
          ni = a;
          
          a.set(&V(T(j, 0), 0)); b.set(&V(T(j, 1), 0)); c.set(&V(T(j, 2), 0));
          b-=a; c-=a; a=b^c; a.normalize();
          nj = a;
          
          Quaternion q;
          q.setDiff(ni, -nj);
          q.getDeg(phi, c);
          a.set(&V(A, 0)); b.set(&V(B, 0));
          if(c*(a-b) < 0.) phi+=180.;
          
          if(jmax==-1 || phi>phimax) { jmax=j; phimax=phi; }
        }
        if(!Tisok(jmax)) {
          Tok.append(jmax);
          Tisok(jmax)=true;
        }
      } else {
        j = neighbors(0);
        if(!Tisok(j)) {
          Tok.append(j);
          Tisok(j)=true;
        }
      }
#endif
    }
  }
  if(k<T.d0) {
    cout <<"mesh.clean warning: not all triangles connected: " <<k <<"<" <<T.d0 <<endl;
    cout <<"WARNING: cutting of all non-connected triangles!!" <<endl;
    Tnew.resizeCopy(k, 3);
    T=Tnew;
    deleteUnusedVertices();
  }
  computeNormals();
}