激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python演化計(jì)算基準(zhǔn)函數(shù)詳解

Python演化計(jì)算基準(zhǔn)函數(shù)詳解

2022-02-17 13:30Robin-hlt Python

這篇文章主要介紹了Python演化計(jì)算基準(zhǔn)函數(shù),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧,希望能夠給你帶來幫助

基準(zhǔn)函數(shù)是測(cè)試演化計(jì)算算法性能的函數(shù)集,由于大部分基準(zhǔn)函數(shù)集都是C/C++編寫,Python編寫的基準(zhǔn)函數(shù)比較少,因此本文實(shí)現(xiàn)了13個(gè)常用基準(zhǔn)函數(shù)的Python版。

 

基準(zhǔn)函數(shù)定義

Python演化計(jì)算基準(zhǔn)函數(shù)詳解

 

代碼實(shí)現(xiàn)

benchmark.py

import numpy as np
import copy
"""
Author : Robin_Hua
update time : 2021.10.14
version : 1.0
"""
class Sphere:
    def __init__(self, x):
        self.x = x
    def getvalue(self):
        res = np.sum(self.x**2)
        return res
class Schwefel2_22:
    def __init__(self, x):
        self.x = x
    def getvalue(self):
        res = np.sum(np.abs(self.x)) + np.prod(np.abs(self.x))
        return res
class Noise:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        res = np.sum(np.arange(1, d + 1) * self.x ** 4) + np.random.random()
        return res
class Schwefel2_21:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        res = np.max(np.abs(self.x))
        return res
class Step:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        res = np.sum(int(self.x + 0.5) ** 2)
        return res
class Rosenbrock:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        res = np.sum(np.abs(100*(self.x[1:] - self.x[:-1]**2)**2 + (1 - self.x[:-1])**2))
        return res
class Schwefel:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        res = 418.9829*d - np.sum(self.x * np.sin(np.sqrt(np.abs(self.x))))
        return res
class Rastrigin:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        res = 10 * d + np.sum(self.x ** 2 - 10 * np.cos(2 * np.pi * self.x))
        return res
class Ackley:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        res = - 20 * np.exp(-0.2 * np.sqrt(np.mean(self.x ** 2)))
        res = res - np.exp(np.mean(np.cos(2 * np.pi * self.x))) + 20 + np.exp(1)
        return res
class Griewank:
    def __init__(self,x):
        self.x = x
    def getvalue(self):
        d = self.x.shape[0]
        i = np.arange(1, d + 1)
        res = 1 + np.sum(self.x ** 2) / 4000 - np.prod(np.cos(self.x / np.sqrt(i)))
        return res
class Generalized_Penalized:
    def __init__(self,x):
        self.x = x
    def u(self,a,k,m):
        temp = copy.deepcopy(self.x)
        temp[-a <= temp.any() <= a] = 0
        temp[temp > a] = k*(temp[temp > a]-a)**m
        temp[temp < -a] = k * (-temp[temp < -a] - a) ** m
        """
        temp = np.zeros_like(self.x)
        d = self.x.shape[0]
        for i in range(d):
            if self.x[i]>a:
                temp[i] = k*(self.x[i]-a)**m
            elif self.x[i]<-a:
                temp[i] = k * (-self.x[i] - a) ** m
            else:
                pass
        """
        return temp
    def getvalue(self):
        d = self.x.shape[0]
        y = 1+1/4*(self.x+1)
        res = np.pi/d*(10*np.sin(np.pi*y[0])**2+np.sum((y[:-1]-1)**2*(1+10*np.sin(np.pi*y[1:])**2))+(y[-1]-1)**2)+np.sum(self.u(10,100,4))
        return res
def benchmark_func(x,func_num):
    func = func_list[func_num]
    res = func(x)
    return res
func_list = [Sphere,Schwefel2_22,Noise,Schwefel2_21,Step,Rosenbrock,Schwefel,Rastrigin,Ackley,Griewank,Generalized_Penalized]

 

調(diào)用方法

輸入為向量x和函數(shù)編號(hào)func_num

import benchmark
import numpy as np
vector = np.random.random(30)
value = benchmark.benchmark_func(x=vector,func_num=0).getvalue()

 

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注服務(wù)器之家的更多內(nèi)容!

原文鏈接:https://blog.csdn.net/Robin_hlt/article/details/120941732

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本黄色网战 | 国产精品99久久99久久久二 | 在线日韩av电影 | 一本色道久久综合亚洲精品小说 | 综合精品久久 | 日本高清无遮挡 | 欧美黄色片一级 | 美女视频免费一区二区 | 久久精品国产99国产精品澳门 | 天天鲁在线视频免费观看 | 日韩 综合 | 国产精品视频在 | 国产日本欧美在线观看 | 精品一区二区久久久久 | 一级毛片电影院 | 精品偷拍久久 | 欧美日韩亚洲在线观看 | 久久精品国产99久久6动漫亮点 | 欧美一级特黄aaaaaaa什 | 国产99一区二区 | 国产午夜亚洲精品理论片大丰影院 | 久久久久久久高清 | 国产精品一区二区三区在线播放 | 狠狠操人人干 | 全免费午夜一级毛片真人 | 成人午夜毛片 | www.91pron| 曰批全过程40分钟免费视频多人 | 中文在线观看www | 久久精品视频16 | 成人在线视频免费看 | 久久精品亚洲国产奇米99 | 欧美亚洲国产一区二区三区 | 成人免费观看av | 男女无套免费视频 | 国产一区二区三区四区五区精品 | 在线看免电影网站 | 久久久久亚洲视频 | 国产欧美精品一区二区三区四区 | 成人国产高清 | 毛片免费视频在线观看 |