void TestAxisLabels() { CPlot2D *plot2D=new CPlot2D(); CDataSet dataSet; CDataPoint point; for (double x=-100.01;x<=100.0;x+=10.0) { point.SetValues(x,x*x*x-x*x+x); dataSet.AddDataPoint(point); } dataSet.SetDatasetColor(0.0,1.0,0.0); dataSet.SetDatasetTitle("x^3-x^2+x"); plot2D->AddDataSet(dataSet); plot2D->SetXAxisTitle("x axis"); plot2D->SetYAxisTitle("y=x^3-x^2+x axis"); plot2D->SetLeftFrameSize(100.0); plot2D->OutputPostScriptPlot("test5_axis_labels.ps"); }
// Loads a new feature space and appends it to the multiset void loadFeatureSpace( string filename, CDataSet< vSparseSample >& ds ) { // Load the data cout<<"Loading "<<filename<<"... "; cout.flush(); CDataSet<CSparseSample> d; parseSparseFile( filename, d, ',', ',', '=' ); cout<<"Loaded "<<d.size()<<" samples; "<<nFeats( d )<<" features"<<endl; // Append the Zhang dataset to the multiset expand( ds, d ); cout<<" The combined dataset is now at "<<ds.size()<<" samples"<<endl; }
void TestTrigFunctions() { CPlot2D *plot2D=new CPlot2D(); CDataSet dataSet; CDataPoint point; for (double x=-3.1515;x<=3.2;x+=0.1) { point.SetValues(x,sin(x)); dataSet.AddDataPoint(point); } dataSet.SetDatasetColor(0.0,0.0,0.0); dataSet.SetDatasetTitle("sin(x)"); plot2D->AddDataSet(dataSet); CDataSet dataSet1; for (double x=-3.1515;x<=3.2;x+=0.1) { point.SetValues(x,cos(x)); dataSet1.AddDataPoint(point); } dataSet1.SetDatasetColor(1.0,0.0,0.0); dataSet1.SetDatasetTitle("cos(x)"); plot2D->AddDataSet(dataSet1); CDataSet dataSet2; for (double x=-3.1515;x<=3.2;x+=0.1) { point.SetValues(x,sin(x)*cos(x)); dataSet2.AddDataPoint(point); } dataSet2.SetDatasetColor(0.0,0.0,1.0); dataSet2.SetDatasetTitle("sin(x)*cos(x)"); plot2D->AddDataSet(dataSet2); plot2D->SetXAxisTitle("variable x"); plot2D->SetYAxisTitle("function"); plot2D->OutputPostScriptPlot("test1_trigfunctions.ps"); }
void CParticleSystem::SetParticlesFromData() { SingletonPointer<CDataManager> DataManager; CDataSet * DataSet = DataManager->GetCurrentDataSet(); if (! DataSet) { return; } Particles.resize(DataSet->Size()); for (uint i = 0; i < DataSet->Size(); ++ i) { CDataRow const & Row = DataSet->GetRow(i); double X = 0, Y = 0, Z = 0; if (XField >= 0) { X = Row.GetFieldAsDouble(XField); } if (YField >= 0) { Y = Row.GetFieldAsDouble(YField); } if (ZField >= 0) { Z = Row.GetFieldAsDouble(ZField); } Particles[i].Data = vec3d(X, Y, Z); Particles[i].Position = vec3d(X, Y, Z); } NormalizeParticlePositions(); UpdateColors(); Update(); }
CGreyModel::CGreyModel(CDataSet& his_data) { m_his_data.assign(his_data.begin(), his_data.end()); m_forecast_data.assign(his_data.begin(), his_data.end()); m_data_size = m_his_data.size(); cout<<"输入数据大小:m_data_size="<<m_data_size<<endl; // print_his_data(); m_init_population_num = 5; //初始种群数目 m_max_population_num = 300; //最大种群数目 m_min_seed = 0; //最小种子数 m_max_seed = 5; //最大种子数 m_max_iteration_num = 100; //最大迭代次数 m_dimension = 2; //求解维数 m_nonlinear_parameter = 2; //非线性调制参数 m_init_stand_dev = 50.00; //初始标准差 m_final_stand_dev = 0.01; //最终标准差 m_a_min = -0.3; //a随机范围下限 m_a_max = 2; //a随机范围上限 m_u_min = 0.00; //u随机范围下限 m_u_max = 200.5; //u随机范围上限 m_curr_population_num = 0; get_model(); forecast_data(); }
//---------------------------------------- int32_t CBratProcessExportAscii::WriteData() { int32_t result = BRATHL_SUCCESS; //CTrace *p = CTrace::GetInstance(); //p->Tracer(1, "Writing data ..."); CObArray::iterator itDataSet; CRecordSet* recordSet = NULL; CDataSet* dataSet = m_product->GetDataSet(); for (itDataSet = dataSet->begin(); itDataSet != dataSet->end() ; itDataSet++) { recordSet = dataSet->GetRecordSet(itDataSet); ///bool firstRecord = (record == dataSet->front()); CExpressionValue exprValueSelect; if (m_alwaysTrue == false) { recordSet->ExecuteExpression(m_select, m_recordName, exprValueSelect, m_product); } if (m_writeHeader) { for (uint32_t indexExpr = 0 ; indexExpr < m_fields.size() ; indexExpr++) { CExpressionValue exprValueData; recordSet->ExecuteExpression(m_fields[indexExpr], m_recordName, exprValueData, m_product); string colName = (m_names[indexExpr].empty() ? m_fields[indexExpr].AsString() : m_names[indexExpr]); string unitStr; unitStr.append(" ("); unitStr.append(m_units[indexExpr].AsString(false, true)); unitStr.append(") "); if (m_units[indexExpr].IsDate() && !m_dateAsPeriod ) { unitStr = ""; } if (m_units[indexExpr].IsDate() && !m_units[indexExpr].HasDateRef() ) { unitStr = ""; } *m_outputFile << colName << unitStr << " " << exprValueData.GetDimensionsAsString() << "\t"; } *m_outputFile << endl; m_writeHeader = false; } if (m_alwaysTrue == false) { if (exprValueSelect.IsTrue() != 1) { //Data doesn't match SELECT options, //------------- continue; //------------- } } for (uint32_t indexExpr = 0 ; indexExpr < m_fields.size() ; indexExpr++) { CExpressionValue exprValueData; recordSet->ExecuteExpression(m_fields[indexExpr], m_recordName, exprValueData, m_product); *m_outputFile << exprValueData.AsString(m_units[indexExpr], m_formats[indexExpr], m_dateAsPeriod) << "\t"; } *m_outputFile << endl; } //p->Tracer(1,"End writing data ..."); return result; }
int main( int argc, char* argv[] ) { // Display usage and/or parse the parameters if( argc < 2 ) { cout<<"Usage: "<<argv[0]<<" <options file>"<<endl; return -1; } CGOStrutParams params; params.load( argv[1] ); params.display(); typedef CKernelLoss<CSparseSample> CSparseKLoss; CDataSet<vSparseSample>::binop_t fcker = CCompositeSparseKernel( false ); CDataSet<CSparseSample>::binop_t fker = CSparseKernel( true ); CDataSet<CSparseSample>::binop_t floss = CSparseKLoss( fker ); function< double( double, double ) > fioker = CProdJointKernel(); /////////////////////////////// CDataSet< vSparseSample > dsi; // Load the datasets loadFeatureSpace( "mousefunc/ge_zhang.sdat.gz", dsi ); loadFeatureSpace( "mousefunc/ge_su.sdat.gz", dsi ); loadFeatureSpace( "mousefunc/i_adj.sdat", dsi ); loadFeatureSpace( "mousefunc/dd_pfam.sdat", dsi ); loadFeatureSpace( "mousefunc/dd_inter.sdat", dsi ); loadFeatureSpace( "mousefunc/phylo.sdat", dsi ); shared_ptr< CFeatMap > pfm( new CFeatMap ); CDataSet<CSparseSample> dsoTr; CDataSet<CSparseSample> dsoTe; // Load the appropriate set of labels if( GO::hasMF( params.ontology() ) ) loadOntologySpace( "molecular function", "mf", dsoTr, dsoTe, pfm ); if( GO::hasBP( params.ontology() ) ) loadOntologySpace( "biological process", "bp", dsoTr, dsoTe, pfm ); if( GO::hasCC( params.ontology() ) ) loadOntologySpace( "cellular compoennt", "cc", dsoTr, dsoTe, pfm ); if( dsoTr.size() < 1 || dsoTe.size() < 1 ) throw std::runtime_error( "No labels loaded" ); // Append hierarchy to the samples cout<<"Training data output space has "<<dsoTr.size()<<" samples; "<<nFeats( dsoTr )<<" features"<<endl; cout<<"Test data output space has "<<dsoTe.size()<<" samples; "<<nFeats( dsoTe )<<" features"<<endl; // DEBUG /* vector< unsigned int > v; for( unsigned int i = 0; i < 400; i++ ) v.push_back( i ); dsoTr.subsample( v );*/ // END OF DEBUG // Combine the data to form a joint output space typedef CIODataSet<vSparseSample, CSparseSample> CIOSet; shared_ptr< CIOSet > pdsio( new CIOSet(fcker, fker, floss, fioker) ); pdsio->addSets( dsi, dsoTr ); pdsio->addSets( dsi, dsoTe ); cout<<"Input space has "<<pdsio->sizeI()<<" samples"<<endl; cout<<"Output space has "<<pdsio->sizeO()<<" samples, "<<nFeats( pdsio->getO() )<<" features"<<endl; string ont; if( GO::hasMF( params.ontology() ) ) ont += "mf"; if( GO::hasBP( params.ontology() ) ) ont += "bp"; if( GO::hasCC( params.ontology() ) ) ont += "cc"; string fnScores = "mfunc-score-" + params.alg_choice() + "-" + ont + ".sdat"; cout<<"Saving prediction scores to "<<fnScores<<endl; // Re-split the data into training and test sets, both using the same output space now // Retrieve the fold sizes vector< unsigned int > foldSizes; foldSizes.push_back( pdsio->sizeI() - dsoTe.size() ); foldSizes.push_back( dsoTe.size() ); // Create the ranges virange_t vTrain, vTest; splitCV( foldSizes, 1, vTrain, vTest ); display( vTrain, vTest ); // Perform the split shared_ptr< CIOSet > pTrain; shared_ptr< CIOSet > pTest; cout<<"About to split"<<endl; pdsio->splitTrainTest( vTrain, vTest, pTrain, pTest ); cout<<"Finished the split"<<endl; pTrain->cache(); pTest->cache(); // Create and add the appropriate test classifier shared_ptr< CClassifier<vSparseSample, CSparseSample> > pclsf = createClassifier<vSparseSample, CSparseSample>( params ); // Train and test the classifier pclsf->train( pTrain ); vector< double > loss = pclsf->test( pTest ); // Report the results double m = std::accumulate( loss.begin(), loss.end(), 0.0 ) / static_cast<double>( loss.size() ); cout<<"Mean loss per test sample: "<<m<<endl; pTrain->cacheIExternal( pTest->getI() ); predScores( *pclsf, pTest->getI(), fnScores ); return 0; }