Skip to content

Instantly share code, notes, and snippets.

@shuyo
Created December 13, 2012 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuyo/4275721 to your computer and use it in GitHub Desktop.
Save shuyo/4275721 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ldig features extractor
# This code is available under the MIT License.
# (c)2012 Nakatani Shuyo / Cybozu Labs Inc.
import sys, os, codecs, numpy
import ldig
model = sys.argv[1]
size = int(sys.argv[2])
ldig = ldig.ldig(model)
features = ldig.load_features()
labels = ldig.load_labels()
param = numpy.load(ldig.param)
top_index = numpy.abs(param).max(axis=1).argsort()[-size:]
f = open("parameters.txt", "wb")
g = codecs.open("features.txt", "wb", "utf-8")
g.write("\t".join(labels))
g.write("\n")
for id in top_index:
phi = param[id,]
f.write("\t".join("%0.5g" % x for x in phi))
f.write("\n")
g.write(features[id][0])
g.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment