Node::Ptr RegionsBuilder::BuildCountryRegionTree(Region const & country, Regions const & allRegions) { auto nodes = MakeSelectedRegionsByCountry(country, allRegions); while (nodes.size() > 1) { auto itFirstNode = std::rbegin(nodes); auto & firstRegion = (*itFirstNode)->GetData(); auto itCurr = itFirstNode + 1; for (; itCurr != std::rend(nodes); ++itCurr) { auto const & currRegion = (*itCurr)->GetData(); if (currRegion.Contains(firstRegion) || (GetWeight(firstRegion) < GetWeight(currRegion) && currRegion.Contains(firstRegion.GetCenter()) && currRegion.CalculateOverlapPercentage(firstRegion) > 50.0)) { (*itFirstNode)->SetParent(*itCurr); (*itCurr)->AddChild(*itFirstNode); // We want to free up memory. firstRegion.DeletePolygon(); nodes.pop_back(); break; } } if (itCurr == std::rend(nodes)) nodes.pop_back(); } return nodes.empty() ? std::shared_ptr<Node>() : ShrinkToFit(nodes.front()); }
void Animal::Eat() { this->SetStrength(GetStrength() + 1 + RandomGenerator::AdditionalPoints()); this->SetWeight(GetWeight() + 1 + RandomGenerator::AdditionalPoints()); this->SetSize(GetSize() + 1 + RandomGenerator::AdditionalPoints()); this->SetCurrentState(Eating); }
void SRRasterization::HandleFragment(int x0, int y0, SRVertex & vertex0, int xEnd, int yEnd, SRVertex & vertex1, int x, int y) { // todo : 做好规范体裁剪后应该不用判定这一步 if (IsInScreen(x, y)) { float weight = GetWeight(x0, y0, xEnd, yEnd, x, y); float distance = Lerp(vertex0.m_pos.z, vertex1.m_pos.z, weight); float cacheDistance = m_depthBuffer->GetDepth(x, y); // if (cacheDistance != FLT_MAX) // { // int test = 0; // } if (x == 281 && y == 203) { int test = 0; } if (distance > cacheDistance) { SRColor srColor = SRColor::Lerp(vertex0.m_color, vertex1.m_color, weight); SRFragment srFragment; srFragment.m_color = srColor; SRColor color = PixelShader(srFragment); m_colorBuffer->SetPixel(x, y, color); m_depthBuffer->SetDepth(x, y, distance); } else { int test = 0; } } }
// Update weights void Connection::UpdateNormal( int idx, data_type act, data_type mu, data_type backAct, data_type &dw_sum ) { int j; data_type w, dw, inAct; for ( j = 0; j < mInModule->GetModuleSize(); j++ ) { w = GetWeight( idx, j ); inAct = (*this.*mInAct)( j ); // learning rate up-adjustment for feedback module may be necessary in order for // the feedback information to overcome possibly ambiguous "perceptual" information if ( mInModule->GetModuleType() == O_FB ) { if ( dynamic_cast<Feedback*>(mInModule)->GetFeedback() != kNoWinner ) { mu = mu * mParameters[F_Bw]; } } // apply the Grossberg learning rule dw = mu * act * ( ( mParameters[K_Lmax] - w ) * inAct - mParameters[L_L] * ( w - mParameters[K_Lmin] ) * ( backAct - w * inAct ) ); // Koutnik variant // dw = mu * act * (inAct - w); // add to sum of weight changes dw_sum += dw; // set the new weight SetWeight( idx, j, dw ); } }
void Animal::SearchingForFood() { this->SetEnergy(GetEnergy() - 1 - (2 * RandomGenerator::AdditionalPoints())); this->SetWeight(GetWeight() - 1 - RandomGenerator::AdditionalPoints()); this->SetSize(GetSize() - 1 - RandomGenerator::AdditionalPoints()); this->SetCurrentState(State::SearchingForFood); }
int main() { CApple a; GetWeight(a); GetTotalWeight(); GetTotalWeight(); }
Stroka CWeightSynGroup::GetWeightStr() const { return Sprintf("[w_agr=%f(agr.number=%i) + w_kwtype=%f(kwcount=%i) +\\n w_user=%f]/3=%f", GetWeightByAgreement().AsDouble(), GetRelevantAgrWeight(m_CheckedAgrs), GetWeightByKwTypes().AsDouble(), m_KwtypesCount, GetUserWeight().AsDouble(), GetWeight().AsDouble()); };
int GetTotalItemWeight( CHARLIST *ch ) { int weight = 0; int a, b, c; for(a=0;a<3;a++) for(b=0;b<3;b++) for(c=0;c<8;c++) if(ch->inv[a][b][c].item_no) weight += GetWeight( ch->inv[a][b][c] ); for(a=0;a<6;a++) if(ch->quick[a].item_no) weight += GetWeight(ch->quick[a]); for(a=0;a<8;a++) if(ch->equip[a].item_no) weight += GetWeight(ch->equip[a]); if( ch->handheld.item_no ) weight += GetWeight( ch->handheld ); return weight; }
// Calculated weighted sum of incoming activations for normal connection data_type Connection::WeightedActivation( int idx ) { data_type newAct = 0.0; for ( int j = 0; j < mInModule->GetModuleSize(); j++ ) newAct += GetWeight( idx, j ) * mInModule->GetActivationR( j ); return newAct; }
//o--------------------------------------------------------------------------o //| Function - bool LoadRemnants( UI32 arrayOffset ) //| Date - 20th January, 2002 //| Programmer - Abaddon //| Modified - //o--------------------------------------------------------------------------o //| Purpose - After handling data specific load, other parts go here //o--------------------------------------------------------------------------o bool CMultiObj::LoadRemnants( void ) { bool rValue = CItem::LoadRemnants(); // Add item weight if item doesn't have it yet if( GetWeight() <= 0 ) SetWeight( 0 ); return rValue; }
TFlt TNNet::TNeuron::SumDOW(const TLayer& NextLayer) const{ TFlt sum = 0.0; // sum our contributions of the errors at the nodes we feed for(int NeuronN = 0; NeuronN < NextLayer.GetNeuronN() - 1; ++NeuronN){ // weight from us to next layer neuron times its gradient sum += GetWeight(NeuronN) * NextLayer.GetGradient(NeuronN); } return sum; }
std::string CCompound::GetInfo() { std::string info = "Compound bodies Volume = "; info += std::to_string(GetVolume()); info += " Weight = "; info += std::to_string(GetWeight()); info += " Density = "; info += std::to_string(GetDensity()); return info; }
float weightTTbarPolarization(LorentzVector p4top,LorentzVector p4w, LorentzVector p4lepton,float PercentVariation){ float final_weight=1; float cos_theta = ttbarPolarizationAngle(p4top,p4w,p4lepton); final_weight = GetWeight( cos_theta,PercentVariation ); return final_weight; }//end of function
void FeedTime(int profileID) { bool feeddone = false; while (!feeddone) { while (GetWeight() < profile[profileID].par_gram) { digitalWrite(13, HIGH); //turn on the vibro feeder Serial.println(GetWeight()); delay(100); } digitalWrite(13, LOW); //turn off the vibro feeder feeddone = true; } myservo.write(profile[profileID].par_pos); delay(500); myservo.write(servo_neutralpos); return; }
void SRRasterization::DrawTriangleTopFlat2(int x1, int y1, SRVertex vertex1, int x2, int y2, SRVertex vertex2, int x3, int y3, SRVertex vertex3) { // 画实心平顶三角形, y3为底 y1在左, y2在右 for (int y = y1; y <= y3; ++y) { int xs, xe; xs = (y - y1) * (x3 - x1) / (y3 - y1) + x1 + 0.5; xe = (y - y2) * (x3 - x2) / (y3 - y2) + x2 + 0.5; SRVertex xsVertex; float weightS = GetWeight(x1, y1, x3, y3, xs, y); xsVertex = SRVertex::Lerp(vertex1, vertex3, weightS); SRVertex xeVertex; float weightE = GetWeight(x3, y3, x2, y2, xe, y); xeVertex = SRVertex::Lerp(vertex3, vertex2, weightE); LineBres(xs, y, xsVertex, xe, y, xeVertex); } }
void SRRasterization::DrawTriangleBelowFlat2(int x1, int y1, SRVertex vertex1, int x2, int y2, SRVertex vertex2, int x3, int y3, SRVertex vertex3) { // 画实心平底三角形, x1为顶 x2在左,x3在右 for (int y = y1; y <= y2; ++y) { int xs, xe; xs = (y - y1) * (x2 - x1) / (y2 - y1) + x1 + 0.5; xe = (y - y1) * (x3 - x1) / (y3 - y1) + x1 + 0.5; SRVertex xsVertex; float weightS = GetWeight(x2, y2, x1, y1, xs, y); xsVertex = SRVertex::Lerp(vertex2, vertex1, weightS); SRVertex xeVertex; float weightE = GetWeight(x1, y1, x3, y3, xe, y); xeVertex = SRVertex::Lerp(vertex1, vertex3, weightE); LineBres(xs, y, xsVertex, xe, y, xeVertex); } }
// Write out weight values to an output stream void Connection::SaveWeights( ofstream *outfile ) { for ( int i = 0; i < *mToSize; i++ ) { for ( int j = 0; j < mInModule->GetModuleSize(); j++ ) { *outfile << GetWeight(i,j) << " "; } *outfile << endl; } }
/* * @brief 主程序 */ int main(void) { Request req; char weightBUf[32]; char devCode[32]; SystemInit(); ModulesInit(); SelectChannel(GPRS_CHANNEL); GPRS_GetDevCode(devCode, sizeof(devCode)); SelectChannel(BLUETOOTH_CHANNEL); while(GetRequest() != SYS_START){} /* 等待接收SYS_START信号以开始工作 */ SendResponse(SYS_START); BT_Println(devCode); while(1) { myWDGInit(30); /* 设置定时器,值为30*2=60s=1min。超时会导致系统认为蓝牙已断开,从而进入alarm模式。 */ req = GetRequest(); /* 获取应用请求,并调用相应功能API */ if(FALSE == TimeoutFlag) { switch(req) { case KEEP_ALIVE: SendResponse(KEEP_ALIVE); ResetWDGCounter(); break; case GET_WEIGHT: SendResponse(GET_WEIGHT); GetWeight(weightBUf); BT_Println(weightBUf); ResetWDGCounter(); break; case UNLOCK_DEVICE: SendResponse(UNLOCK_DEVICE); LOCK_Unlock(); /* 解锁电子锁 */ ResetWDGCounter(); break; default: BT_Println("Request invalid."); } }else { while(1) { ReportLocation(); } } } return 0; }
wxString wxFontBase::GetWeightString() const { wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); switch ( GetWeight() ) { case wxNORMAL: return wxT("wxNORMAL"); case wxBOLD: return wxT("wxBOLD"); case wxLIGHT: return wxT("wxLIGHT"); default: return wxT("wxDEFAULT"); } }
// Write out weight values to an output stream void Connection::Print( ostream *os ) { *os << mInModule->GetModuleName() << endl; AdjustStream( *os, 3, 6, kLeft, true ); for ( int i = 0; i < *mToSize; i++ ) { for ( int j = 0; j < mInModule->GetModuleSize(); j++ ) *os << GetWeight(i,j) << "\t"; *os << endl; } SetStreamDefaults( *os ); }
wxString wxFontBase::GetWeightString() const { wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" ); switch ( GetWeight() ) { case wxFONTWEIGHT_NORMAL: return "wxFONTWEIGHT_NORMAL"; case wxFONTWEIGHT_BOLD: return "wxFONTWEIGHT_BOLD"; case wxFONTWEIGHT_LIGHT: return "wxFONTWEIGHT_LIGHT"; default: return "wxFONTWEIGHT_DEFAULT"; } }
// Calculated weighted sum of incoming activations for time-delay connection data_type Connection::WeightedDelay( int idx ) { // if the internal clock is indicating mDelay updates have passed, get incoming act if ( mTime == mDelay ) { mWtAct[idx] = 0.0; for ( int j = 0; j < mInModule->GetModuleSize(); j++ ) mWtAct[idx] += GetWeight( idx, j ) * mInModule->GetDelayAct( j ); } return mWtAct[idx]; }
void Event::ApplyTopReweight(){ if( GetWeight() -> GetMC() . find("TT") == string::npos) { // not ttbar sample return; } if (not ExistSF("topreweight") ) { Logger::getInstance().LogN("Event",__FUNCTION__,"WARNING","TOP SF DOES NOT EXIST",5); return; } double pt1=-1,pt2=-1; // look for gen particles for(auto const &g : genparticles_) { //Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("considering particle with pt=%f, and pdg=%i",g->Pt(),g->GetPdgId())); if (g->GetPdgId() == 6 ) pt1 = g->Pt(); if (g->GetPdgId() == -6) pt2 = g->Pt(); if(pt1 >0 and pt2>0) break; } if (pt1<0 or pt2<0) { Logger::getInstance().LogN("Event",__FUNCTION__,"WARNING",Form("I didn't find two tops for reweighting"),5); return; } //else{ // Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("I found two tops for reweighting, pt1=%f, pt2=%f",pt1,pt2)); //} // SetPtEtaSF("topreweight",pt1,pt2); ApplySF("topreweight"); if (GetWeight()->GetSF("topreweight")->get() < .001) { Logger::getInstance().LogN("Event",__FUNCTION__,"WARNING","Top Reweight very small:",20,Form("sf=%lf, pt1=%f pt2=%f",GetWeight()->GetSF("topreweight")->get(),pt1,pt2)); } }
void PhdWeighingScaleUpdateMeasurements(void) { /* User can update the Measured value from the Weiging Scale*/ /* Please go through IEEE_STD_11073_10417 (Weighing Scale device spec)*/ UINT16_VAL Weight; #if defined PHD_USE_RTCC_FOR_TIME_STAMP rtccTimeDate TimeStamp ; #endif POINTER Src; BYTE i; /*************** Copy Measurement Date from Program Memory to RAM *******/ Src.bRom = MEASUREMENT_DATA; for(i=0;i<MEASUREMENT_DATA_SIZE;i++) { PhdAppBuffer[i] = *Src.bRom++; } /*********** Update Scan Report No **********************/ PhdAppBuffer[24] = scanReportNo.byte.HB; //MSB PhdAppBuffer[25] = scanReportNo.byte.LB; //LSB scanReportNo.Val++; // Increment scanReportNo for the next transfer. /********* Update Weight data ******************/ Weight.Val = GetWeight(); PhdAppBuffer[36]= Weight.byte.HB; //Measured analog voltage LSB PhdAppBuffer[37]= Weight.byte.LB; //Measured analog voltage MSB /************ Update Time Stamp **********************/ #if defined PHD_USE_RTCC_FOR_TIME_STAMP RtccReadTimeDate(&TimeStamp); PhdAppBuffer[38] = 0x20; //Year 1 PhdAppBuffer[39] = TimeStamp.f.year ; //Year 2TimeStamp.f.year PhdAppBuffer[40] = TimeStamp.f.mon; // Month PhdAppBuffer[41] = TimeStamp.f.mday; // Day PhdAppBuffer[42] = TimeStamp.f.hour; // Hour PhdAppBuffer[43] = TimeStamp.f.min; // Minute PhdAppBuffer[44] = TimeStamp.f.sec; // Seconds PhdAppBuffer[45] = 0x00; #else /* Time Stamp = 12:30:00, 20th July 2011*/ PhdAppBuffer[38] = 0x20; //Year 1 PhdAppBuffer[39] = 0x11; //Year 2 PhdAppBuffer[40] = 0x11; // Month PhdAppBuffer[41] = 0x18; // Day PhdAppBuffer[42] = 0x14; // Hour PhdAppBuffer[43] = 0x39; // Minute PhdAppBuffer[44] = 0x00; // Seconds PhdAppBuffer[45] = 0x00; #endif }
void GaussianBlur::InitializeSampleWeights() { UINT sampleCount = mMaterial->SampleOffsets().TypeDesc().Elements; mSampleWeights.resize(sampleCount); mSampleWeights[0] = GetWeight(0); float totalWeight = mSampleWeights[0]; for (UINT i = 0; i < sampleCount / 2; i++) { float weight = GetWeight((float)i + 1); mSampleWeights[i * 2 + 1] = weight; mSampleWeights[i * 2 + 2] = weight; totalWeight += weight * 2; } // Normalize the weights so that they sum to one for (UINT i = 0; i < mSampleWeights.size(); i++) { mSampleWeights[i] /= totalWeight; } }
void Graph::ShortestPath(int v) //求任意两点间的最短路径 { bool *S = new bool[CurrentNumVertices]; //最短路径顶点集,是否加入 double dist[NumVertices] = { MaxDist }; int i, j, k; double w, Min; for (i = 0; i < CurrentNumVertices; i++) { dist[i] = GetWeight(v, i); S[i] = false; if (i != v && dist[i] < MaxDist) path[i] = v; else path[i] = -1; } // 初始化路径数组 S[v] = true; dist[v] = 0; //顶点v加入顶点集合 for (i = 0; i < CurrentNumVertices - 1; i++) //求解各顶点最短路径 { Min = MaxDist; int u = v; //选不在S中具有最短路径的顶点u for (j = 0; j < CurrentNumVertices; j++) if (!S[j] && dist[j] < Min){ u = j; Min = dist[j]; } S[u] = true; //将顶点u加入集合S for (k = 0; k < CurrentNumVertices; k++) { w = GetWeight(u, k); if (!S[k] && w < MaxDist &&dist[u] + w < dist[k]) { //顶点k未加入S dist[k] = dist[u] + w; path[k] = u; //修改到k的最短路径 } } } delete[]S; }
void CParasite::Jump(CStateManager& mgr, EStateMsg msg, float) { switch (msg) { case EStateMsg::Activate: AddMaterial(EMaterialTypes::GroundCollider, mgr); SetMomentumWR({0.f, 0.f, -GetWeight()}); x742_28_onGround = false; x5d6_24_alignToFloor = false; x742_27_landed = false; x743_27_inJump = true; break; case EStateMsg::Update: SetMomentumWR({0.f, 0.f, -GetWeight()}); break; case EStateMsg::Deactivate: RemoveMaterial(EMaterialTypes::GroundCollider, mgr); SetMomentumWR(zeus::skZero3f); x742_28_onGround = true; x742_27_landed = false; x743_27_inJump = false; break; } }
//#define VERBOSE 2 void Event::ApplyBTagSF(int wp) { SetWPSF("btag",wp); // loose, for sf #ifdef VERBOSE if (VERBOSE>1)Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG","Starting BTAG SF"); #endif //Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("-> Considering NCJ=%d",NcentralJets() )); for (int i=0;i<NcentralJets() ;++i) { Jet *j=GetCentralJet(i); SetJetFlavorSF("btag",j->Flavor()); if (j->IsBJet() ) // is btagged { GetWeight()->GetSF("btag")->SetVeto(0); } else{ //GetWeight()->GetSF("btag")->SetVeto(1); //1.-x //GetWeight()->GetSF("btag")->SetVeto(0); //??? continue; } SetPtEtaSF("btag",j->Pt(), j->Eta() ); #ifdef VERBOSE if(VERBOSE>1)Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("Applying btag sf for jet: %f,%f,%d = %f",j->Pt(),j->Eta(),j->Flavor(),GetWeight()->GetSF("btag")->get())); #endif //Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("-> Applying SF of %e for bjet=%d flavor=%d",GetWeight()->GetSF("btag")->get(),j->IsBJet(),j->Flavor())); if (GetWeight()->GetSF("btag")->get() <.2 or GetWeight()->GetSF("btag")->get()>2.) continue; // not believable ApplySF("btag"); } #ifdef VERBOSE if(VERBOSE>1)Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG","End BTAG SF"); #endif }
//---------------------------------------------------------------------------- void VertexCollapse::InitializeHeap (int iVQuantity, Vector3* akVertex, bool bClosed) { // Build the initial heap of weights, a max heap. The weights are set // to negative values so that we get a min heap. TO DO: Modify the // code to directly implement a min heap. m_iHQuantity = iVQuantity; m_akRecord = new Record[m_iHQuantity]; m_apkHeap = new Record*[m_iHQuantity]; int i; for (i = 0; i < m_iHQuantity; i++) { m_akRecord[i].m_iVIndex = i; m_akRecord[i].m_iHIndex = i; m_akRecord[i].m_pkLAdj = &m_akRecord[(m_iHQuantity+i-1)%m_iHQuantity]; m_akRecord[i].m_pkRAdj = &m_akRecord[(i+1)%m_iHQuantity]; m_apkHeap[i] = &m_akRecord[i]; } int iQm1 = m_iHQuantity - 1; if ( bClosed ) { int iQm2 = m_iHQuantity - 2; m_akRecord[0].m_fWeight = GetWeight(iQm1,0,1,akVertex); m_akRecord[iQm1].m_fWeight = GetWeight(iQm2,iQm1,0,akVertex); } else { m_akRecord[0].m_fWeight = FLT_MAX; m_akRecord[iQm1].m_fWeight = FLT_MAX; } for (int iM = 0, iZ = 1, iP = 2; iZ < iQm1; iM++, iZ++, iP++) m_akRecord[iZ].m_fWeight = GetWeight(iM,iZ,iP,akVertex); }
double LinearNeuron::Output(const double /*_time*/) { double inputValue = 0; for (const auto &connection : this->incomingConnections_) { auto inConnection = connection.second; inputValue += inConnection->GetInputNeuron()->Output() * inConnection->GetWeight(); } double result = this->gain_ * (inputValue - this->bias_); return result; }