void TrainModel( const NJson::TJsonValue& params, const NCatboostOptions::TOutputFilesOptions& outputOptions, const TMaybe<TCustomObjectiveDescriptor>& objectiveDescriptor, const TMaybe<TCustomMetricDescriptor>& evalMetricDescriptor, TPool& learnPool, bool allowClearPool, const TVector<const TPool*>& testPoolPtrs, TFullModel* model, const TVector<TEvalResult*>& evalResultPtrs) const override { Y_UNUSED(objectiveDescriptor); Y_UNUSED(evalMetricDescriptor); Y_UNUSED(allowClearPool); CB_ENSURE(testPoolPtrs.size() == 1, "Multiple eval sets not supported for GPU"); Y_VERIFY(evalResultPtrs.size() == testPoolPtrs.size()); NCatboostCuda::TrainModel(params, outputOptions, learnPool, *testPoolPtrs[0], model); evalResultPtrs[0]->GetRawValuesRef().resize(model->ObliviousTrees.ApproxDimension); }
void InsertItem(int iItem, ListItem* pListItem) { for (int i = 0; i < pListItem->GetItemHeight(); i++) { m_vItems.Insert(iItem, pListItem); } if (iItem <= m_iSelItem) { SetSelItemByIdx(m_iSelItem + pListItem->GetItemHeight()); } if (m_pScrollPane) { m_pScrollPane->SetSize(m_vItems.GetCount()); if (iItem <= m_iTopItem) { m_pScrollPane->SetPos(m_iTopItem + pListItem->GetItemHeight()); } } NeedPaint(); }
static void OutputShapValues(const TVector<TVector<double>>& shapValues, TFileOutput& out) { for (size_t documentIdx = 0; documentIdx < shapValues.size(); ++documentIdx) { int featureCount = shapValues[documentIdx].size(); for (int featureIdx = 0; featureIdx < featureCount; ++featureIdx) { out << shapValues[documentIdx][featureIdx] << (featureIdx + 1 == featureCount ? '\n' : '\t'); } } }
void Matrix::Transform(const TVector<Point>& vSource, TVector<Point>& vDest) const { int count = vSource.GetCount(); vDest.SetCount(count); for (int index = 0; index < count; index++) { float x = vSource[index].X(); float y = vSource[index].Y(); vDest.Set( index, Point( m_m[0][0] * x + m_m[0][1] * y + m_m[0][3], m_m[1][0] * x + m_m[1][1] * y + m_m[1][3] ) ); } }
static TVector<TFeaturePathElement> ExtendFeaturePath(const TVector<TFeaturePathElement>& oldFeaturePath, double zeroPathsFraction, double onePathsFraction, int feature) { const size_t pathLength = oldFeaturePath.size(); TVector<TFeaturePathElement> newFeaturePath(pathLength + 1); Copy(oldFeaturePath.begin(), oldFeaturePath.begin() + pathLength, newFeaturePath.begin()); const double weight = pathLength == 0 ? 1.0 : 0.0; newFeaturePath[pathLength] = TFeaturePathElement(feature, zeroPathsFraction, onePathsFraction, weight); for (int elementIdx = pathLength - 1; elementIdx >= 0; --elementIdx) { newFeaturePath[elementIdx + 1].Weight += onePathsFraction * newFeaturePath[elementIdx].Weight * (elementIdx + 1) / (pathLength + 1); newFeaturePath[elementIdx].Weight = zeroPathsFraction * newFeaturePath[elementIdx].Weight * (pathLength - elementIdx) / (pathLength + 1); } return newFeaturePath; }
int GetItemIdx(ListItem* pListItem) { int cItems = m_vItems.GetCount(); for (int iItem = 0; iItem < cItems; iItem++) { if (m_vItems[iItem] == pListItem) return iItem; } return -1; }
int GetItemIdxByData(long lItemData) { int cItems = m_vItems.GetCount(); for (int iItem = 0; iItem < cItems; iItem++) { if (m_vItems[iItem]->GetItemData() == lItemData) return iItem; } return -1; }
TVector<TString> SplitInto(const TString &s, char delim, TVector<TString> &elems, ui32 numberOfSplits) { std::stringstream ss(s); TString item; ui32 iter = 0; while (std::getline(ss, item, delim)) { elems.push_back(item); iter++; if (iter >= numberOfSplits) { TString rest; while (std::getline(ss, item)) { rest += item; } elems.push_back(rest); break; } } return elems; }
TValue get(const TId id) const final { if (id >= m_vector.size()) { throw osmium::not_found{id}; } const TValue value = m_vector[id]; if (value == osmium::index::empty_value<TValue>()) { throw osmium::not_found{id}; } return value; }
void FBinarySerializer::Save(TVector<bool>& VectorData) { const SizeT VectorSize = VectorData.size(); Serialize(VectorSize); for (auto&& Element: VectorData) { Serialize(static_cast<bool>(Element)); } }
/* find if any of the current balls intersect with each other in the * current timestep. returns the index of the 2 intersecting balls, * the point and time of intersection */ int find_collision(TVector& point, double& timePoint, double time2, int& ball1, int& ball2) { TVector relativeV; TRay rays; double Mytime = 0.0, Add = time2/150.0, timedummy = 10000, timedummy2 = -1; TVector posi; /* Test all balls against each other in 150 small steps */ for (int i = 0; i < ball_count - 1; i++){ for (int j = i+1; j < ball_count; j++){ // Find Distance relativeV = ball_vel[i]-ball_vel[j]; rays = TRay(old_pos[i],TVector::unit(relativeV)); Mytime = 0.0; // If distance detween centers greater than 2*radius an // intersection occurred loop to find the exact intersection point if ( (rays.dist(old_pos[j])) > ball_r * 2 ) continue; while (Mytime < time2) { Mytime += Add; posi = old_pos[i] + relativeV*Mytime; if (posi.dist(old_pos[j]) <= ball_r * 2 ) { point = posi; if (timedummy > (Mytime - Add)) timedummy = Mytime-Add; ball1 = i; ball2 = j; break; } } } } if (timedummy!=10000) { timePoint=timedummy; return 1; } return 0; }
void FindSequenceDialog::aaSearch () { int a , b ; TVector *v = c->vec ; if ( v->getType() != TYPE_VECTOR && v->getType() != TYPE_SEQUENCE && v->getType() != TYPE_PRIMER ) return ; wxString s = getQuery() ; for ( a = 0 ; a < v->items.size() ; a++ ) { wxString ls = v->items[a].getAminoAcidSequence() ; if ( ls.IsEmpty() ) continue ; int dir = v->items[a].getDirection() ; int off = v->items[a].getOffset() ; vector <Tdna2aa> dna2aa ; p = 0 ; b = subsearch ( ls , s , p ) ; while ( b != -1 ) { if ( lb->GetCount() > FIND_MAX ) return ; if ( dna2aa.size() == 0 ) v->items[a].translate ( v , NULL , dna2aa ) ; int from = dir==1?b:last ; int to = dir==1?last:b ; wxString msg ; if ( off != -1 ) msg = wxString::Format ( _T(" [%d-%d]") , from+off , to+off ) ; from = dna2aa[from].dna[0] + 1 ; to = dna2aa[to].dna[2] + 1 ; if ( from > to ) { int x = from ; from = to ; to = x ; } lb->Append ( wxString::Format ( _T("%s: %s (%d-%d)%s") , txt("amino_acid").c_str() , v->items[a].name.c_str() , from , to , msg.c_str() ) ) ; vi.Add ( -1 ) ; p = b + 1 ; b = subsearch ( ls , s , p ) ; } } // Fixed reading frames wxString ss ; ss = v->getSequence() ; if ( v->isCircular() ) ss += ss.Left ( 2 ) ; else ss += _T(" ") ; aaSubSearch ( ss , 0 , 1 , txt("m_aa_1") ) ; // Reading frame +1 aaSubSearch ( ss , 1 , 1 , txt("m_aa_2") ) ; // Reading frame +2 aaSubSearch ( ss , 2 , 1 , txt("m_aa_3") ) ; // Reading frame +3 ss = v->transformSequence ( true , false ) ; if ( v->isCircular() ) ss = ss.Right ( 2 ) + ss ; else ss = _T(" ") + ss ; aaSubSearch ( ss , -1 , -1 , txt("m_aa_m1") ) ; // Reading frame -1 aaSubSearch ( ss , -2 , -1 , txt("m_aa_m2") ) ; // Reading frame -2 aaSubSearch ( ss , -3 , -1 , txt("m_aa_m3") ) ; // Reading frame -3 }
float GetRadius(const Matrix& mat) { float radius = 0; int count = m_vvertex.GetCount(); for(int index = 0; index < count; index++) { Vector vec = mat.Transform(m_vvertex[index].GetPosition()); radius = max(radius, vec.Length()); } return radius; }
void DeltaWheel(int dz) { if (dz != 0 ) { //ZDebugOutput("MouseDZ: " + ZString(dz) + "\n"); m_z += float(dz); if (m_vvalueObject.GetCount() >= 3) { m_vvalueObject[0]->GetValue()->SetValue(m_z); } } }
JoystickInputStream* GetJoystick(int index) { if ( index >= 0 && index < m_vjoystickInputStream.GetCount() ) { return m_vjoystickInputStream[index]; } else { return NULL; } }
const TValue get(const TId id) const final { try { const TValue& value = m_vector.at(id); if (value == osmium::index::empty_value<TValue>()) { not_found_error(id); } return value; } catch (std::out_of_range&) { not_found_error(id); } }
static void AssignRandomWeights(int learnSampleCount, TLearnContext* ctx, TFold* fold) { TVector<float> sampleWeights; sampleWeights.yresize(learnSampleCount); const ui64 randSeed = ctx->Rand.GenRand(); NPar::TLocalExecutor::TExecRangeParams blockParams(0, learnSampleCount); blockParams.SetBlockSize(10000); ctx->LocalExecutor.ExecRange([&](int blockIdx) { TFastRng64 rand(randSeed + blockIdx); rand.Advance(10); // reduce correlation between RNGs in different threads const float baggingTemperature = ctx->Params.ObliviousTreeOptions->BootstrapConfig->GetBaggingTemperature(); float* sampleWeightsData = sampleWeights.data(); NPar::TLocalExecutor::BlockedLoopBody(blockParams, [&rand, sampleWeightsData, baggingTemperature](int i) { const float w = -FastLogf(rand.GenRandReal1() + 1e-100); sampleWeightsData[i] = powf(w, baggingTemperature); })(blockIdx); }, 0, blockParams.GetBlockCount(), NPar::TLocalExecutor::WAIT_COMPLETE); TFold& ff = *fold; ff.AssignPermuted(sampleWeights, &ff.SampleWeights); if (!ff.LearnWeights.empty()) { for (int i = 0; i < learnSampleCount; ++i) { ff.SampleWeights[i] *= ff.LearnWeights[i]; } } const int approxDimension = ff.GetApproxDimension(); for (TFold::TBodyTail& bt : ff.BodyTailArr) { for (int dim = 0; dim < approxDimension; ++dim) { double* weightedDerData = bt.WeightedDer[dim].data(); const double* derData = bt.Derivatives[dim].data(); const float* sampleWeightsData = ff.SampleWeights.data(); ctx->LocalExecutor.ExecRange([=](int z) { weightedDerData[z] = derData[z] * sampleWeightsData[z]; }, NPar::TLocalExecutor::TExecRangeParams(bt.BodyFinish, bt.TailFinish).SetBlockSize(4000) , NPar::TLocalExecutor::WAIT_COMPLETE); } } }
int FindBallCol(TVector& point, double& TimePoint, double Time2, int& BallNr1, int& BallNr2) { TVector RelativeV; TRay rays; double MyTime=0.0, Add=Time2/150.0, Timedummy=10000, Timedummy2=-1; TVector posi; //Test all balls against eachother in 150 small steps for (int i=0;i<NrOfBalls-1;i++) { for (int j=i+1;j<NrOfBalls;j++) { RelativeV=ArrayVel[i]-ArrayVel[j]; rays=TRay(OldPos[i],TVector::unit(RelativeV)); MyTime=0.0; if ( (rays.dist(OldPos[j])) > 40) continue; while (MyTime<Time2) { MyTime+=Add; posi=OldPos[i]+RelativeV*MyTime; if (posi.dist(OldPos[j])<=40) { point=posi; if (Timedummy>(MyTime-Add)) Timedummy=MyTime-Add; BallNr1=i; BallNr2=j; break; } } } } if (Timedummy!=10000) { TimePoint=Timedummy; return 1; } return 0; }
void RemoveItemByIdx(int iItem) { int numRemoved = 0; if (iItem != -1) { // find the first matching item while (iItem > 1 && m_vItems[iItem-1] == m_vItems[iItem]) { iItem--; } // now remove all the matching items TRef<ListItem> pListItem = m_vItems[iItem]; while (iItem < m_vItems.GetCount() && m_vItems[iItem] == pListItem) { m_vItems.Remove(iItem); numRemoved++; } if (iItem <= m_iSelItem) { SetSelItemByIdx(m_iSelItem - numRemoved); } else { SetSelItemByIdx(m_iSelItem); } if (m_pScrollPane) { // save the old top item, because shrinking the scroll pane could change it int iOldTopItem = m_iTopItem; m_pScrollPane->SetSize(m_vItems.GetCount()); if (iItem < iOldTopItem) { SetScrollPosition(max(iOldTopItem - numRemoved, 0)); } else { SetScrollPosition(min(iOldTopItem, max(m_vItems.GetCount() - m_cVisibleItems, 0))); } } NeedPaint(); } }
void Update() { if (m_bFocus) { m_pmouseInputStream->Update(); int count = m_vjoystickInputStream.GetCount(); for(int index = 0; index < count; index++) { m_vjoystickInputStream[index]->Update(); } } }
void CGunShotgun::Create() { TVector<int, 2> frameLayout; frameLayout.Set(8, 2); m_entity = CLasagne::GetInstance()->LoadAnimatedImage("./media/graphics/characters/guns/shotgun/gun.png", frameLayout); if (!m_entity) return; m_audio = CLasagne::GetInstance()->LoadAudioFile("./media/sound/guns/shotgun.wav"); m_entity->SetDepth(5); static const int NoofBullets = 9; for (int bulletIndex = 0; bulletIndex < NoofBullets; ++bulletIndex) { CBulletBase *bulletBase = new CBulletShotgun(); bulletBase->Create(); m_bullet.push_back(bulletBase); } }
void UniformHLSL::outputHLSLSamplerUniformGroup(TInfoSinkBase &out, const HLSLTextureSamplerGroup textureGroup, const TVector<const TIntermSymbol *> &group, unsigned int *groupTextureRegisterIndex) { if (group.empty()) { return; } unsigned int groupRegisterCount = 0; for (const TIntermSymbol *uniform : group) { const TType &type = uniform->getType(); const TString &name = uniform->getSymbol(); unsigned int registerCount; unsigned int samplerArrayIndex = declareUniformAndAssignRegister(type, name, ®isterCount); groupRegisterCount += registerCount; if (type.isArray()) { out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type) << " = {"; for (int i = 0; i < type.getArraySize(); ++i) { if (i > 0) out << ", "; out << (samplerArrayIndex + i); } out << "};\n"; } else { out << "static const uint " << DecorateIfNeeded(uniform->getName()) << " = " << samplerArrayIndex << ";\n"; } } TString suffix = TextureGroupSuffix(textureGroup); // Since HLSL_TEXTURE_2D is the first group, it has a fixed offset of zero. if (textureGroup != HLSL_TEXTURE_2D) { out << "static const uint textureIndexOffset" << suffix << " = " << (*groupTextureRegisterIndex) << ";\n"; out << "static const uint samplerIndexOffset" << suffix << " = " << (*groupTextureRegisterIndex) << ";\n"; } out << "uniform " << TextureString(textureGroup) << " textures" << suffix << "[" << groupRegisterCount << "]" << " : register(t" << (*groupTextureRegisterIndex) << ");\n"; out << "uniform " << SamplerString(textureGroup) << " samplers" << suffix << "[" << groupRegisterCount << "]" << " : register(s" << (*groupTextureRegisterIndex) << ");\n"; *groupTextureRegisterIndex += groupRegisterCount; }
StringGridImageImpl(int columns, int rows, IEngineFont* pfont) : m_pfont(pfont), m_vvstr(rows), m_vcolor(rows), m_vColumn(columns) { for (int index = 0; index < rows; index++) { m_vvstr.Get(index).SetCount(columns); } m_ysizeRow = (float)(m_pfont->GetTextExtent("W").Y()); }
void UpdateAll() { bool bNeedPaint = false; for (int iItem = 0; iItem < m_vItems.GetCount(); iItem += m_vItems[iItem]->GetItemHeight()) { if (m_vItems[iItem]->Update()) bNeedPaint = true; } if (bNeedPaint) NeedPaint(); }
SEXP CatBoostCalcRegularFeatureEffect_R(SEXP modelParam, SEXP poolParam, SEXP fstrTypeParam, SEXP threadCountParam) { SEXP result = NULL; R_API_BEGIN(); TFullModelHandle model = reinterpret_cast<TFullModelHandle>(R_ExternalPtrAddr(modelParam)); TPoolHandle pool = reinterpret_cast<TPoolHandle>(R_ExternalPtrAddr(poolParam)); TString fstrType = CHAR(asChar(fstrTypeParam)); TVector<TVector<double>> effect = GetFeatureImportances(*model, *pool, fstrType, asInteger(threadCountParam)); size_t resultSize = 0; if (!effect.empty()) { resultSize = effect.size() * effect[0].size(); } result = PROTECT(allocVector(REALSXP, resultSize)); for (size_t i = 0, k = 0; i < effect.size(); ++i) { for (size_t j = 0; j < effect[0].size(); ++j) { REAL(result)[k++] = effect[i][j]; } } R_API_END(); UNPROTECT(1); return result; }
void CGunMachinegun::Create() { TVector<int, 2> frameLayout; frameLayout.Set(8, 2); m_entity = CLasagne::GetInstance()->LoadAnimatedImage("./data/graphics/characters/guns/machinegun/gun.png", frameLayout, 5); if (!m_entity) return; CLasagne::GetInstance()->DisableEntity(&m_entity); m_audio = CLasagne::GetInstance()->LoadAudioFile("./data/sound/guns/machinegun.wav"); static const int NoofBullets = 45; for (int bulletIndex = 0; bulletIndex < NoofBullets; ++bulletIndex) { CBulletBase *bulletBase = new CBulletMachinegun(); bulletBase->Create(); m_bullet.push_back(bulletBase); } }
TIntermAggregate *EmulatePrecision::createRoundingFunctionCallNode(TIntermTyped *roundedChild) { const ImmutableString *roundFunctionName = &kAngleFrmString; if (roundedChild->getPrecision() == EbpLow) roundFunctionName = &kAngleFrlString; TIntermSequence *arguments = new TIntermSequence(); arguments->push_back(roundedChild); TVector<const TVariable *> parameters; TType *paramType = new TType(roundedChild->getType()); paramType->setPrecision(EbpHigh); paramType->setQualifier(EvqIn); parameters.push_back(new TVariable(mSymbolTable, kParamXName, static_cast<const TType *>(paramType), SymbolType::AngleInternal)); return TIntermAggregate::CreateRawFunctionCall( *getInternalFunction(*roundFunctionName, roundedChild->getType(), arguments, parameters, true), arguments); }
void CalcOnlineCTRsBatch(const TVector<TCalcOnlineCTRsBatchTask>& tasks, const TTrainData& data, TLearnContext* ctx) { auto calcer = [&](int i) { size_t totalLeafCount; ComputeOnlineCTRs(data, *tasks[i].Fold, tasks[i].Projection, ctx, tasks[i].Ctr, &totalLeafCount); }; ctx->LocalExecutor.ExecRange(calcer, 0, tasks.size(), NPar::TLocalExecutor::WAIT_COMPLETE); }
static TVector<TVector<double>> CalcSoftmax(const TVector<TVector<double>>& approx, NPar::TLocalExecutor* localExecutor) { TVector<TVector<double>> probabilities = approx; const int threadCount = localExecutor->GetThreadCount() + 1; const int blockSize = (approx[0].ysize() + threadCount - 1) / threadCount; auto calcSoftmaxInBlock = [&](const int blockId) { int lastLineId = Min((blockId + 1) * blockSize, approx[0].ysize()); TVector<double> line(approx.size()); TVector<double> softmax(approx.size()); for (int lineInd = blockId * blockSize; lineInd < lastLineId; ++lineInd) { for (int dim = 0; dim < approx.ysize(); ++dim) { line[dim] = approx[dim][lineInd]; } CalcSoftmax(line, &softmax); for (int dim = 0; dim < approx.ysize(); ++dim) { probabilities[dim][lineInd] = softmax[dim]; } } }; localExecutor->ExecRange(calcSoftmaxInBlock, 0, threadCount, NPar::TLocalExecutor::WAIT_COMPLETE); return probabilities; }
void SetFocus(bool bFocus) { if (m_bFocus != bFocus) { m_bFocus = bFocus; int count = m_vjoystickInputStream.GetCount(); for(int index = 0; index < count; index++) { m_vjoystickInputStream[index]->SetFocus(m_bFocus); } } }