<commit_before>/*
 * DistributionContainer.C
 *
 *  Created on: Jul 6, 2012
 *      Author: alfoa
 */
#include "DistributionContainer.h"
//#include "Factory.h"
//#include "distribution_1D.h"
#include "distribution_min.h"
#include "distribution_base_ND.h"
#include <iostream>
#include <math.h>
#include <cmath>
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <map>
//#include <MooseRandom.h>
#include <boost/random/mersenne_twister.hpp>

using namespace std;

#define throwError(msg) { std::cerr << "\n\n" << msg << "\n\n"; throw std::runtime_error("Error"); }

class DistributionContainer;

class RandomClass {
  boost::random::mt19937 rng; 
  const double range;
public:
  RandomClass() : range(rng.max() - rng.min()) {};
  void seed(unsigned int seed) {
    rng.seed(seed);
  }
  double random() {
    return (rng()-rng.min())/range;
  }
};

DistributionContainer::DistributionContainer()
{
  _random = new RandomClass();
  _at_least_a_dist_triggered = false;
  _last_dist_triggered = "";
}
DistributionContainer::~DistributionContainer()
{
  delete _random;
}


void
DistributionContainer::addDistributionInContainer(const std::string & type, const std::string & name, BasicDistribution * dist){
   // create the distribution type
  //distribution * dist = dynamic_cast<distribution *>(_factory.create(type, name, params));
   if (_dist_by_name.find(name) == _dist_by_name.end())
    _dist_by_name[name] = dist;
   else
     throwError("Distribution with name " << name << " already exists");

   _dist_by_trigger_status[name] = false;
   _at_least_a_dist_triggered = false;

   //_dist_by_type[type].push_back(dist);

}

void
DistributionContainer::addDistributionInContainerND(const std::string & type, const std::string & name, BasicDistributionND * dist){
   // create the distribution type
  //distribution * dist = dynamic_cast<distribution *>(_factory.create(type, name, params));
   if (_dist_by_name.find(name) == _dist_by_name.end())
     _dist_nd_by_name[name] = dist;
   else
     throwError("Distribution with name " << name << " already exists");

   _dist_by_trigger_status[name] = false;
   _at_least_a_dist_triggered = false;

   //_dist_by_type[type].push_back(dist);

}

std::string
DistributionContainer::getType(char *  DistAlias){
  return getType(std::string(DistAlias));
}

std::string
DistributionContainer::getType(std::string DistAlias){

    if(_dist_by_name.find(DistAlias) != _dist_by_name.end())
    {
       BasicDistribution * dist = _dist_by_name.find(DistAlias)->second;
       std::string type = getDistributionType(*dist);
       if(type == "DistributionError")
       {
         throwError("getType: Type for distribution " << DistAlias << " not found");
       }
       return type;
    }
    else if (_dist_nd_by_name.find(DistAlias) != _dist_nd_by_name.end())
    {
      BasicDistributionND * dist = _dist_nd_by_name.find(DistAlias)->second;
      std::string type = getDistributionType(*dist);
      if(type == "DistributionError")
      {
        throwError("getType :Type for distribution " << DistAlias << " not found");
      }
      return type;
    }
    else{
       throwError("getType: Distribution " << DistAlias << " not found in distribution container");
       return "DistributionError";
    }
}

void
DistributionContainer::seedRandom(unsigned int seed){
  std::cout << "seedRandom " << seed << std::endl;
  //srand( seed );
  //_random.seed(seed);
  //MooseRandom::seed(seed);
  _random->seed(seed);
  
}
double
DistributionContainer::random(){
  //return (static_cast<double>(rand())/static_cast<double>(RAND_MAX));
  //return _random.rand();
  //return MooseRandom::rand();
  return _random->random();
}

bool
DistributionContainer::checkCdf(std::string DistAlias, double value){
  bool result;
  if (Cdf(std::string(DistAlias),value) >= getVariable("ProbabilityThreshold",DistAlias)){
    result=true;
    _dist_by_trigger_status[DistAlias] = true;
    _last_dist_triggered = DistAlias;
    _at_least_a_dist_triggered = true;<commit_msg>Removing print statement.<commit_after>/*
 * DistributionContainer.C
 *
 *  Created on: Jul 6, 2012
 *      Author: alfoa
 */
#include "DistributionContainer.h"
//#include "Factory.h"
//#include "distribution_1D.h"
#include "distribution_min.h"
#include "distribution_base_ND.h"
#include <iostream>
#include <math.h>
#include <cmath>
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <map>
//#include <MooseRandom.h>
#include <boost/random/mersenne_twister.hpp>

using namespace std;

#define throwError(msg) { std::cerr << "\n\n" << msg << "\n\n"; throw std::runtime_error("Error"); }

class DistributionContainer;

class RandomClass {
  boost::random::mt19937 rng; 
  const double range;
public:
  RandomClass() : range(rng.max() - rng.min()) {};
  void seed(unsigned int seed) {
    rng.seed(seed);
  }
  double random() {
    return (rng()-rng.min())/range;
  }
};

DistributionContainer::DistributionContainer()
{
  _random = new RandomClass();
  _at_least_a_dist_triggered = false;
  _last_dist_triggered = "";
}
DistributionContainer::~DistributionContainer()
{
  delete _random;
}


void
DistributionContainer::addDistributionInContainer(const std::string & type, const std::string & name, BasicDistribution * dist){
   // create the distribution type
  //distribution * dist = dynamic_cast<distribution *>(_factory.create(type, name, params));
   if (_dist_by_name.find(name) == _dist_by_name.end())
    _dist_by_name[name] = dist;
   else
     throwError("Distribution with name " << name << " already exists");

   _dist_by_trigger_status[name] = false;
   _at_least_a_dist_triggered = false;

   //_dist_by_type[type].push_back(dist);

}

void
DistributionContainer::addDistributionInContainerND(const std::string & type, const std::string & name, BasicDistributionND * dist){
   // create the distribution type
  //distribution * dist = dynamic_cast<distribution *>(_factory.create(type, name, params));
   if (_dist_by_name.find(name) == _dist_by_name.end())
     _dist_nd_by_name[name] = dist;
   else
     throwError("Distribution with name " << name << " already exists");

   _dist_by_trigger_status[name] = false;
   _at_least_a_dist_triggered = false;

   //_dist_by_type[type].push_back(dist);

}

std::string
DistributionContainer::getType(char *  DistAlias){
  return getType(std::string(DistAlias));
}

std::string
DistributionContainer::getType(std::string DistAlias){

    if(_dist_by_name.find(DistAlias) != _dist_by_name.end())
    {
       BasicDistribution * dist = _dist_by_name.find(DistAlias)->second;
       std::string type = getDistributionType(*dist);
       if(type == "DistributionError")
       {
         throwError("getType: Type for distribution " << DistAlias << " not found");
       }
       return type;
    }
    else if (_dist_nd_by_name.find(DistAlias) != _dist_nd_by_name.end())
    {
      BasicDistributionND * dist = _dist_nd_by_name.find(DistAlias)->second;
      std::string type = getDistributionType(*dist);
      if(type == "DistributionError")
      {
        throwError("getType :Type for distribution " << DistAlias << " not found");
      }
      return type;
    }
    else{
       throwError("getType: Distribution " << DistAlias << " not found in distribution container");
       return "DistributionError";
    }
}

void
DistributionContainer::seedRandom(unsigned int seed){
  //std::cout << "seedRandom " << seed << std::endl;
  //srand( seed );
  //_random.seed(seed);
  //MooseRandom::seed(seed);
  _random->seed(seed);
  
}
double
DistributionContainer::random(){
  //return (static_cast<double>(rand())/static_cast<double>(RAND_MAX));
  //return _random.rand();
  //return MooseRandom::rand();
  return _random->random();
}

bool
DistributionContainer::checkCdf(std::string DistAlias, double value){
  bool result;
  if (Cdf(std::string(DistAlias),value) >= getVariable("ProbabilityThreshold",DistAlias)){
    result=true;
    _dist_by_trigger_status[DistAlias] = true;
    _last_dist_triggered = DistAlias;
    _at_least_a_dist_triggered = true;
{'fraction_non_alphanumeric': 0.14315867891730816, 'fraction_numerical': 0.0027315619567916563, 'mean_word_length': 4.472146739130435, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 39, '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': '661575', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2551, 'n_words': 503}