def __init__(self, source, examples, max_iter=10000, min_improv=1e-10, verbose=0, knowledge=None, leakprob=None, propagate_evidence=True, normalize=False, **extra): """ :param source: filename of file containing input model :type source: str :param examples: list of observed terms / value :type examples: list[tuple(Term, bool)] :param max_iter: maximum number of iterations to run :type max_iter: int :param min_improv: minimum improvement in log-likelihood for convergence detection :type min_improv: float :param verbose: verbosity level :type verbose: int :param knowledge: class to use for knowledge compilation :type knowledge: class :param leakprob: Add all true evidence atoms with the given probability to avoid 'inconsistent evidence' errors. This also allows to learn a program without constants and retrieve the constants from the evidence file. (default: None) :type leakprob: float or None :param extra: catch all for additional parameters (not used) """ SemiringProbability.__init__(self) LogicProgram.__init__(self) self.source = source # The names of the atom for which we want to learn weights. self.names = [] # The weights to learn. # The initial weights are of type 'float'. # When necessary they are replaced by a dictionary [t(arg1, arg2, ...) -> float] # for weights of form t(SV, arg1, arg2, ...). self._weights = [] self.examples = examples self.leakprob = leakprob self.leakprobatoms = None self.propagate_evidence = propagate_evidence self._compiled_examples = None self.max_iter = max_iter self.min_improv = min_improv self.verbose = verbose self.iteration = 0 if knowledge is None: knowledge = get_evaluatable() self.knowledge = knowledge self.output_mode = False self.extra = extra self._enable_normalize = normalize self._adatoms = []
def __init__(self, weights): SemiringProbability.__init__(self) self._weights = weights