<commit_before>// (C) 2014 <NAME>

#pragma once

#include <chrono>
#include <random>
#include <tuple>

#include <boost/graph/graphml.hpp>

#include "algorithm.hpp"
#include "graph.hpp"

template <class Iterator>
void generate_seeds(Iterator begin, Iterator end, std::string seed) {
  std::seed_seq seq(seed.begin(), seed.end());
  seq.generate(begin, end);
}

double pr_within(double x) {
  return x <= 1
    ?  .5*x*x*x*x - 8./3*x*x*x + M_PI*x*x
    : -.5*x*x*x*x - 4*x*x*atan(sqrt(x*x-1)) + 4./3*(2*x*x+1)*sqrt(x*x-1) + (M_PI-2)*x*x + 1./3;
};

template <class Graph>
class test_suite {
public:
  unsigned size() const { return seeds.size() * degrees.size() * sizes.size(); }

  std::string type() const { return t; }

  std::tuple<Graph, unsigned, double, double> get(unsigned i) const {
    auto run = i % seeds.size();
    std::default_random_engine generator(seeds[run]);
    auto expected_degree = degrees[(i / seeds.size()) % degrees.size()];
    auto n = sizes[i / seeds.size() / degrees.size()];
    auto d = expected_degree;
    auto tree_degree = 2.*(n-1)/n;
    bool mst = found("mst", t);
    bool unite = !found("++", t);
    Graph G(n), G_shuffled(n);

    // use d in [0,1] to mean density (since connected graphs have d > 1 anyway)
    if(unite && d <= 1) d *= n-1;

    if(found("path", t)) {
      add_spider(G, 1, generator);
      // the overlap satisfies    y     = a    x     + b
      // full graph satisfies:    0     = a  (n-1)   + b
      // tree graph satisfies: 2(n-1)/n = a 2(n-1)/n + b
      // so we must subtract this:
      if(unite) d -= 2./(2.-n) * d + 1. + n/(n-2.);
    }

    double parameter;
    if(found("rgg", t)) {
      if(mst && unite) d -= d<2 ? tree_degree : 1/sinh(d-sqrt(2.)); // approximate fit
      parameter = find_argument(d/(n-1), pr_within, 0, sqrt(2.));
      Geometric points(n, generator);
      points.add_random_geometric(G, parameter);
      if(mst) points.add_mst(G);
    }
    else if(found("gnp", t)) {
      if(mst && unite) d -= d<2 ? tree_degree : 1/(2*M_PI*sinh(d-M_PI/sqrt(3.))); // approximate fit
      parameter = d<0 ? 0 : d/(n-1);
      add_edges_uniform(G, parameter, generator, mst);
    }

    copy_edges_shuffled(G, G_shuffled, generator);
    return std::make_tuple(G_shuffled, run, expected_degree, parameter);
  }

  template<class Sizes, class Degrees>
  test_suite(std::string t, unsigned z, Sizes ns, Degrees ds, std::string seed)
      : t(t), sizes(ns), degrees(ds) {
    seeds.resize(z);
    generate_seeds(seeds.begin(), seeds.end(), seed);
  }
private:
  std::string t;
  std::vector<unsigned> sizes;
  std::vector<double> degrees;
  std::vector<unsigned> seeds;
};

template <class Graph>
class file_suite {
public:
  std::tuple<Graph, unsigned, double, double> get(unsigned i) const {
    return std::make_tuple(graphs[i], i, 0, 0);
  }

  unsigned size() const { return graphs.size(); }

  file_suite(std::string f) : t(f.substr(0, f.find('.'))) {
    std::ifstream file(f);
    if(!file.good()) {
      throw std::invalid_argument("File does not exist: " + f);
    }<commit_msg>model name in file suite<commit_after>// (C) 2014 <NAME>

#pragma once

#include <chrono>
#include <random>
#include <tuple>

#include <boost/graph/graphml.hpp>

#include "algorithm.hpp"
#include "graph.hpp"

template <class Iterator>
void generate_seeds(Iterator begin, Iterator end, std::string seed) {
  std::seed_seq seq(seed.begin(), seed.end());
  seq.generate(begin, end);
}

double pr_within(double x) {
  return x <= 1
    ?  .5*x*x*x*x - 8./3*x*x*x + M_PI*x*x
    : -.5*x*x*x*x - 4*x*x*atan(sqrt(x*x-1)) + 4./3*(2*x*x+1)*sqrt(x*x-1) + (M_PI-2)*x*x + 1./3;
};

template <class Graph>
class test_suite {
public:
  unsigned size() const { return seeds.size() * degrees.size() * sizes.size(); }

  std::string type() const { return t; }

  std::tuple<Graph, unsigned, double, double> get(unsigned i) const {
    auto run = i % seeds.size();
    std::default_random_engine generator(seeds[run]);
    auto expected_degree = degrees[(i / seeds.size()) % degrees.size()];
    auto n = sizes[i / seeds.size() / degrees.size()];
    auto d = expected_degree;
    auto tree_degree = 2.*(n-1)/n;
    bool mst = found("mst", t);
    bool unite = !found("++", t);
    Graph G(n), G_shuffled(n);

    // use d in [0,1] to mean density (since connected graphs have d > 1 anyway)
    if(unite && d <= 1) d *= n-1;

    if(found("path", t)) {
      add_spider(G, 1, generator);
      // the overlap satisfies    y     = a    x     + b
      // full graph satisfies:    0     = a  (n-1)   + b
      // tree graph satisfies: 2(n-1)/n = a 2(n-1)/n + b
      // so we must subtract this:
      if(unite) d -= 2./(2.-n) * d + 1. + n/(n-2.);
    }

    double parameter;
    if(found("rgg", t)) {
      if(mst && unite) d -= d<2 ? tree_degree : 1/sinh(d-sqrt(2.)); // approximate fit
      parameter = find_argument(d/(n-1), pr_within, 0, sqrt(2.));
      Geometric points(n, generator);
      points.add_random_geometric(G, parameter);
      if(mst) points.add_mst(G);
    }
    else if(found("gnp", t)) {
      if(mst && unite) d -= d<2 ? tree_degree : 1/(2*M_PI*sinh(d-M_PI/sqrt(3.))); // approximate fit
      parameter = d<0 ? 0 : d/(n-1);
      add_edges_uniform(G, parameter, generator, mst);
    }

    copy_edges_shuffled(G, G_shuffled, generator);
    return std::make_tuple(G_shuffled, run, expected_degree, parameter);
  }

  template<class Sizes, class Degrees>
  test_suite(std::string t, unsigned z, Sizes ns, Degrees ds, std::string seed)
      : t(t), sizes(ns), degrees(ds) {
    seeds.resize(z);
    generate_seeds(seeds.begin(), seeds.end(), seed);
  }
private:
  std::string t;
  std::vector<unsigned> sizes;
  std::vector<double> degrees;
  std::vector<unsigned> seeds;
};

template <class Graph>
class file_suite {
public:
  std::tuple<Graph, unsigned, double, double> get(unsigned i) const {
    return std::make_tuple(graphs[i], i, 0, 0);
  }

  unsigned size() const { return graphs.size(); }

  file_suite(std::string f)
      : t(f.substr(f.rfind('/')+1, f.rfind('.')-f.rfind('/')-1)) {
    std::ifstream file(f);
    if(!file.good()) {
      throw std::invalid_argument("File does not exist: " + f);
    }
{'fraction_non_alphanumeric': 0.18485631256054247, 'fraction_numerical': 0.017274782047142397, 'mean_word_length': 3.127248500999334, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 33, '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': '1262630', 'n_tokens_mistral': 2386, 'n_tokens_neox': 2296, 'n_words': 560}