int TGnuPlot::AddPlot(const TFltV& YValV, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style) { TFltKdV XYValV(YValV.Len(), 0); for (int i = 0; i < YValV.Len(); i++) { XYValV.Add(TFltKd(TFlt(i+1), TFlt(YValV[i]))); } return AddPlot(XYValV, SeriesTy, Label, Style); }
int TGnuPlot::AddPlot(const TIntFltPrV& 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(TFlt(XYValV[i].Val1), TFlt(XYValV[i].Val2))); } return AddPlot(XYFltValV, SeriesTy, Label, Style); }
TEST(TNEANet, AddEdgeAttributeError) { PNEANet Graph; Graph = TNEANet::New(); TStr StrAttr("name"); TStr FltAttr("weight"); TStr IntAttr("test"); Graph->AddStrAttrE(StrAttr); Graph->AddFltAttrE(FltAttr); Graph->AddIntAttrE(IntAttr); int NumEdges = 5; for (int i = 0; i < NumEdges + 1; i++) { Graph->AddNode(i); } for (int i = 0; i < NumEdges; i++) { Graph->AddEdge(i, i+1, i); Graph->AddIntAttrDatE(i, TInt(i), IntAttr); Graph->AddFltAttrDatE(i, TFlt(i), FltAttr); TInt Val(i); Graph->AddStrAttrDatE(i, Val.GetStr(), StrAttr); } Graph->DelNode(0); for (int j = 1; j < NumEdges; j++) { ASSERT_EQ(Graph->GetIntAttrDatE(j, IntAttr), TInt(j)); ASSERT_EQ(Graph->GetFltAttrDatE(j, FltAttr), TFlt(j)); TInt Val(j); ASSERT_EQ(Graph->GetStrAttrDatE(j, StrAttr), Val.GetStr()); } }
void TGraphKey::TakeSig(const PNGraph& Graph, const int& MnSvdGraph, const int& MxSvdGraph) { const int Edges = Graph->GetEdges(); Nodes = Graph->GetNodes(); VariantId = 0; SigV.Gen(2+Nodes, 0); // degree sequence TIntPrV DegV(Nodes, 0); for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) { DegV.Add(TIntPr(NodeI.GetInDeg(), NodeI.GetOutDeg())); } DegV.Sort(false); SigV.Add(TFlt(Nodes)); SigV.Add(TFlt(Edges)); for (int i = 0; i < DegV.Len(); i++) { SigV.Add(DegV[i].Val1()); SigV.Add(DegV[i].Val2()); } // singular values signature // it turns out that it is cheaper to do brute force isomorphism // checking than to calculate SVD and then check isomorphism if (Nodes >= MnSvdGraph && Nodes < MxSvdGraph) { // perform full SVD TFltVV AdjMtx(Nodes+1, Nodes+1); TFltV SngValV; TFltVV LSingV, RSingV; TIntH NodeIdH; // create adjecency matrix for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) { NodeIdH.AddKey(NodeI.GetId()); } for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) { const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1; for (int e = 0; e < NodeI.GetOutDeg(); e++) { const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1; // no self edges if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1; } } try { // can fail to converge but results seem to be good TSvd::Svd(AdjMtx, LSingV, SngValV, RSingV); } catch(...) { printf("\n***No SVD convergence: G(%d, %d): SngValV.Len():%d\n", Nodes(), Graph->GetEdges(), SngValV.Len()); } // round singular values SngValV.Sort(false); for (int i = 0; i < SngValV.Len(); i++) { SigV.Add(TMath::Round(SngValV[i], RoundTo)); } } //printf("SIG:\n"); for (int i = 0; i < SigV.Len(); i++) { printf("\t%f\n", SigV[i]); } SigV.Pack(); }
int generate_vms_instructions(std::string file_name, MNM_Vms_Factory* vms_factory, MNM_Link_Factory *link_factory) { /* find file */ std::ofstream _vms_info_file; _vms_info_file.open(file_name, std::ios::out); if (!_vms_info_file.is_open()){ printf("Error happens when open _vms_info_file\n"); exit(-1); } std::string _info; MNM_Dlink *_link; std::string _str; for (auto _map_it : vms_factory -> m_link_vms_map){ MNM_Link_Vms *_vms = _map_it.second; _link = link_factory -> get_link(_vms -> m_detour_link_ID); if (_link -> m_ffs < TFlt(60.0 * 1600.0 / 3600.0)){ _info = std::string("Congestion ahead, take next exit to link ") + std::to_string(_vms -> m_detour_link_ID) + "(The suggestion should be paired with DMS on the arterials guiding drivers).\n"; } else{ if (_link -> get_link_tt() > _link -> m_length / _link -> m_ffs){ _info = std::string("Congestion ahead, ") + std::to_string(static_cast<int>(_link -> get_link_tt()/60)) + std::string(" minutes to get to next exit.\n"); } else{ _info = std::string("Drive with care!\n"); } } _str = std::to_string(_map_it.first) + " " + _info; // printf("%s\n", _str.c_str()); _vms_info_file << _str; } _vms_info_file.close(); return 0; }
void TNNet::TNeuron::UpdateInputWeights(TLayer& PrevLayer, const TFlt& LearnRate, const TFlt& Momentum, const TBool& UpdateWeights){ // the weights to be updated are in the OutEdgeV // in the neurons in the preceding layer for(int NeuronN = 0; NeuronN < PrevLayer.GetNeuronN(); ++NeuronN){ TNeuron& Neuron = PrevLayer.GetNeuron(NeuronN); TFlt OldDeltaWeight = Neuron.GetDeltaWeight(Id); //TFlt OldWeight = Neuron.GetWeight(Id); TFlt OldSumDeltaWeight = Neuron.GetSumDeltaWeight(Id); TFlt NewDeltaWeight = // individual input magnified by the gradient and train rate LearnRate * Neuron.GetOutVal() * Gradient // add momentum = fraction of previous delta weight, if we are not in batch mode + (UpdateWeights && OldSumDeltaWeight == 0.0 ? Momentum : TFlt()) * OldDeltaWeight; if(UpdateWeights){ if(OldSumDeltaWeight != 0.0){ NewDeltaWeight = OldSumDeltaWeight + NewDeltaWeight; Neuron.SetSumDeltaWeight(Id, 0.0); } Neuron.SetDeltaWeight(Id, NewDeltaWeight); Neuron.UpdateWeight(Id, NewDeltaWeight); } else{ Neuron.SumDeltaWeights(Id, NewDeltaWeight); } } }
int TGnuPlot::AddErrBar(const TFltV& YValV, const TFltV& DeltaYV, const TStr& Label) { IAssert(YValV.Len() == DeltaYV.Len()); TFltKdV XYFltValV(YValV.Len(), 0); for (int i = 0; i < YValV.Len(); i++) { XYFltValV.Add(TFltKd(TFlt(i+1), YValV[i])); } return AddErrBar(XYFltValV, DeltaYV, Label); }
MNM_Link_Vms::MNM_Link_Vms(TInt ID, TInt link_ID, PNEGraph graph) { m_ID = ID; m_my_link_ID = link_ID; m_detour_link_ID = -1; m_compliance_ratio = TFlt(1); m_out_link_vec = std::vector<TInt>(); m_link_path_map = std::unordered_map<TInt, std::vector<MNM_Path*>*>(); hook_link(graph); }
void TSAppSrvFun::SetFldNmFlt(TStrKdV& FldNmValPrV, const TStr& FldNm, const double& FldVal) { SetFldNmVal(FldNmValPrV, FldNm, TFlt(FldVal).GetStr()); }
TGraphKey::TGraphKey(const TSFltV& GraphSigV) : Nodes(-1), EdgeV(), SigV(), VariantId(0) { SigV.Gen(GraphSigV.Len()); for (int i = 0; i < GraphSigV.Len(); i++) { SigV[i] = TFlt(TMath::Round(GraphSigV[i], RoundTo)); } }
TGraphKey::TGraphKey(const TIntV& GraphSigV) : Nodes(-1), EdgeV(), SigV(), VariantId(0) { SigV.Gen(GraphSigV.Len()); for (int i = 0; i < GraphSigV.Len(); i++) { SigV[i] = TFlt(GraphSigV[i]()); } }
TStringKernel::TStringKernel(TSIn& SIn) { KernelType = TInt(SIn); Lambda = TFlt(SIn); SeqLen = TInt(SIn); GapLen = TInt(SIn); AlphN = TInt(SIn); LinCombV.Load(SIn); WeightV.Load(SIn); }