bool NNet::createNet( int numberOfInputs, int numberOfOutputs, std::vector<int> layerSize ) { int numberOfCells = 0; std::vector<int> _layerSize; std::vector<int> inputs; std::vector<int> outputs; _layerSize.push_back( numberOfInputs ); // adding hidden layers for ( int i = 0; i < layerSize.size();i++ ) { _layerSize.push_back( layerSize[i] ); } _layerSize.push_back( numberOfOutputs ); std::vector<netConnection> connections; // find out numberOfCells for ( int i = 0; i < _layerSize.size(); i++ ) { numberOfCells += _layerSize[i]; } // create input indices for ( int i = 0; i < numberOfInputs; i++ ) { inputs.push_back( i ); } // create output indices for ( int i = 0; i < numberOfOutputs; i++ ) { outputs.push_back( numberOfCells - numberOfOutputs + i ); } // create connections int offset = 0; for ( int i = 0; i < _layerSize.size() - 1;i++ ) { int count = 0; for ( int j = offset; j < offset + _layerSize[i];j++ ) { int nextOffset = offset + _layerSize[i]; for ( int k = nextOffset; k < nextOffset + _layerSize[i+1];k++ ) { //std::cout << "S: " << j << " R: " << k << std::endl; connections.push_back( netConnection( j, k, 0 ) ); } count++; } offset += count; } generateNet( inputs, outputs, connections ); }
void SpotWorker::startServer() { tcpServer_ = new QTcpServer(this); if (!tcpServer_->listen(QHostAddress::Any, 2718)) { /* QMessageBox::warning(this, tr("Error"), tr("Failed to start server: %1.") .arg(anyWho->errorString())); */ DEBUG printf("SpotWorker::startServer(): Epic error!\n"); return; } DEBUG printf("TCP server started!\n"); connect(tcpServer_, SIGNAL(newConnection()), this, SLOT(netConnection()) ); }
bool NNet::readConnectionSection( std::ifstream &f ) { std::vector <std::string> connectionStrList; /*----------------------------------------- Read Connection Information ------------------------------------------*/ while ( !f.eof() ) { std::string tmpStr; f >> tmpStr; if ( tmpStr[ 0 ] == '#' ) { getline( f, tmpStr ); } else { connectionStrList.push_back( tmpStr ); } if ( tmpStr == "</connections>" ) break; } if ( connectionStrList[ 0 ] != "<connections>" ) { std::cerr << "Error: Connections section missing!" << std::endl; return false; } if ( connectionStrList[ connectionStrList.size() - 1 ] != "</connections>" ) { std::cerr << "Error: Missing </connections>!" << std::endl; return false; } /*-------------------------------------------- Convert connectionList to netList Start with i = 1 because first entry is <connections> tag. Stop with < connectionList.size() - 2 because size is one too much and last entry is </conections> tag. This concerns also most of the following for-loops ----------------------------------------------*/ if (( connectionStrList.size() - 2 ) % 3 != 0 ) { std::cerr << "Error: Wrong number of Entries in \"<connections> </connections>\" - Section!" << std::endl; return false; } for ( unsigned int i = 1;i < connectionStrList.size() - 2;i += 3 ) { int tmpVal = atoi( connectionStrList[ i ].c_str() ); if (( connectionStrList[ i ] != "0" ) && ( tmpVal == 0 ) ) { std::cerr << "Error: Entry " << i << " in \"<connections> </connections>\" - Section is not a valid integer number!" << std::endl; return false; } tmpVal = atoi( connectionStrList[ i + 1 ].c_str() ); if (( connectionStrList[ i + 1 ] != "0" ) && ( tmpVal == 0 ) ) { std::cerr << "Error: Entry " << i + 1 << " in \"<connections> </connections>\" - Section is not a valid integer number!" << std::endl; return false; } double tmpVal2 = atof( connectionStrList[ i + 2 ].c_str() ); if (( connectionStrList[ i + 2 ] != "0" ) && ( tmpVal2 == 0 ) ) { std::cerr << "Error: Entry " << i + 2 << " in \"<connections> </connections>\" - Section is not a valid floating point number!" << std::endl; return false; } // netConnection tmpConnection; // tmpConnection(connectionStrList[ i ],connectionStrList[ i + 1 ],connectionStrList[ i + 2 ]); connectionList.push_back( netConnection( connectionStrList[ i ], connectionStrList[ i + 1 ], connectionStrList[ i + 2 ] ) ); } return true; }