<commit_before>// Except for any way in which it interferes with <NAME>'s 2009
// copyright assertion in the article "Burg’s Method, Algorithm and Recursion":
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
#include "burg.hpp"

#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <vector>

// Example program using burg_method and model selection
int main()
{
    using namespace std;

    // Sample size decreased to show model selection criteria differences.
    const std::size_t N = 10;

    // Create data to approximate from [Collomb2009]'s example.
    //
    // Notice that this isn't the most nicely conditioned problem
    // and truncating coefficients (as we'll do for display below)
    // causes roots to appear outside the unit circle.
    vector<long double> data(N, 0.0);
    for (size_t i = 0; i < N; i++)
    {
        data[i] =     cos(i*0.01) + 0.75*cos(i*0.03)
                + 0.5*cos(i*0.05) + 0.25*cos(i*0.11);
    }

    // Get linear prediction coefficients for orders 0 through maxorder
    size_t maxorder = 7;
    long double mean;
    vector<long double> params, sigma2e, gain, autocor;
    burg_method(data.begin(), data.end(), mean, maxorder,
                back_inserter(params), back_inserter(sigma2e),
                back_inserter(gain), back_inserter(autocor),
                /* subtract mean?    */ false,
                /* output hierarchy? */ true);

    // Display orders, mean squared discrepancy, and model coefficients
    printf("%2s  %9s %9s %s\n", "AR", "RMS/N", "Gain", "Filter Coefficients");
    printf("%2s  %9s %9s %s\n", "--", "-----", "----", "-------------------");
    for (size_t p = 0, c = 0; p <= maxorder; ++p)
    {
        printf("%2lu  %9.2Le %9.2Le [ 1 ", p, sigma2e[p], gain[p]);<commit_msg>Control example order, sample size<commit_after>// Except for any way in which it interferes with <NAME>'s 2009
// copyright assertion in the article "Burg’s Method, Algorithm and Recursion":
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
#include "burg.hpp"

#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <vector>

// Example program using burg_method and model selection
int main(int argc, char *argv[])
{
    using namespace std;

    // Maximum model estimation order to perform (limited by N)
    size_t maxorder = argc > 1 && atol(argv[1]) >= 0
                      ? atol(argv[1])
                      : 7;

    // Default sample size shows model selection criteria differences
    const std::size_t N = argc > 2 && atol(argv[2]) > 0
                        ? atol(argv[2])
                        : 10;


    // Create data to approximate from [Collomb2009]'s example.
    //
    // Notice that this isn't the most nicely conditioned problem
    // and truncating coefficients (as we'll do for display below)
    // causes roots to appear outside the unit circle.
    vector<long double> data(N, 0.0);
    for (size_t i = 0; i < N; i++)
    {
        data[i] =     cos(i*0.01) + 0.75*cos(i*0.03)
                + 0.5*cos(i*0.05) + 0.25*cos(i*0.11);
    }

    // Estimate process parameters using Burg's method
    printf("Estimating at most an AR(%lu) model using %lu samples\n\n",
           maxorder, N);

    long double mean;
    vector<long double> params, sigma2e, gain, autocor;
    burg_method(data.begin(), data.end(), mean, maxorder,
                back_inserter(params), back_inserter(sigma2e),
                back_inserter(gain), back_inserter(autocor),
                /* subtract mean?    */ false,
                /* output hierarchy? */ true);

    // Display orders, mean squared discrepancy, and model coefficients
    printf("%2s  %9s %9s %s\n", "AR", "RMS/N", "Gain", "Filter Coefficients");
    printf("%2s  %9s %9s %s\n", "--", "-----", "----", "-------------------");
    for (size_t p = 0, c = 0; p <= maxorder; ++p)
    {
        printf("%2lu  %9.2Le %9.2Le [ 1 ", p, sigma2e[p], gain[p]);
{'fraction_non_alphanumeric': 0.1483644859813084, 'fraction_numerical': 0.02780373831775701, 'mean_word_length': 2.3976190476190475, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5340571', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1334, 'n_words': 460}