Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
get minimal director dot features example to work
- Loading branch information
Soeren Sonnenburg
committed
May 31, 2012
1 parent
ea40ed5
commit 018e453
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
examples/undocumented/python_modular/features_director_dot__modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy | ||
try: | ||
from shogun.Features import DirectorDotFeatures | ||
except ImportError: | ||
print "recompile shogun with --enable-swig-directors" | ||
import sys | ||
sys.exit(0) | ||
|
||
data=None | ||
|
||
class NumpyFeatures(DirectorDotFeatures): | ||
def __init__(self, d): | ||
global data | ||
data = d | ||
DirectorDotFeatures.__init__(self) | ||
|
||
def add_to_dense_sgvec(self, alpha, vec_idx1, vec2, abs): | ||
vec2+=alpha*numpy.abs(data[vec_idx1]) | ||
|
||
def get_num_vectors(self): | ||
return data.shape[0] | ||
|
||
def get_dim_feature_space(self): | ||
return data.shape[1] | ||
|
||
traindat = numpy.random.random_sample((10,10)) | ||
parameter_list=[[traindat]] | ||
|
||
def features_director_dot_modular (fm_train_real=traindat): | ||
feats_train=NumpyFeatures(fm_train_real) | ||
feats_train.io.enable_file_and_line() | ||
data=feats_train.get_computed_dot_feature_matrix() | ||
print data | ||
print fm_train_real | ||
|
||
return data | ||
|
||
if __name__=='__main__': | ||
print('DirectorLinear') | ||
features_director_dot_modular(*parameter_list[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters