【DELM分類】基于鴿群算法改進(jìn)深度學(xué)習(xí)極限學(xué)習(xí)機(jī)實現(xiàn)數(shù)據(jù)分類附matlab代碼
1 簡介
人工神經(jīng)網(wǎng)絡(luò)的最大缺點是訓(xùn)練時間太長從而限制其實時應(yīng)用范圍,近年來,極限學(xué)習(xí)機(jī)(Extreme Learning Machine, ELM)的提出使得前饋神經(jīng)網(wǎng)絡(luò)的訓(xùn)練時間大大縮短,然而當(dāng)原始數(shù)據(jù)混雜入大量噪聲變量時,或者當(dāng)輸入數(shù)據(jù)維度非常高時,極限學(xué)習(xí)機(jī)算法的綜合性能會受到很大的影響.深度學(xué)習(xí)算法的核心是特征映射,它能夠摒除原始數(shù)據(jù)中的噪聲,并且當(dāng)向低維度空間進(jìn)行映射時,能夠很好的起到對數(shù)據(jù)降維的作用,因此我們思考利用深度學(xué)習(xí)的優(yōu)勢特性來彌補(bǔ)極限學(xué)習(xí)機(jī)的弱勢特性從而改善極限學(xué)習(xí)機(jī)的性能.為了進(jìn)一步提升DELM預(yù)測精度,本文采用麻雀搜索算法進(jìn)一步優(yōu)化DELM超參數(shù),仿真結(jié)果表明,改進(jìn)算法的預(yù)測精度更高。





2 部分代碼
AW = .46
BW = .46
CW = .08
def comparator(pigeon):
? ?return pigeon.fitness()
def cos_sim(gx, x):
? ?na = numpy.linalg.norm(gx)
? ?nb = numpy.linalg.norm(x)
? ?if na == 0 and nb == 0:
? ? ? ?return 1
? ?if na == 0:
? ? ? ?return 0
? ?if nb == 0:
? ? ? ?return 0
? ?d = numpy.dot(gx, x)
? ?return d / (na * nb)
class Pigeon:
? ?def __init__(self, random=False):
? ? ? ?if random:
? ? ? ? ? ?self.__x = [rand.uniform(L, U) for _ in range(0, get_number_of_inputs())]
? ? ? ? ? ?self.__v = [rand.uniform(0, 1) for _ in range(0, get_number_of_inputs())]
? ? ? ?else:
? ? ? ? ? ?self.__x = [.0] * get_number_of_inputs()
? ? ? ? ? ?self.__v = [.0] * get_number_of_inputs()
? ? ? ?self.__fitness = None
? ? ? ?self.tpr = .0
? ? ? ?self.fpr = .0
? ?def update_velocity_and_path(self, pg, t):
? ? ? ?self.__v = [(vi * exp(-R * t) + rand.uniform(0, 1) * (pg.__x[i] - self.__x[i])) for i, vi in
? ? ? ? ? ? ? ? ? ?enumerate(self.__v)]
? ? ? ?self.__x = [xi + self.__v[i] for i, xi in enumerate(self.__x)]
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?def mutate(self, prop):
? ? ? ?self.__x = [self.__x[i] if prop <= rand.uniform(0, 1) else self.__x[i] + R * rand.uniform(-1, 1)
? ? ? ? ? ? ? ? ? ?for i in range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?@staticmethod
? ?def desirable_destination_center(pop, np):
? ? ? ?pop.sort(key=comparator)
? ? ? ?n = len(pop[0].__x)
? ? ? ?xc = [.0] * n
? ? ? ?xf = [.0] * n
? ? ? ?f = 0
? ? ? ?for i in range(0, np):
? ? ? ? ? ?fi = pop[i].fitness()
? ? ? ? ? ?f += fi
? ? ? ? ? ?for j in range(0, n):
? ? ? ? ? ? ? ?xf[j] += pop[i].__x[j] * fi
? ? ? ?for c in range(0, n):
? ? ? ? ? ?xc[c] = xf[c] / (np * f)
? ? ? ?return xc
? ?def update_path(self, xc):
? ? ? ?self.__x = [(xi + rand.uniform(0, 1) * (xc[i] - xi)) for i, xi in enumerate(self.__x)]
? ? ? ?self.__fitness = None
? ?def fitness(self):
? ? ? ?if not self.__fitness:
? ? ? ? ? ?self.tpr, self.fpr, n = calc_fitness(self.__x)
? ? ? ? ? ?if n == 0:
? ? ? ? ? ? ? ?return float("inf")
? ? ? ? ? ?a = 1.0 / (self.tpr * 100)
? ? ? ? ? ?b = self.fpr * 100
? ? ? ? ? ?self.__fitness = n + a + b
? ? ? ?return self.__fitness
? ?def __get_id(self):
? ? ? ?return "-".join(map(str, self.__x))
? ?def __str__(self):
? ? ? ?return "[" + ", ".join(format(x, "6.6f") for x in self.__x) + "] " + str(self.fitness())
? ?def __hash__(self):
? ? ? ?return hash(self.__get_id())
? ?def __eq__(self, other):
? ? ? ?return isinstance(other, Pigeon) and self.__get_id() == other.__get_id()
? ?def attr(self):
? ? ? ?return get_attr(self.__x)
? ?def x(self):
? ? ? ?return self.__x;
class CosinePigeon:
? ?def __init__(self, random=False):
? ? ? ?if random:
? ? ? ? ? ?self.__x = [rand.getrandbits(1) for _ in range(0, get_number_of_inputs())]
? ? ? ?else:
? ? ? ? ? ?self.__x = [0] * get_number_of_inputs()
? ? ? ?self.__fitness = None
? ? ? ?self.tpr = .0
? ? ? ?self.fpr = .0
? ?def update_velocity_and_path(self, pg, t):
? ? ? ?v = cos_sim(pg.__x, self.__x)
? ? ? ?self.__x = [self.__x[i] if v > rand.uniform(0, 1) else pg.__x[i] for i in range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?def mutate(self, prop):
? ? ? ?self.__x = [self.__x[i] if prop <= rand.uniform(0, 1) else 1 - self.__x[i]
? ? ? ? ? ? ? ? ? ?for i in range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?@staticmethod
? ?def desirable_destination_center(pop, np):
? ? ? ?pop.sort(key=comparator)
? ? ? ?n = len(pop[0].__x)
? ? ? ?xc = [.0] * n
? ? ? ?for i in range(0, np):
? ? ? ? ? ?for j in range(0, n):
? ? ? ? ? ? ? ?xc[j] += pop[i].__x[j]
? ? ? ?for j in range(0, n):
? ? ? ? ? ?xc[j] = xc[j] / n
? ? ? ?return xc
? ?# @staticmethod
? ?# def desirable_destination_center(pop, np):
? ?# ? ? pop.sort(key=comparator)
? ?# ? ? n = len(pop[0].__x)
? ?# ? ? xc = [.0] * n
? ?# ? ? xf = [.0] * n
? ?# ? ? f = .0
? ?# ? ? for i in range(0, np):
? ?# ? ? ? ? fi = pop[i].fitness()
? ?# ? ? ? ? f += fi
? ?# ? ? ? ? for j in range(0, n):
? ?# ? ? ? ? ? ? xf[j] += pop[i].__x[j] * fi
? ?# ? ? for c in range(0, n):
? ?# ? ? ? ? xc[c] = xf[c] / (np * f)
? ?# ? ? avg = sum(xc) / len(xc)
? ?# ? ? return [1 if xc[i] >= avg else 0 for i in range(0, n)]
? ?# def update_path(self, xc):
? ?# ? ? v = cos_sim(xc, self.__x)
? ?# ? ? self.__x = [self.__x[i] if v > rand.uniform(0, 1) else xc[i] for i in range(0, get_number_of_inputs())]
? ?# ? ? self.__fitness = None
? ?def update_path(self, xc):
? ? ? ?self.__x = [self.__x[i] if xc[i] > rand.uniform(0, 1) else (1 - self.__x[i]) for i in
? ? ? ? ? ? ? ? ? ?range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ?def fitness(self):
? ? ? ?if not self.__fitness:
? ? ? ? ? ?self.tpr, self.fpr, n = calc_fitness(self.__x)
? ? ? ? ? ?if n == 0:
? ? ? ? ? ? ? ?return float("inf")
? ? ? ? ? ?a = AW * (1.0 / self.tpr)
? ? ? ? ? ?b = BW * self.fpr
? ? ? ? ? ?c = CW * (n / get_number_of_inputs())
? ? ? ? ? ?self.__fitness = a + b + c
? ? ? ?return self.__fitness
? ?def __get_id(self):
? ? ? ?return "-".join(map(str, self.__x))
? ?def __str__(self):
? ? ? ?return "[" + ", ".join(format(x, "6.6f") for x in self.__x) + "] " + str(self.fitness())
? ?def __hash__(self):
? ? ? ?return hash(self.__get_id())
? ?def __eq__(self, other):
? ? ? ?return isinstance(other, CosinePigeon) and self.__get_id() == other.__get_id()
? ?def attr(self):
? ? ? ?return get_attr(self.__x)
? ?def x(self):
? ? ? ?return self.__x;
class SigmoidalPigeon:
? ?def __init__(self, random=False):
? ? ? ?if random:
? ? ? ? ? ?self.__x = [rand.getrandbits(1) for _ in range(0, get_number_of_inputs())]
? ? ? ? ? ?self.__v = [rand.uniform(0, 1) for _ in range(0, get_number_of_inputs())]
? ? ? ?else:
? ? ? ? ? ?self.__x = [0] * get_number_of_inputs()
? ? ? ? ? ?self.__v = [.0] * get_number_of_inputs()
? ? ? ?self.__fitness = None
? ? ? ?self.tpr = .0
? ? ? ?self.fpr = .0
? ?def update_velocity_and_path(self, pg, t):
? ? ? ?self.__v = [(vi * exp(-R * t) + rand.uniform(0, 1) * (pg.__x[i] - self.__x[i])) for i, vi in
? ? ? ? ? ? ? ? ? ?enumerate(self.__v)]
? ? ? ?for i in range(0, get_number_of_inputs()):
? ? ? ? ? ?s = 1.0 / (1.0 + exp(-self.__v[i]/2))
? ? ? ? ? ?self.__x[i] = 1 if s > rand.uniform(0, 1) else 0
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?@staticmethod
? ?def desirable_destination_center(pop, np):
? ? ? ?pop.sort(key=comparator)
? ? ? ?n = len(pop[0].__x)
? ? ? ?xc = [.0] * n
? ? ? ?for i in range(0, np):
? ? ? ? ? ?for j in range(0, n):
? ? ? ? ? ? ? ?xc[j] += pop[i].__x[j]
? ? ? ?for j in range(0, n):
? ? ? ? ? ?xc[j] = xc[j] / n
? ? ? ?return xc
? ?def update_path(self, xc):
? ? ? ?self.__x = [self.__x[i] if xc[i] > rand.uniform(0, 1) else (1 - self.__x[i]) for i in
? ? ? ? ? ? ? ? ? ?range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ?def fitness(self):
? ? ? ?if not self.__fitness:
? ? ? ? ? ?self.tpr, self.fpr, n = calc_fitness(self.__x)
? ? ? ? ? ?if n == 0:
? ? ? ? ? ? ? ?return float("inf")
? ? ? ? ? ?a = AW * (1.0 / self.tpr)
? ? ? ? ? ?b = BW * self.fpr
? ? ? ? ? ?c = CW * (n / get_number_of_inputs())
? ? ? ? ? ?self.__fitness = a + b + c
? ? ? ?return self.__fitness
? ?def mutate(self, prop):
? ? ? ?self.__x = [self.__x[i] if prop <= rand.uniform(0, 1) else 1 - self.__x[i]
? ? ? ? ? ? ? ? ? ?for i in range(0, get_number_of_inputs())]
? ? ? ?self.__fitness = None
? ? ? ?return self
? ?def __get_id(self):
? ? ? ?return "-".join(map(str, self.__x))
? ?def __str__(self):
? ? ? ?return "[" + ", ".join(format(x, "6.6f") for x in self.__x) + "] " + str(self.fitness())
? ?def __hash__(self):
? ? ? ?return hash(self.__get_id())
? ?def __eq__(self, other):
? ? ? ?return isinstance(other, Pigeon) and self.__get_id() == other.__get_id()
? ?def attr(self):
? ? ? ?return get_attr(self.__x)
3 仿真結(jié)果

4 參考文獻(xiàn)
[1]馬萌萌. 基于深度學(xué)習(xí)的極限學(xué)習(xí)機(jī)算法研究[D]. 中國海洋大學(xué), 2015.
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號處理、元胞自動機(jī)、圖像處理、路徑規(guī)劃、無人機(jī)等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。
