基于长短期记忆网络和凸优化算法的综合智能电网的可再生能源预测(Python代码实现)

👨‍🎓个人主页:研学社的博客 

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Python代码、数据


💥1 概述

技术的进步使可再生能源(太阳能、风能等)得以大规模利用。将传统能源和可再生能源相结合的智能电网被认为是一种可持续的发电解决方案。然而,所有可再生能源都受到环境因素(如风速、太阳辐射强度、云层)的影响,这些因素会导致这些能源产生的电力波动。此外,可用性受每日/年度周期的影响(例如,太阳能仅在白天可用)。而智能计量支持实时需求预测;还需要预测可再生能源发电量的精确模型。准确的预测模型将确保电网稳定、顺利调度和能源管理。例如,如果模型预测可再生能源在一定时间段内中断,智能电网必须在该时间段内无缝切换到传统能源,并确保发电量满足需求预测。本文提出了基于数据源的各种基于学习的可再生能源预测模型;以及用于供需匹配的调度策略。此外,还可以使用模拟软件对微电网进行真实建模。这里定义的问题是提出一个框架:现实地模拟微电网;预测(可再生)能源的需求和供应;无缝安排可再生能源(和常规能源)供应以满足需求;并提供关于智能电网系统功能的可操作见解。

方法:

  1. 微电网/公用事业系统的模拟。
  2. 使用统计/机器学习方法开发能源生产预测模型。(使用长短期记忆网络(LSTMs)和向量自动回归(VAR)完成 - 提供代码)。
  3. 使用表征良好的优化算法为公用事业/微电网控制器开发调度系统(通过使用凸优化算法模块 Cvxpy 完成 - 提供的代码)。
  4. 最后一步是将预测模型和调度程序与仿真设置集成在一起.

📚2 运行结果

 

 

 部分代码:

#To be called at every 24 hour distribution, generates the demand supply distribution
def dataGenerator(XTestSolarHour, XTestWindHour, XTestDemandHour, weighs):
  #Solar Energy generation
  yPredSolar = model.predict(XTestSolarHour)
  XTestSolarHour = XTestSolarHour.reshape((XTestSolarHour.shape[0],XTestSolarHour.shape[2]))
  invyPredSolar = np.concatenate((yPredSolar, XTestSolarHour[:, 1:]), axis = 1)
  invyPredSolar = scalerOne.inverse_transform(invyPredSolar)
  invyPredSolar = invyPredSolar[:, 0]

  # yTestSolar = yTestSolar.reshape((len(yTestSolar), 1))
  # invyTestSolar = np.concatenate((yTestSolar, XTestSolar[:, 1:]), axis = 1)
  # invyTestSolar = scalerOne.inverse_transform(invyTestSolar)
  # invyTestSolar = invyTestSolar[:, 0]

  #Wind Energy Generation
  yPredWind = modelOne.predict(XTestWindHour)
  XTestWindHour = XTestWindHour.reshape((XTestWindHour.shape[0],XTestWindHour.shape[2]))
  invyPredWind = np.concatenate((yPredWind, XTestWindHour[:, 1:]), axis = 1)
  invyPredWind = scalerTwo.inverse_transform(invyPredWind)
  invyPredWind = invyPredWind[:, 0]

  # yTestWind = yTestWind.reshape((len(yTestWind), 1))
  # invyTestWind = np.concatenate((yTestWind, XTestWind[:, 1:]), axis = 1)
  # invyTestWind = scalerTwo.inverse_transform(invyTestWind)
  # invyTestWind = invyTestWind[:, 0]

  #Demand
  yPredDemand = modelTwo.predict(XTestDemandHour)
  XTestDemandHour = XTestDemandHour.reshape((XTestDemandHour.shape[0],XTestDemandHour.shape[2]))
  invyPredDemand = np.concatenate((yPredDemand, XTestDemandHour[:, 1:]), axis = 1)
  invyPredDemand = scalerThree.inverse_transform(invyPredDemand)
  invyPredDemand = invyPredDemand[:, 0]
    
  # yTestDemand = yTestDemand.reshape((len(yTestDemand), 1))
  # invyTestDemand = np.concatenate((yTestDemand, XTestDemand[:, 1:]), axis = 1)
  # invyTestDemand = scalerThree.inverse_transform(invyTestDemand)
  # invyTestDemand = invyTestDemand[:, 0]

  #Elastic and Inelastic demand
  invyPredDemandInElastic = 0.7*invyPredDemand
  invyPredDemandElastic = 0.3*invyPredDemand
  elasticDemandSum = np.sum(invyPredDemandElastic)

  #Renewable energy output
  renewableEnergyOutput = invyPredSolar + invyPredWind

  #Splitting the above into different prosumers according to a schema, of course in real life, with more computational power
  #One can train separately for each prosumer
  arrayinvyPredDemandInelastic = np.outer(np.array(weighs), np.array(invyPredDemandInElastic))
  arrayRenewableEnergyOutput = np.outer(np.array(weighs), np.array(renewableEnergyOutput))
  arrayElasticDemandSum = np.array(weighs)*elasticDemandSum

  #returns

  return arrayinvyPredDemandInelastic, arrayRenewableEnergyOutput, arrayElasticDemandSum

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]王辉. 基于LSTM模型的环渤海地区可再生能源预测研究[D].天津理工大学,2020.DOI:10.27360/d.cnki.gtlgy.2020.000309.

[2]范刘洋. 考虑可再生能源预测误差的电力系统鲁棒调度研究[D].上海交通大学,2017.

🌈4 Python代码、数据

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
蜣螂优化算法(Cockroach Swarm Optimization,CSO)可以用于优化神经网络的参数。以下是使用CSO算法优化长短期记忆神经网络(LSTM)的Python代码实现。 首先,我们需要导入必要的库和模块: ```python import numpy as np import math import random import copy import matplotlib.pyplot as plt from keras.models import Sequential from keras.layers import Dense, LSTM from sklearn.metrics import mean_squared_error ``` 然后,我们可以定义一些常量和函数: ```python # 定义常量 POP_SIZE = 20 # 种群数量 DIM = 20 # 参数数量 MAX_GEN = 100 # 迭代次数 UPPER_BOUND = 1 # 参数上界 LOWER_BOUND = -1 # 参数下界 ALPHA = 0.5 # 振幅因子 BETA = 0.5 # 速度因子 GAMMA = 0.5 # 随机因子 CR = 0.5 # 交叉率 F = 1 # 缩放因子 H = 0.1 # 步长因子 ITER = 10 # 迭代次数 # 定义函数 def sigmoid(x): return 1 / (1 + np.exp(-x)) def lstm_model(params): model = Sequential() model.add(LSTM(units=int(params[0]), input_shape=(1, 1), activation=sigmoid, recurrent_activation=sigmoid)) model.add(Dense(units=1)) model.compile(optimizer='adam', loss='mse') return model def evaluate(individual): model = lstm_model(individual) x_train = np.array([[[1]]]) y_train = np.array([0]) for i in range(ITER): model.fit(x_train, y_train, epochs=1, verbose=0) y_pred = model.predict(x_train) y_train = y_pred return mean_squared_error(y_train, [0]) def init_population(pop_size, dim): population = [] for i in range(pop_size): individual = np.random.uniform(LOWER_BOUND, UPPER_BOUND, dim) population.append(individual) return population def select(population, fitness): idx1 = random.randint(0, len(population) - 1) idx2 = random.randint(0, len(population) - 1) if fitness[idx1] < fitness[idx2]: return copy.deepcopy(population[idx1]) else: return copy.deepcopy(population[idx2]) def cso(): population = init_population(POP_SIZE, DIM) fitness = [evaluate(individual) for individual in population] best_individual = copy.deepcopy(population[np.argmin(fitness)]) best_fitness = min(fitness) for i in range(MAX_GEN): new_population = [] for j in range(POP_SIZE): x = copy.deepcopy(population[j]) y = select(population, fitness) z = select(population, fitness) v = np.clip(x + ALPHA * (y - z), LOWER_BOUND, UPPER_BOUND) r = np.random.uniform(0, 1, DIM) t = np.random.uniform(0, 1, DIM) for k in range(DIM): if r[k] < CR: v[k] = x[k] + F * (best_individual[k] - x[k]) + H * (t[k] - 0.5) u = np.clip(v + BETA * (best_individual - x), LOWER_BOUND, UPPER_BOUND) r = np.random.uniform(0, 1) if r < GAMMA: for k in range(DIM): u[k] = np.random.uniform(LOWER_BOUND, UPPER_BOUND) new_population.append(u) population = new_population fitness = [evaluate(individual) for individual in population] if min(fitness) < best_fitness: best_individual = copy.deepcopy(population[np.argmin(fitness)]) best_fitness = min(fitness) print('Generation %d, Best Fitness: %.8f' % (i + 1, best_fitness)) return best_individual ``` 最后,我们可以运行CSO算法并输出最优解: ```python best_individual = cso() print('Best Individual: ', best_individual) ``` 这样就完成了使用CSO算法优化LSTM神经网络Python代码实现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值