Example #1
0
    def visit(self, node: Node, path=None):
        if path is None:
            path = []
        if isinstance(node, Statement):
            node.scope = self.scopes[-1]
            self.parents.append(node)

        if 'visit_' + class_name(node) in dir(self):
            getattr(self, 'visit_' + class_name(node))(node, path)

        elif isinstance(node, (list, tuple)):
            for i, v in enumerate(node):
                v.path = Path(node, i)
                self.visit(v, path + [v.path])
        else:
            getattr(self, 'enter_' + class_name(node))(node, path)

            for f in node.FIELDS:
                v = getattr(node, f)
                if v:
                    v.path = Path(node, f)
                    self.visit(v, path + [v.path])

            getattr(self, 'leave_' + class_name(node))(node, path)

        if isinstance(node, Statement):
            self.parents.pop()
Example #2
0
    def visit(self, node: Node):
        if node == self.terminal:
            raise Complete()
        if isinstance(node, (list, tuple)):
            for i, v in enumerate(node):
                self.visit(v)
        else:
            getattr(self, 'enter_' + class_name(node))(node)

            for f in node.FIELDS:
                v = getattr(node, f)
                if v:
                    self.visit(v)

            getattr(self, 'leave_' + class_name(node))(node)
Example #3
0
    def __init__(self, classifier, datamanager, category):
        self.now = str(datetime.now())
        self.log_path = os.path.join(datamanager.PATHS["LOGS"], "grid_search",
                                     class_name(classifier), category)
        log_file = os.path.join(self.log_path, self.now + ".log")

        super(GridSearch, self).__init__(classifier,
                                         datamanager,
                                         log_file=log_file)
        self.category = category
        self.grid_search_obj = None
Example #4
0
    def __init__(self, classifier, datamanager, category):
        self.now = str(datetime.now())
        self.log_path = os.path.join(datamanager.PATHS["LOGS"],
                    "grid_search",
                    class_name(classifier),
                    category)
        log_file = os.path.join(self.log_path, self.now + ".log")

        super(GridSearch, self).__init__(classifier, datamanager, log_file = log_file)
        self.category = category
        self.grid_search_obj = None
Example #5
0
    def visit(self, node: Node):
        if isinstance(node, Statement):
            self.parents.append(node)

        if 'visit_' + class_name(node) in dir(self):
            getattr(self, 'visit_' + class_name(node))(node)

        elif isinstance(node, (list, tuple)):
            for i, v in enumerate(node):
                self.visit(v)
        else:
            getattr(self, 'enter_' + class_name(node))(node)

            for f in node.FIELDS:
                v = getattr(node, f)
                if v:
                    self.visit(v)

            getattr(self, 'leave_' + class_name(node))(node)

        if isinstance(node, Statement):
            self.parents.pop()
Example #6
0
def evaluate(category, clf, datamanager, data=(None, None)):
    """Run evaluation of a classifier, for one category.

    If data isn't set explicitly, the test set is
    used by default.
    """
    log_file = os.path.join(datamanager.PATHS["LOGS"], "evaluation", class_name(clf), category)
    log_file = os.path.join(log_file, str(datetime.now()) + ".log")

    vcd = VisualConceptDetection(None, datamanager, log_file=log_file)
    clf = vcd.load_object("Classifier", category, clf)
    vcd.classifier = clf
    if (data[0] is None) or (data[1] is None):
        return vcd.evaluate_test_set(category)
    else:
        return vcd.evaluate(X_test=data[0], y_test=data[1])
Example #7
0
def evaluate(category, clf, datamanager, data=(None, None)):
    """Run evaluation of a classifier, for one category.

    If data isn't set explicitly, the test set is
    used by default.
    """
    log_file = os.path.join(datamanager.PATHS["LOGS"], "evaluation",
                            class_name(clf), category)
    log_file = os.path.join(log_file, str(datetime.now()) + ".log")

    vcd = VisualConceptDetection(None, datamanager, log_file=log_file)
    clf = vcd.load_object("Classifier", category, clf)
    vcd.classifier = clf
    if (data[0] is None) or (data[1] is None):
        return vcd.evaluate_test_set(category)
    else:
        return vcd.evaluate(X_test=data[0], y_test=data[1])
Example #8
0
    def grid_search(self, params, X=None, y=None, weight_samples=False):
        """Perform a nested grid search.

        Args:
            params: Parameter hash, specifiying the parameter configurations
                for the grid search (see http://scikit-learn.org/stable/modules/grid_search.html).
            X: Matrix of sample data.
            y: Vector of class labels.
            weight_samples: Whether to use grid search with weighted
                samples or not.
        """
        self.logger.info("Grid search for %s at %s" %
            (class_name(self.classifier), datetime.now()))
        self.logger.info("Category: %s" % self.category)
        self.logger.info("Parameters: %s" % params)
        self.logger.info("Initial sample weighting: %s" % weight_samples)
        result = self.search(params, X, y, weight_samples)
        joblib.dump(result, os.path.join(self.log_path, self.now + ".grid"), compress=3)
        return result
Example #9
0
    def grid_search(self, params, X=None, y=None, weight_samples=False):
        """Perform a nested grid search.

        Args:
            params: Parameter hash, specifiying the parameter configurations
                for the grid search (see http://scikit-learn.org/stable/modules/grid_search.html).
            X: Matrix of sample data.
            y: Vector of class labels.
            weight_samples: Whether to use grid search with weighted
                samples or not.
        """
        self.logger.info("Grid search for %s at %s" %
                         (class_name(self.classifier), datetime.now()))
        self.logger.info("Category: %s" % self.category)
        self.logger.info("Parameters: %s" % params)
        self.logger.info("Initial sample weighting: %s" % weight_samples)
        result = self.search(params, X, y, weight_samples)
        joblib.dump(result,
                    os.path.join(self.log_path, self.now + ".grid"),
                    compress=3)
        return result
Example #10
0
 def expr(self, expr: Expr) -> ir.Value:
     return getattr(self, class_name(expr))(expr)
Example #11
0
 def statement(self, statement: Statement):
     getattr(self, class_name(statement))(statement)