def setFileChoice(filechoice): log('setFileChoice triggered') if isNone(filechoice): return [] setFile(filechoice) # clearOptions() return []
def load(filename): if isNone(filename): return None from os.path import join, exists file = join(dir_datafiles, filename) if not exists(file): return None return pkl.load(open(file, 'rb'))
def precalculate(n): if isNone(n): return nu exists, data = existsData() if not exists: return [] data.precalculate() data.save() return []
def updateMatrixProfile(*args): outcol = args[-2] blockindex = args[-1] if isNone(outcol): return [go.Figure(), [], []] exists, data = existsData() kwargs = {} if not isNone(outcol): kwargs['outcol'] = outcol if not isNone(blockindex): kwargs['blockindex'] = blockindex exists, data = existsData() fo = f'{data.originalfilename}' if exists else [] if exists: return [ data.matrixProfileFigure(**kwargs), data.contrastiveExplainOutlierBlock(**kwargs), fo ]
def explain(self, html=False): if isNone(self.literal[0]): return 'There was no explanation found by contrastive foil trees.' literals = [ self.operatorcorrected[s] for s in np.argsort([l.feature for l in self.literal]) ] literals = [self.explainLiteral(literal) for literal in literals] literals = " and ".join(literals) if not html else "<br />and ".join( literals) msg = '' if self.completeInput: msg = f'Predicted "{self.fact}" instead of "{self.foil}", because{"<br />" if html else ": "}{literals}' msg.format() else: msg = f'Decission was taken, because{"<br />" if html else ": "}{literals}' return msg
def __init__(self, literal, features, fact=None, foil=None, weight=None, complete=False): assert type(literal) == Literal or isNone(literal) or ( all([type(lit) == Literal for lit in literal]) and type(literal) == list), 'Only Literals are allowed. Either one Literal or a list' literal = literal if type(literal) == list else [literal] assert type(features) == list and all( [type(feat) == str for feat in features]), 'Please provide a list of features' self.literal = literal self.__features = features self.fact = fact self.foil = foil self.weight = weight self.completeInput = complete
def updateSlider(val): if isNone(val): return nu return []
def renderMPSettings(outcolumn): if isNone(outcolumn): return [0, 0, {}, []] exists, data = existsData() mv = data.getOutlierBlockLengths(outcolumn) if exists else 0 return [0, mv, {i: str(i) for i in range(mv)}, []]