Revision as of 03:17, 3 April 2008 by Jinha (Talk)

  • Script to convert data from the LIBSVM to the FANN format
#!/usr/bin/python
 
# Syntax: convert.py inputFile nData nFeature nOutput
import sys
import string
import Numeric
 
# Open input file
inFile = open(sys.argv[1], 'r')
 
# Print out the first line
print sys.argv[2], sys.argv[3], sys.argv[4]
 
for line in inFile:
    # Initialize feature vector to all zero
    feature = Numeric.zeros(int(sys.argv[3]))
    sline = string.split(line)
 
    # Iterate through and update the value for the feature
    for num in sline[2:]:
        snum = string.split(num,":")
        feature[int(snum[0])-1] = float(snum[1])
 
    # Print out the feature vector
    for a in feature:
        print a,
 
    # Print out the output
    print
    print sline[0]
 
# Close file
inFile.close()

Alumni Liaison

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett