// BpNet.h:interfacefortheBpclass. // // E-Mail:zengzhijun369@163.com /**/ ///////////////////////////////////////////////////////////////////// / #include stdafx.h #include BpNet.h #include math.h #ifdef_DEBUG #undef THIS_FILE static char
//BpNet.h: interface for the Bp class.
//
//E-Mail:zengzhijun369@163.com
/**///////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BpNet.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/**///////////////////////////////////////////////////////////////////////
// Construction/Destruction
/**///////////////////////////////////////////////////////////////////////
BpNet::BpNet()
{
error=1.0;
e=0.0;
rate_w=0.05; //权值学习率(输入层--隐含层)
rate_w1=0.047; //权值学习率 (隐含层--输出层)
rate_b1=0.05; //隐含层阀值学习率
rate_b2=0.047; //输出层阀值学习率
error=1.0;
e=0.0;
rate_w=0.05; //权值学习率(输入层--隐含层)
rate_w1=0.047; //权值学习率 (隐含层--输出层)
rate_b1=0.05; //隐含层阀值学习率
rate_b2=0.047; //输出层阀值学习率
}
BpNet::~BpNet()
{
}
void winit(double w[],int sl)//权值初始化
{int i;
double randx();
for(i=0;isl;i++)
{
*(w+i)=0.2*randx();
}
}
double randx()//kqy error
{double d;
d=(double) rand()/32767.0;
return d;
}
void BpNet::init()
{
winit((double*)w,innode*hidenode);
winit((double*)w1,hidenode*outnode);
winit(b1,hidenode);
winit(b2,outnode);
}
void BpNet::train(double p[trainsample][innode],double t[trainsample][outnode])
{
double pp[hidenode];//隐含结点的校正误差
double qq[outnode];//希望输出值与实际输出值的偏差
double yd[outnode];//希望输出值
double x[innode]; //输入向量
double x1[hidenode];//隐含结点状态值
double x2[outnode];//输出结点状态值
double o1[hidenode];//隐含层激活值
double o2[hidenode];//输出层激活值
for(int isamp=0;isamptrainsample;isamp++)//循环训练一次样品
{
for(int i=0;iinnode;i++)
x[i]=p[isamp][i];
for(i=0;ioutnode;i++)
yd[i]=t[isamp][i];
//构造每个样品的输入和输出标准
for(int j=0;jhidenode;j++)
{
o1[j]=0.0;
for(i=0;iinnode;i++)
o1[j]=o1[j]+w[i][j]*x[i];//隐含层各单元输入激活值
x1[j]=1.0/(1+exp(-o1[j]-b1[j]));//隐含层各单元的输出kqy1
// if(o1[j]+b1[j]>0) x1[j]=1;
//else x1[j]=0;
}
for(int k=0;koutnode;k++)
{
o2[k]=0.0;
for(j=0;jhidenode;j++)
o2[k]=o2[k]+w1[j][k]*x1[j];//输出层各单元输入激活值
x2[k]=1.0/(1.0+exp(-o2[k]-b2[k]));//输出层各单元输出
// if(o2[k]+b2[k]>0) x2[k]=1;
// else x2[k]=0;
}
for(k=0;koutnode;k++)
{
e=0.0;
qq[k]=(yd[k]-x2[k])*x2[k]*(1.-x2[k]);//希望输出与实际输出的偏差
e+=fabs(yd[k]-x2[k])*fabs(yd[k]-x2[k]);//计算均方差
for(j=0;jhidenode;j++)
w1[j][k]=w1[j][k]+rate_w1*qq[k]*x1[j];//下一次的隐含层和输出层之间的新连接权
e=sqrt(e);
error=e;
}
for(j=0;jhidenode;j++)
{
pp[j]=0.0;
for(k=0;koutnode;k++)
pp[j]=pp[j]+qq[k]*w1[j][k];
pp[j]=pp[j]*x1[j]*(1-x1[j]);//隐含层的校正误差
for(i=0;iinnode;i++)
w[i][j]=w[i][j]+rate_w*pp[j]*x[i];//下一次的输入层和隐含层之间的新连接权
}
for(k=0;koutnode;k++)
b2[k]=b2[k]+rate_b2*qq[k];//下一次的隐含层和输出层之间的新阈值
for(j=0;jhidenode;j++)
b1[j]=b1[j]+rate_b1*pp[j];//下一次的输入层和隐含层之间的新阈值
}//end isamp样品循环
}
/**////////////////////////////end train/////////////////////////////
/////////////////////////////////////////////////////////////////
double *BpNet::recognize(double *p)
{
double x[innode]; //输入向量
double x1[hidenode];//隐含结点状态值
double x2[outnode];//输出结点状态值
double o1[hidenode];//隐含层激活值
double o2[hidenode];//输出层激活值
for(int i=0;iinnode;i++)
x[i]=p[i];
for(int j=0;jhidenode;j++)
{
o1[j]=0.0;
for(int i=0;iinnode;i++)
o1[j]=o1[j]+w[i][j]*x[i];//隐含层各单元激活值
x1[j]=1.0/(1.0+exp(-o1[j]-b1[j]));//隐含层各单元输出
//if(o1[j]+b1[j]>0) x1[j]=1;
// else x1[j]=0;
}
for(int k=0;koutnode;k++)
{
o2[k]=0.0;
for(int j=0;jhidenode;j++)
o2[k]=o2[k]+w1[j][k]*x1[j];//输出层各单元激活值
x2[k]=1.0/(1.0+exp(-o2[k]-b2[k]));//输出层各单元输出
//if(o2[k]+b2[k]>0) x2[k]=1;
//else x2[k]=0;
}
for(k=0;koutnode;k++)
{
shuchu[k]=x2[k];
}
return shuchu;
}/**/////////////////////////////end sim///////////////////////////
void BpNet::writetrain()
{//曾志军 for 2006.7
AfxMessageBox("你还没有训练呢,训练后再写吧!请不要乱写,除非你认为这次训练是最好的,否则会覆盖我训练好的权值,那样你又要花时间训练!");
AfxMessageBox("你认为这次训练结果是最好的,就存下来,下次就不要花时间训练了!",MB_YESNO,NULL);
FILE *stream0;
FILE *stream1;
FILE *stream2;
FILE *stream3;

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version
