Пример #1
0
 def convert_old_study(self):
     print "Converting Divisi1 to Divisi2 study."
     from csc.divisi2.network import conceptnet_matrix
     cnet_matrix = conceptnet_matrix('en')
     divisi2.save(
         cnet_matrix,
         self.study_path(os.path.join("Matrices", "conceptnet_en.smat")))
Пример #2
0
def expand_study(study_name):
    study = StudyDirectory(study_name).get_study()
    theblend, concepts = study.get_assoc_blend()
    U, S, V = theblend.normalize_all().svd(k=50)
    doc_rows = divisi2.aligned_matrix_multiply(study.get_documents_matrix(), U)
    projections = U.extend(doc_rows)
    spectral = divisi2.reconstruct_activation(projections, S, post_normalize=True)
    divisi2.save(spectral, study_name+'/Results/expanded.rmat')
Пример #3
0
def expand_study(study_name):
    study = StudyDirectory(study_name).get_study()
    theblend, concepts = study.get_assoc_blend()
    U, S, V = theblend.normalize_all().svd(k=50)
    doc_rows = divisi2.aligned_matrix_multiply(study.get_documents_matrix(), U)
    projections = U.extend(doc_rows)
    spectral = divisi2.reconstruct_activation(projections,
                                              S,
                                              post_normalize=True)
    divisi2.save(spectral, study_name + '/Results/expanded.rmat')
Пример #4
0
def learnit():
    ccipca = CCIPCAProcessor((8193, 400), plot=False, amnesia=1.0)
    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(524288)
    )
    for segment in pipe:
        segment /= np.max(segment)
        print np.max(segment)
        audiolab.play(segment)
    divisi2.save(ccipca.ccipca.matrix, 'chess2.eigs')
Пример #5
0
def make_divisi_matrix(filename):
    parsedlist = inform_parser(filename)
    game = filename.split('.')[0]
    thinglist = [(1 if x[3] else -1, english.normalize(x[0].replace('^', "'")), ('right', x[1], english.normalize(x[2].replace('^', "'")))) for x in parsedlist]
    # Write out the confusingly-named overlist. First, the nouns.
    overlist = open(game + '.over', 'w')
    for concept1, rel, concept2, val in parsedlist:
        if rel == 'HasProperty' and concept2 == 'mark_as_thing':
            print >> overlist, concept1
            print concept1

    # Now the verbs.
    verbs = verb_reader(filename)
    for verb in verbs:
        print >> overlist, verb
    overlist.close()

    game_matrix = divisi2.make_sparse(thinglist).normalize_all()
    divisi2.save(game_matrix, game + '.pickle')
    return game_matrix
Пример #6
0
def graph_from_file(filename):
    bn = TrustNetwork(output=None)
    found_conjunctions = set()
    counter = 0
    with codecs.open(filename, encoding='utf-8') as file:
        for line in file:
            print 'scan:', counter
            counter += 1
            line = line.strip()
            if line:
                source, target, prop_str = line.split('\t')
                bn.scan_edge(source, target)
    bn.make_matrices()
    total = counter
    counter = 0
    with codecs.open(filename, encoding='utf-8') as file:
        for line in file:
            print 'add edge:', counter, '/', total
            counter += 1
            line = line.strip()
            if line:
                source, target, prop_str = line.split('\t')
                props = eval(prop_str)
                weight = props['weight']
                dependencies = None
                if 'dependencies' in props and len(props['dependencies']) > 1:
                    bn.add_conjunction_piece(source, target, weight)
                else:
                    bn.add_edge(source, target, weight)
    file.close()
    
    bn.make_fast_matrix()
    bn.make_fast_conjunctions()
    divisi2.save(list(bn.nodes), filename+'.nodelist.pickle')
    divisi2.save(bn._fast_matrix_up, filename+'.up.pickle')
    divisi2.save(bn._fast_matrix_down, filename+'.down.pickle')
    divisi2.save(bn._fast_conjunctions, filename+'.conjunctions.pickle')
    
    return bn
Пример #7
0
def graph_from_file(filename):
    bn = TrustNetwork(output=None)
    found_conjunctions = set()
    counter = 0
    with codecs.open(filename, encoding='utf-8') as file:
        for line in file:
            print 'scan:', counter
            counter += 1
            line = line.strip()
            if line:
                source, target, prop_str = line.split('\t')
                bn.scan_edge(source, target)
    bn.make_matrices()
    total = counter
    counter = 0
    with codecs.open(filename, encoding='utf-8') as file:
        for line in file:
            print 'add edge:', counter, '/', total
            counter += 1
            line = line.strip()
            if line:
                source, target, prop_str = line.split('\t')
                props = eval(prop_str)
                weight = props['weight']
                dependencies = None
                if 'dependencies' in props and len(props['dependencies']) > 1:
                    bn.add_conjunction_piece(source, target, weight)
                else:
                    bn.add_edge(source, target, weight)
    file.close()

    bn.make_fast_matrix()
    bn.make_fast_conjunctions()
    divisi2.save(list(bn.nodes), filename + '.nodelist.pickle')
    divisi2.save(bn._fast_matrix_up, filename + '.up.pickle')
    divisi2.save(bn._fast_matrix_down, filename + '.down.pickle')
    divisi2.save(bn._fast_conjunctions, filename + '.conjunctions.pickle')

    return bn
Пример #8
0
 def convert_old_study(self):
     print "Converting Divisi1 to Divisi2 study."
     from csc.divisi2.network import conceptnet_matrix
     cnet_matrix = conceptnet_matrix('en')
     divisi2.save(cnet_matrix, self.study_path(os.path.join("Matrices",
     "conceptnet_en.smat")))
Пример #9
0
from plca.plca import SIPLCA2, EPS, shift
from plca.basilica import Basilica
from musicproc.analyze import *
from musicproc.harmonic_prior import harmonic_prior
from csc import divisi2
import numpy as np
from matplotlib import pyplot as plt
np.seterr(invalid='raise')

#pitch = divisi2.load('clocks.pitch.pickle')
analyzer = MusicAnalyzer(window_size=44100, subsample=1470)
audio = AudioData.from_file('high-hopes.ogg')
pitch = analyzer.quantize_equal(np.abs(analyzer.analyze_pitch(audio, 120)), 1470)
divisi2.save(pitch, 'high-hopes.pitch.pickle')

alphaWf = harmonic_prior(96, 0, 6, 0)
alphaWt = np.vstack([np.linspace(0.01, 0, 30)]*6)

bas = Basilica(pitch, 6, 30, alphaWf=alphaWf, alphaWt=alphaWt, betaHf=0.1, betaHt=0.05)

def play_reconstruction(rec):
    analyzer.reconstruct_W(rec).play()

Wf, Zf, Hf, Wt, Zt, Ht, meta_Hf, meta_Ht, rec = bas.run(pitch, nsubiter=20, niter=1, play_func=play_reconstruction)

Пример #10
0
def save(db):
        divisi2.save(db.idea_matrix,"idea_mat.pickle")