本文整理汇总了C++中TFltV::Last方法的典型用法代码示例。如果您正苦于以下问题:C++ TFltV::Last方法的具体用法?C++ TFltV::Last怎么用?C++ TFltV::Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFltV
的用法示例。
在下文中一共展示了TFltV::Last方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlotSngValDistr
void PlotSngValDistr(const PNGraph& Graph, const int& SngVals, const TStr& FNmPref, TStr DescStr) {
const int NBuckets = 50;
TFltV SngValV;
for (int f = 1; SngValV.Empty() && f < 4; f++) {
TSnap::GetSngVals(Graph, f*SngVals, SngValV);
}
SngValV.Sort(true);
THash<TFlt, TFlt> BucketCntH;
double Step = (SngValV.Last()-SngValV[0]) / double(NBuckets-1);
for (int i = 0; i < NBuckets; i++) {
BucketCntH.AddDat(SngValV[0]+Step*(i+0.5), 0);
}
for (int i = 0; i < SngValV.Len(); i++) {
const int Bucket = (int) floor((SngValV[i]-SngValV[0]) / Step);
BucketCntH[Bucket] += 1;
}
TFltPrV EigCntV;
BucketCntH.GetKeyDatPrV(EigCntV);
if (DescStr.Empty()) { DescStr = FNmPref; }
TGnuPlot::PlotValV(EigCntV, "sngDistr."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f", DescStr.CStr(),
Graph->GetNodes(), Graph->GetEdges(), SngValV.Last().Val), "Singular value", "Count", gpsAuto, false, gpwLinesPoints);
}
示例2: GetCfy
double TLogRegPredict::GetCfy(const TFltV& AttrV, const TFltV& NewTheta) {
int len = AttrV.Len();
double res = 0;
if (len < NewTheta.Len()) {
res = NewTheta.Last(); //if feature vector is shorter, add an intercept
}
for (int i = 0; i < len; i++) {
if (i < NewTheta.Len()) {
res += AttrV[i] * NewTheta[i];
}
}
double mu = 1 / (1 + exp(-res));
return mu;
}
示例3: FindComsByAGM
/// estimate number of communities using AGM
int TAGMUtil::FindComsByAGM(const PUNGraph& Graph, const int InitComs, const int MaxIter, const int RndSeed, const double RegGap, const double PNoCom, const TStr PltFPrx) {
TRnd Rnd(RndSeed);
int LambdaIter = 100;
if (Graph->GetNodes() < 200) {
LambdaIter = 1;
}
if (Graph->GetNodes() < 200 && Graph->GetEdges() > 2000) {
LambdaIter = 100;
}
//Find coms with large C
TAGMFit AGMFitM(Graph, InitComs, RndSeed);
if (PNoCom > 0.0) {
AGMFitM.SetPNoCom(PNoCom);
}
AGMFitM.RunMCMC(MaxIter, LambdaIter, "");
int TE = Graph->GetEdges();
TFltV RegV;
RegV.Add(0.3 * TE);
for (int r = 0; r < 25; r++) {
RegV.Add(RegV.Last() * RegGap);
}
TFltPrV RegComsV, RegLV, RegBICV;
TFltV LV, BICV;
//record likelihood and number of communities with nonzero P_c
for (int r = 0; r < RegV.Len(); r++) {
double RegCoef = RegV[r];
AGMFitM.SetRegCoef(RegCoef);
AGMFitM.MLEGradAscentGivenCAG(0.01, 1000);
AGMFitM.SetRegCoef(0.0);
TVec<TIntV> EstCmtyVV;
AGMFitM.GetCmtyVV(EstCmtyVV, 0.99);
int NumLowQ = EstCmtyVV.Len();
RegComsV.Add(TFltPr(RegCoef, (double) NumLowQ));
if (EstCmtyVV.Len() > 0) {
TAGMFit AFTemp(Graph, EstCmtyVV, Rnd);
AFTemp.MLEGradAscentGivenCAG(0.001, 1000);
double CurL = AFTemp.Likelihood();
LV.Add(CurL);
BICV.Add(-2.0 * CurL + (double) EstCmtyVV.Len() * log((double) Graph->GetNodes() * (Graph->GetNodes() - 1) / 2.0));
}
else {
break;
}
}
// if likelihood does not exist or does not change at all, report the smallest number of communities or 2
if (LV.Len() == 0) {
return 2;
}
else if (LV[0] == LV.Last()) {
return (int) TMath::Mx<TFlt>(2.0, RegComsV[LV.Len() - 1].Val2);
}
//normalize likelihood and BIC to 0~100
int MaxL = 100;
{
TFltV& ValueV = LV;
TFltPrV& RegValueV = RegLV;
double MinValue = TFlt::Mx, MaxValue = TFlt::Mn;
for (int l = 0; l < ValueV.Len(); l++) {
if (ValueV[l] < MinValue) {
MinValue = ValueV[l];
}
if (ValueV[l] > MaxValue) {
MaxValue = ValueV[l];
}
}
while (ValueV.Len() < RegV.Len()) {
ValueV.Add(MinValue);
}
double RangeVal = MaxValue - MinValue;
for (int l = 0; l < ValueV.Len(); l++) {
RegValueV.Add(TFltPr(RegV[l], double(MaxL) * (ValueV[l] - MinValue) / RangeVal));
}
}
{
TFltV& ValueV = BICV;
TFltPrV& RegValueV = RegBICV;
double MinValue = TFlt::Mx, MaxValue = TFlt::Mn;
for (int l = 0; l < ValueV.Len(); l++) {
if (ValueV[l] < MinValue) {
MinValue = ValueV[l];
}
if (ValueV[l] > MaxValue) {
MaxValue = ValueV[l];
}
}
while (ValueV.Len() < RegV.Len()) {
ValueV.Add(MaxValue);
}
double RangeVal = MaxValue - MinValue;
for (int l = 0; l < ValueV.Len(); l++) {
RegValueV.Add(TFltPr(RegV[l], double(MaxL) * (ValueV[l] - MinValue) / RangeVal));
}
//.........这里部分代码省略.........