#使用bp用神经网络算法预测风化前后变化值 import numpy as ggfrom numpy import dot random ones_like exp ones zeros multiply zeros_likeimport matplotlibpyplot as pltimport math # 若是10个作为数据 先以铅钡二氧化硅为例 使用风化后预测风化前# 三类数据输入每类取7
import numpy as np from numpy import dot, random, ones_like, exp, ones, zeros, multiply, zeros_like import matplotlib.pyplot as plt import math
若是10个作为数据 先以铅钡二氧化硅为例 使用风化后预测风化前
三类数据输入,每类取7个作为训练数据,3个作为测试数据 先是测试模拟
定义三类数据
kind1 = np.array([[51.26, 3.16, 2.87], [19.79, 2.32, -5.8], [39.57, 2.18, -3.39], [35.78, 1.21, -4.73], [20.14, 1.58, -4.78], [33.59, 1.01, -3.63], [25.42, 1.40, -1.89], [29.15, 1.44, -3.22], [17.98, 1.33, -4.38], [12.38, 1.33, -4.38]], dtype=float).reshape(-1, 3) label1 = np.zeros_like(kind1) label1[:, 0] = ones([len(label1)], dtype=float) kind1 = np.hstack((kind1, label1)) ext = np.ones(len(kind1)) ext = ext.reshape(10, -1) kind1 = np.hstack((ext, kind1))
kind2 = np.array([[-0.24, 0.93, -1.01], [-1.18, 0.39, -0.39], [0.74, 0.96, -1.16], [-0.38, 1.94, -0.48], [0.02, 0.72, -0.17], [0.44, 1.31, -0.14], [0.21, 0.03, -2.21], [0.37, 0.28, -1.8], [0.18, 1.22, 0.16], [0.46, 1.49, 0.68]]).reshape(-1, 3) label2 = zeros_like(kind2) label2[:, 1] = ones([len(label2)], dtype=float) kind2 = np.hstack((ext, kind2, label2))
kind3 = np.array([[31.94, 1.17, 0.64], [36.93, 3.45, -1.33], [55.21, 0.99, 2.69], [34.34, 3.19, 1.51], [44.26, 1.79, -0.87], [22.65, -0.22, -1.39], [18.96, -0.44, -0.92], [32.65, 0.83, 1.97], [33.44, 0.68, -0.99], [48.12, -0.45, 0.08]]).reshape(-1, 3) label3 = zeros_like(kind3) label3[:, 2] = ones([len(label3)], dtype=float) kind3 = np.hstack((ext, kind3, label3))
将三类数据合并为一个数据集
all_kind = np.vstack((kind1, kind2, kind3))
将训练数据和测试数据分开
train_mate = np.vstack((kind1[:7], kind2[:7], kind3[:7])) test_mate = np.vstack((kind1[7:], kind2[7:], kind3[7:]))
函数及导数预测
def ta_h(x): return math.tanh(x)
def diff_tag_h(x): return 1.0 / (1 + pow(x, 2))
sigmoid函数
def sigmoid(x): return 1.0 / (1 + exp(-x))
sigmoid函数的导数
def diff_sigmoid(x): out = sigmoid(x) return out * (1 - out)
原文地址: https://www.cveoy.top/t/topic/h5Mz 著作权归作者所有。请勿转载和采集!