本文整理汇总了C++中TFltPrV类的典型用法代码示例。如果您正苦于以下问题:C++ TFltPrV类的具体用法?C++ TFltPrV怎么用?C++ TFltPrV使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TFltPrV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddExpFit
int TGnuPlot::AddExpFit(const int& PlotId, const TGpSeriesTy& SeriesTy, const double& FitXOffset, const TStr& Style) {
const TGpSeries& Plot = SeriesV[PlotId];
if(Plot.XYValV.Empty()) return -1;
const TFltKdV& XY = Plot.XYValV;
double A, B, R2, SigA, SigB, Chi2;
// power fit
TFltPrV XYPr;
int s;
for (s = 0; s < XY.Len(); s++) {
if (XY[s].Key-FitXOffset > 0) {
XYPr.Add(TFltPr(XY[s].Key-FitXOffset, XY[s].Dat)); } //!!! skip zero values
}
TSpecFunc::ExpFit(XYPr, A, B, SigA, SigB, Chi2, R2);
TStr Label, StyleStr=Style;
if (FitXOffset == 0) { Label = TStr::Fmt("%.4g exp(%.4g x) R^2:%.2g", A, B, R2); }
else { Label = TStr::Fmt("%.4g exp(%.4g x - %g) R^2:%.2g", A, B, FitXOffset, R2); }
if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
const int FitId = AddFunc(TStr::Fmt("%f*exp(%f*x-%f)", A, B, FitXOffset),
SeriesTy, Label, StyleStr);
return FitId;
/*SeriesV.Add();
TGpSeries& NewPlot = SeriesV.Last();
TFltKdV& EstXY = NewPlot.XYValV;
for (s = 0; s < XYPr.Len(); s++) {
EstXY.Add(TFltKd(XYPr[s].Val1+FitXOffset, A*exp(B*XYPr[s].Val1)));
}
NewPlot.SeriesTy = SeriesTy;
if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
else { NewPlot.WithStyle = Style; }
return SeriesV.Len() - 1;*/
}
示例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: AddLogFit
int TGnuPlot::AddLogFit(const int& PlotId, const TGpSeriesTy& SeriesTy, const TStr& Style) {
const TGpSeries& Plot = SeriesV[PlotId];
if(Plot.XYValV.Empty()) return -1;
const TFltKdV& XY = Plot.XYValV;
double A, B, R2, SigA, SigB, Chi2;
// power fit
TFltPrV XYPr;
int s;
for (s = 0; s < XY.Len(); s++) {
if (XY[s].Key > 0) {
XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat)); } //!!! skip zero values
}
TSpecFunc::LogFit(XYPr, A, B, SigA, SigB, Chi2, R2);
TStr StyleStr=Style;
if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
const int FitId = AddFunc(TStr::Fmt("%f+%f*log(x)", A, B),
SeriesTy, TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2), StyleStr);
return FitId;
/*SeriesV.Add();
TGpSeries& NewPlot = SeriesV.Last();
TFltKdV& EstXY = NewPlot.XYValV;
for (s = 0; s < XYPr.Len(); s++) {
EstXY.Add(TFltKd(XYPr[s].Val1, A+B*log((double)XYPr[s].Val1)));
}
NewPlot.Label = TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2);
NewPlot.SeriesTy = SeriesTy;
if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
else { NewPlot.WithStyle = Style; }
return SeriesV.Len() - 1;*/
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
}
示例7: 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; }
}
示例8: GetValV
void TGStatVec::GetValV(const TGStatVal& XVal, const TGStatVal& YVal, TFltPrV& ValV) const {
ValV.Gen(Len(), 0);
double x;
for (int t = 0; t < Len(); t++) {
if (XVal == gsvTime) { x = t+1; }
else { x = At(t)->GetVal(XVal); }
ValV.Add(TFltPr(x, At(t)->GetVal(YVal)));
}
}
示例9: TEST
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
const int ExpClosedTr = 3; // Expected closed triads
const int ExpOpenTr = 9; // Expected open triads
// Test TUNGraph
PUNGraph GraphTUN = TriadGetTestTUNGraph();
TFltPrV DegToCCfV;
int64 ClosedTr = 0;
int64 OpenTr = 0;
TSnap::GetClustCf(GraphTUN, DegToCCfV, ClosedTr, OpenTr);
TestDegToCCfVector(DegToCCfV);
EXPECT_EQ(ExpClosedTr, ClosedTr);
EXPECT_EQ(ExpOpenTr, OpenTr);
// TNGraph should be treated as TUNGraph for calculations
PNGraph GraphTN = TriadGetTestTNGraph();
DegToCCfV.Clr();
ClosedTr = 0;
OpenTr = 0;
TSnap::GetClustCf(GraphTN, DegToCCfV, ClosedTr, OpenTr);
TestDegToCCfVector(DegToCCfV);
EXPECT_EQ(ExpClosedTr, ClosedTr);
EXPECT_EQ(ExpOpenTr, OpenTr);
// TNEGraph is not treated the same! Be careful with multigraphs
PNEGraph GraphTNE = TriadGetTestTNEGraph();
DegToCCfV.Clr();
ClosedTr = 0;
OpenTr = 0;
TSnap::GetClustCf(GraphTNE, DegToCCfV, ClosedTr, OpenTr);
for (TFltPr *Pair = DegToCCfV.BegI(); Pair < DegToCCfV.EndI(); Pair++) {
double Diff = Pair->Val2 - 5.0/9.0; // Used for case 4
Diff = (Diff < 0) ? -1.0*Diff : Diff; // Used for case 4
switch ((int) Pair->Val1) {
case 2:
EXPECT_EQ(1.0, Pair->Val2);
break;
case 4:
EXPECT_GT(0.00001, Diff); // Due to floats being imprecise
break;
case 7:
EXPECT_EQ(2.0/3.0, Pair->Val2);
break;
case 15:
EXPECT_EQ(0.3, Pair->Val2);
break;
default:
ASSERT_FALSE(true); // Shouldn't have degrees other than listed
break;
}
}
EXPECT_EQ(ExpClosedTr, ClosedTr);
EXPECT_EQ(ExpOpenTr, OpenTr);
}
示例10: 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);
}
示例11: 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)); }
}
示例12: 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
}
示例13: GnuPlot
void TFfGGen::PlotFireSize(const TStr& FNmPref, const TStr& DescStr) {
TGnuPlot GnuPlot("fs."+FNmPref, TStr::Fmt("%s. Fire size. G(%d, %d)",
DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges()));
GnuPlot.SetXYLabel("Vertex id (iterations)", "Fire size (node out-degree)");
TFltPrV IdToOutDegV;
for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
IdToOutDegV.Add(TFltPr(NI.GetId(), NI.GetOutDeg())); }
IdToOutDegV.Sort();
GnuPlot.AddPlot(IdToOutDegV, gpwImpulses, "Node out-degree");
GnuPlot.SavePng();
}
示例14: TEST
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
const int expected_closed = 3; // Expected closed triads
const int expected_open = 9; // Expected open triads
// Test TUNGraph
PUNGraph Graph_TUNGraph = TriadGetTestTUNGraph();
TFltPrV DegToCCfV;
int64 closed = 0, open = 0;
TSnap::GetClustCf(Graph_TUNGraph, DegToCCfV, closed, open);
TestDegToCCfVector(DegToCCfV);
EXPECT_EQ(expected_closed, closed);
EXPECT_EQ(expected_open, open);
// TNGraph should be treated as TUNGraph for calculations
PNGraph Graph_TNGraph = TriadGetTestTNGraph();
DegToCCfV.Clr();
closed = 0, open = 0;
TSnap::GetClustCf(Graph_TNGraph, DegToCCfV, closed, open);
TestDegToCCfVector(DegToCCfV);
EXPECT_EQ(expected_closed, closed);
EXPECT_EQ(expected_open, open);
// TNEGraph is not treated the same! Be careful with multigraphs
PNEGraph Graph_TNEGraph = TriadGetTestTNEGraph();
DegToCCfV.Clr();
closed = 0, open = 0;
TSnap::GetClustCf(Graph_TNEGraph, DegToCCfV, closed, open);
for (TFltPr *pair = DegToCCfV.BegI(); pair < DegToCCfV.EndI(); pair++) {
double diff = pair->Val2 - 5.0/9.0; // Used for case 4
diff = (diff < 0) ? -1.0*diff : diff; // Used for case 4
switch ((int) pair->Val1) {
case 2:
EXPECT_EQ(1.0, pair->Val2);
break;
case 4:
EXPECT_GT(0.00001, diff); // Due to floats being imprecise
break;
case 7:
EXPECT_EQ(2.0/3.0, pair->Val2);
break;
case 15:
EXPECT_EQ(0.3, pair->Val2);
break;
default:
ASSERT_FALSE(true); // Shouldn't have degrees other than listed
break;
}
}
EXPECT_EQ(expected_closed, closed);
EXPECT_EQ(expected_open, open);
}
示例15: 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();
}