Пример #1
0
void CSvmModel::RunSvmPredict( const string& strDataFile, const string& strModelFile, REAL& rOutput )
{
	//the svm prediction command is,
	//Usage: svm-predict [options] test_file model_file output_file

	char buf[_MAX_LINE];
	ostrstream ostr( buf, ELEMENTS(buf) );
	ostr<<SVM_PREDICT_CMD<<" "<<strDataFile.c_str()<<" "<<strModelFile.c_str()<<" "<<SVM_PREDICT_FILE<<endl;
	system( buf );

	ifstream ifg( SVM_PREDICT_FILE );
	ifg>>rOutput;
}
Пример #2
0
void CHostSet::LoadFromFile( const char* strFile )
{
	ifstream ifg(strFile);
	char buf[MAXLINE];

	while( !ifg.eof() && !ifg.fail() ){
		ifg>>buf;
		if( strncmp(buf, "//", 2)==0 )continue;
		ParseHostName( buf );
//		hostent* phent = gethostbyname( buf );
//		if( phent!=NULL ){
//			IN_ADDR addr;
//			bcopy( phent->h_addr, &addr, sizeof(IN_ADDR) );
//			Add( addr, true );
//		}
	}
}
Пример #3
0
void CSvmModel::TransformToSvmData( const string& strDataFile, int nInputs, int nOutputs, int nPredId, const string& strOutput )
{
	vector<REAL> vcInputs(nInputs);
	vector<REAL> vcOutputs(nOutputs);

	ifstream ifg( strDataFile.c_str() );
	ofstream ofg( strOutput.c_str() );

	while( !ifg.eof() && !ifg.fail() ){
		//read all the input and input vectors at each line
		for( int i=0; i<nInputs; i++ )ifg>>vcInputs[i];
		for( i=0; i<nOutputs; i++ )ifg>>vcOutputs[i];

		if( ifg.eof() || ifg.fail() )break;

		TransformSvmLine( ofg, vcInputs, vcOutputs, nPredId );
	}
}
Пример #4
0
void CRegionalMetaModel::ReadTrainingData( const string& strDataFile, int nInputs, int nOutputs, vector< vector<REAL> >& vcInputs, vector< vector<REAL> >& vcOutputs )
{
	ifstream ifg( strDataFile.c_str() );
	char buf[_MAX_LINE];
	while( true ){
		ifg.getline( buf, ELEMENTS(buf) );
		if( ifg.fail() || ifg.eof() )break;

		istrstream istr(buf);
		vector<REAL> vci(nInputs);
		for( int i=0; i<nInputs; i++ )istr>>vci[i];

		vector<REAL> vco(nOutputs);
		for( i=0; i<nOutputs; i++ )istr>>vco[i];

		vcInputs.push_back( vector<REAL>() );
		vcInputs.back().swap( vci );

		vcOutputs.push_back( vector<REAL>() );
		vcOutputs.back().swap( vco );
	}
}
Пример #5
0
void CNeuralModel::Train( const string& strTrainData, const string& strValidData )
{
	if( m_pNeuralNet!=NULL ){
		delete m_pNeuralNet;
		m_pNeuralNet = NULL;
	}

	double rValidRatio = 0.3;
	int count = 0;
	char buf[_MAX_LINE];
	{
		std::ifstream ifg( strTrainData.c_str() );
		std::ofstream ofgTrain( TRAIN_FILE );
		std::ofstream ofgValid( VALID_FILE );

		ifg.getline( buf, ELEMENTS(buf) );
		while( !ifg.eof() && !ifg.fail() ){
			trimleft( buf );
			if( buf[0]!=NULL ){
				count++;
				if( count%4 == 0 ){
//				if( uni_rand()<rValidRatio ){
					ofgValid<<buf<<endl;
				}else{
					ofgTrain<<buf<<endl;
				}
			}
			ifg.getline( buf, ELEMENTS(buf) );
		}
	}

	m_pNeuralNet = new CMiniNeuralNet();
	double rError = RunMatlabNet( NET_CMD, &m_vcLayerNodes[0], m_vcLayerNodes.size(), &m_vcTrainBias[0], 
		TRAIN_FILE, MODEL_FILE, VALID_FILE );
	cout<<"Error: "<<rError<<endl;
	m_pNeuralNet->Create( &m_vcLayerNodes[0], m_vcLayerNodes.size(), NeuroTanSig );
	m_pNeuralNet->LoadMatlabNet( MODEL_FILE );
}
Пример #6
0
void fault_tree_graph::print_FTAs()
{
    std::set<ft_vertex_t> tasks;
    std::pair< ft_vertex_iter,ft_vertex_iter> ft_vtxs;
    for (ft_vtxs = boost::vertices(ig); ft_vtxs.first != ft_vtxs.second; ++ft_vtxs.first)
        if (ig[*ft_vtxs.first].layer == Layer::TASK)
            tasks.insert(*ft_vtxs.first);
        
    //loop:
    for (std::set<ft_vertex_t>::iterator it = tasks.begin();it != tasks.end();++it)
    {
        typedef boost::property_map<FT_Graph, boost::vertex_color_t>::type color_map_t;
        color_map_t colorMap = get(boost::vertex_color, ig);; //Create a color map
        PRINT_DEBUG("pre bfs step with node: "+ ig[*it].name);
#ifdef DEBUG
        FT_Graph::vertex_iterator ita, itEnd;
        for (boost::tie(ita, itEnd) = boost::vertices(ig); ita != itEnd; ita++)
        {
        std::cout << "Color of node prebfs " << *ita << " is " << colorMap[*ita] << std::endl;
        }
#endif
        FTA_visitor vis = FTA_visitor(*it);
        try
        {
        boost::breadth_first_search(ig, *it,boost::color_map(colorMap).visitor(vis) );
        }
        catch (int exception)
        {
            if (exception == 1)
                PRINT_DEBUG("found");
        }
#ifdef DEBUG
        
        for (boost::tie(ita, itEnd) = boost::vertices(ig); ita != itEnd; ita++)
        {
        std::cout << "Color of node " << *ita << " is " << colorMap[*ita] << std::endl;
        }
#endif
//visit
        PRINT_DEBUG("bfs step passed");
        boost::filtered_graph<FT_Graph,true_edge_predicate<FT_Graph>,FT_print_filter_c> ifg (ig,true_edge_predicate<FT_Graph>(ig),FT_print_filter_c(ig,colorMap));
        PRINT_DEBUG("filter step passed");
        //filter
        std::ofstream myfile;
        myfile.open ("/home/emanuele/Documents/tmp_graph/"+ig[*it].name+".dot");
        boost::write_graphviz(myfile, ig,make_vertex_writer(boost::get(&FT_Node::crit, ig),boost::get (&FT_Node::name, ig))); //should use a different template: crit is mapped on the first three colors of layers
        myfile.close(); 
        PRINT_DEBUG("print step passed");
        //print
        
        FT_Graph::vertex_iterator it2, it2End;
        for (boost::tie(it2, it2End) = boost::vertices(ig); it2 != it2End; it2++)
        {
         colorMap[*it2] = boost::default_color_type::white_color; 
        }
    }
}