Beispiel #1
0
    def __init__(self, est1, est2, msg_hdl=None, hist_list=[], nit=10,
                 comp_cost=False, prt_period=0, is_complex=False, map_est=False):
        Solver.__init__(self, hist_list)
        self.est1 = est1
        self.est2 = est2
        if msg_hdl is None:
            msg_hdl = estim.MsgHdlSimp(is_complex=is_complex,
                                       map_est=map_est,
                                       shape=self.est1.shape)
        self.msg_hdl = msg_hdl
        self.nit = nit
        self.comp_cost = comp_cost
        self.prt_period = prt_period

        # Check if dimensions match
        if self.est1.shape != self.est2.shape:
            err_str = '%s shape %s does not match %s shape %s' %\
                (self.est1.name, str(self.est1.shape),
                 self.est2.name, str(self.est2.shape))
            raise common.VpException(err_str)
        if self.est1.shape != self.msg_hdl.shape:
            err_str = '%s shape %s does not match msg_hdl shape %s' %\
                (self.est1.name, str(self.est1.shape),
                 str(self.msg_hdl.shape))
            raise common.VpException(err_str)

        if self.est1.var_axes != self.est2.var_axes:
            err_str = '%s var_axes %s does not match %s var_axes %s' %\
                (self.est1.name, str(self.est1.var_axes),
                 self.est2.name, str(self.est2.var_axes))
            raise common.VpException(err_str)
        if self.est1.var_axes != self.msg_hdl.var_axes:
            err_str = '%s var_axes %s does not match msg_hdl var_axes %s' %\
                (self.est1.name, str(self.est1.var_axes),
                 str(self.msg_hdl.var_axes))
Beispiel #2
0
 def __init__(self, est1, est2, msg_hdl, hist_list=[], nit=10,\
     comp_cost=False,prt_period=0):
     Solver.__init__(self, hist_list)
     self.est1 = est1
     self.est2 = est2
     self.msg_hdl = msg_hdl
     self.nit = nit
     self.comp_cost = comp_cost
     self.prt_period = prt_period
Beispiel #3
0
    def __init__(self, est_list, msg_hdl_list=[], hist_list=[], nit=10,\
        comp_cost=False,prt_period=0):
        Solver.__init__(self, hist_list)
        self.est_list = est_list
        self.msg_hdl_list = msg_hdl_list
        self.nit = nit
        self.comp_cost = comp_cost
        self.prt_period = prt_period

        # Check if all estimators can compute the cost
        nlayers = len(self.est_list)
        for i in range(nlayers):
            esti = self.est_list[i]
            if self.comp_cost and not esti.cost_avail:
                errstr = "Requested cost computation, but cost_avail==False"\
                    + " for estimator " + str(i)
                raise common.VpException(errstr)
            self.comp_cost = self.comp_cost and esti.cost_avail
Beispiel #4
0
    def __init__(self, est0, est1, A, hist_list=[], nit=10,\
        comp_cost=True, prt_period=0, is_complex=False, map_est=False,\
        step_adapt=False,step=0.95,step_min=1e-6):
        Solver.__init__(self, hist_list)
        self.est0 = est0
        self.est1 = est1
        self.A = A
        self.nit = nit
        self.comp_cost = comp_cost
        self.prt_period = prt_period
        self.is_complex = is_complex
        self.map_est = map_est

        # Get dimensions
        self.shape0 = A.shape0
        self.shape1 = A.shape1
        self.var_axes0 = A.var_axes0
        self.var_axes1 = A.var_axes1

        # Step size parameters
        self.step = step
        self.step_adapt = step_adapt
        self.step_min = step_min  # min step size
        self.step_dec = 0.5  # decrement on a failure
        self.step_inc = 1.1  # decrement on a failure

        # Check if dimensions match
        if self.est0.shape != self.shape0:
            err_str = '%s shape %s does not match operator input shape %s' %\
                (self.est0.name, str(self.est0.shape), str(self.shape0))
            raise ValueError(err_str)
        if self.est1.shape != self.shape1:
            err_str = '%s shape %s does not match operator output shape %s' %\
                (self.est1.name, str(self.est1.shape), str(self.shape1))
            raise ValueError(err_str)
        if self.est0.var_axes != self.var_axes0:
            err_str = '%s var_axes %s does not match operator input var_axes %s' %\
                (self.est0.name, str(self.est0.var_axes), str(self.var_axes0))
            raise ValueError(err_str)
        if self.est1.var_axes != self.var_axes1:
            err_str = '%s var_axes %s does not match operator input var_axes %s' %\
                (self.est1.name, str(self.est1.var_axes), str(self.var_axes1))
            raise ValueError(err_str)
Beispiel #5
0
    def __init__(self, est_list, msg_hdl_list=[], hist_list=[], nit=10,\
        comp_cost=False,prt_period=0):
        Solver.__init__(self, hist_list)
        self.est_list = est_list
        self.msg_hdl_list = msg_hdl_list
        self.nit = nit
        self.comp_cost = comp_cost
        self.prt_period = prt_period
        self.time_iter = 0  # Computation time for last iteration

        # Check dimensions
        nlayers = len(self.est_list)
        if self.est_list[0].nvars != 1:
            raise ValueError('First estimator must take 1 variable')
        if self.est_list[-1].nvars != 1:
            raise ValueError('Last estimator must take 1 variable')
        for i in range(0, nlayers - 1):
            msg_hdl_shape = self.msg_hdl_list[i].shape
            msg_hdl_var_axes = self.msg_hdl_list[i].var_axes
            if i > 0:
                if (self.est_list[i].nvars != 2):
                    errstr = 'Estimator %s must take 2 variables'\
                        % self.est_list[i].name
                    raise ValueError(errstr)

            if i == 0:
                shape0 = self.est_list[i].shape
                var_axes0 = self.est_list[i].var_axes
            else:
                shape0 = self.est_list[i].shape[1]
                var_axes0 = self.est_list[i].var_axes[1]
            if i == nlayers - 2:
                shape1 = self.est_list[i + 1].shape
                var_axes1 = self.est_list[i + 1].var_axes
            else:
                shape1 = self.est_list[i + 1].shape[0]
                var_axes1 = self.est_list[i + 1].var_axes[0]

            if shape0 != shape1:
                errstr = 'Est %s shape %s does not match est %s shape %s'\
                    % (est_list[i].name, str(shape0), est_list[i+1].name, str(shape1))
                raise ValueError(errstr)
            if shape0 != msg_hdl_shape:
                errstr = 'Est %s shape %s does not match msg_hdl shape %s'\
                    % (est_list[i].name, str(shape0), str(msg_hdl_shape))
                raise ValueError(errstr)

            if var_axes0 != var_axes1:
                errstr = 'Est %s var_axes %s does not match est %s var_axes %s'\
                    % (est_list[i].name, str(var_axes0), est_list[i+1].name, str(var_axes1))
            if var_axes0 != msg_hdl_var_axes:
                errstr = 'Est %s var_axes %s does not match msg_hdl var_axes %s'\
                    % (est_list[i].name, str(var_axes0), str(msg_hdl_var_axes))
                raise ValueError(errstr)

        # Check if all estimators can compute the cost
        for i in range(nlayers):
            esti = self.est_list[i]
            if self.comp_cost and not esti.cost_avail:
                errstr = "Requested cost computation, but cost_avail==False"\
                    + " for estimator " + str(i)
                raise common.VpException(errstr)
            self.comp_cost = self.comp_cost and esti.cost_avail