def _assemble_cond(self, node_id):
        feature_idx = self._tree.feature[node_id]
        threshold = self._tree.threshold[node_id]

        # sklearn's trees internally work with float32 numbers, so in order
        # to have consistent results across all supported languages, we convert
        # all thresholds into float32.
        threshold = threshold.astype(np.float32)

        return utils.lte(ast.FeatureRef(feature_idx), ast.NumVal(threshold))
Example #2
0
 def _assemble_cond(self, node_id):
     feature_idx = self._tree.feature[node_id]
     threshold_num_val = ast.NumVal(self._tree.threshold[node_id])
     return utils.lte(ast.FeatureRef(feature_idx), threshold_num_val)
Example #3
0
def atan(expr):
    expr = ast.IdExpr(expr, to_reuse=True)
    expr_abs = ast.AbsExpr(expr, to_reuse=True)

    expr_reduced = ast.IdExpr(ast.IfExpr(
        utils.gt(expr_abs, ast.NumVal(2.4142135623730950488)),
        utils.div(ast.NumVal(1.0), expr_abs),
        ast.IfExpr(
            utils.gt(expr_abs, ast.NumVal(0.66)),
            utils.div(utils.sub(expr_abs, ast.NumVal(1.0)),
                      utils.add(expr_abs, ast.NumVal(1.0))), expr_abs)),
                              to_reuse=True)

    P0 = ast.NumVal(-8.750608600031904122785e-01)
    P1 = ast.NumVal(1.615753718733365076637e+01)
    P2 = ast.NumVal(7.500855792314704667340e+01)
    P3 = ast.NumVal(1.228866684490136173410e+02)
    P4 = ast.NumVal(6.485021904942025371773e+01)
    Q0 = ast.NumVal(2.485846490142306297962e+01)
    Q1 = ast.NumVal(1.650270098316988542046e+02)
    Q2 = ast.NumVal(4.328810604912902668951e+02)
    Q3 = ast.NumVal(4.853903996359136964868e+02)
    Q4 = ast.NumVal(1.945506571482613964425e+02)
    expr2 = utils.mul(expr_reduced, expr_reduced, to_reuse=True)
    z = utils.mul(
        expr2,
        utils.div(
            utils.sub(
                utils.mul(
                    expr2,
                    utils.sub(
                        utils.mul(
                            expr2,
                            utils.sub(
                                utils.mul(expr2,
                                          utils.sub(utils.mul(expr2, P0), P1)),
                                P2)), P3)), P4),
            utils.add(
                Q4,
                utils.mul(
                    expr2,
                    utils.add(
                        Q3,
                        utils.mul(
                            expr2,
                            utils.add(
                                Q2,
                                utils.mul(
                                    expr2,
                                    utils.add(
                                        Q1,
                                        utils.mul(expr2,
                                                  utils.add(Q0,
                                                            expr2)))))))))))
    z = utils.add(utils.mul(expr_reduced, z), expr_reduced)

    ret = utils.mul(
        z,
        ast.IfExpr(utils.gt(expr_abs, ast.NumVal(2.4142135623730950488)),
                   ast.NumVal(-1.0), ast.NumVal(1.0)))
    ret = utils.add(
        ret,
        ast.IfExpr(
            utils.lte(expr_abs, ast.NumVal(0.66)), ast.NumVal(0.0),
            ast.IfExpr(utils.gt(expr_abs, ast.NumVal(2.4142135623730950488)),
                       ast.NumVal(1.570796326794896680463661649),
                       ast.NumVal(0.7853981633974483402318308245))))
    ret = utils.mul(
        ret,
        ast.IfExpr(utils.lt(expr, ast.NumVal(0.0)), ast.NumVal(-1.0),
                   ast.NumVal(1.0)))

    return ret