Search in sources :

Example 11 with Node

use of com.alibaba.alink.operator.common.tree.Node in project Alink by alibaba.

the class TreeObj method initialRoot.

public final void initialRoot() {
    for (int i = 0; i < numTrees; ++i) {
        Node root = TreeObj.ofNode();
        addNodeInfoPair(ofNodeInfoPair(root, -1, null).initialRoot(i * numLocalBaggingRow, (i + 1) * numLocalBaggingRow));
        roots.add(root);
    }
}
Also used : Node(com.alibaba.alink.operator.common.tree.Node)

Example 12 with Node

use of com.alibaba.alink.operator.common.tree.Node in project Alink by alibaba.

the class SplitInstances method split.

public static NodeInfoPair split(NodeInfoPair.NodeInfo nodeInfo, EpsilonApproQuantile.WQSummary summary, int[] indices, Data data) {
    int mid = data.splitInstances(nodeInfo.node, summary, indices, nodeInfo.slice);
    int oobMid = data.splitInstances(nodeInfo.node, summary, indices, nodeInfo.oob);
    nodeInfo.node.setNextNodes(new Node[] { new Node(), new Node() });
    return new NodeInfoPair(// left
    new NodeInfoPair.NodeInfo(nodeInfo.node.getNextNodes()[0], new Slice(nodeInfo.slice.start, mid), new Slice(nodeInfo.oob.start, oobMid), nodeInfo.depth + 1, nodeInfo.baggingFeatures), // right
    new NodeInfoPair.NodeInfo(nodeInfo.node.getNextNodes()[1], new Slice(mid, nodeInfo.slice.end), new Slice(oobMid, nodeInfo.oob.end), nodeInfo.depth + 1, null));
}
Also used : Slice(com.alibaba.alink.operator.common.tree.parallelcart.data.Slice) Node(com.alibaba.alink.operator.common.tree.Node)

Example 13 with Node

use of com.alibaba.alink.operator.common.tree.Node in project Alink by alibaba.

the class IForestsModelMapper method predictResultDetail.

@Override
protected Tuple2<Object, String> predictResultDetail(SlicedSelectedSample selection) throws Exception {
    Node[] root = treeModel.roots;
    Row inputBuffer = inputBufferThreadLocal.get();
    selection.fillRow(inputBuffer);
    transform(inputBuffer);
    int len = root.length;
    Object result = null;
    if (len > 0) {
        double hSum = 0.0;
        for (Node node : root) {
            hSum += predict(inputBuffer, node, 1);
        }
        result = s(hSum / len, totalC);
    }
    return new Tuple2<>(result, null);
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Node(com.alibaba.alink.operator.common.tree.Node) Row(org.apache.flink.types.Row)

Example 14 with Node

use of com.alibaba.alink.operator.common.tree.Node in project Alink by alibaba.

the class NodeJPanel method multiNodeDistribution.

public static double multiNodeDistribution(TreeModelViz.Node4CalcPos node4CalcPos) {
    double multi = 1.0;
    Node node = node4CalcPos.node;
    if (node.getCounter().getDistributions() == null || node.getCounter().getDistributions().length < 1) {
        return 0.0;
    }
    if (node.isLeaf()) {
        for (int j = 0; j < node.getCounter().getDistributions().length; ++j) {
            multi *= node.getCounter().getDistributions()[j];
        }
    } else {
        if (node.getCounter().getWeightSum() == 0.0) {
            return 0.0;
        }
        for (int j = 0; j < node.getCounter().getDistributions().length; ++j) {
            multi *= node.getCounter().getDistributions()[j] / node.getCounter().getWeightSum();
        }
    }
    return multi;
}
Also used : Node(com.alibaba.alink.operator.common.tree.Node)

Aggregations

Node (com.alibaba.alink.operator.common.tree.Node)14 Slice (com.alibaba.alink.operator.common.tree.parallelcart.data.Slice)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 Row (org.apache.flink.types.Row)2 DefaultDistributedInfo (com.alibaba.alink.common.io.directreader.DefaultDistributedInfo)1 DistributedInfo (com.alibaba.alink.common.io.directreader.DistributedInfo)1 LabelCounter (com.alibaba.alink.operator.common.tree.LabelCounter)1