void PluginConfiguration::readSessionConfig(KConfigBase* config, const QString& groupPrefix)
{
    kDebug(DEBUG_AREA) << "** CONFIG-MGR **: Reading session config: " << groupPrefix;
    // Read session config
    /// \todo Rename it!
    KConfigGroup scg(config, groupPrefix + SESSION_GROUP_SUFFIX);
    m_session_dirs = scg.readPathEntry(CONFIGURED_DIRS_ITEM, QStringList{});
    m_pch_header= scg.readPathEntry(PCH_FILE_ITEM, QString{});
    m_clang_params = scg.readPathEntry(CLANG_CMDLINE_PARAMS_ITEM, QString{});
    m_use_ltgt = scg.readEntry(USE_LT_GT_ITEM, QVariant{false}).toBool();
    m_use_cwd = scg.readEntry(USE_CWD_ITEM, QVariant{false}).toBool();
    m_ignore_ext = scg.readEntry(IGNORE_EXTENSIONS_ITEM, QStringList{});
    m_open_first = scg.readEntry(OPEN_FIRST_INCLUDE_ITEM, QVariant{false}).toBool();
    m_use_wildcard_search = scg.readEntry(USE_WILDCARD_SEARCH_ITEM, QVariant{false}).toBool();
    m_highlight_completions = scg.readEntry(HIGHLIGHT_COMPLETIONS_ITEM, QVariant{true}).toBool();
    m_sanitize_completions = scg.readEntry(SANITIZE_COMPLETIONS_ITEM, QVariant{true}).toBool();
    m_auto_completions = scg.readEntry(AUTO_COMPLETIONS_ITEM, QVariant{true}).toBool();
    m_include_macros = scg.readEntry(INCLUDE_MACROS_ITEM, QVariant{true}).toBool();
    m_use_prefix_column = scg.readEntry(USE_PREFIX_COLUMN_ITEM, QVariant{false}).toBool();
    m_append_sanitizer_rules_on_import = scg.readEntry(APPEND_ON_IMPORT_ITEM, QVariant{false}).toBool();
    //
    auto monitor_flags = scg.readEntry(MONITOR_DIRS_ITEM, QVariant{0}).toInt();
    if (monitor_flags < int(MonitorTargets::last__))
        m_monitor_flags = static_cast<MonitorTargets>(monitor_flags);
    else
        m_monitor_flags = MonitorTargets::nothing;
    //
    for (const auto& index : scg.readEntry(ENABLED_INDICES_ITEM, QStringList{}))
    {
        try
        {
            m_enabled_indices.insert(index::fromString(index));
        }
        catch (...)
        {
            /// \todo Make some spam?
            continue;
        }
    }
    m_config_dirty = false;

    kDebug(DEBUG_AREA) << "Got per session configured include path list: " << m_session_dirs;

    readGlobalConfig();

    Q_EMIT(sessionDirsChanged());
    Q_EMIT(dirWatchSettingsChanged());
}
void PluginConfiguration::writeSessionConfig(KConfigBase* config, const QString& groupPrefix)
{
    kDebug(DEBUG_AREA) << "** CONFIG-MGR **: Writing session config: " << groupPrefix;
    if (!m_config_dirty)
    {
        kDebug(DEBUG_AREA) << "Config isn't dirty!!!";
        readSessionConfig(config, groupPrefix);
        return;
    }

    // Write session config
    KConfigGroup scg(config, groupPrefix + SESSION_GROUP_SUFFIX);
    scg.writePathEntry(CONFIGURED_DIRS_ITEM, m_session_dirs);
    scg.writePathEntry(PCH_FILE_ITEM, m_pch_header.toLocalFile());
    scg.writeEntry(CLANG_CMDLINE_PARAMS_ITEM, m_clang_params);
    scg.writeEntry(IGNORE_EXTENSIONS_ITEM, m_ignore_ext);
    scg.writeEntry(MONITOR_DIRS_ITEM, int(m_monitor_flags));
    scg.writeEntry(AUTO_COMPLETIONS_ITEM, m_auto_completions);
    scg.writeEntry(HIGHLIGHT_COMPLETIONS_ITEM, m_highlight_completions);
    scg.writeEntry(INCLUDE_MACROS_ITEM, m_include_macros);
    scg.writeEntry(OPEN_FIRST_INCLUDE_ITEM, m_open_first);
    scg.writeEntry(SANITIZE_COMPLETIONS_ITEM, m_sanitize_completions);
    scg.writeEntry(USE_CWD_ITEM, m_use_cwd);
    scg.writeEntry(USE_LT_GT_ITEM, m_use_ltgt);
    scg.writeEntry(USE_PREFIX_COLUMN_ITEM, m_use_prefix_column);
    scg.writeEntry(USE_WILDCARD_SEARCH_ITEM, m_use_wildcard_search);
    scg.writeEntry(APPEND_ON_IMPORT_ITEM, m_append_sanitizer_rules_on_import);
    {
        auto enabled_indices = QStringList{};
        for (const auto& index : m_enabled_indices)
            enabled_indices << index::toString(index);
        scg.writeEntry(ENABLED_INDICES_ITEM, enabled_indices);
    }

    scg.sync();

    // Write global config
    KConfigGroup gcg(KGlobal::config(), GLOBAL_CONFIG_GROUP_NAME);
    gcg.writePathEntry(CONFIGURED_DIRS_ITEM, m_system_dirs);
    writeSanitizeRulesTo(gcg);
    gcg.sync();
    m_config_dirty = false;
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {

    // Generate data from a sine
    vec X = linspace(0, 2*pi, 200);
    vec Y = sin(X);                          // True function

    // Randomly select a subset of the data as observations,
    // and add white noise
    ivec Iobs = randperm(NUM_X).left(NUM_OBS);
    vec Xobs = X(Iobs);
    mat XobsMat = mat(Xobs);      // PSGP requires a matrix of inputs (not a vector)
    vec Yobs = Y(Iobs) + sqrt(NOISE_VAR)*randn(NUM_OBS);   // Noisy observations

    // Covariance function: Gaussian + Nugget
    double range = 0.5;           // Initial range
    double sill = 1;              // Initial sill
    double nugget = NOISE_VAR;    // Nugget variance

    GaussianCF   gaussianCovFunc(range, sill);
    WhiteNoiseCF nuggetCovFunc(nugget);
    SumCF covFunc;
    covFunc.add(gaussianCovFunc);
    covFunc.add(nuggetCovFunc);

    // Initialise psgp
    PSGP psgp(XobsMat, Yobs, covFunc, NUM_ACTIVE);

    // Use a Gaussian likelihood model with fixed variance
    GaussianLikelihood gaussLik(nugget);

    // Compute the posterior (first guess), which projects the whole observed data
    // onto a subset of optimal active points.
    psgp.computePosterior(gaussLik);

    // Estimate parameters using Scaled Conjugate Gradients
    SCGModelTrainer scg(psgp);
    scg.Train(10);

    // Recompute the posterior and active points for the new parameters
    psgp.resetPosterior();
    psgp.computePosterior(gaussLik);


    // Make predictions - we use the Gaussian covariance function only
    // to make non-noisy prediction (no nugget)
    vec psgpmean = zeros(NUM_X);
    vec psgpvar  = zeros(NUM_X);
    psgp.makePredictions(psgpmean, psgpvar, mat(X), gaussianCovFunc);

    // Plot results
    GraphPlotter gplot = GraphPlotter();

    // Plot psgp mean and variance
    gplot.plotPoints(X, psgpmean, "psgp mean", LINE, BLUE);
    gplot.plotPoints(X, psgpmean + 2.0*sqrt(psgpvar), "error bar", LINE, CYAN);
    gplot.plotPoints(X, psgpmean - 2.0*sqrt(psgpvar), "error bar", LINE, CYAN);

    // Plot true function and observations
    gplot.plotPoints(X, Y, "true function", LINE, RED);
    gplot.plotPoints(Xobs, Yobs, "observations", CROSS, BLACK);

    // Plot active points
    vec activeX = (psgp.getActiveSetLocations()).get_col(0);
    vec activeY = Yobs(psgp.getActiveSetIndices());
    gplot.plotPoints(activeX, activeY, "active points", CIRCLE, BLUE);

    return 0;
}