def __init__(self,n_features=None): from featFunctions import FeatFunctions import numpy as np import opengm from numpy.random import randn,randint # Initialize the FeatureFunction object: self.FF = FeatFunctions(n_features)
class BuildGM(object): """docstring for BuildGM""" def __init__(self,n_features=None): from featFunctions import FeatFunctions import numpy as np import opengm from numpy.random import randn,randint # Initialize the FeatureFunction object: self.FF = FeatFunctions(n_features) def sigmoid(self,z): return 1/(1+np.exp(-z)) # Create functions for factors: def funCreator(self,name,y_name_list,feat_list_names,obsString): # print name # Get the set of functions using the dicionary: feature_set = [] for feature_name in feat_list_names: if feature_name in self.FF.featName_function: feature_set.append(self.FF.featName_function[feature_name]) else: print feature_name,'not found' # Get the list of observed features: obs_feat_list = self.FF.getObsFeatures(obsString,feature_set) # The function to return def foo(y_idxs): # This is used when the function is defined over more than one variable: y_name_list_str = '_'.join(y_name_list) y_idx_str = '_'.join(str(x) for x in y_idxs) # Get the features conditioned to y_clique featureIdx = FF.getYXFeatures(y_name_list_str,y_idx_str,obs_feat_list) # print featureIdx,'\n' z = featureIdx.dot(theta)[0] # Do the sigmoid: return sigmoid(z) # Give a name to the function foo.__name__ = name return foo