def _setattr_helper__(self, name, value):
   if hasattr(self, name):
       # get target class
       targetClass=getattr(self,name).__class__
       # convert class to native representation
       return name,to_native_class_converter(givenValue=value,nativeClass=targetClass)
   else:
       raise NameError("%s has no attribute named \'%s\' , the parameter attributes are : %s " % (str(solverParamClass),str(name),str(self.getParameterNames()) ))
    def get_cpp_parameter(cls, operator, accumulator, parameter):
        _meta_parameter = parameter
        # get hyper parameter (as minStCut for graphcut, or the subsolver for
        # dualdec.)
        hyperParamKeywords = inferenceClasses.hyperParameterKeywords
        numHyperParams = len(hyperParamKeywords)
        userHyperParams = [None]*numHyperParams
        collectedHyperParameters = 0
        # get the users hyper parameter ( if given)

        if(_meta_parameter is not None):
            for hpIndex, hyperParamKeyword in enumerate(hyperParamKeywords):
                if hyperParamKeyword in _meta_parameter.kwargs:
                    userHyperParams[hpIndex] = _meta_parameter.kwargs.pop(
                        hyperParamKeyword)
                    collectedHyperParameters += 1

            # check if ZERO or ALL hyperParamerts have been collected
            if collectedHyperParameters != 0 and collectedHyperParameters != numHyperParams:
                raise RuntimeError("All or none hyper-parameter must be given")

        # check if the WHOLE tuple of hyperParameters is allowed
        if collectedHyperParameters != 0:
            if tuple(str(x) for x in userHyperParams) not in inferenceClasses.implDict:
                raise RuntimeError("%s is not an allowed hyperParameter\nAllowed hyperParameters are %s" % (
                    repr(userHyperParams), repr(inferenceClasses.implDict.keys())))
        else:
            userHyperParams = defaultHyperParams

        #try:
        # get the selected inference class and the parameter
        if(numHyperParams == 0):
            
            _selectedInfClass, _selectedInfParamClass = inferenceClasses.implDict[
                    "__NONE__"][(operator, accumulator)]
        else:
            hp = tuple(str(x) for x in userHyperParams)
            _selectedInfClass, _selectedInfParamClass = inferenceClasses.implDict[
                hp][(operator, accumulator)]
        #except:
        #    dictStr=str(inferenceClasses.implDict)
        #    raise RuntimeError("given seminring (operator = %s ,accumulator = %s) is not implemented for this solver\n %s" % \
        #        (operator, accumulator,dictStr))

        if _meta_parameter is None:
            cppParam = self._selectedInfClass._parameter()
            cppParam.set()
        else:
            cppParam = to_native_class_converter(
                givenValue=_meta_parameter, nativeClass=_selectedInfParamClass)
            assert cppParam is not None

        return cppParam
 def _setattr_helper__(self, name, value):
     if hasattr(self, name):
         # get target class
         targetClass = getattr(self, name).__class__
         # convert class to native representation
         return name, to_native_class_converter(givenValue=value,
                                                nativeClass=targetClass)
     else:
         raise NameError(
             "%s has no attribute named \'%s\' , the parameter attributes are : %s "
             % (str(solverParamClass), str(name),
                str(self.getParameterNames())))
    def inference_init(self, gm, accumulator=None, parameter=None):
        # self._old_init()
        # set up basic properties
        self.gm = gm
        self.operator = gm.operator
        if accumulator is None:
            self.accumulator = defaultAccumulator(gm)
        else:
            self.accumulator = accumulator
        self._meta_parameter = parameter
        # get hyper parameter (as minStCut for graphcut, or the subsolver for
        # dualdec.)
        hyperParamKeywords = self._infClasses.hyperParameterKeywords
        numHyperParams = len(hyperParamKeywords)
        userHyperParams = [None] * numHyperParams
        collectedHyperParameters = 0
        # get the users hyper parameter ( if given)

        if (self._meta_parameter is not None):
            for hpIndex, hyperParamKeyword in enumerate(hyperParamKeywords):
                if hyperParamKeyword in self._meta_parameter.kwargs:
                    userHyperParams[hpIndex] = self._meta_parameter.kwargs.pop(
                        hyperParamKeyword)
                    collectedHyperParameters += 1

            # check if ZERO or ALL hyperParamerts have been collected
            if collectedHyperParameters != 0 and collectedHyperParameters != numHyperParams:
                raise RuntimeError("All or none hyper-parameter must be given")

        # check if the WHOLE tuple of hyperParameters is allowed
        if collectedHyperParameters != 0:
            if tuple(
                    str(x)
                    for x in userHyperParams) not in inferenceClasses.implDict:
                raise RuntimeError(
                    "%s is not an allowed hyperParameter\nAllowed hyperParameters are %s"
                    % (repr(userHyperParams),
                       repr(inferenceClasses.implDict.keys())))
        else:
            userHyperParams = defaultHyperParams

        try:
            # get the selected inference class and the parameter
            if (numHyperParams == 0):

                self._selectedInfClass, self._selectedInfParamClass = inferenceClasses.implDict[
                    "__NONE__"][(self.operator, self.accumulator)]
            else:
                hp = tuple(str(x) for x in userHyperParams)
                self._selectedInfClass, self._selectedInfParamClass = inferenceClasses.implDict[
                    hp][(self.operator, self.accumulator)]
        except:
            dictStr = str(inferenceClasses.implDict)
            raise RuntimeError("given seminring (operator = %s ,accumulator = %s) is not implemented for this solver\n %s" % \
                (self.operator, self.accumulator,dictStr))

        if self._meta_parameter is None:
            self.parameter = self._selectedInfClass._parameter()
            self.parameter.set()
        else:
            self.parameter = to_native_class_converter(
                givenValue=self._meta_parameter,
                nativeClass=self._selectedInfParamClass)
            assert self.parameter is not None

        self.inference = self._selectedInfClass(self.gm, self.parameter)
    def inference_init(self, gm, accumulator=None, parameter=None):
        # self._old_init()
        # set up basic properties
        self.gm = gm
        self.operator = gm.operator
        if accumulator is None:
            self.accumulator = defaultAccumulator(gm)
        else:
            self.accumulator = accumulator
        self._meta_parameter = parameter
        # get hyper parameter (as minStCut for graphcut, or the subsolver for
        # dualdec.)
        hyperParamKeywords = self._infClasses.hyperParameterKeywords
        numHyperParams = len(hyperParamKeywords)
        userHyperParams = [None]*numHyperParams
        collectedHyperParameters = 0
        # get the users hyper parameter ( if given)

        if(self._meta_parameter is not None):
            for hpIndex, hyperParamKeyword in enumerate(hyperParamKeywords):
                if hyperParamKeyword in self._meta_parameter.kwargs:
                    userHyperParams[hpIndex] = self._meta_parameter.kwargs.pop(
                        hyperParamKeyword)
                    collectedHyperParameters += 1

            # check if ZERO or ALL hyperParamerts have been collected
            if collectedHyperParameters != 0 and collectedHyperParameters != numHyperParams:
                raise RuntimeError("All or none hyper-parameter must be given")

        # check if the WHOLE tuple of hyperParameters is allowed
        if collectedHyperParameters != 0:
            if tuple(str(x) for x in userHyperParams) not in inferenceClasses.implDict:
                raise RuntimeError("%s is not an allowed hyperParameter\nAllowed hyperParameters are %s" % (
                    repr(userHyperParams), repr(inferenceClasses.implDict.keys())))
        else:
            userHyperParams = defaultHyperParams

        try:
            # get the selected inference class and the parameter
            if(numHyperParams == 0):
                
                self._selectedInfClass, self._selectedInfParamClass = inferenceClasses.implDict[
                        "__NONE__"][(self.operator, self.accumulator)]
            else:
                hp = tuple(str(x) for x in userHyperParams)
                self._selectedInfClass, self._selectedInfParamClass = inferenceClasses.implDict[
                    hp][(self.operator, self.accumulator)]
        except:
            dictStr=str(inferenceClasses.implDict)
            raise RuntimeError("given seminring (operator = %s ,accumulator = %s) is not implemented for this solver\n %s" % \
                (self.operator, self.accumulator,dictStr))

        if self._meta_parameter is None:
            self.parameter = self._selectedInfClass._parameter()
            self.parameter.set()
        else:
            self.parameter = to_native_class_converter(
                givenValue=self._meta_parameter, nativeClass=self._selectedInfParamClass)
            assert self.parameter is not None

        self.inference = self._selectedInfClass(self.gm, self.parameter)