예제 #1
0
파일: qre.py 프로젝트: wenshen/gambit
    def trace_strategic_path(self, game, max_lambda=1000000.0, callback=None):
        points = []

        def on_step(game, points, p, callback):
            qre = LogitQRE(
                p[-1],
                game.mixed_strategy_profile(
                    point=[math.exp(x) for x in p[:-1]]))
            points.append(qre)
            if callback: callback(qre)

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            try:
                pctrace.trace_path(
                    [math.log(x) for x in p.profile],
                    0.0,
                    max_lambda,
                    lambda x: sym_compute_lhs(game, x),
                    lambda x: sym_compute_jac(game, x),
                    hStart=self.h_start,
                    maxDecel=self.max_decel,
                    callback=lambda p: on_step(game, points, p, callback),
                    crit=None,
                    maxIter=100)
            except KeyboardInterrupt:
                pass

            return points
        else:
            raise NotImplementedError
예제 #2
0
파일: qre.py 프로젝트: gambitproject/gambit
    def trace_strategic_path(self, game, max_lambda=1000000.0, callback=None):
        points = [ ]
        def on_step(game, points, p, callback):
            qre = LogitQRE(p[-1],
                           game.mixed_strategy_profile(point=[math.exp(x) for x in p[:-1]]))
            points.append(qre)
            if callback:  callback(qre)

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            try:
                pctrace.trace_path([ math.log(x) for x in p.profile ],
                                   0.0, max_lambda,
                                   lambda x: sym_compute_lhs(game, x),
                                   lambda x: sym_compute_jac(game, x),
                                   hStart=self.h_start,
                                   maxDecel=self.max_decel,
                                   callback=lambda p: on_step(game, points, p, callback),
                                   crit=None,
                                   maxIter=100)
            except KeyboardInterrupt:
                pass

            return points
        else:
            raise NotImplementedError
예제 #3
0
파일: qre.py 프로젝트: wenshen/gambit
    def compute_criterion(self, game, f):
        def criterion_wrap(x, t):
            """
            This translates the internal representation of the tracer
            into a QRE object.
            """
            return f(
                LogitQRE(
                    x[-1],
                    game.mixed_strategy_profile(
                        point=[math.exp(z) for z in x[:-1]])))

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            point = pctrace.trace_path([math.log(x) for x in p.profile],
                                       0.0,
                                       1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       hStart=1.0,
                                       crit=criterion_wrap,
                                       maxIter=100)

            return LogitQRE(
                point[-1],
                game.mixed_strategy_profile(
                    point=[math.exp(x) for x in point[:-1]]))
        else:
            raise NotImplementedError
예제 #4
0
파일: qre.py 프로젝트: wenshen/gambit
    def compute_fit_sshist(self, game, data, callback=None):
        """
        Find lambda parameter for which QRE best fits the data
        using the sum of squares of distances in the histogram of
        the data.
        """
        def diff_dist(data, point, tangent):
            return 2.0 * sum([(math.exp(p) - d) * t * math.exp(p)
                              for (p, t, d) in zip(point, tangent, data)])

        if game.is_symmetric:
            p = game.mixed_strategy_profile()
            point = pctrace.trace_path([math.log(x) for x in p.profile],
                                       0.0,
                                       1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       hStart=1.0,
                                       crit=lambda x, t: diff_dist(data, x, t),
                                       maxIter=100,
                                       callback=callback)

            qre = LogitQRE(
                point[-1],
                game.mixed_strategy_profile(
                    point=[math.exp(x) for x in point[:-1]]))
            return qre
        else:
            raise NotImplementedError
예제 #5
0
파일: qre.py 프로젝트: wenshen/gambit
    def compute_max_like(self, game, data):
        log_like = lambda data, profile: \
                   sum([ x*math.log(y) for (x, y) in zip(data, profile) ])
        diff_log_like = lambda data, point, tangent: \
                        sum([ x*y for (x, y) in zip(data, tangent[:-1]) ])

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            point = pctrace.trace_path(
                [math.log(x) for x in p.profile],
                0.0,
                1000000.0,
                lambda x: sym_compute_lhs(game, x),
                lambda x: sym_compute_jac(game, x),
                hStart=1.0,
                crit=lambda x, t: diff_log_like(data, x, t),
                maxIter=100)

            qre = LogitQRE(
                point[-1],
                game.mixed_strategy_profile(
                    point=[math.exp(x) for x in point[:-1]]))
            qre.logL = log_like(data, qre)
            return qre
        else:
            raise NotImplementedError
예제 #6
0
파일: qre.py 프로젝트: wenshen/gambit
    def compute_at_lambda(self, game, lam, callback=None):
        if callback is not None:
            on_step = lambda p: callback(
                LogitQRE(
                    p[-1],
                    game.mixed_strategy_profile(
                        point=[math.exp(x) for x in p[:-1]])))
        else:
            on_step = None

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            point = pctrace.trace_path([math.log(x) for x in p.profile],
                                       0.0,
                                       1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       crit=lambda x, t: x[-1] - lam,
                                       callback=on_step,
                                       maxIter=100)

            return LogitQRE(
                point[-1],
                game.mixed_strategy_profile(
                    point=[math.exp(x) for x in point[:-1]]))
        else:
            raise NotImplementedError
예제 #7
0
파일: qre.py 프로젝트: gambitproject/gambit
    def compute_fit_sshist(self, game, data, callback=None):
        """
        Find lambda parameter for which QRE best fits the data
        using the sum of squares of distances in the histogram of
        the data.
        """
        def diff_dist(data, point, tangent):
            return 2.0 * sum([ (math.exp(p)-d) * t * math.exp(p)
                               for (p, t, d) in zip(point, tangent, data) ])

        if game.is_symmetric:
            p = game.mixed_strategy_profile()
            point = pctrace.trace_path([ math.log(x) for x in p.profile ],
                                       0.0, 1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       hStart=1.0,
                                       crit=lambda x,t: diff_dist(data,x,t),
                                       maxIter=100,
                                       callback=callback)

            qre = LogitQRE(point[-1],
                           game.mixed_strategy_profile(point=[math.exp(x) for x in point[:-1]]))
            return qre
        else:
            raise NotImplementedError
예제 #8
0
파일: qre.py 프로젝트: skunath/gambit
    def compute_max_like(self, game, data):
        diff_log_like = lambda data, point, tangent: \
                        sum([ x*y for (x, y) in zip(data, tangent[:-1]) ])

        if game.is_symmetric:
            p = game.mixed_profile()

            point = pctrace.trace_path([ math.log(x) for x in p.profile ],
                                       0.0, 1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       hStart=1.0,
                                       crit=lambda x,t: diff_log_like(data,x,t),
                                       maxIter=100)

            return LogitQRE(point[-1],
                            game.mixed_profile(point=[math.exp(x) for x in point[:-1]]))
        else:
            raise NotImplementedError
예제 #9
0
파일: qre.py 프로젝트: gambitproject/gambit
    def compute_at_lambda(self, game, lam, callback=None):
        if callback is not None:
            on_step = lambda p: callback(LogitQRE(p[-1],
                                                  game.mixed_strategy_profile(point=[math.exp(x) for x in p[:-1]])))
        else:
            on_step = None

        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            point = pctrace.trace_path([ math.log(x) for x in p.profile ],
                                       0.0, 1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       crit=lambda x,t: x[-1] - lam,
                                       callback=on_step,
                                       maxIter=100)

            return LogitQRE(point[-1],
                            game.mixed_strategy_profile(point=[math.exp(x) for x in point[:-1]]))
        else:
            raise NotImplementedError
예제 #10
0
파일: qre.py 프로젝트: gambitproject/gambit
    def compute_criterion(self, game, f):
        def criterion_wrap(x, t):
            """
            This translates the internal representation of the tracer
            into a QRE object.
            """
            return f(LogitQRE(x[-1],
                              game.mixed_strategy_profile(point=[math.exp(z) for z in x[:-1]])))
            
        if game.is_symmetric:
            p = game.mixed_strategy_profile()

            point = pctrace.trace_path([ math.log(x) for x in p.profile ],
                                       0.0, 1000000.0,
                                       lambda x: sym_compute_lhs(game, x),
                                       lambda x: sym_compute_jac(game, x),
                                       hStart=1.0,
                                       crit=criterion_wrap,
                                       maxIter=100)

            return LogitQRE(point[-1],
                            game.mixed_strategy_profile(point=[math.exp(x) for x in point[:-1]]))
        else:
            raise NotImplementedError