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 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
Exemple #3
0
    def run(self, results):
        par1 = self.getValueOfParameter("parameter 1")
        par2 = self.getValueOfParameter("parameter 2")
        title = self.getValueOfParameter("title")
        
        if(par1==""):
            return False
        
        if(par2==""):
            return False
        
        x = pycalimero.doublevector();
        y = pycalimero.doublevector();

	for i in results:
	    x.append(i.getResults(par1)[0])
	    y.append(i.getResults(par2)[0])

        dialogform = Dialog(QApplication.activeWindow())
        fig = Figure((5.0, 4.0), dpi=100)
        ax = SubplotZero(fig, 1, 1, 1)
        fig.add_subplot(ax)

        for n in ["top", "right"]:
            ax.axis[n].set_visible(False)
            
        for n in ["bottom", "left"]:
            ax.axis[n].set_visible(True)   
        
        if(not(x.__len__())):
            return False
        
        if(not(y.__len__())):
            return False
        
        ax.plot (x, y, '.')
        ax.set_title(title)
        
        dialogform.showFigure(fig)
        return True
    def eval(self,iterationparameters, observedparameters, objectivefunctionparameters):
        result = pycalimero.doublevector()
        resultvalue = 0.0
        allparameters = []
        allparameters.extend(iterationparameters)
        allparameters.extend(observedparameters)
        allparameters.extend(objectivefunctionparameters)
        
        for i in allparameters:
            resultvalue += sum(i.getValues())

        result.push_back(resultvalue)
        return result
    def eval(self,iterationparameters, observedparameters, objectivefunctionparameters):
        result = pycalimero.doublevector()
        resultvalue = 1.0
        result.push_back(resultvalue)
        
        iterations = int(self.getValueOfParameter("iterations"))
        n = int(self.getValueOfParameter("fac n"))
        
        for i in range(iterations):
            for ni in range(n):
                resultvalue *= (ni+1)

        return result
 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 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   
Exemple #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