Пример #1
0
 double probability(unsigned int r) const
 {
   if(r == classes()-1)
     return 1.0/fac<double>(classes());
   else
     return static_cast<double>(r+1)/fac<double>(r+2);
 }
Пример #2
0
 double probability(unsigned int r) const
 {
   if(r == classes()-1)
     return 1-fac<double>(d)/std::pow(d, static_cast<double>(d+classes()-2))* 
       stirling2<double>(d+classes()-2, d);
   else
     return fac<double>(d)/std::pow(d, static_cast<double>(d+r)) * 
       stirling2<double>(d+r-1, d-1);
 }
Пример #3
0
 double probability(unsigned int r) const
 {
   ++r;       // transform to 1 <= r <= 5
   double result = range;
   for(unsigned int i = 1; i < r; ++i)
     result *= range-i;
   return result / std::pow(range, static_cast<double>(classes())) *
     stirling2<double>(classes(), r);
 }
Пример #4
0
// Generates random instances.
// num: number of instances to be generated.
// dataSize: number of features to be generated.
// eSize: number of expected outputs.
// strLen: length of random strings generated.
// instances: input/output vector of instances
void genRandInsts( const int& num, const int& dataSize, const int& eSize,
const int& strLen, std::vector<Instance>& instances ){
	std::shared_ptr<std::vector<std::string> > features(new std::vector<std::string>());
	std::shared_ptr<std::vector<std::string> > classes(new std::vector<std::string>());
	// Generate sudo names for features and classes
	for( int i = 0; i < dataSize; ++i){
		features->push_back(randS(strLen));
	}
	for( int i = 0; i < eSize; ++i){
		classes->push_back(randS(strLen));
	}
	// Generate instances
	for( int i = 0; i < num; ++i ){
		// Generate sudo data for each instance
		std::vector<double>* data = new std::vector<double>();
		std::vector<double>* expected = new std::vector<double>();
		for( int j = 0; j < dataSize; ++j ){
			data->push_back(randD());
		}
		for( int j = 0; j < dataSize; ++j ){
			expected->push_back(randD());
		}
		instances.push_back( Instance( randS(strLen), data, expected, features, classes ));
	}
}
Пример #5
0
  std::string get_single_class(SEXP x) {
    SEXP klass = Rf_getAttrib(x, R_ClassSymbol);
    if (!Rf_isNull(klass)) {
      CharacterVector classes(klass);
      return collapse_utf8(classes);
    }

    if (Rf_isMatrix(x)) {
      return "matrix";
    }

    switch (TYPEOF(x)) {
    case INTSXP:
      return "integer";
    case REALSXP :
      return "numeric";
    case LGLSXP:
      return "logical";
    case STRSXP:
      return "character";

    case VECSXP:
      return "list";
    default:
      break;
    }

    // just call R to deal with other cases
    // we could call R_data_class directly but we might get a "this is not part of the api"
    klass = Rf_eval(Rf_lang2(Rf_install("class"), x), R_GlobalEnv);
    return CHAR(STRING_ELT(klass,0));
  }
Пример #6
0
 void run(NumberGenerator f, Counter & count, int n) const
 {
   assert(f.min() == 0 &&
          static_cast<unsigned int>(f.max()) == classes()-1);
   for(int i = 0; i < n; ++i)
     count(f());
 }
    void testCalculateSplitPoints()
    {
      // validation points below were verified in weka
      int c[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 };
      vector<int> classes(c, c + 20);
      vector<double> values;
      for (unsigned int i = 0; i < classes.size(); i++)
      {
        values.push_back(i);
      }
      

      FayyadMdlDiscretizer uut;
      // call this just to set up internal data structures
      FayyadMdlDiscretizer::SplitPoints points = uut.calculateSplitPoints(classes, values);
      CPPUNIT_ASSERT_EQUAL(1, (int)points.size());
      CPPUNIT_ASSERT_EQUAL(7, points[0]);

      int c2[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
      std::vector<int> classes2(c2, c2 + 1000);
      vector<double> values2;
      for (unsigned int i = 0; i < classes2.size(); i++)
      {
        values2.push_back(i);
      }
      points = uut.calculateSplitPoints(classes2, values2);
      CPPUNIT_ASSERT_EQUAL(3, (int)points.size());
      CPPUNIT_ASSERT_EQUAL(85, points[0]);
      CPPUNIT_ASSERT_EQUAL(729, points[1]);
      CPPUNIT_ASSERT_EQUAL(848, points[2]);
    }
    void testFindBestSplitPoint()
    {
      int c[] = { 1, 1, 0, 0, 1 };
      std::vector<int> classes(c, c + 5);
      vector<double> values;
      for (unsigned int i = 0; i < classes.size(); i++)
      {
        values.push_back(i);
      }

      FayyadMdlDiscretizer uut;
      // call this just to set up internal data structures
      uut.calculateSplitPoints(classes, values);

      double gain;
      ASSERT_DBL_EQL(1, uut._findBestSplitPoint(0, 5, gain));
      ASSERT_DBL_EQL(0.970950594 - (2.0 * 0.0 + 3.0 * 0.918295834) / 5.0, gain);
      
      ASSERT_DBL_EQL(0, uut._findBestSplitPoint(0, 2, gain));
      ASSERT_DBL_EQL(0.0, gain);
      
      ASSERT_DBL_EQL(1, uut._findBestSplitPoint(1, 2, gain));
      ASSERT_DBL_EQL(1.0, gain);
      
      ASSERT_DBL_EQL(3, uut._findBestSplitPoint(2, 3, gain));
      ASSERT_DBL_EQL(0.918295834, gain);
    }
Пример #9
0
 double probability(unsigned int r) const
 {
   double p = beta-alpha;
   if(r == classes()-1)
     return std::pow(1-p, static_cast<double>(r));
   else
     return p * std::pow(1-p, static_cast<double>(r));
 }
Пример #10
0
 double probability(unsigned int r) const
 {
   assert(classes() == 4);
   assert(m == (1<<25));
   assert(n == 512);
   static const double prob[] = { 0.368801577, 0.369035243, 0.183471182,
                                  0.078691997 };
   return prob[r];
 }
Пример #11
0
void File::readClasses() {
    hsize_t dims;
    m_iOrder = readiOrder();
    H5::Group group(openGroup( "dark" ));
    H5::DataSet classes(group.openDataSet("classes"));
    assert( classes.getSpace().getSimpleExtentNdims() == 1 );
    classes.getSpace().getSimpleExtentDims (&dims);
    m_classes.insert(m_classes.end(),dims,classEntry());
    classes.read( &(m_classes[0]), m_classType );
    }
Пример #12
0
 void run(NumberGenerator f, Counter & count, int n) const
 {
   unsigned int range = f.max()+1;
   assert(f.min() == 0 && range*range == classes());
   for(int i = 0; i < n; ++i) {
     int y1 = f();
     int y2 = f();
     count(y1 + range * y2);
   }
 }
Пример #13
0
Interaction::CommandResult* CCreateClass::create(Visualization::Item* /*source*/, Visualization::Item* target,
	const QString& name, const QStringList& attributes)
{
	auto pr = dynamic_cast<OOModel::Project*> (target->node());

	OOModel::Class* cl = nullptr;
	bool newModel = false;
	if (pr)
	{
		cl = new OOModel::Class();
		if (!name.isEmpty()) cl->setName(name);

		// Set visibility
		if (attributes.first() == "private" ) cl->setVisibility(OOModel::Visibility::PRIVATE);
		else if (attributes.first()  == "protected" ) cl->setVisibility(OOModel::Visibility::PROTECTED);
		else if (attributes.first()  == "public" ) cl->setVisibility(OOModel::Visibility::PUBLIC);
		else cl->setVisibility(OOModel::Visibility::DEFAULT);

		pr->beginModification("create class");
		pr->classes()->append(cl);
		pr->endModification();
	}
	else
	{
		newModel = true;
		auto model = new Model::Model();
		cl = dynamic_cast<OOModel::Class*> (model->createRoot("Class"));

		cl->beginModification("set project name");

		if (!name.isEmpty()) cl->setName(name);

		// Set visibility
		if (attributes.first() == "private" ) cl->setVisibility(OOModel::Visibility::PRIVATE);
		else if (attributes.first()  == "protected" ) cl->setVisibility(OOModel::Visibility::PROTECTED);
		else if (attributes.first()  == "public" ) cl->setVisibility(OOModel::Visibility::PUBLIC);
		else cl->setVisibility(OOModel::Visibility::DEFAULT);

		cl->endModification();

		target->scene()->addTopLevelItem( new Visualization::RootItem(cl) );
		target->scene()->listenToModel(model);
	}

	target->setUpdateNeeded(Visualization::Item::StandardUpdate);
		if (newModel) target->scene()->addPostEventAction(new Interaction::SetCursorEvent(target->scene(), cl,
				Interaction::SetCursorEvent::CursorDefault, true));
		else target->scene()->addPostEventAction(new Interaction::SetCursorEvent(target, cl,
				Interaction::SetCursorEvent::CursorDefault, true));

	return new Interaction::CommandResult();
}
Пример #14
0
 void run(UniformRandomNumberGenerator f, Counter & count, int n) const
 {
   typedef typename UniformRandomNumberGenerator::result_type result_type;
   assert(std::numeric_limits<result_type>::is_integer);
   assert(f.min() == 0);
   assert(f.max() == static_cast<result_type>(range-1));
   std::vector<result_type> v(classes());
   for(int i = 0; i < n; ++i) {
     for(unsigned int j = 0; j < classes(); ++j)
       v[j] = f();
     std::sort(v.begin(), v.end());
     result_type prev = v[0];
     int r = 1;     // count different values in v
     for(unsigned int i = 1; i < classes(); ++i) {
       if(prev != v[i]) {
         prev = v[i];
         ++r;
       }
     }
     count(r-1);
   }
 }
Пример #15
0
void PrintToFiles()
{
	::EnumWindows(enumWindowsProc, NULL);

	std::string wnd;
	std::string wndname;

	std::ofstream names("window-names.txt");
	for (auto &p : g_windows)
	{
		Nena::Converter::ToString(wnd, (UINT32) p.first);
		wndname = p.second;

		names << wnd.c_str() << " " << wndname << "\n";

		OutputDebugStringA("-window: ");
		OutputDebugStringA(wndname.c_str());
		OutputDebugStringA("\n");

	}
	names.close();

	std::ofstream images("window-images.txt");
	for (auto &p : g_images)
	{
		Nena::Converter::ToString(wnd, (UINT32) p.first);
		wndname = p.second;

		images << wnd.c_str() << " " << wndname.c_str() << "\n";

		OutputDebugStringA("-image: ");
		OutputDebugStringA(wndname.c_str());
		OutputDebugStringA("\n");
	}
	images.close();

	std::ofstream classes("window-classes.txt");
	for (auto &p : g_classes)
	{
		Nena::Converter::ToString(wnd, (UINT32) p.first);
		wndname = p.second;

		classes << wnd.c_str() << " " << wndname.c_str() << "\n";

		OutputDebugStringA("-class: ");
		OutputDebugStringA(wndname.c_str());
		OutputDebugStringA("\n");
	}
	classes.close();
}
Пример #16
0
void File::writeClasses() {
    H5::Group group(openGroup( "dark" ));
    H5::DataSet classes(group.openDataSet("classes"));
    assert( classes.getSpace().getSimpleExtentNdims() == 1 );

    hsize_t dataSize = m_classes.size();
    hsize_t Zero = 0;
    H5::DataSpace spaceDisk(1,&dataSize);
    H5::DataSpace spaceMem(1,&dataSize);
    classes.extend(&dataSize);
    spaceDisk.selectHyperslab(H5S_SELECT_SET,&dataSize,&Zero);
    spaceMem.selectHyperslab(H5S_SELECT_SET,&dataSize,&Zero);
    classes.write( &(m_classes[0]), m_classType, spaceMem, spaceDisk );
    //classes.flush(H5F_SCOPE_LOCAL);
    }
Пример #17
0
 void run(NumberGenerator & f, Counter & count, int n) const
 {
   typedef typename NumberGenerator::result_type result_type;
   unsigned int length = 0;
   for(int i = 0; i < n; ) {
     result_type value = f();
     if(value < low || value > high)
       ++length;
     else {
       count((std::min)(length, classes()-1));
       length = 0;
       ++i;
     }
   }
 }
Пример #18
0
void UnterfacePass::run_pass(DexClassesVector& dexen, ConfigFiles& cfg) {
  Scope scope = build_class_scope(dexen);

  InterfaceImplementations interfaces(scope);
  assert(interfaces.print_all());

  auto one_level = exclude(interfaces,
      HAS_SUPER | HAS_CHILDREN | NO_VMETHODS,
      IMPL_MULTIPLE_INTERFACES |
          HAS_SUPER |
          HAS_CHILDREN |
          IS_ABSTRACT |
          NO_MATCH_INTERFACE_METHODS |
          HAS_MULTIPLE_INSTANCE_FIELDS |
          MULTIPLE_ARGS_CTOR |
          HAS_CLINIT |
          NO_VMETHODS |
          HAS_STATIC_FIELDS |
          HAS_DIRECT_METHODS);
  interfaces.analyze_candidates(one_level, "No hierarchy, perfect match");

  // optimize
  std::vector<DexClass*> untfs;
  std::unordered_set<DexClass*> removed;
  //optimize(scope, candidates, untfs, removed);

  // write back
  DexClassesVector outdex;
  DexClasses& orig_classes = dexen[0];
  DexClasses classes(orig_classes.size() + untfs.size() - removed.size());
  int pos = 0;
  for (int i = 0; i < orig_classes.size(); ++i) {
    auto cls = orig_classes.get(i);
    if (removed.find(cls) == removed.end()) {
      classes.insert_at(cls, pos++);
    }
  }
  for (auto untf : untfs) {
    classes.insert_at(untf, pos++);
  }
  outdex.emplace_back(std::move(classes));
  for (size_t i = 1; i < dexen.size(); i++) {
    outdex.emplace_back(std::move(dexen[i]));
  }
  dexen = std::move(outdex);
}
Пример #19
0
 void run(UniformRandomNumberGenerator f, Counter & count, int n) const
 {
   typedef typename UniformRandomNumberGenerator::result_type result_type;
   double range = f.max() - f.min() + 1.0;
   result_type low = static_cast<result_type>(alpha * range);
   result_type high = static_cast<result_type>(beta * range);
   unsigned int length = 0;
   for(int i = 0; i < n; ) {
     result_type value = f() - f.min();
     if(value < low || value > high)
       ++length;
     else {
       count(std::min(length, classes()-1));
       length = 0;
       ++i;
     }
   }
 }
Пример #20
0
Model::Node* Project::navigateTo(Model::Node* source, QString path)
{
	QString symbol = extractFrontSymbol(path);
	Model::Node* found = nullptr;

	// Is the target symbol name the module's name
	if (isAncestorOf(source) && symbol == symbolName()) found = this;

	if (!found) found = projects()->findFirstSymbolDefinition(symbol);
	if (!found) found = libraries()->findFirstSymbolDefinition(symbol);
	if (!found) found = modules()->findFirstSymbolDefinition(symbol);
	if (!found) found = classes()->findFirstSymbolDefinition(symbol);
	if (!found) return ExtendableNode::navigateTo(source, path);

	QString rest = extractSecondaryPath(path);
	if (!rest.isEmpty()) return found->navigateTo(this, rest);
	else return found;
}
Пример #21
0
// Returns in gens a generating set for Zm* /<p>, and in ords the
// order of these generators. Return value is the order of p in Zm*.
long findGenerators(vector<long>& gens, vector<long>& ords, long m, long p)
{
  gens.clear();
  ords.clear();
  // Compute the generators for (Z/mZ)^*
  vector<long> classes(m);
  vector<long> orders(m);

  for (long i=0; i<m; i++) { // initially each element in its own class
    if (GCD(i,m)!=1) classes[i] = 0; // i is not in (Z/mZ)^*
    else             classes[i] = i;
  }

  // Start building a representation of (Z/mZ)^*, first use the generator p
  conjClasses(classes,p % m,m);  // merge classes that have a factor of p

  // The order of p is the size of the equivalence class of 1
#if 0
  long ordP = std::count(classes.begin(), classes.end(), 1);
       // count(from,to,val) returns # of elements in (from,to) with value=val
#else
   long ordP = 0;
   for (long i = 0; i < lsize(classes); i++)
      if (classes[i] == 1) ordP++;
#endif

  // Compute orders in (Z/mZ)^*/<p> while comparing to (Z/mZ)^*
  while (true) {
    compOrder(orders,classes,true,m);
    // if the orders of i in Zm* /<p> and Zm* are not the same, then
    // order[i] contains the order in Zm* /<p> with negative sign

    long idx = argmax(orders, &gtAbsVal); // find the element with largest order
    long largest = orders[idx];

    if (abs(largest) == 1) break;   // Trivial group, we are done

    // store generator with same order as in (Z/mZ)^*
    gens.push_back(idx);
    ords.push_back(largest);
    conjClasses(classes,idx,m); // merge classes that have a factor of idx
  }
  return ordP;
}
Пример #22
0
DexClasses DexLoader::load_dex(const char* location, dex_stats_t* stats) {
  m_file.open(location, boost::iostreams::mapped_file::readonly);
  if (!m_file.is_open()) {
    fprintf(stderr, "error: cannot create memory-mapped file: %s\n", location);
    exit(EXIT_FAILURE);
  }
  auto dh = reinterpret_cast<const dex_header*>(m_file.const_data());
  validate_dex_header(dh, m_file.size());
  if (dh->class_defs_size == 0) {
    return DexClasses(0);
  }
  m_idx = new DexIdx(dh);
  auto off = (uint64_t)dh->class_defs_off;
  auto limit = off + dh->class_defs_size * sizeof(dex_class_def);
  always_assert_log(off < m_file.size(), "class_defs_off out of range");
  always_assert_log(limit <= m_file.size(), "invalid class_defs_size");
  m_class_defs =
      reinterpret_cast<const dex_class_def*>(m_file.const_data() + off);
  DexClasses classes(dh->class_defs_size);
  m_classes = &classes;

  auto lwork = new class_load_work[dh->class_defs_size];
  auto wq =
      workqueue_mapreduce<class_load_work*, std::vector<std::exception_ptr>>(
        class_work, exc_reducer);
  for (uint32_t i = 0; i < dh->class_defs_size; i++) {
    lwork[i].dl = this;
    lwork[i].num = i;
    wq.add_item(&lwork[i]);
  }
  const auto exceptions = wq.run_all();
  delete[] lwork;

  if (!exceptions.empty()) {
    // At least one of the workers raised an exception
    aggregate_exception ae(exceptions);
    throw ae;
  }

  gather_input_stats(stats, dh);

  return classes;
}
Пример #23
0
 void run(UniformRandomNumberGenerator f, Counter & count, int n) const
 {
   typedef typename UniformRandomNumberGenerator::result_type result_type;
   result_type init = (up ? f.min() : f.max());
   result_type previous = init;
   unsigned int length = 0;
   for(int i = 0; i < n; ++i) {
     result_type val = f();
     if(up ? previous <= val : previous >= val) {
       previous = val;
       ++length;
     } else {
       count(std::min(length, classes())-1);
       length = 0;
       previous = init;
       // don't use this value, so that runs are independent
     }
   }
 }
    void testDelta()
    {
      int c[] = { 1, 1, 0, 0, 1 };
      std::vector<int> classes(c, c + 5);
      vector<double> values;
      for (unsigned int i = 0; i < classes.size(); i++)
      {
        values.push_back(i);
      }

      FayyadMdlDiscretizer uut;
      // call this just to set up internal data structures
      uut.calculateSplitPoints(classes, values);

      // calculate it manually
      double k = 2, k1 = 1, k2 = 2;
      double ent = 0.970950594, entLeft = 0.0, entRight = 0.918295834;
      double delta = log(pow(3.0, k) - 2) / log(2.0) -
        (k * ent - k1 * entLeft - k2 * entRight);
      ASSERT_DBL_EQL(delta, uut._calculateDelta(0, 5, 1));
    }
Пример #25
0
void JNICALL OnVMInit(jvmtiEnv *jvmti, JNIEnv *jniEnv, jthread thread) {
    IMPLICITLY_USE(thread);

    TimeUtils::init(); // required to init OS X's clock service

    // Forces the creation of jmethodIDs of the classes that had already
    // been loaded (eg java.lang.Object, java.lang.ClassLoader) and
    // OnClassPrepare() misses.
    jint class_count;
    JvmtiScopedPtr<jclass> classes(jvmti);
    JVMTI_ERROR((jvmti->GetLoadedClasses(&class_count, classes.GetRef())));
    jclass *classList = classes.Get();
    for (int i = 0; i < class_count; ++i) {
        jclass klass = classList[i];
        CreateJMethodIDsForClass(jvmti, klass);
    }

    if (!configuration.host.empty() && !configuration.port.empty()) {
        controller->start();
    }
}
Пример #26
0
void trainMulticlassSvm(CvSVM& classifier, Mat trainingFeatures, vector<int> classLabels, int kFolds)
{
    /* Model parameters */
    CvSVMParams params;
    params.kernel_type = CvSVM::LINEAR;
    params.svm_type = CvSVM::C_SVC;

    /* Leave-one-out or k-folds crossvalidation? */
    if (kFolds <= 0) {
        kFolds = trainingFeatures.rows;
    }

    /* The SVM wants class labels as floats (weird) */
    Mat classes(classLabels.size(), 1, CV_32FC1);
    for (size_t i = 0; i < classLabels.size(); i++) {
        classes.at<float>(i, 0) = classLabels[i];
    }

    /* Now train the shit out of it */
    classifier.train_auto(trainingFeatures, classes, Mat(), Mat(), params, kFolds);
}
    void testEntropy()
    {
      int c[] = { 1, 1, 0, 0, 1 };
      std::vector<int> classes(c, c + 5);
      vector<double> values;
      for (unsigned int i = 0; i < classes.size(); i++)
      {
        values.push_back(i);
      }

      FayyadMdlDiscretizer uut;
      // call this just to set up internal data structures
      uut.calculateSplitPoints(classes, values);

      ASSERT_DBL_EQL(0.970950594, uut._calculateEntropy(0, 5));
      ASSERT_DBL_EQL(0, uut._calculateEntropy(0, 2));
      ASSERT_DBL_EQL(0, uut._calculateEntropy(0, 0));
      ASSERT_DBL_EQL(0, uut._calculateEntropy(0, 1));
      ASSERT_DBL_EQL(1.0, uut._calculateEntropy(0, 4));
      ASSERT_DBL_EQL(1.0, uut._calculateEntropy(1, 4));
      ASSERT_DBL_EQL(0.918295834, uut._calculateEntropy(2, 3));
    }
Пример #28
0
int display_net(list<string>::iterator &ifname,
		bool signd, bool load, list<string> *mats) {
  // create network
  idx<ubyte> classes(1,1);
  load_matrix<ubyte>(classes, conf->get_cstring("classes"));
  answer_module<T,T,T> *answer = create_answer<T,T,T>(*conf, classes.dim(0));
  if (!answer) eblerror("no answer module found");
  uint noutputs = answer->get_nfeatures();
  parameter<T> theparam;
  intg thick;
  module_1_1<T> *net = create_network<T>(theparam, *conf, thick, noutputs);
  cout << "Network parameters: " << theparam << endl;
  vector<string> weights =
      string_to_stringvector(conf->get_string("weights_file"));
  // loading weights
  theparam.load_x(weights);
  // displaying internals
  uint h0 = 0, w0 = 0;
#ifdef __GUI__
  disable_window_updates();
  clear_window();
  if (show_filename) {
    gui << at(h0, w0) << black_on_white() << ifname->c_str();
    h0 += 16;
  }
  if (autorange) // automatic range
    lg.display_internals(*net, h0, w0, zoom, (T) 0, (T) 0, maxwidth);
  else // fixed range
    lg.display_internals(*net, h0, w0, zoom, (T) range[0], (T) range[1],
			 maxwidth);
  // update title
  string title;
  title << "matshow: " << ebl::basename(ifname->c_str());
  set_window_title(title.c_str());
  enable_window_updates();
#endif
  return 1;
}
Пример #29
0
static int skip_white()
{
/**************************************
 *
 *	s k i p _ w h i t e
 *
 **************************************
 *
 * Functional description
 *	Skip over white space and comments in input stream
 *
 **************************************/
	SSHORT c;

	while ((c = nextchar()) != EOF) {

		const SSHORT char_class = classes(c);
		if (char_class & CHR_white)
			continue;
		if (c == '/') {
			SSHORT next = nextchar();
			if (next != '*') {
				retchar(next);
				return c;
			}
			c = nextchar();
			while ((next = nextchar()) &&
				   (next != EOF) && !(c == '*' && next == '/'))
			{
				c = next;
			}
			continue;
		}
		break;
	}

	return c;
}
Пример #30
0
 void run(NumberGenerator & f, Counter & count, int n) const
 {
   typedef typename NumberGenerator::result_type result_type;
   result_type init =
     runs_direction_helper<
       up,
       !std::numeric_limits<result_type>::is_integer
     >::init(result_type());
   result_type previous = init;
   unsigned int length = 0;
   for(int i = 0; i < n; ++i) {
     result_type val = f();
     if(up ? previous <= val : previous >= val) {
       previous = val;
       ++length;
     } else {
       count((std::min)(length, classes())-1);
       length = 0;
       previous = init;
       // don't use this value, so that runs are independent
     }
   }
 }