MapLoader::MapLoader() :_working_dir("maps") { _name = "maploader"; CheckDirExist(_working_dir); AddFunc("ldmap", &MapLoader::LoadMap); AddFunc("setwkdir", &MapLoader::SetWordDir); AddFunc("ldxml", &MapLoader::LoadXML); }
/* 模組初始化 */ AnnMind::AnnMind() { _name = "ANN"; _desc = "Artifical Neural Network prac."; AddFunc("anntrain", &AnnMind::Trainning); }
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;*/ }
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;*/ }
void CRecentFuncList::UpdateMenu(CCmdUI* pCmdUI, CVector* pVec, BOOL bEnable) { CMruMenu menu(8,_T("Recent Function")); pMruVec = pVec; if (GetCount() == 0) { CFunc func = DEMO_APP->GetDirector()->GetProcess()->GetCurrentFunction(); if (!func.IsEmpty()) AddFunc(func); } menu.SetList(this); menu.UpdateMenu(pCmdUI, bEnable ? ValidMru : InvalidMru); }
MapCreater::MapCreater() :_working_dir("maps") { _name = "mapcreater"; CheckDirExist(_working_dir); AddFunc("newmap", &MapCreater::NewMap); AddFunc("newarea", &MapCreater::NewArea); AddFunc("mfmap", &MapCreater::ModifyMap); AddFunc("mfarea", &MapCreater::ModifyArea); AddFunc("delmap", &MapCreater::DeleteMap); AddFunc("delarea", &MapCreater::DeleteArea); AddFunc("setwkdir", &MapCreater::SetWordDir); }
// 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;*/ }
Server::Server() :_run(true) ,_log("./logs/server.log") { _name = "server"; AddFunc("ss", &Server::ServerStart); AddFunc("startserver", &Server::ServerStart); AddFunc("stopserver", &Server::ServerStop); AddFunc("closes", &Server::StopSession); AddFunc("si", &Server::DispSession); AddFunc("sesinfo", &Server::DispSession); }
// some kind of least squares power-law fitting that cutts the tail until the fit is good int TGnuPlot::AddPwrFit3(const int& PlotId, const TGpSeriesTy& SeriesTy, const double& MinX, const TStr& Style, double& Intercept, double& Slope, double& R2) { if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1; const TGpSeries& Plot = SeriesV[PlotId]; if(Plot.XYValV.Empty()) return -1; double A, B, SigA, SigB, Chi2, MinY=TFlt::Mx; const TFltKdV& XY = Plot.XYValV; //SeriesV.Add(); //TGpSeries& NewPlot = SeriesV.Last(); //TFltKdV& EstXY = NewPlot.XYValV; TFltPrV FitXY, NewFitXY; for (int s = 0; s < XY.Len(); s++) { if (XY[s].Key > 0 && XY[s].Key >= MinX) { FitXY.Add(TFltPr(XY[s].Key, XY[s].Dat)); //!!! skip zero values MinY = TMath::Mn(MinY, XY[s].Dat()); } } MinY = TMath::Mn(1.0, MinY); // power fit (if tail is too fat, cut everything where // extrapolation sets the value < MinY while (true) { TSpecFunc::PowerFit(FitXY, A, B, SigA, SigB, Chi2, R2); NewFitXY.Clr(false); //EstXY.Clr(false); for (int s = 0; s < FitXY.Len(); s++) { const double YVal = A*pow(FitXY[s].Val1(), B); if (YVal < MinY) continue; //EstXY.Add(TFltKd(FitXY[s].Val1, YVal)); NewFitXY.Add(TFltPr(FitXY[s].Val1, FitXY[s].Val2)); } if (NewFitXY.Len() < 10 || FitXY.Last().Val1 < 1.2 * NewFitXY.Last().Val1) { break; } else { FitXY.Swap(NewFitXY); } } TStr StyleStr=Style; if (StyleStr.Empty()) { StyleStr = "linewidth 3"; } const int FitId = AddFunc(TStr::Fmt("%f*x**%f", A, B), SeriesTy, TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2), StyleStr); return FitId; /*NewPlot.Label = TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2); Intercept = A; Slope = B; NewPlot.SeriesTy = SeriesTy; if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; } else { NewPlot.WithStyle = Style; } return SeriesV.Len() - 1;*/ }
void LuaParser::SetupEnv() { LUA_OPEN_LIB(L, luaopen_base); LUA_OPEN_LIB(L, luaopen_math); LUA_OPEN_LIB(L, luaopen_table); LUA_OPEN_LIB(L, luaopen_string); //LUA_OPEN_LIB(L, luaopen_io); //LUA_OPEN_LIB(L, luaopen_os); //LUA_OPEN_LIB(L, luaopen_package); //LUA_OPEN_LIB(L, luaopen_debug); // delete some dangerous/unsynced functions lua_pushnil(L); lua_setglobal(L, "dofile"); lua_pushnil(L); lua_setglobal(L, "loadfile"); lua_pushnil(L); lua_setglobal(L, "loadlib"); lua_pushnil(L); lua_setglobal(L, "require"); lua_pushnil(L); lua_setglobal(L, "gcinfo"); lua_pushnil(L); lua_setglobal(L, "collectgarbage"); // FIXME: replace "random" as in LuaHandleSynced (can write your own for now) lua_getglobal(L, "math"); lua_pushstring(L, "random"); lua_pushnil(L); lua_rawset(L, -3); lua_pushstring(L, "randomseed"); lua_pushnil(L); lua_rawset(L, -3); lua_pop(L, 1); // pop "math" AddFunc("DontMessWithMyCase", DontMessWithMyCase); GetTable("Spring"); AddFunc("Echo", Echo); AddFunc("TimeCheck", TimeCheck); EndTable(); GetTable("VFS"); AddFunc("DirList", DirList); AddFunc("SubDirs", SubDirs); AddFunc("Include", Include); AddFunc("LoadFile", LoadFile); AddFunc("FileExists", FileExists); EndTable(); }
// linear fit on log-log scales{% int TGnuPlot::AddPwrFit1(const int& PlotId, const TGpSeriesTy& SeriesTy, const TStr& Style) { if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1; const TGpSeries& Plot = SeriesV[PlotId]; if(Plot.XYValV.Empty()) return -1; const TFltKdV& XY = Plot.XYValV; double A, B, R2, SigA, SigB, Chi2, MinY = TFlt::Mx, MinX = TFlt::Mx; // 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 MinX = TMath::Mn(MinX, XY[s].Key()); MinY = TMath::Mn(MinY, XY[s].Dat()); } } MinY = TMath::Mn(1.0, MinY); TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2); TStr StyleStr=Style; if (StyleStr.Empty()) { StyleStr = "linewidth 3"; } const int FitId = AddFunc(TStr::Fmt("%f*x**%f", A, B), SeriesTy, TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2), StyleStr); return FitId; /*SeriesV.Add(); TGpSeries& NewPlot = SeriesV.Last(); const int FitId = SeriesV.Len() - 1; NewPlot.DataFNm = ; TFltKdV& EstXY = NewPlot.XYValV; for (s = 0; s < XYPr.Len(); s++) { const double YVal = A*pow(XYPr[s].Val1(), B); if (YVal < MinY) continue; EstXY.Add(TFltKd(XYPr[s].Val1, YVal)); } NewPlot.Label = ; NewPlot.SeriesTy = SeriesTy; if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; } else { NewPlot.WithStyle = Style; } //if (MinX < 5.0) MinX = 5.0; //AddPwrFit2(PlotId, SeriesTy, MinX);*/ }
void SetUpFuncTable() { AddFunc("debug", do_debug ,"int"); AddFunc("debugfunc", do_debug_func ,"int"); AddFunc("h", ShowHistory ,"void"); AddFunc("cd", do_cd ,"int"); AddFunc("mkdir", do_mkdir ,"int"); AddFunc("echo", do_echo ,"void"); AddFunc("setprompt", do_set_prompt ,"void"); AddFunc("where", do_where ,"void"); AddFunc("exit", do_exit ,"void"); AddFunc("quit", do_exit ,"void"); AddFunc("tset", tset ,"void"); AddFunc("listcommands", ShowFuncNames ,"void"); AddFunc("printargs", do_printargs ,"void"); AddFunc("silent", do_silent ,"int"); AddFunc("setenv", do_setenv ,"void"); AddFunc("getenv", do_getenv ,"char*"); AddFunc("printenv", do_printenv ,"void"); }