nodeloss.java

来自「此编码是一个数据挖掘的决策树各种算法。以作为入门提示」· Java 代码 · 共 50 行

JAVA
50
字号
package id3;
import java.lang.*;
import java.io.*;

/** Class used for node accuracies. Stores the total weight of instances this node
 * is responsible for, and also the total losses incurred by this node.
 *
 */
public class NodeLoss {
    //added by JL
    
    /** The total weight of instances in this node.
     */
    public double totalWeight;
    /** Total losses incurred by this node.
     */
    public double totalLoss;
    /** The totalLoss value squared.
     */
    public double totalLossSquared;
    
    private double UNDEFINED_REAL = -1.7976931348623157E+308;
    
    /** Constructor. All values are set to the undefined value.
     */
    NodeLoss(){
        totalWeight = UNDEFINED_REAL;
        totalLoss = UNDEFINED_REAL;
        totalLossSquared = UNDEFINED_REAL;
    }
    
    /** Display this NodeLoss object to a BufferedWriter.
     * @param ostream The BufferedWriter to which this NodeLoss is displayed.
     */
    public void display(BufferedWriter ostream) {
        String output = new String(totalLoss + "/" + totalWeight + " (squared=" + totalLossSquared + ")");
        try{ostream.write(output,0,output.length());}
        catch(Exception e){}
    }
    
    /** Updates the total weight and total loss information.
     * @param weight The new total weight.
     * @param loss The new loss value.
     */
    public void update(double weight, double loss){
        totalWeight = totalWeight + weight;
        totalLoss = totalLoss + (weight * loss);
        totalLossSquared = totalLossSquared + (weight * loss * loss);
    }
}//End of NodeLoss class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?