本文整理汇总了C++中TFltPrV::Len方法的典型用法代码示例。如果您正苦于以下问题:C++ TFltPrV::Len方法的具体用法?C++ TFltPrV::Len怎么用?C++ TFltPrV::Len使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFltPrV
的用法示例。
在下文中一共展示了TFltPrV::Len方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalcEffDiam
double CalcEffDiam(const TFltPrV& DistNbrsCdfV, const double& Percentile) {
TIntFltKdV KdV(DistNbrsCdfV.Len(), 0);
for (int i = 0; i < DistNbrsCdfV.Len(); i++) {
KdV.Add(TIntFltKd(int(DistNbrsCdfV[i].Val1()), DistNbrsCdfV[i].Val2));
}
return CalcEffDiam(KdV, Percentile);
}
示例2: AddErrBar
int TGnuPlot::AddErrBar(const TFltPrV& XYValV, const TFltV& DeltaYV, const TStr& Label) {
TFltKdV XYFltValV(XYValV.Len(), 0);
for (int i = 0; i < XYValV.Len(); i++) {
XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
}
return AddErrBar(XYFltValV, DeltaYV, Label);
}
示例3: AddPlot
int TGnuPlot::AddPlot(const TFltPrV& XYValV, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style) {
TFltKdV XYFltValV(XYValV.Len(), 0);
for (int i = 0; i < XYValV.Len(); i++) {
XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
}
return AddPlot(XYFltValV, SeriesTy, Label, Style);
}
示例4: Normalize
void TGUtil::Normalize(TFltPrV& PdfV) {
double Sum = 0.0;
for (int i = 0; i < PdfV.Len(); i++) {
Sum += PdfV[i].Val2; }
if (Sum <= 0.0) { return; }
for (int i = 0; i < PdfV.Len(); i++) {
PdfV[i].Val2 /= Sum; }
}
示例5: IAssert
void TSirSR2Model::SetMediaBlogV(const TFltPrV& _MediaV, const TFltPrV& _BlogV) {
IAssert(_MediaV.Len() == _BlogV.Len());
MediaV.Clr(false); BlogV.Clr(false);
for (int i = 0; i < _MediaV.Len(); i++) {
MediaV.Add(_MediaV[i].Val2);
BlogV.Add(_BlogV[i].Val2);
}
}
示例6: MakeExpBins
void TGnuPlot::MakeExpBins(const TFltPrV& XYValV, TFltPrV& ExpXYValV, const double& BinFactor, const double& MinYVal) {
TFltKdV KdV(XYValV.Len(), 0), OutV;
for (int i = 0; i < XYValV.Len(); i++) {
KdV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2)); }
KdV.Sort();
TGnuPlot::MakeExpBins(KdV, OutV, BinFactor, MinYVal);
ExpXYValV.Gen(OutV.Len(), 0);
for (int i = 0; i < OutV.Len(); i++) {
ExpXYValV.Add(TFltPr(OutV[i].Key, OutV[i].Dat)); }
}
示例7: GetNEFromAccDistr
void GetNEFromAccDistr(const TFltPrV& deg, int& nodes, int& edges){
double nodesD = deg[0].Val2.Val, edgesD = 0;
for (int i = 0; i < deg.Len(); i++){
if (i == deg.Len()-1)
edgesD += deg[i].Val1.Val * deg[i].Val2.Val;
else edgesD += deg[i].Val1.Val * (deg[i].Val2.Val - deg[i+1].Val2.Val);
}
nodes = static_cast<int>(nodesD);
edges = static_cast<int>(edgesD);
// edges /= 2; as Deg = inDeg + outDeg
}
示例8: GetCumDistr
void GetCumDistr(const TFltPrV& nonCum, TFltPrV& res){
for (int i = nonCum.Len() - 1; i >=0; i--){
TFlt count;
if (i == nonCum.Len() - 1)
count = nonCum[i].Val2.Val;
else
count = nonCum[i].Val2.Val + res[res.Len()-1].Val2.Val;
TFltPr val(nonCum[i].Val1, count);
res.Add(val);
}
res.Sort();
}
示例9: exp
// MLE power-coefficient
int TGnuPlot::AddPwrFit2(const int& PlotId, const TGpSeriesTy& SeriesTy, const double& MinX, const TStr& Style) {
const TGpSeries& Plot = SeriesV[PlotId];
if(Plot.XYValV.Empty()) return -1;
const TFltKdV& XY = Plot.XYValV;
// power fit
TFltPrV XYPr;
double MinY = TFlt::Mx;
for (int s = 0; s < XY.Len(); s++) {
if (XY[s].Key > 0.0) {
XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
MinY = TMath::Mn(MinY, XY[s].Dat());
}
}
if (XYPr.Empty()) return -1;
MinY = TMath::Mn(1.0, MinY);
// determine the sign of power coefficient
double CoefSign = 0.0;
{ double A, B, R2, SigA, SigB, Chi2;
TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2);
CoefSign = B > 0.0 ? +1.0 : -1.0; }
const double PowerCf = CoefSign * TSpecFunc::GetPowerCoef(XYPr, MinX);
int Mid = (int) exp(log((double)XYPr.Len())/2.0);
if (Mid >= XYPr.Len()) { Mid = XYPr.Len()-1; }
const double MidX = XYPr[Mid].Val1();
const double MidY = XYPr[Mid].Val2();
const double B = MidY / pow(MidX, PowerCf);
TStr StyleStr=Style;
if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
const int FitId = AddFunc(TStr::Fmt("%f*x**%f", B, PowerCf),
SeriesTy, TStr::Fmt("MLE = x^{%.4g}", PowerCf), StyleStr);
return FitId;
/*SeriesV.Add();
TGpSeries& NewPlot = SeriesV.Last();
TFltKdV& XYFit = NewPlot.XYValV;
XYFit.Gen(XYPr.Len(), 0);
for (int s = 0; s < XYPr.Len(); s++) {
const double XVal = XYPr[s].Val1;
const double YVal = B * pow(XYPr[s].Val1(), PowerCf);
if (YVal < MinY || XVal < MinX) continue;
XYFit.Add(TFltKd(XVal, YVal));
}
NewPlot.Label = TStr::Fmt("PowerFit: %g", PowerCf);
NewPlot.SeriesTy = SeriesTy;
if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
else { NewPlot.WithStyle = Style; }
return SeriesV.Len() - 1;*/
}
示例10: CalcAvgDiamPdf
double CalcAvgDiamPdf(const TFltPrV& DistNbrsPdfV) {
double Paths=0, SumLen=0;
for (int i = 0; i < DistNbrsPdfV.Len(); i++) {
SumLen += DistNbrsPdfV[i].Val1 * DistNbrsPdfV[i].Val2;
Paths += DistNbrsPdfV[i].Val2;
}
return SumLen/Paths;
}
示例11: ExpBinning
// CHECK
void ExpBinning(const TFltPrV& deg, TFltPrV& degSparse, const int& BinRadix){
TFlt maxDeg(deg[deg.Len()-1].Val1.Val), minDeg(deg[0].Val1.Val);
bool maxPowerReached = false;
// idx - index of border, previdx - index of previous border
int power = 0, previdx = 0, idx, binSize;
TFltPr val;
double binBorder = 0.0;
while (binBorder <= minDeg)
binBorder = pow(static_cast<double>(BinRadix), power++);
TFltPr v(minDeg, deg[0].Val2.Val);
degSparse.Add(v);
bool isExact = false;
while (!maxPowerReached){
if (binBorder >= maxDeg){
// when last element of deg was previous bin border
if (previdx == deg.Len() - 1)
break;
// if we have another elements
binBorder = maxDeg;
maxPowerReached = true;
}
// find next element
idx = FindVal1Elem(deg, binBorder, isExact);
// if bin size == 0
if (previdx + 1 == idx && !isExact)
continue;
if (!isExact)
idx = idx - 1;
double sum = 0.0;
binSize = idx - previdx;
for (int i = previdx + 1; i <= idx; i++){
sum += deg[i].Val2.Val;
}
sum /= binSize;
// if prevBinBorder was the smallest degree, it can be more than binBorder / BinRadix
double SumBinBorder = previdx > 0 ? binBorder + static_cast<double>(binBorder) / BinRadix : binBorder + static_cast<double>(minDeg);
double avgDeg = SumBinBorder / 2.0;
val.Val1 = avgDeg; val.Val2 = sum;
degSparse.Add(val);
previdx = idx;
binBorder = pow(static_cast<double>(BinRadix), power++);
}
}
示例12: PlotInvParticipRat
// Inverse participation ratio: normalize EigVec to have L2=1 and then I=sum_k EigVec[i]^4
// see Spectra of "real-world" graphs: Beyond the semicircle law by Farkas, Derenyi, Barabasi and Vicsek
void PlotInvParticipRat(const PUNGraph& Graph, const int& MaxEigVecs, const int& TimeLimit, const TStr& FNmPref, TStr DescStr) {
TFltPrV EigIprV;
GetInvParticipRat(Graph, MaxEigVecs, TimeLimit, EigIprV);
if (DescStr.Empty()) { DescStr = FNmPref; }
if (EigIprV.Empty()) { DescStr+=". FAIL"; EigIprV.Add(TFltPr(-1,-1)); return; }
TGnuPlot::PlotValV(EigIprV, "eigIPR."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f (%d values)",
DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges(), EigIprV.Last().Val1(), EigIprV.Len()),
"Eigenvalue", "Inverse Participation Ratio of corresponding Eigenvector", gpsLog10Y, false, gpwPoints);
}
示例13: GetNodesEdgesCountFromDegDistr
void GetNodesEdgesCountFromDegDistr(const TFltPrV& deg, int& nodes, int& edges){
double nodesD = 0, edgesD = 0;
for (int i = 0; i < deg.Len(); i++){
nodesD += deg[i].Val2.Val;
edgesD += deg[i].Val1.Val * deg[i].Val2.Val;
}
nodes = static_cast<int>(nodesD);
edges = static_cast<int>(edgesD);
// edges /= 2; as Deg = inDeg + outDeg
}
示例14: FindVal1Elem
int FindVal1Elem(const TFltPrV& vec, const TFlt& elem, bool& isExact){
for (int i = 0; i < vec.Len(); i++){
if (vec[i].Val1.Val == elem){
isExact = true;
return i;
}
if (vec[i].Val1.Val > elem){
return i-1;
}
}
return false;
}
示例15: GetPoints
void GetPoints(const TFlt& maxDegLog, const TFlt& minDegLog, const int& NInt, const TFltPrV& base, TFltPrV& points){
int beginIndex = 0;
// ignore nodes with zero degree (for Kronecker graphs)
/*if (base[0].Val1.Val != 0)
points.Add(base[beginIndex]);
else {
points.Add(base[++beginIndex]);
}*/
points.Add(base[beginIndex]);
TFlt baseMaxDeg = base[base.Len()-1].Val1.Val,
baseMinDeg = base[beginIndex].Val1.Val;
for (int i = beginIndex + 1; i < NInt; i++){
// deg - degree to be found in base
TFlt degRound (pow (10, minDegLog.Val + i * (maxDegLog.Val - minDegLog.Val) / NInt));
TInt degInt(static_cast<int>(degRound.Val));
TFlt deg(degInt);
// if deg < baseMinDeg (for cases when baseMinDeg > minDeg)
if (deg.Val <= baseMinDeg)
continue;
// if deg > baseMaxDeg, add last point and finish
if (deg.Val >= baseMaxDeg){
points.Add(base[base.Len()-1]);
break;
}
// we have two cases: when we can find an exact value of deg, or when we have not this value
bool isExact = false;
int index = FindVal1Elem(base, deg, isExact);
if (isExact){
points.Add(base[index]);
}
else
{
TFltPr x;
x.Val1.Val = deg;
x.Val2.Val = ( base[index].Val2.Val + base [index + 1].Val2.Val ) / 2;
points.Add(x);
}
}
}