Skip to content

Yes, ranges can be reported too. If you like to continue analyzing the remaining input space despite finding a violation, you can return vote.PASS instead of vote.FAIL, see example below. #3

Description

@XAI360
    Yes, ranges can be reported too. If you like to continue analyzing the remaining input space despite finding a violation, you can return vote.PASS instead of vote.FAIL, see example below.
import vote

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_digits

digits = load_digits()
rf = RandomForestClassifier(n_estimators=10)
rf.fit(digits.data, digits.target)

e = vote.Ensemble.from_sklearn(rf)
error_margin = 1

for xvec, label in zip(digits.data, digits.target):
    
    def check_robustness(m):
        o = vote.mapping_check_argmax(m, label)
        
        if o == vote.FAIL:
            conds = ['x%d ∈ %s' % (dim, [m.inputs[dim].lower, m.inputs[dim].upper])
                                   for dim in range(m.nb_inputs)]
            print(', '.join(conds))
            print('-' * 80)
            return vote.PASS
        
        return o
    
    input_region = [(max(x - error_margin, 0), min(255, x + error_margin))
                    for x in xvec]
    e.absref(check_robustness, input_region)

Originally posted by @john-tornblom in #2 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions