Beispiel #1
0
    def check_error(self):
        while True:
            self.imp.fresh_randomness(self.n_samples)
            self.s = self.imp.run_all()
            error = get_confidence_interval(self.s.pas, self.s.pbs,
                                            self.confidence, self.eps_err_goal)

            if error * 4 < self.eps_err_goal and self.n_samples / 1.4 >= self.min_n_samples:
                self.n_samples = int(self.n_samples / 1.4)
                logger.debug(
                    "Error too small:%s, decreasing size of network to %s...",
                    error, self.n_samples)
            elif error > self.eps_err_goal and self.n_samples < self.max_n_samples:
                self.n_samples = self.n_samples * 2
                logger.debug(
                    "Error too large:%s, increasing size of network to %s...",
                    error, self.n_samples)
            elif math.isnan(error):
                logger.warning(
                    "Error is nan, resetting size of network to %s...",
                    self.n_samples)
                break
            else:
                break
        logger.info("Tensorflow: eps=%s+-%s", self.s.eps, error)
Beispiel #2
0
    def score_internal(self, a, b, o):
        logger.debug('Scorer: Computing probabilities')
        pa = self.get_prob(a, o)
        pb = self.get_prob(b, o)

        logger.info("Scorer: Comparing probabilities pa and pb:\t%s\t%s", pa,
                    pb)

        eps = self.score_from_probability(pa, pb)
        return eps
Beispiel #3
0
    def score(self, a, b, o):

        logger.debug("Scorer: Started")

        # sanity checks
        if np.isnan(a).any() or np.isnan(b).any() or np.isnan(o).any():
            logger.warning(
                "Scorer: Parameters contain 'nan', will not call PSI. Returning 0.0 instead..."
            )
            ret = 0.0
        else:
            with time_measure('scorer-time'):
                ret = self.score_internal(a, b, o)

        logger.debug("Scorer: Finished (Result:%s)", ret)

        return ret
Beispiel #4
0
 def get_prob(self, a, o):
     psi_script = self.alg.get_psi_script(a, o)
     logger.debug(psi_script)
     res = run_on_string(psi_script, psi_flags)
     logger.debug("PSI time:%s", res.time)
     logger.data('psi-time', res.time)
     if res.error is not "":
         logger.error("PSI error:" + res.error)
         raise Exception("PSI error:" + res.error)
     logger.debug("PSI output:%s", res.output)
     if res.output == "DiracDelta[-r+1]":
         ret = 1.0
     else:
         ret = regex.sub("", res.output)
         logger.debug('Evaluating cleaned up expression: %s', ret)
         ret = ev.eval_prob(ret)
     logger.debug("PSI Scorer: Returning evaluated probability %s", ret)
     return ret
Beispiel #5
0
    def optimize(self, s):
        if np.isnan(self.s.a).any() or np.isnan(self.s.d).any() or np.isnan(
                self.s.o).any():
            logger.warning(
                "Parameters contain 'nan', will not run gradient descent. Returning 0.0 instead..."
            )
        elif np.isnan(self.s.eps):
            logger.warning(
                "eps is 'nan', will not run gradient descent. Returning 0.0 instead..."
            )
        elif np.isinf(self.s.eps):
            logger.warning(
                "eps is already 'inf', will not run gradient descent....")
        else:
            logger.debug("Starting optimization step")
            self.imp.minimize(self.optimizer)
            logger.debug("Finished optimization step")
            self.check_error()

        logger.data('n_samples', self.n_samples)
        logger.info("Result after step (optimized,%s):\n%s", s,
                    self.current_state())

        return self.s.eps