def eval(self,iterationparameters, observedparameters, objectivefunctionparameters):
        #search for number of vectors
        numberofvectors = 0
        numberofvectors = numberofvectors+iterationparameters.__len__()
        numberofvectors = numberofvectors+observedparameters.__len__()
        numberofvectors = numberofvectors+objectivefunctionparameters.__len__()
        
        if(numberofvectors!=1):
            pycalimero.log("Only one vector is allowed in ReverseVector", pycalimero.Warning)
        
        #search for vectors and check their size
        vectors = pycalimero.doublevectorvector()
        
        for var in iterationparameters:
            vectors.append(var.getValues())
        
        for var in observedparameters:
            vectors.append(var.getValues())
        
        
        for var in objectivefunctionparameters:
            vectors.append(var.getValues())

        #calculate
        result = pycalimero.doublevector()
        
        for value in vectors[0]:
            result.append(-value)
            
        return result
 def start(self,calibrationvars, objectivevars, env, calibration):
     pycalimero.log("Start BruteForceSearch_P",pycalimero.Standard)
     result =  self.bruteforcesearch(calibrationvars,0,env)
     pycalimero.barrier()
     pycalimero.log("BruteForceSearch_P DONE",pycalimero.Standard)
     
     return result;
Beispiel #3
0
    def start(self, calibrationvars, objectivevars, env, calibration):
        self.calibrationvars = calibrationvars
        self.objectivevars = objectivevars
        self.calibration = calibration
        self.env = env
        global error
        global maxerror
        global alg
        global minimize
        maxerror = float(self.getValueOfParameter("max Error"))
        global baseevo
        error = False
        minimize = False
        verbose = False

        if self.getValueOfParameter("minimize objetive funtion") == "1":
            minimize = True

        if self.getValueOfParameter("verbose") == "1":
            verbose = True

        pycalimero.log("Pybrain_GA START", pycalimero.Standard)

        baseevo = SimpleEvo(extractData(self.calibrationvars), calibrationvars, objectivevars, env, calibration)

        alg = GA(objf, baseevo.x)
        alg.maxEvaluations = int(self.getValueOfParameter("max Iteration"))
        alg.minimize = minimize
        alg.desiredEvaluation = float(self.getValueOfParameter("max Error"))
        alg.verbose = verbose
        alg.learn()

        pycalimero.log("Pybrain_GA DONE", pycalimero.Standard)

        return True
 def bruteforcesearch(self, calibrationvars, currentvar, env):
     var = calibrationvars[currentvar]
     
     for currentvalue in frange(var.min,var.max,var.step) + [var.max]:
         result = pycalimero.doublevector()
         result.append(currentvalue)
         var.setValues(result)
     
         if (currentvar==(calibrationvars.__len__()-1)):
             if (pycalimero.execIteration(calibrationvars) == False):
                 pycalimero.log("BruteForceSearch_P stoped by user",pycalimero.Standard)
                 return False
         else:
             if(self.bruteforcesearch(calibrationvars,currentvar+1,env)==False):
                 return True
         
     return True
  def eval(self,iterationparameters, observedparameters, objectivefunctionparameters):
      #search for vectors and check their size
      vectors = pycalimero.doublevectorvector()
      
      for var in iterationparameters:
          vectors.append(var.getValues())
      
      for var in observedparameters:
          vectors.append(var.getValues())
      
      
      for var in objectivefunctionparameters:
          vectors.append(var.getValues())
      
      if(vectors.__len__()!=2):
          pycalimero.log("Only two vectors are allowed in VectorErrorSquare", pycalimero.Error)
          return pycalimero.doublevector(1,999999999999999)
      
      
      if(vectors[0].__len__() < vectors[1].__len__()):
          tmp = pycalimero.doublevector(vectors[0])
          while(tmp.__len__() < vectors[1].__len__()): 
              tmp.append(999)
          
          vectors[0]=tmp;
 
      if(vectors[0].__len__() > vectors[1].__len__()):
          tmp = pycalimero.doublevector(vectors[1])
          while(tmp.__len__() < vectors[0].__len__()): 
              tmp.append(999)
          
          vectors[1]=tmp;
          
      #calculate
      result = pycalimero.doublevector(vectors[0].__len__())
      
      for index,value1 in enumerate(vectors[0]):
          result[index] = math.pow(value1 - vectors[1][index],2)
      
      return result
    def eval(self,iterationparameters, observedparameters, objectivefunctionparameters):
        #search for number of vectors
        numberofvectors = 0
        numberofvectors = numberofvectors+iterationparameters.__len__()
        numberofvectors = numberofvectors+observedparameters.__len__()
        numberofvectors = numberofvectors+objectivefunctionparameters.__len__()
        
        if(numberofvectors!=2):
            pycalimero.log("Only two vectors are allowed in VectorError", pycalimero.Warning)
        
        #search for vectors and check their size
        vectors = pycalimero.doublevectorvector()
        
        for var in iterationparameters:
            vectors.append(var.getValues())
        
        for var in observedparameters:
            vectors.append(var.getValues())
        
        
        for var in objectivefunctionparameters:
            vectors.append(var.getValues())
        
        if(vectors[0].__len__()!=vectors[1].__len__()):
            pycalimero.log("Vectors do not have the same size in VectorError", pycalimero.Warning)

        #calculate
        result = pycalimero.doublevector()
        
        index = 0
        for value1 in vectors[0]:
            currentresult = value1 - vectors[1][index]
            result.append(currentresult)
            index = index+1
        
        return result   
    def start(self,calibrationvars, objectivevars, env, calibration):
        pycalimero.log("Start TemplateAlgorithm",pycalimero.Standard)
        
        for i in range(0,int(self.getValueOfParameter("max iterations"))):
            #pycalimero.log("Run iteration",pycalimero.LogLevel.standard)
            if (pycalimero.execIteration(calibrationvars) == False):
                pycalimero.log("TemplateAlgorithm stoped by user",pycalimero.Standard)
                return True

            pycalimero.barrier()
            #pycalimero.log("Finish iteration",pycalimero.LogLevel.standard)
            
        pycalimero.log("TemplateAlgorithm DONE",pycalimero.Standard)
        return True
Beispiel #8
0
def objf(x):
    xpars = array([], float32)
    calibrationvars = None
    calibration = None
    objectivevars = None
    env = None
    global error
    global baseevo
    global maxerror
    global minimize
    global alg

    if error:
        alg.maxEvaluations = 1
        return maxerror

    if isinstance(x, Evolvable):
        xpars = x.x
        calibrationvars = x.calibrationvars
        calibration = x.calibration
        objectivevars = x.objectivevars
        env = x.env
    else:
        xpars = x
        calibrationvars = baseevo.calibrationvars
        calibration = baseevo.calibration
        objectivevars = baseevo.objectivevars
        env = baseevo.env

    for index, value in enumerate(xpars):
        correctvalue = max(
            calibrationvars[index].min,
            min(calibrationvars[index].max, floor(value / calibrationvars[index].step) * calibrationvars[index].step),
        )
        currentvalue = pycalimero.doublevector()
        currentvalue.append(double(correctvalue))
        calibrationvars[index].setValues(currentvalue)

    if error:
        return maxerror

    if not pycalimero.execIteration(calibrationvars):
        error = True
        return maxerror
    else:
        pycalimero.barrier()

    result = 0.0
    resultindex = calibration.getNumOfComplete() - 1
    iterationresult = calibration.getIterationResults()[resultindex]

    for opar in objectivevars:
        result = result + sum(iterationresult.getResults(opar.getName()))

    if minimize and (result < maxerror):
        pycalimero.log("Algorithm reached maximal error", pycalimero.Standard)
        alg.maxEvaluations = 1
        return maxerror

    if (not minimize) and result > maxerror:
        pycalimero.log("Algorithm reached maximal error", pycalimero.Standard)
        alg.maxEvaluations = 1
        return maxerror
    return result