📄 entropyscaler.cpp
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn/Knut Magne Risvik
// Date..........:
// Description...:
// Revisions.....:
//===================================================================
#include <stdafx.h> // Precompiled headers.
#include <copyright.h>
#include <kernel/algorithms/entropyscaler.h>
#include <kernel/structures/decisiontable.h>
#include <kernel/basic/set.h>
#include <kernel/basic/algorithm.h>
#include <kernel/basic/message.h>
#include <kernel/utilities/mathkit.h>
#include <kernel/system/math.h>
//-------------------------------------------------------------------
// Static methods (file scope).
//===================================================================
//-------------------------------------------------------------------
// Method........: StaticLog2
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Computes the the base-2 logarithm.
// Comments......: Invokes an extra function call, but..
// Revisions.....:
//===================================================================
static float
StaticLog2(float x) {
// Define a nice constant.
const double log2 = 0.301029995664;
return (log(x) / log2);
}
//-------------------------------------------------------------------
// Method........: StaticComputeProportion
// Author........: Aleksander 豩rn/Knut Magne Risvik
// Date..........:
// Description...: Computes the proportions of objects within the
// range [begin, end) that belong to the given decision
// classes.
//
// Comments......: Made static so as to not obfuscate the header file
// and make it less readable. Consider making it a
// member method if any classes are to be derived from
// EntropyScaler.
// Revisions.....:
//===================================================================
static bool
StaticComputeProportions(const Vector(OrthogonalScaler::OVPair) &objects, // Input: The objects (indices) and their attribute values (sorted by the latter).
int begin, // Input: Start index (included).
int end, // Input: End index (excluded).
const DecisionTable &table, // Input: The table the objects belong to.
int decision_attribute, // Input: Index of decision attribute.
bool masked, // Input: Operate on a masked table?
const Vector(int) &decision_classes, // Input: The distinct decision classes.
Vector(float) &proportions) { // Output: The proportions (estimated probabilities).
// Verify input.
if (begin >= end)
return false;
// How many decision classes are there?
int no_decision_classes = decision_classes.size();
Vector(int) counts;
// Initialize count vector.
counts.reserve(no_decision_classes);
int i, j;
for (i = 0; i < no_decision_classes; i++)
counts.push_back(0);
int no_total = 0;
// Iterate over given range, and count.
for (i = begin; i < end; i++) {
// Find out which decision class the current object belongs to.
int object_no = objects[i].first;
int decision_class = table.GetEntry(object_no, decision_attribute, masked);
// A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -