为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 股票分析> 正文

神经网络在股票分析开题报告(股票分析 神经网络)

发布时间:2022-03-04-20:10:14 来源:卫信股票网 股票分析

跨境电子商务案例分析论文开题报告怎么?跨境电子商务案例分析论文开

跨境电子商务的,案例分析OK开题报告

神经网络在股票分析开题报告

行业现状分析怎么写-存在问题及发展前景分析开题报告怎么?我国证券市场的现状、存在问题

这是一篇模板,你可以看看的

数学建模 有一种学派 叫神经网络派 无论什么问题

一种神经网络建模方法。属于智能信息处理技术领域。基于结构风险最小化原则,结合合作协作进化算法,同时进行神经网络的网络结构和连接权值学习,最终得到网络结构和连接权值之间最优折衷,方法具体包括数据处理、网络学习和网络估计预测三个基本步骤。同时进行网络结构和连接权值的学习,较好地解决了传统神经网络学习中存在的结果与初始值相关、收敛速度慢、易陷于局部最小值、误差函数必须可导、过学习等实际问题,提高了网络的学习能力和泛化能力。可应用于心脏病智能诊断、工业领域中的故障诊断、软测量等,经济领域的股票价格预测、商品价格预测等假设输入的是5个参数,输出1个参数。

神经网络的节点结构为 5-n-1(n是中间层节点数,数目根据实验效果确定,可选5~10个)

关于输入延迟,不清楚意思。

是否可以做这样的数据处理:

假设t 时间的5个输入数据和t+1时间的1个输出数据对应,则以这一对数据作为训练样本,也不需要其理解神经网络中的延时处理机制。

训练函数写法:net=train(net,t 时间的输入数据,t+1时间的输入数据);

神经网络在股票分析开题报告

神经网络算法 实验报告 C++

算法数值实验

一、实验目的

Matlab

软件神经网络工具箱的使用;

神经网络的基本工作原理;

神经网络的基本应用

Matlab

程序设计的基本方法

二、实验内容

给定七个输入的单层神经元以及输入

,比较不同传递函数所得到的输出结

果.其中网络权值向量

[ 0 .

0 .

0 .

0 .

0 .

0 .

0 .

,网络输入

[ 1 .

0 .

1 .

0 .

0 .

1 .

训练一个隐层(含五个神经元)的单输出

网络,给出动态逼近过程和训练

好的权值和闻值.

设定精度要求,并利用输入和目标进行训练;

画出样本点示意图;

在同一个图上画出样本点示意图.// annbp.cpp: implementation of the cannbp class.

//

//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "annbp.h"

#include "math.h"

//////////////////////////////////////////////////////////////////////

// construction/destruction

//////////////////////////////////////////////////////////////////////

cannbp::cannbp()

eta1=0.3;

momentum1=0.3;

cannbp::~cannbp()

double cannbp::drnd()

return ((double) rand() / (double) bigrnd);

/*** 返回-1.0到1.0之间的双精度随机数 ***/

double cannbp::dpn1()

return (double) (rand())/(32767/2)-1;

/*** 作用函数,目前是s型函数 ***/

double cannbp::squash(double x)

return (1.0 / (1.0 + exp(-x)));

/*** 申请1维双精度实数数组 ***/

double* cannbp::alloc_1d_dbl(int n)

double *new1;

new1 = (double *) malloc ((unsigned) (n * sizeof (double)));

if (new1 == null) {

afxmessagebox("alloc_1d_dbl: couldn't allocate array of doubles\n");

return (null);

}

return (new1);

/*** 申请2维双精度实数数组 ***/

double** cannbp::alloc_2d_dbl(int m, int n)

int i;

double **new1;

new1 = (double **) malloc ((unsigned) (m * sizeof (double *)));

if (new1 == null) {

afxmessagebox("alloc_2d_dbl: couldn't allocate array of dbl ptrs\n");

return (null);

}

for (i = 0; i < m; i++) {

new1[i] = alloc_1d_dbl(n);

}

return (new1);

/*** 随机初始化权值 ***/

void cannbp::bpnn_randomize_weights(double **w, int m, int n)

int i, j;

for (i = 0; i <= m; i++) {

for (j = 0; j <= n; j++) {

w[i][j] = dpn1();

}

}

/*** 0初始化权值 ***/

void cannbp::bpnn_zero_weights(double **w, int m, int n)

int i, j;

for (i = 0; i <= m; i++) {

for (j = 0; j <= n; j++) {

w[i][j] = 0.0;

}

}

/*** 设置随机数种子 ***/

void cannbp::bpnn_initialize(int seed)

cstring msg,s;

msg="random number generator seed:";

s.format("%d",seed);

afxmessagebox(msg+s);

srand(seed);

/*** 创建bp网络 ***/

bpnn* cannbp::bpnn_internal_create(int n_in, int n_hidden, int n_out)

bpnn *newnet;

newnet = (bpnn *) malloc (sizeof (bpnn));

if (newnet == null) {

printf("bpnn_create: couldn't allocate neural network\n");

return (null);

}

newnet->input_n = n_in;

newnet->hidden_n = n_hidden;

newnet->output_n = n_out;

newnet->input_units = alloc_1d_dbl(n_in + 1);

newnet->hidden_units = alloc_1d_dbl(n_hidden + 1);

newnet->output_units = alloc_1d_dbl(n_out + 1);

newnet->hidden_delta = alloc_1d_dbl(n_hidden + 1);

newnet->output_delta = alloc_1d_dbl(n_out + 1);

newnet->target = alloc_1d_dbl(n_out + 1);

newnet->input_weights = alloc_2d_dbl(n_in + 1, n_hidden + 1);

newnet->hidden_weights = alloc_2d_dbl(n_hidden + 1, n_out + 1);

newnet->input_prev_weights = alloc_2d_dbl(n_in + 1, n_hidden + 1);

newnet->hidden_prev_weights = alloc_2d_dbl(n_hidden + 1, n_out + 1);

return (newnet);

/* 释放bp网络所占地内存空间 */

void cannbp::bpnn_free(bpnn *net)

int n1, n2, i;

n1 = net->input_n;

n2 = net->hidden_n;

free((char *) net->input_units);

free((char *) net->hidden_units);

free((char *) net->output_units);

free((char *) net->hidden_delta);

free((char *) net->output_delta);

free((char *) net->target);

for (i = 0; i <= n1; i++) {

free((char *) net->input_weights[i]);

free((char *) net->input_prev_weights[i]);

}

free((char *) net->input_weights);

free((char *) net->input_prev_weights);

for (i = 0; i <= n2; i++) {

free((char *) net->hidden_weights[i]);

free((char *) net->hidden_prev_weights[i]);

}

free((char *) net->hidden_weights);

free((char *) net->hidden_prev_weights);

free((char *) net);

/*** 创建一个bp网络,并初始化权值***/

bpnn* cannbp::bpnn_create(int n_in, int n_hidden, int n_out)

bpnn *newnet;

newnet = bpnn_internal_create(n_in, n_hidden, n_out);

#ifdef initzero

bpnn_zero_weights(newnet->input_weights, n_in, n_hidden);

#else

bpnn_randomize_weights(newnet->input_weights, n_in, n_hidden);

#endif

bpnn_randomize_weights(newnet->hidden_weights, n_hidden, n_out);

bpnn_zero_weights(newnet->input_prev_weights, n_in, n_hidden);

bpnn_zero_weights(newnet->hidden_prev_weights, n_hidden, n_out);

return (newnet);

void cannbp::bpnn_layerforward(double *l1, double *l2, double **conn, int n1, int n2)

double sum;

int j, k;

/*** 设置阈值 ***/

l1[0] = 1.0;

/*** 对于第二层的每个神经元 ***/

for (j = 1; j <= n2; j++) {

/*** 计算输入的加权总和 ***/

sum = 0.0;

for (k = 0; k <= n1; k++) {

sum += conn[k][j] * l1[k];

}

l2[j] = squash(sum);

}

/* 输出误差 */

void cannbp::bpnn_output_error(double *delta, double *target, double *output, int nj, double *err)

int j;

double o, t, errsum;

errsum = 0.0;

for (j = 1; j <= nj; j++) {

o = output[j];

t = target[j];

delta[j] = o * (1.0 - o) * (t - o);

errsum += abs(delta[j]);

}

*err = errsum;

/* 隐含层误差 */

void cannbp::bpnn_hidden_error(double *delta_h, int nh, double *delta_o, int no, double **who, double *hidden, double *err)

int j, k;

double h, sum, errsum;

errsum = 0.0;

for (j = 1; j <= nh; j++) {

h = hidden[j];

sum = 0.0;

for (k = 1; k <= no; k++) {

sum += delta_o[k] * who[j][k];

}

delta_h[j] = h * (1.0 - h) * sum;

errsum += abs(delta_h[j]);

}

*err = errsum;

/* 调整权值 */

void cannbp::bpnn_adjust_weights(double *delta, int ndelta, double *ly, int nly, double **w, double **oldw, double eta, double momentum)

double new_dw;

int k, j;

ly[0] = 1.0;

for (j = 1; j <= ndelta; j++) {

for (k = 0; k <= nly; k++) {

new_dw = ((eta * delta[j] * ly[k]) + (momentum * oldw[k][j]));

w[k][j] += new_dw;

oldw[k][j] = new_dw;

}

}

/* 进行前向运算 */

void cannbp::bpnn_feedforward(bpnn *net)

int in, hid, out;

in = net->input_n;

hid = net->hidden_n;

out = net->output_n;

/*** feed forward input activations. ***/

bpnn_layerforward(net->input_units, net->hidden_units,

net->input_weights, in, hid);

bpnn_layerforward(net->hidden_units, net->output_units,

net->hidden_weights, hid, out);

/* 训练bp网络 */

void cannbp::bpnn_train(bpnn *net, double eta, double momentum, double *eo, double *eh)

int in, hid, out;

double out_err, hid_err;

in = net->input_n;

hid = net->hidden_n;

out = net->output_n;

/*** 前向输入激活 ***/

bpnn_layerforward(net->input_units, net->hidden_units,

net->input_weights, in, hid);

bpnn_layerforward(net->hidden_units, net->output_units,

net->hidden_weights, hid, out);

/*** 计算隐含层和输出层误差 ***/

bpnn_output_error(net->output_delta, net->target, net->output_units,

out, &out_err);

bpnn_hidden_error(net->hidden_delta, hid, net->output_delta, out,

net->hidden_weights, net->hidden_units, &hid_err);

*eo = out_err;

*eh = hid_err;

/*** 调整输入层和隐含层权值 ***/

bpnn_adjust_weights(net->output_delta, out, net->hidden_units, hid,

net->hidden_weights, net->hidden_prev_weights, eta, momentum);

bpnn_adjust_weights(net->hidden_delta, hid, net->input_units, in,

net->input_weights, net->input_prev_weights, eta, momentum);

/* 保存bp网络 */

void cannbp::bpnn_save(bpnn *net, char *filename)

cfile file;

char *mem;

int n1, n2, n3, i, j, memcnt;

double dvalue, **w;

n1 = net->input_n; n2 = net->hidden_n; n3 = net->output_n;

printf("saving %dx%dx%d network to '%s'\n", n1, n2, n3, filename);

try

{

file.open(filename,cfile::modewrite|cfile::modecreate|cfile::modenotruncate);

}

catch(cfileexception* e)

{

e->reporterror();

e->delete();

}

file.write(&n1,sizeof(int));

file.write(&n2,sizeof(int));

file.write(&n3,sizeof(int));

memcnt = 0;

w = net->input_weights;

mem = (char *) malloc ((unsigned) ((n1+1) * (n2+1) * sizeof(double)));

// mem = (char *) malloc (((n1+1) * (n2+1) * sizeof(double)));

for (i = 0; i <= n1; i++) {

for (j = 0; j <= n2; j++) {

dvalue = w[i][j];

//fastcopy(&mem[memcnt], &dvalue, sizeof(double));

fastcopy(&mem[memcnt], &dvalue, sizeof(double));

memcnt += sizeof(double);

}

}

file.write(mem,sizeof(double)*(n1+1)*(n2+1));

free(mem);

memcnt = 0;

w = net->hidden_weights;

mem = (char *) malloc ((unsigned) ((n2+1) * (n3+1) * sizeof(double)));

// mem = (char *) malloc (((n2+1) * (n3+1) * sizeof(double)));

for (i = 0; i <= n2; i++) {

for (j = 0; j <= n3; j++) {

dvalue = w[i][j];

fastcopy(&mem[memcnt], &dvalue, sizeof(double));

//fastcopy(&mem[memcnt], &dvalue, sizeof(double));

memcnt += sizeof(double);

}

}

file.write(mem, (n2+1) * (n3+1) * sizeof(double));

// free(mem);

file.close();

return;

/* 从文件中读取bp网络 */

bpnn* cannbp::bpnn_read(char *filename)

char *mem;

bpnn *new1;

int n1, n2, n3, i, j, memcnt;

cfile file;

try

{

file.open(filename,cfile::moderead|cfile::modecreate|cfile::modenotruncate);

}

catch(cfileexception* e)

{

e->reporterror();

e->delete();

}

// printf("reading '%s'\n", filename);// fflush(stdout);

file.read(&n1, sizeof(int));

file.read(&n2, sizeof(int));

file.read(&n3, sizeof(int));

new1 = bpnn_internal_create(n1, n2, n3);

// printf("'%s' contains a %dx%dx%d network\n", filename, n1, n2, n3);

// printf("reading input weights..."); // fflush(stdout);

memcnt = 0;

mem = (char *) malloc (((n1+1) * (n2+1) * sizeof(double)));

file.read(mem, ((n1+1)*(n2+1))*sizeof(double));

for (i = 0; i <= n1; i++) {

for (j = 0; j <= n2; j++) {

//fastcopy(&(new1->input_weights[i][j]), &mem[memcnt], sizeof(double));

fastcopy(&(new1->input_weights[i][j]), &mem[memcnt], sizeof(double));

memcnt += sizeof(double);

}

}

free(mem);

// printf("done\nreading hidden weights..."); //fflush(stdout);

memcnt = 0;

mem = (char *) malloc (((n2+1) * (n3+1) * sizeof(double)));

file.read(mem, (n2+1) * (n3+1) * sizeof(double));

for (i = 0; i <= n2; i++) {

for (j = 0; j <= n3; j++) {

//fastcopy(&(new1->hidden_weights[i][j]), &mem[memcnt], sizeof(double));

fastcopy(&(new1->hidden_weights[i][j]), &mem[memcnt], sizeof(double));

memcnt += sizeof(double);

}

}

free(mem);

file.close();

printf("done\n"); //fflush(stdout);

bpnn_zero_weights(new1->input_prev_weights, n1, n2);

bpnn_zero_weights(new1->hidden_prev_weights, n2, n3);

return (new1);

void cannbp::createbp(int n_in, int n_hidden, int n_out)

net=bpnn_create(n_in,n_hidden,n_out);

void cannbp::freebp()

bpnn_free(net);

void cannbp::train(double *input_unit,int input_num, double *target,int target_num, double *eo, double *eh)

for(int i=1;i<=input_num;i++)

{

net->input_units[i]=input_unit[i-1];

}

for(int j=1;j<=target_num;j++)

{

net->target[j]=target[j-1];

}

bpnn_train(net,eta1,momentum1,eo,eh);

void cannbp::identify(double *input_unit,int input_num,double *target,int target_num)

for(int i=1;i<=input_num;i++)

{

net->input_units[i]=input_unit[i-1];

}

bpnn_feedforward(net);

for(int j=1;j<=target_num;j++)

{

target[j-1]=net->output_units[j];

}

void cannbp::save(char *filename)

bpnn_save(net,filename);

void cannbp::read(char *filename)

net=bpnn_read(filename);

void cannbp::setbparm(double eta, double momentum)

eta1=eta;

momentum1=momentum;

void cannbp::initialize(int seed)

bpnn_initialize(seed);