代码拉取完成,页面将自动刷新
同步操作将从 ZzqiZQute/BPNNDemoQt 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "trainthread.h"
#include "bpnetworkqt.h"
#include "mainwindow.h"
#include "surface.h"
#include "surfacenode.h"
#include <QMutex>
TrainThread::TrainThread(MainWindow* window, Surface* surface, BPNetworkQt *network, QMutex* mutex):
mNetwork(network),
mWindow(window),
mSurface(surface),
mMutex(mutex)
{
mChanged=false;
mPause=false;
mClassCnt=mWindow->getClassifierCnt();
}
TrainThread::~TrainThread()
{
}
int TrainThread::type() const
{
return mType;
}
void TrainThread::setType(int type)
{
mType = type;
}
double TrainThread::err() const
{
return mErr;
}
void TrainThread::setErr(double err)
{
mErr = err;
}
int TrainThread::time() const
{
return mTime;
}
void TrainThread::setTime(int time)
{
mTime = time;
}
void TrainThread::onDataChanged()
{
mChanged=true;
}
void TrainThread::onResetTrainCnt()
{
mNetwork->reset();
}
void TrainThread::onStop()
{
emit sigStop();
}
void TrainThread::onPause(int i)
{
if(i==0)
{
mPause=true;
}else{
mPause=false;
}
}
void TrainThread::onLearnRateChanged(double value)
{
mNetwork->setLearnRate(value);
}
void TrainThread::train()
{
if(mChanged)
{
mChanged=false;
QList<SurfaceNode> mNodeList=mSurface->nodeList();
int dim=mNodeList.count();
mNetwork->setSampleDim(dim);
double* d=new double[dim];
for(int i=0;i<dim;i++)
{
d[i]=mNodeList.at(i).pos().x();
}
mNetwork->setInput(0,d);
d=new double[dim];
for(int i=0;i<dim;i++)
{
d[i]=1.0-mNodeList.at(i).pos().y();
}
mNetwork->setInput(1,d);
int typecnt=mWindow->getClassifierCnt();
for(int j=0;j<typecnt;j++)
{
d=new double[dim];
for(int i=0;i<dim;i++)
{
d[i]=mNodeList.at(i).type()==j?1.0:0;
}
mNetwork->setOutput(j,d);
}
}
mMutex->lock();
mCurrentErr=mNetwork->train();
mMutex->unlock();
emit trainOnce(mNetwork->getTrainCnt(),mCurrentErr);
//QThread::usleep(0);
}
void TrainThread::run()
{
if(mType==0)
{
if(mNetwork->checkSample())
{
mNetwork->reset();
while(mNetwork->getTrainCnt()<mTime){
while(mPause);
train();
}
emit trainFinished();
}
}else if(mType==1){
if(mNetwork->checkSample())
{
mNetwork->reset();
mCurrentErr=mErr+1;
while(mCurrentErr>=mErr){
while(mPause);
train();
}
emit trainFinished();
}
}else{
if(mNetwork->checkSample())
{
mNetwork->reset();
while(1){
while(mPause);
train();
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。