?? splitscore.java
字號:
splitAndLabelDist + "-->fatal_error");
// ASSERT(numerator != Globals.UNDEFINED_REAL);
gain = numerator / divisor;
cache.gainRatio = gain;
if (gain < 0)
Error.err("SplitScore::get_gain_ratio: negative gain: " +
gain + "=" + numerator + '/' + divisor + "-->fatal_error");
}
if (gain < 0)
Error.err("SplitScore::get_gain_ratio: negative gain: "+ gain +"-->fatal_error");
return gain;
}
/** Returns cache.splitEntropy, first checking to see if it has yet been set.
* This method updates the cache.
* @return The split entropy value stored in the cache.
*/
public double get_split_entropy() {
valid_cache(); // Percolate validCache to the cache members.
if (cache.splitEntropy == Globals.UNDEFINED_REAL && has_distribution(true))
cache.splitEntropy = Entropy.entropy(get_split_dist(), total_weight());
return cache.splitEntropy;
}
/** Sets the split score criterion.
* @param choice The chosen split score criterion.
* @see #mutualInfo
* @see #normalizedMutualInfo
* @see #rainRatio
* @see #mutualInfoRatio
* @see #externalScore
*/
public void set_split_score_criterion(byte choice)
{splitScoreCriterion = choice; }
/** Clear (delete) distribution array data.
*
*/
public void reset() {
// delete cache.splitDist;
cache.splitDist = null;
// delete cache.labelDist;
cache.labelDist = null;
// delete splitAndLabelDist;
splitAndLabelDist = null;
theExternalScore = Globals.UNDEFINED_REAL;
validCache = false;
valid_cache();
}
/** Stores the cache.splitDist array.
*
* @param sDist The split distribution array to be cached.
*/
public void set_split_dist(double[] sDist) {
valid_cache(); // Percolate validCache to the cache members.
// Only delete one object's distribution if it doesn't share its
// location with the one passed in--otherwise by deleting one, we'd
// be deleting both.
if (cache.splitDist == sDist)
Error.fatalErr("SplitScore::set_split_dist: got my own pointer");
// delete cache.splitDist;
cache.splitDist = sDist;
sDist = null;
// DBGSLOW(OK());
}
//public void set_split_and_label_dist(double[][] sAndLDist)
/** Stores the splitAndLabelDist array.
* @param sAndLDist The new split and label distribution.
* @return The old split and label distribution.
*/
public double[][] set_split_and_label_dist(double[][] sAndLDist) {
valid_cache(); // Percolate validCache to the cache members.
// We can't compare for equality and use our results because
// the caller's reference may be a reference to an automatic variable,
// in which case our delete would screw it up.
// Only delete one object's distribution if it doesn't share its
// location with the one passed in--otherwise by deleting one, we'd
// be deleting both.
if (splitAndLabelDist == sAndLDist)
Error.fatalErr("SplitScore::set_split_and_label_dist: got my own pointer");
reset();
splitAndLabelDist = sAndLDist;
sAndLDist = null;
return sAndLDist;
}
private void copy_dist(SplitScore source) {
if (this != source) {
reset();
copy_split_and_label_dist(source);
validCache = false;
}
}
private void copy_split_and_label_dist(SplitScore source) {
// When the new distribution differs from the old, but the array is
// of the same size, don't delete the old splitAndLabelDist array.
// Reuse it.
valid_cache(); // Percolate validCache to the cache members.
if (splitAndLabelDist != null && source.splitAndLabelDist != null &&
splitAndLabelDist.length == source.splitAndLabelDist.length) {
// Keep the splitAndLabelDist, but nothing else in the cache.
double[][] savedDistribution = splitAndLabelDist;
splitAndLabelDist = null;
reset();
splitAndLabelDist = savedDistribution;
theExternalScore = Globals.UNDEFINED_REAL;
splitAndLabelDist = source.get_split_and_label_dist();
}
else {
reset();
if (source.splitAndLabelDist != null)
splitAndLabelDist = Matrix.copy(source.get_split_and_label_dist());
}
}
/** Set the external score. The score must be non-negative, although we could
* change it to anything but UNDEFINED_REAL.
* @param extScore The external score value.
*/
public void set_external_score(double extScore) {
if (extScore < 0)
Error.fatalErr("SplitScore::set_external_score: score="+extScore
+" is negative");
if (!has_distribution(false))
Error.fatalErr("SplitScore::set_external_score: no distribution");
MLJ.ASSERT(extScore != Globals.UNDEFINED_REAL,
"SplitScore.set_external_score: extScore == Globals.UNDEFINED_REAL.");
theExternalScore = extScore;
}
/** Checks if an external score has been set.
* @return TRUE if the external score is set, FALSE otherwise.
*/
public boolean has_external_score(){return theExternalScore != Globals.UNDEFINED_REAL;}
/** Produces formatted display of contents of object. This method updates the
* cache. Does not abort on unset data.
*/
public void display() {
display(Globals.Mcout,DisplayPref.defaultDisplayPref);
}
/** Produces formatted display of contents of object. This method updates the
* cache. Does not abort on unset data. This method updates the cache.
* @param stream The Writer to be displayed to.
*/
public void display(Writer stream) {
display(stream,DisplayPref.defaultDisplayPref);
}
/** Produces formatted display of contents of object. This method updates the
* cache. Does not abort on unset data. This method updates the cache.
* @param stream The Writer to be displayed to.
* @param dp The display preferences.
*/
public void display(Writer stream, DisplayPref dp) {
String endl = "\n";
String INDENT = " ";
String UNSET = "unset";
double val;
try{
if (dp.preference_type() == DisplayPref.ASCIIDisplay) {
valid_cache();
stream.write("SplitScore:" + endl);
stream.write(INDENT + "split score criterion = "
+ splitScoreCriterionEnum[get_split_score_criterion()] + endl);
if (!has_distribution(false))
stream.write(INDENT + "has no cache data" + endl);
else {
stream.write(INDENT + "total weight = ");
if (Globals.UNDEFINED_REAL == (val = total_weight()))
stream.write(UNSET + endl);
else
stream.write(val + endl);
if (num_splits() > 0)
stream.write(INDENT + "number of splitting values = "
+ num_splits() + endl);
stream.write(INDENT + "entropy = ");
if (Globals.UNDEFINED_REAL == (val = get_entropy()))
stream.write(UNSET + endl);
else
stream.write(val + endl);
stream.write(INDENT + "split entropy = ");
if (Globals.UNDEFINED_REAL == (val = get_split_entropy()))
stream.write(UNSET + endl);
else
stream.write(val + endl);
stream.write(INDENT + "conditional entropy = ");
if (Globals.UNDEFINED_REAL == (val = get_cond_entropy()))
stream.write(UNSET + endl);
else
stream.write(val + endl);
stream.write(INDENT + "mutual information = "
+ get_mutual_info(false) + endl);
stream.write(INDENT + "normalized mutual information = "
+ get_mutual_info(true) + endl);
stream.write(INDENT + "gain ratio = ");
if (Globals.UNDEFINED_REAL == (val = get_gain_ratio()))
stream.write(UNSET + endl);
else
stream.write(val + endl);
if (has_external_score())
stream.write(INDENT + "external score = " + get_external_score()
+ endl);
// Choose not to stream the arrays at low log levels.
// Note that we use stream, not get_log_stream() here
// because they should go to the same stream.
int LEVEL = 4;
if (has_distribution(false)) {
if (get_log_level() >= LEVEL) stream.write(INDENT + "splitAndLabelDist = "
+ get_split_and_label_dist() + endl);
if (get_log_level() >= LEVEL) stream.write(INDENT + "labelDist = "
+ get_label_dist() + endl);
if (get_log_level() >= LEVEL) stream.write(INDENT + "splitDist = "
+ get_split_dist() + endl);
}
}
}
}catch(IOException e){e.printStackTrace(); System.exit(1);}
}
/** Assigns the given SplitScore data to this SplitScore.
* @param rhs The SplitScore to be copied.
* @return This SplitScore after assignment.
*/
public SplitScore assign(SplitScore rhs) {
if (this != rhs) {
copy_dist(rhs);
splitScoreCriterion = rhs.splitScoreCriterion;
theExternalScore = rhs.theExternalScore;
}
return (this);
}
/** Returns the split and label distribution array and releases ownership.
*
* @return The split and label distribution.
*/
public double[][] release_split_and_label_dist() {
double[][] distribution = splitAndLabelDist;
if (distribution == null)
Error.fatalErr("SplitScore::release_split_and_label_dist: there is no "
+"distribution to release");
splitAndLabelDist = null;
reset();
return distribution;
}
/** Returns the label distribution array and releases ownership.
* @return The label distribution.
*/
public double[] release_label_dist() {
get_label_dist();
double[] distribution = cache.labelDist;
if (distribution == null)
Error.fatalErr("SplitScore::release_label_dist: there is no "
+"label distribution to release");
cache.labelDist = null;
return distribution;
}
/** Returns the split distribution array and releases ownership.
* @return The split distribution.
*/
public double[] release_split_dist() {
get_split_dist();
double[] distribution = cache.splitDist;
if (distribution == null)
Error.fatalErr("SplitScore::release_split_dist: there is no "
+"split distribution to release");
cache.splitDist = null;
return distribution;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -