def load(node_file, matrix_up, matrix_down, conjunction_file): trust = TrustNetwork() nodes = divisi2.load(node_file) trust.nodes = OrderedSet(nodes) trust._fast_matrix_up = divisi2.load(matrix_up) trust._fast_matrix_down = divisi2.load(matrix_down) trust._fast_conjunctions = divisi2.load(conjunction_file) return trust
def load(node_file, matrix_up, matrix_down, conjunction_file): trust = TrustNetwork() nodes = divisi2.load(node_file) trust.nodes = OrderedSet(nodes) trust._fast_matrix_up = divisi2.load(matrix_up) trust._transition_matrix = divisi2.load(matrix_down) trust._fast_conjunctions = divisi2.load(conjunction_file) return trust
def load(node_file, matrix_file, conjunction_file): trust = BeliefNetwork() nodes = divisi2.load(node_file) for node in nodes: trust.nodes.add(node) trust.node_objs[node] = Node(node) trust._fast_matrix = divisi2.load(matrix_file) trust._fast_conjunctions = divisi2.load(conjunction_file) return trust
def make_sim(): # Get similarity from the expanded version of ConceptNet. # This is not blended with anything yet. conceptnet = divisi2.load('conceptnet_big.pickle') #.normalize_all() U, S, V = conceptnet.svd(k=100) sim = divisi2.reconstruct_similarity(U, S, offset=0.1) return sim
def createTuples(filePath): print "Creating Tuples..." proj = divisi2.load(filePath) labels = proj.row_labels d = dict() for i in range(len(labels)): d[tuple(proj[i])] = labels[i] return d
def make_exclude_file(game): overlist = [] gamematix = divisi2.load(game + '.pickle') nouns = gamematix.row_labels overlist += nouns overlist += verb_reader(game+'.inf') overlist = [x.lower() for x in overlist] return overlist
def make_blend(thefile): conceptnet = divisi2.network.conceptnet_matrix('en') thegame = divisi2.load(thefile).normalize_all() blended_matrix = blend(conceptnet, thegame) u,s,v = blended_matrix().svd() similarity = divisi2.reconstruct_similarity(u,s) pd[thefile.split('.')[0]] = similarity return similarity
def make_blend(thefile): conceptnet = divisi2.network.conceptnet_matrix('en').normalize_all() thegame = divisi2.load(thefile).normalize_all() blended_matrix = blend([conceptnet, thegame], [0.9, 0.1]) u,s,v = blended_matrix.svd() similarity = divisi2.reconstruct_similarity(u, s) # offset=1.5) pd.mkdir(thefile.split('.')[0]) pd[thefile.split('.')[0]]['blend'] = similarity return similarity
def getSMatrix(self): if 'smatrix' in self.cache: return self.cache['smatrix'] graphFilename = self.graph.exported() if not graphFilename: graphFilename = self.graph.export() self.graph.save() matrix = divisi2.load(graphFilename) smatrix = divisi2.network.sparse_matrix(matrix, 'nodes', 'features', cutoff=1) self.cache['smatrix'] = smatrix return smatrix
def __init__(self,db=None,mat_string=None): self.d={} self.ideas_list=[] self.related_ideas_dict={} self.f=None self.read_from_file(db) #create a sparse matrix from ideas. if mat_string==None: self.idea_matrix=divisi2.SparseMatrix.square_from_named_entries([(0,0,0)]) else: self.idea_matrix=divisi2.load(mat_string) self.categories=None
def generate(): ccipca = CCIPCAProcessor((8193, 200), plot=False) ccipca.output_ccipca = CCIPCA(divisi2.load('chess.eigs')) pipe = ronwtools.Pipeline( ronwtools.AudioSource('../koyaanisqatsi.ogg'), ronwtools.Mono(), ronwtools.STFT(nfft=16384, nhop=4096, winfun=np.hanning), ccipca, ronwtools.ISTFT(nfft=16384, nhop=4096, winfun=np.hanning), ronwtools.Framer(1048576) ) for segment in pipe: print np.max(segment) segment /= np.max(segment) audiolab.play(segment)
def create(filePath, resultPath): f = open('spectralMatrix.txt', 'w') proj = divisi2.load(filePath) labels = proj.row_labels for i in labels: f.write(i + ' ') count = 0 p = proj.row_named(i) while count < len(p): if count == len(p) - 1: f.write(str(p[count]) + '\n') else: f.write(str(p[count]) + ' ') count += 1 f.close()
def create(filePath, resultPath): f = open('spectralMatrix.txt', 'w') proj = divisi2.load(filePath) labels = proj.row_labels for i in labels: f.write(i+' ') count = 0 p = proj.row_named(i) while count < len(p): if count == len(p) - 1: f.write(str(p[count]) + '\n') else: f.write(str(p[count])+' ') count+=1 f.close()
def createSpectralMatrix(): # proj is a ReconstructedMatrix of the form terms:terms. proj = divisi2.load('C:\Users\LLPadmin\Desktop\luminoso\ThaiFoodStudy\Results\spectral.rmat') # create sparse matrix for clusters of the form terms:clusters (row, col). clusterMatrix, cluster_names, term_names, termsDict = randomClustersMatrix(proj.col_labels, 10) count = 0 while True: count += 1 clusterMatrix = divisi2.aligned_matrix_multiply(proj.left, divisi2.aligned_matrix_multiply(proj.right,clusterMatrix)) repeat = normalize(clusterMatrix, termsDict, cluster_names, term_names) if repeat: print count break return clusterMatrix
def correlate(): ccipca = CCIPCAProcessor((8193, 200), plot=False, amnesia=1.0) ccipca.ccipca = CCIPCA(divisi2.load('chess.eigs')) ccipca.ccipca.iteration = 100000 ccipca.output_ccipca = ccipca.ccipca pipe = ronwtools.Pipeline( ronwtools.AudioSource('../chess.ogg'), ronwtools.Mono(), ronwtools.STFT(nfft=16384, nhop=4096, winfun=np.hanning), ccipca, ronwtools.ISTFT(nfft=16384, nhop=4096, winfun=np.hanning), ronwtools.Framer(1048576) ) for segment in pipe: print np.max(segment) segment /= np.max(segment) audiolab.play(segment)
def createSpectralMatrix(k): # proj is a ReconstructedMatrix of the form terms:terms. proj = divisi2.load(os.path.abspath('../../ThaiFoodStudy')+'/Results/spectral.rmat') #proj = examples.spreading_activation() # create sparse matrix for clusters of the form terms:clusters (row, col). clusterMatrix, cluster_names, term_names, termsDict = randomClustersMatrix(proj.row_labels, k) count = 0 while True: count += 1 print count clusterMatrix = divisi2.aligned_matrix_multiply(proj.left, divisi2.aligned_matrix_multiply(proj.right,clusterMatrix)) repeat = normalize(clusterMatrix, termsDict, cluster_names, term_names) if repeat: print "Aftert "+str(count)+" iterations, we got acceptable clusters." break return clusterMatrix
def createSpectralMatrix(k): # proj is a ReconstructedMatrix of the form terms:terms. proj = divisi2.load( os.path.abspath('../../ThaiFoodStudy') + '/Results/spectral.rmat') #proj = examples.spreading_activation() # create sparse matrix for clusters of the form terms:clusters (row, col). clusterMatrix, cluster_names, term_names, termsDict = randomClustersMatrix( proj.row_labels, k) count = 0 while True: count += 1 print count clusterMatrix = divisi2.aligned_matrix_multiply( proj.left, divisi2.aligned_matrix_multiply(proj.right, clusterMatrix)) repeat = normalize(clusterMatrix, termsDict, cluster_names, term_names) if repeat: print "Aftert " + str( count) + " iterations, we got acceptable clusters." break return clusterMatrix
def get_matrices(self): return dict((os.path.basename(filename), divisi2.load(filename)) for filename in self.get_matrices_files() if filename.endswith('.smat'))
def game_synonyms(game, threshold=1): dict = {} for obj in divisi2.load(game + '.pickle').row_labels: dict[obj] = [ x[0] for x in game_sims(game, obj, threshold=threshold) ] return dict
def load(db): db.idea_matrix=divisi2.load("idea_mat.pickle")
from csc import divisi2 import numpy as np import json, luminoso2, time, urllib2 from divisi2 import DenseMatrix from csc_utils.ordered_set import OrderedSet from charm_exceptions import * #model = luminoso2.load('pldb_2011_may') model = luminoso2.load('hack_2011_oct/Model') sponsormat = divisi2.load("sponsors.dmat") doc_matrix = model.get_doc_matrix('pldb') tag_matrix = model.get_tag_matrix() tag_matrix = model.get_tag_matrix() tag_matrix = DenseMatrix.concatenate(tag_matrix, sponsormat) for i in xrange(doc_matrix.shape[0]): doc_matrix.row_labels[i] = doc_matrix.row_labels[i].replace('hack_2011_oct/Documents', 'PLDBDocs') # print doc_matrix.row_labels[i] def get_related_sponsors(email, n=10): if not ('sponsor', email) in tag_matrix.row_labels: return [] vec = tag_matrix.row_named(('sponsor', email)) got = divisi2.dot(tag_matrix, vec) results = [] for tag, weight in got.top_items(len(got)): key, value = tag if key == 'sponsor': results.append((value, weight)) if len(results) >= n: