/* * This function suffers from the same ills as the refine command * above. We will fix the g_curinst and the g_search_inst pointers * but nothing else. Any one else looking at those instance had * better be notified otherwise. */ int Asc_BrowMakeAlikeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) { struct TypeDescription *desc,*desc1,*desc2; struct Instance *i1, *i2; UNUSED_PARAMETER(cdata); (void)argv; /* stop gcc whine about unused parameter */ if ( argc != 3 ) { Tcl_SetResult(interp, "wrong # args : Usage \"bmakealike\" current search", TCL_STATIC); return TCL_ERROR; } i1 = g_curinst; i2 = g_search_inst; if (i1 && i2) { desc1 = InstanceTypeDesc(i1); desc2 = InstanceTypeDesc(i2); if (desc1==desc2) { MergeCliques(i1,i2); } else { if (0 != (desc = MoreRefined(desc1,desc2))) { if (desc == desc1) { /* desc1 more refined than desc2*/ i2 = RefineClique(i2,desc,NULL); } else { i1 = RefineClique(i1,desc,NULL); } MergeCliques(i1,i2); g_curinst = i1; g_search_inst = i2; /* patch the pointers */ } else { g_curinst = i1; g_search_inst = i2; /* patch the pointers */ Tcl_SetResult(interp, "Instances are unconformable", TCL_STATIC); return TCL_ERROR; } } } else { Tcl_SetResult(interp, "Invalid instances in b_makealike", TCL_STATIC); return TCL_ERROR; } return TCL_OK; }
void CJtreeInfEngine::MarginalNodes( const int *query, int querySz, int notExpandJPD ) { // bad-args check PNL_CHECK_IS_NULL_POINTER(query); PNL_CHECK_RANGES( querySz, 1, m_pGraphicalModel->GetNumberOfNodes() ); // bad-args check end /* // the following should be working differently for the case of doing the // whole EnterEvidence procedure or just CollectEvidence for the root node if( ( m_lastOpDone != opsDistribute ) && ( m_lastOpDone != opsMargNodes ) ) { if( m_lastOpDone != opsCollect ) { PNL_THROW( CInvalidOperation, " cannot perform marginalization, infEngine inconsistent " ); } int numOfClqsContQuery; const int *clqsContQuery; m_pOriginalJTree->GetClqNumsContainingSubset( querySz, query, &numOfClqsContQuery, &clqsContQuery ); PNL_CHECK_FOR_ZERO(numOfClqsContQuery); if( std::find( clqsContQuery, clqsContQuery + numOfClqsContQuery, m_JTreeRootNode ) == clqsContQuery + numOfClqsContQuery ) { PNL_THROW( CInvalidOperation, " cannot marginalize to the non-root-clq nodes set " ); } //////// this is to debug for( int i = 0; i < numOfClqsContQuery; ++i ) { CPotential *pJPot = m_pJTree->GetNodePotential(clqsContQuery[i]) ->Marginalize( query, querySz ); CPotential *pJPot1 = pJPot->GetNormalized(); pJPot1->Dump(); delete pJPot; delete pJPot1; } /////////////////////////////////////////////////////// MarginalizeCliqueToQuery( m_JTreeRootNode, querySz, query ); m_lastOpDone = opsMargNodes; } else { */ int numOfClqsContQuery; const int *clqsContQuery; m_pJTree->GetClqNumsContainingSubset( querySz, query, &numOfClqsContQuery, &clqsContQuery ); if(numOfClqsContQuery) { if( std::find( clqsContQuery, clqsContQuery + numOfClqsContQuery, m_JTreeRootNode ) != ( clqsContQuery + numOfClqsContQuery ) ) { MarginalizeCliqueToQuery( m_JTreeRootNode, querySz, query, notExpandJPD ); } else { MarginalizeCliqueToQuery( *clqsContQuery, querySz, query, notExpandJPD ); } } else { const int* clqDomain; int clqSize; CPotential *resPot = NULL; delete m_pQueryJPD; m_pQueryJPD = NULL; ShrinkJTreeCliques(querySz, const_cast<int*>(query)); resPot = MergeCliques(querySz, const_cast<int*>(query)); resPot->GetDomain(&clqSize, &clqDomain); if( !pnlIsIdentical(querySz, const_cast<int*>(query), clqSize, const_cast<int*>(clqDomain)) ) { m_pQueryJPD = resPot->Marginalize(const_cast<int*>(query), querySz); } else { m_pQueryJPD = static_cast<CPotential*>(resPot->Clone()); } m_pQueryJPD->Normalize(); delete resPot; } }