Commits

Jian Zhou committed 845efde

minor output behavior fixes and improvement for svmhierarchy

  • Participants
  • Parent commits b286d4a

Comments (0)

Files changed (4)

File src/svmstruct.h

 			stringstream ss;
 			int mark=1;
 			ss << GeneName << '\t';
-			for(size_t j=0;j<=num_class;j++){
+			for(size_t j=0;j<num_class;j++){
 				if(TargetM[j])
 					if(mark){
 						if(returnindex)
 				ss<<'\t';
 
 			mark=1;
-			for(size_t j=0;j<=num_class;j++){
+			for(size_t j=0;j<num_class;j++){
 				if(ValueM[j])
 					if(mark){
 						if(returnindex)
 			if(mark)
 				ss<<"??";
 			ss <<'\t';
-			for(size_t j=1;j<=num_class;j++)
+			for(size_t j=0;j<num_class;j++)
 				ss << Scores[j]<<'\t';
 			return ss.str();
 		}

File src/svmstructtree.cpp

 		if (!ifsm.is_open())
 			cerr << "Could not read Onto file" << endl;
 
-		static const size_t c_iBuffer = 65532; //change this if not enough
+		static const size_t c_iBuffer = 1024; //change this if not enough
 		char acBuffer[c_iBuffer];
 		vector<string> vecstrTokens;
 		map<string,int>::iterator it;
 				onto_map[vecstrTokens[0]]=currentindex;
 				onto_map_rev[currentindex]=vecstrTokens[0];
 				newnode= (ONTONODE *)my_malloc(sizeof(ONTONODE));
+				cerr << "Read new Onto Term: "<< vecstrTokens[0]<<endl;
 				nodes.push_back(newnode);
 				tempnodes.push_back(newtempnode);
 				//shall I add node name to tree structure?
 				if(it == onto_map.end()) {
 					currentindex = onto_map.size();
 					onto_map[vecstrTokens[i]]=currentindex;
+					cerr << "Read new Onto Term: "<< vecstrTokens[i]<<endl;
 					onto_map_rev[currentindex]=vecstrTokens[i];
 					newnode= (ONTONODE *)my_malloc(sizeof(ONTONODE));
 					nodes.push_back(newnode);
 		vector<string> vecstrTokens;
 		vector<char> multilabels;
 		vector<SVMLabel> vecLabels;
-
+		ONTONODE *pnode;
 
 		if(struct_parm.num_classes==0)
 			cerr<< "Ontology must be read before reading labels!"<<endl;
 				continue;
 			}
 
-			for (int i=1; i<multilabels.size();i++)
+			for (int i=0; i<multilabels.size();i++)
 				multilabels[i]=0;
 			for(int i=1; i < vecstrTokens.size();i++){
 				it =  onto_map.find(vecstrTokens[i]);
 				if(it == onto_map.end())
-					cerr<< "Unknown term: "<<vecstrTokens[1]<<endl;
+					cerr<< "Unknown term: "<<vecstrTokens[i]<<endl;
 				else{
-					multilabels[onto_map[vecstrTokens[i]]]=1; // no label propagation currently, labels should be already propagated
+					multilabels[onto_map[vecstrTokens[i]]]=1; 
 					struct_parm.treeStruct.nodes[ onto_map[vecstrTokens[i]] ]->inputlabelCount++;
+					if(struct_verbosity>=3)	
+						cout<<vecstrTokens[0]<<'\t'<<vecstrTokens[i];
+					//label propagation; add print propagation process
+					pnode=struct_parm.treeStruct.nodes[onto_map[vecstrTokens[i]]]->parent;		
+					while(pnode){
+						multilabels[pnode->index]=1;
+						struct_parm.treeStruct.nodes[pnode->index]->inputlabelCount++;
+						if(struct_verbosity>=3)	
+							cout<<'\t'<<onto_map_rev[pnode->index];
+						pnode = struct_parm.treeStruct.nodes[pnode->index]->parent;
+					}
+					if(struct_verbosity>=3)
+						cout<<endl;
+					//end label propagation
+					
 				}
 			}
 			vecLabels.push_back(SVMArc::SVMLabel(vecstrTokens[0], multilabels));
-
 		}
 		return vecLabels;
 	}
 
 					vecResult[iDoc - 1].num_class=struct_parm.num_classes;
 					vecResult[iDoc - 1].Scores.reserve(struct_parm.num_classes);
-					for (k = 0; k <= struct_parm.num_classes; k++)
+					for (k = 0; k < struct_parm.num_classes; k++)
 						vecResult[iDoc - 1].Scores.push_back(label.scores[k]);
 					FreeDoc(pattern.doc);
 				}

File src/svmstructtree.h

 		//MEMBER functions wraps learning
 		void Learn(SAMPLE &sample) {
 			//cerr << "SLACK NORM =" << struct_parm.slack_norm << endl;
-			cerr << "Algorithm " << Alg << "selected."<<endl;
+			cerr << "Algorithm " << Alg << " selected."<<endl;
 
 			if(Alg == 0)
 				svm_learn_struct(sample,&struct_parm,&learn_parm,&kernel_parm,&structmodel,NSLACK_ALG);

File tools/SVMhierarchy/SVMhierarchy.cpp

 		return 1;
 	}
 
-
-	//  cout << "there are " << vecLabels.size() << " labels processed" << endl;
-	size_t iFile;
-	vector<string> PCLs;
-	if (sArgs.input_given) {
-		if (!PCL.Open(sArgs.input_arg, sArgs.skip_arg, sArgs.mmap_flag)) {
-			cerr << "Could not open input PCL" << endl;
-			return 1;
-		}
-	}
-
-
-
-	//Read labels from file
+		//Read labels from file
 	vector<SVMArc::SVMLabel> vecLabels;
 	set<string> setLabeledGenes;
 	if (sArgs.labels_given) {
 
 	SVM.InitializeLikAfterReadLabels();
 
+
+	//  cout << "there are " << vecLabels.size() << " labels processed" << endl;
+	size_t iFile;
+	vector<string> PCLs;
+	if (sArgs.input_given) {
+		if (!PCL.Open(sArgs.input_arg, sArgs.skip_arg, sArgs.mmap_flag)) {
+			cerr << "Could not open input PCL" << endl;
+			return 1;
+		}
+	}
+
+
+
+
+
 	//Training
 	SAMPLE* pTrainSample;
 	vector<SVMArc::SVMLabel> pTrainVector[sArgs.cross_validation_arg];