bool TabularCPT::Validate() const { int parent_size = ParentSize(), child_size = ChildSize(); for (int p = 0; p < parent_size; p++) { double sum = 0; for (int c = 0; c < child_size; c++) { sum += GetValue(p, c); } if (fabs(sum - 1.0) > 1e-6) { vector<int> index = Variable::ComputeIndexVec(parents_, p); cerr << "ERROR: Probabilities do not sum to one when parents = ["; for (int i = 0; i < index.size(); i++) { cerr << (i == 0 ? "" : ", ") << parents_[i]->name() << "=" << parents_[i]->GetValue(index[i]); } cerr << "]" << endl; cerr << " Sum = " << sum << "; Entries: ["; for (int i = 0; i < child_size; i++) { cerr << (i == 0 ? "" : ", ") << child_->GetValue(i) << "=" << GetValue(p, i); } cerr << "]" << endl; return false; } } return true; }
void TabularCPT::ComputeSparseChildDistribution() { int parent_size = ParentSize(), child_size = ChildSize(); sparse_values_.resize(parent_size); for (int p = 0; p < parent_size; p++) { for (int c = 0; c < child_size; c++) { if (GetValue(p, c) > 0) sparse_values_[p].push_back( pair<int, double>(c, GetValue(p, c))); } } }
EXPORT_C void CHuiLayout::UpdateChildLayout(TInt aIndex, TInt aTransitionTime) { THuiRealRect rect; TSize size; TPoint pos; TInt ordinal = ChildOrdinal(aIndex); CHuiVisual* child = iHuiLayoutPrivateData->iChildren[aIndex]; TInt flags = child->Flags(); TInt transitionTime = aTransitionTime; if(flags & EHuiVisualFlagManualTransitionTime) { // override the parent's transition time with our local one. transitionTime = TransitionTime(); } // if either flag is missing, call child rect... TBool bothManual = (flags & EHuiVisualFlagManualPosition) && (flags & EHuiVisualFlagManualSize); if(!bothManual) { TInt childRectStatus = ChildRect(ordinal, rect); if(childRectStatus != THuiLayoutChildRectNotImplemented) { if(!(flags & EHuiVisualFlagManualPosition) && (childRectStatus & THuiLayoutChildRectPosUpdateNeeded)) { child->SetPos(rect.iTl, transitionTime); } if(!(flags & EHuiVisualFlagManualSize) && (childRectStatus & THuiLayoutChildRectSizeUpdateNeeded)) { child->SetSize(rect.Size(), transitionTime); } } else { if(!(flags & EHuiVisualFlagManualPosition) && ChildPos(ordinal, pos)) { child->SetPos(pos, transitionTime); } if(!(flags & EHuiVisualFlagManualSize) && ChildSize(ordinal, size)) { child->SetSize(size, transitionTime); } } } child->ReportLayoutUpdate(); }
CPT* TabularCPT::CreateNoisyVariant(double noise) const { int parent_size = ParentSize(), child_size = ChildSize(); TabularCPT* cpt = new TabularCPT(child_, parents_); cpt->map_.clear(); cpt->values_.resize(parent_size); for (int i = 0; i < parent_size; i++) cpt->values_[i].resize(child_size); for (int p = 0; p < parent_size; p++) { for (int c = 0; c < child_size; c++) { cpt->values_[p][c] = (GetValue(p, c) + noise / child_size) / (1 + noise); } } return cpt; }
void CComponentControl::ConstructL(TInt aChildren, TInt aOwners, TPoint aPt, TSize aSize, TRgb aPenColor, TRgb aBrushColor, CGraphicsContext::TBrushStyle aBrushStyle) { //Construct the base window of the control CTestRectGc::ConstructL(aPt, aSize, aPenColor, aBrushColor, aBrushStyle); InitComponentArrayL(); TSize ChildSize(aSize.iWidth/2, aSize.iHeight/2); TPoint Offset; if (aOwners&1) Offset.SetXY(0,0); else Offset = aPt; CreateChildControlL(aChildren, aOwners>>1, Offset, ChildSize, aPenColor, aBrushColor, aBrushStyle); CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(ChildSize.iWidth, 0), ChildSize, aPenColor, aBrushColor, aBrushStyle); CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(0, ChildSize.iHeight), ChildSize, aPenColor, aBrushColor, aBrushStyle); CreateChildControlL(aChildren, aOwners>>1, Offset+TSize(ChildSize.iWidth, ChildSize.iHeight), ChildSize, aPenColor, aBrushColor, aBrushStyle); }
double Function::ComputeConstrainedMaximum(const NamedVar* var, int value) const { if (var->values().size() <= value) throw std::invalid_argument( "Variable " + var->name() + " cannot have value " + to_string(value) + "."); // cout << "Computing constrained maximum (" << var->name() << " = " << value << ")" << endl; // cout << *this << endl; int parent_size = ParentSize(); int child_size = ChildSize(); double max = Globals::NEG_INFTY; if (var == child_) { for (int p = 0; p < parent_size; p++) if (GetValue(p, value) > max) max = GetValue(p, value); } else { int id = -1; for (int i = 0; i < parents_.size(); i++) if (parents_[i] == var) { id = i; break; } for (int p = 0; p < parent_size; p++) { vector<int> vec = Variable::ComputeIndexVec(parents_, p); if (id == -1 || vec[id] == value) { for (int c = 0; c < child_size; c++) { if (GetValue(p, c) > max) { max = GetValue(p, c); } } } } } // cout << "max = " << max << endl; return max; }
void HorizontalScrollbar::ConstructHorizontalScrollbar(const UI::ScrollbarStyle& ScrollStyle) { // Create the rects we'll use UnifiedVec2 ChildPosition(0,0,0,0); UnifiedVec2 ChildSize(1,1,0,0); UnifiedRect ChildRect(ChildPosition,ChildSize); if( UI::SB_NoButtons == ScrollStyle ) { // Create our objects this->ScrollBack = ParentScreen->CreateButton(this->Name+".ScrollBack",ChildRect); this->ScrollBack->SetHorizontalSizingRules(UI::SR_Fill_Available); this->ScrollBack->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->ScrollBack,0); this->Scroller = ParentScreen->CreateButton(this->Name+".Scroller",ChildRect); this->Scroller->SetManualTransformUpdates(true); this->AddChild(this->Scroller,1); } else { //Get the position for all items involved and configure their offsets if(UI::SB_Separate == ScrollStyle) { // Create our objects this->UpLeftButton = ParentScreen->CreateButton(this->Name+".LeftButton",ChildRect); this->UpLeftButton->SetHorizontalPositioningRules(UI::PF_Anchor_Left); this->UpLeftButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->UpLeftButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->UpLeftButton,0); this->ScrollBack = ParentScreen->CreateButton(this->Name+".ScrollBack",ChildRect); this->ScrollBack->SetHorizontalSizingRules(UI::SR_Fill_Available); this->ScrollBack->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->ScrollBack,1); this->DownRightButton = ParentScreen->CreateButton(this->Name+".RightButton",ChildRect); this->DownRightButton->SetHorizontalPositioningRules(UI::PF_Anchor_Right); this->DownRightButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->DownRightButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->DownRightButton,2); this->Scroller = ParentScreen->CreateButton(this->Name+".Scroller",ChildRect); this->Scroller->SetManualTransformUpdates(true); this->AddChild(this->Scroller,3); } else if(UI::SB_TogetherDownRight == ScrollStyle) { // Create our objects this->ScrollBack = ParentScreen->CreateButton(this->Name+".ScrollBack",ChildRect); this->ScrollBack->SetHorizontalSizingRules(UI::SR_Fill_Available); this->ScrollBack->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->ScrollBack,0); this->UpLeftButton = ParentScreen->CreateButton(this->Name+".LeftButton",UnifiedRect(UnifiedVec2(-1,-1,0,0),ChildSize)); this->UpLeftButton->SetHorizontalPositioningRules(UI::PF_Anchor_Right | UI::PF_Anchor_SelfSize); this->UpLeftButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->UpLeftButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->UpLeftButton,1); this->DownRightButton = ParentScreen->CreateButton(this->Name+".RightButton",ChildRect); this->DownRightButton->SetHorizontalPositioningRules(UI::PF_Anchor_Right); this->DownRightButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->DownRightButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->DownRightButton,2); this->Scroller = ParentScreen->CreateButton(this->Name+".Scroller",ChildRect); this->Scroller->SetManualTransformUpdates(true); this->AddChild(this->Scroller,3); } else if(UI::SB_TogetherUpLeft == ScrollStyle) { // Create our objects this->UpLeftButton = ParentScreen->CreateButton(this->Name+".LeftButton",ChildRect); this->UpLeftButton->SetHorizontalPositioningRules(UI::PF_Anchor_Left); this->UpLeftButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->UpLeftButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->UpLeftButton,0); this->DownRightButton = ParentScreen->CreateButton(this->Name+".RightButton",UnifiedRect(UnifiedVec2(1,1,0,0),ChildSize)); this->DownRightButton->SetHorizontalPositioningRules(UI::PF_Anchor_Left | UI::PF_Anchor_SelfSize); this->DownRightButton->SetHorizontalSizingRules(UI::SR_Match_Other_Axis); this->DownRightButton->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->DownRightButton,1); this->ScrollBack = ParentScreen->CreateButton(this->Name+".ScrollBack",ChildRect); this->ScrollBack->SetHorizontalSizingRules(UI::SR_Fill_Available); this->ScrollBack->SetVerticalSizingRules(UI::SR_Unified_Dims); this->AddChild(this->ScrollBack,2); this->Scroller = ParentScreen->CreateButton(this->Name+".Scroller",ChildRect); this->Scroller->SetManualTransformUpdates(true); this->AddChild(this->Scroller,3); } } Rect TempDims; if( this->ActDims != TempDims ) { TempDims = this->ActDims; this->UpdateDimensions(TempDims,TempDims); } this->SubscribeToChildEvents(); }