Skip to content

Commit

Permalink
PACF plot (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-xmr authored Jan 26, 2022
1 parent cb8a848 commit ca19c7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lib-base/src/MatplotACF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void MatplotACF::Plot(const EnjoLib::VecD & dat, int lags, const EnjoLib::Str &
AlgoSTDIVec<double>().Reverse(&reversed);
//ofs << dat.PrintPython("dat") << Nl;
ofs << reversed.PrintPython("dat") << Nl;
ofs << "plotData(dat, " << lags << ", '" << title << "')" << Nl;
ofs << "plotACF(dat, " << lags << ", '" << title << "')" << Nl;
ofs << "plotPACF(dat, " << lags << ", '" << title << "')" << Nl;
}

ToolsMixed().SystemCallWarn("python3 " + scriptOut, "MatplotACF::Plot()");
Expand Down
4 changes: 2 additions & 2 deletions src/lib-base/src/OptimizerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void OptimizerBase::operator()()
Consume(dataNewT.at(i));
if (gcfgMan.cfgOpti->OPTI_RANDOM_EARLY_STOP && IsEarlyStop())
{
LOGL << "Early stop. The recent changes were less than " << gcfgMan.cfgOpti->OPTI_RANDOM_MIN_DIFF_PROMILE << " ‰ after " << i << " iterations.\n";
LOGL << "Early stop. The recent variance changes were less than " << gcfgMan.cfgOpti->OPTI_RANDOM_MIN_DIFF_PROMILE << " ‰ after " << i << " iterations.\n";
break;
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ void OptimizerBase::PlotVariance() const
const float scaleY = 0.5;
const Formatters fmt;
ELO
GnuplotPlotTerminal1d(m_goalsMod.Diffs().Smooth(GetSmoothing()), "Variance changes:", scaleX, scaleY);
GnuplotPlotTerminal1d(m_goalsMod.Diffs().Smooth(GetSmoothing()), "Variance changes (low values mean that no better solution can be found):", scaleX, scaleY);
LOG << "Best │ " << fmt.VecLabel() << "\n";
LOG << fmt.FormatVar(m_goalMax) << " " << fmt.FormatVec(m_goals) << Endl;
const StatsUtil::Distrib & distrib = StatsUtil().GetDistrib(m_goals);
Expand Down
24 changes: 21 additions & 3 deletions src/tsqsim-lib/static/scripts/plot_acf_pacf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,28 @@
#from pandas.plotting import register_matplotlib_converters
#from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
#register_matplotlib_converters()
from statsmodels.tsa.stattools import acf, pacf


def plotData(data, lags):
def plotACF(data, lags, title):
obj = pd.plotting.autocorrelation_plot(data)
obj.set_xlim([0, lags])
obj.set_title("Autocorr. (" + str(lags) + ") " + title)
plt.show()

def plotPACF(data, lags, title):
pacf_vals = pacf(data)
#fig = plt.figure()
y = pacf_vals#[:lags]
length = len(y)
if lags > length:
lags = length
x = list(range(lags))
print(len(x))
print(length)
plt.bar(x, y)
plt.grid()
plt.title("Partial Autocorr. (" + str(lags) + ") " + title)
plt.show()

def demo():
Expand All @@ -41,12 +58,13 @@ def demo():
#acf_plot = plot_acf(df_ice_cream.production, lags=100)

a = [1, 2, 3, 4, 5, 6]
plotData(a, 4)
plotACF(a, 4, "demo")
plotPACF(a, 4, "demo")
#obj = pd.plotting.autocorrelation_plot(df_ice_cream.production)
#plt.show()


#acf_plot = plot_acf(a, lags=5)
#acf_plot.show()

#demo()
demo()

0 comments on commit ca19c7a

Please sign in to comment.