Beispiel #1
0
 def OnWeibullButton(self, event):
     """Retrieve Weibull parameters from selected timeseries."""
     index = self.list_box_1.GetSelections()
     if self.valid_selections(1):
         # Fetch timeseries from dictionary
         ts = self.active_timeseries[index[0]]['timeseries']
         # Fetch ts name from dictionary
         name = self.active_timeseries[index[0]]['name']
         # Set statusbar message
         self.frame_1_statusbar.SetStatusText("Weibull Parameters for "+str(name))
         # Collect stats of timeseries
         stats = analysis.get_statistics(ts.compressed())  
         c, k = analysis.get_weibull_params(stats['mean'],stats['std'])
         # Create statictext string
         text = "C: "+str(c)+"\n"+"K: "+str(k)+"\n"
         self.results_panel_text.SetLabel(text)
Beispiel #2
0
 def OnStatButton(self, event):
     """Generate statistics and print to panel."""
     index = self.list_box_1.GetSelections()
     if self.valid_selections(1):
         # Fetch timeseries from dictionary
         ts = self.active_timeseries[index[0]]['timeseries']
         # Fetch ts name from dictionary
         name = self.active_timeseries[index[0]]['name']
         # Set statusbar message
         self.frame_1_statusbar.SetStatusText("Stats for "+str(name))
         # Collect stats of timeseries
         stats = analysis.get_statistics(ts.compressed())            
         # Create statictext string
         text = ""
         for field, value in stats.iteritems():
             text = ''.join(text+str(field)+": "+str(value)+"\n")
         self.results_panel_text.SetLabel(text)
Beispiel #3
0
 def OnWeibullButton(self, event):
     """Retrieve Weibull parameters from selected timeseries."""
     index = self.list_box_1.GetSelections()
     if self.valid_selections(1):
         # Fetch timeseries from dictionary
         ts = self.active_timeseries[index[0]]['timeseries']
         # Fetch ts name from dictionary
         name = self.active_timeseries[index[0]]['name']
         # Set statusbar message
         self.frame_1_statusbar.SetStatusText("Weibull Parameters for " +
                                              str(name))
         # Collect stats of timeseries
         stats = analysis.get_statistics(ts.compressed())
         c, k = analysis.get_weibull_params(stats['mean'], stats['std'])
         # Create statictext string
         text = "C: " + str(c) + "\n" + "K: " + str(k) + "\n"
         self.results_panel_text.SetLabel(text)
Beispiel #4
0
 def OnStatButton(self, event):
     """Generate statistics and print to panel."""
     index = self.list_box_1.GetSelections()
     if self.valid_selections(1):
         # Fetch timeseries from dictionary
         ts = self.active_timeseries[index[0]]['timeseries']
         # Fetch ts name from dictionary
         name = self.active_timeseries[index[0]]['name']
         # Set statusbar message
         self.frame_1_statusbar.SetStatusText("Stats for " + str(name))
         # Collect stats of timeseries
         stats = analysis.get_statistics(ts.compressed())
         # Create statictext string
         text = ""
         for field, value in stats.iteritems():
             text = ''.join(text + str(field) + ": " + str(value) + "\n")
         self.results_panel_text.SetLabel(text)
Beispiel #5
0
def main(fname, oname, n=20, verbose=False):
    cbow = CBOW()
    realcards = jdecode.mtg_open_file(str(os.path.join(datadir, 'output.txt')), verbose=verbose)
    real_by_name = {c.name: c for c in realcards}
    lm = ngrams.build_ngram_model(realcards, 3, separate_lines=separate_lines, verbose=verbose)
    cards = jdecode.mtg_open_file(fname, verbose=verbose)
    stats = analysis.get_statistics(fname, lm=lm, sep=separate_lines, verbose=verbose)

    selected = []
    for i in range(0, len(cards)):
        if select_card(cards, stats, i):
            selected += [(i, cards[i])]

    limit = 3000

    random.shuffle(selected)
    #selected = selected[:limit]

    if verbose:
        print(('computing nearest cards for ' + str(len(selected)) + ' candindates...'))
    cbow_nearest = cbow.nearest_par([i_c[1] for i_c in selected])
    for i in range(0, len(selected)):
        (j, card) = selected[i]
        selected[i] = (j, card, cbow_nearest[i])
    if verbose:
        print('...done')

    final = []
    for (i, card, nearest) in selected:
        for dist, rname in nearest:
            realcard = real_by_name[rname]
            if compare_to_real(card, realcard):
                final += [(i, card, realcard, dist)]
                break

    for (i, card, realcard, dist) in final:
        print('-- real --')
        print(realcard.format())
        print('-- fake --')
        print(card.format())
        print('-- stats --')
        perp_per = stats['ngram']['perp_per'][i]
        perp_max = stats['ngram']['perp_max'][i]
        print(dist)
        print(perp_per)
        print(perp_max)
        print('----')

    if not oname is None:
        with open(oname, 'wt') as ofile:
            ofile.write(utils.mse_prepend)
            for (i, card, realcard, dist) in final:
                name = realcard.name
                writecard(realcard, name, ofile)
                writecard(card, name, ofile)
            ofile.write('version control:\n\ttype: none\napprentice code: ')
            # Copy whatever output file is produced, name the copy 'set' (yes, no extension).
            if os.path.isfile('set'):
                print('ERROR: tried to overwrite existing file "set" - aborting.')
                return
            shutil.copyfile(oname, 'set')
            # Use the freaky mse extension instead of zip.
            with zipfile.ZipFile(oname+'.mse-set', mode='w') as zf:
                try:
                    # Zip up the set file into oname.mse-set.
                    zf.write('set') 
                finally:
                    if verbose:
                        print('Made an MSE set file called ' + oname + '.mse-set.')
                    # The set file is useless outside the .mse-set, delete it.
                    os.remove('set')
def main(fname, oname, n=20, verbose=False):
    cbow = CBOW()
    realcards = jdecode.mtg_open_file(str(os.path.join(datadir, 'output.txt')), verbose=verbose)
    real_by_name = {c.name: c for c in realcards}
    lm = ngrams.build_ngram_model(realcards, 3, separate_lines=separate_lines, verbose=verbose)
    cards = jdecode.mtg_open_file(fname, verbose=verbose)
    stats = analysis.get_statistics(fname, lm=lm, sep=separate_lines, verbose=verbose)

    selected = []
    for i in range(0, len(cards)):
        if select_card(cards, stats, i):
            selected += [(i, cards[i])]

    limit = 3000

    random.shuffle(selected)
    #selected = selected[:limit]

    if verbose:
        print('computing nearest cards for ' + str(len(selected)) + ' candindates...')
    cbow_nearest = cbow.nearest_par(map(lambda (i, c): c, selected))
    for i in range(0, len(selected)):
        (j, card) = selected[i]
        selected[i] = (j, card, cbow_nearest[i])
    if verbose:
        print('...done')

    final = []
    for (i, card, nearest) in selected:
        for dist, rname in nearest:
            realcard = real_by_name[rname]
            if compare_to_real(card, realcard):
                final += [(i, card, realcard, dist)]
                break

    for (i, card, realcard, dist) in final:
        print '-- real --'
        print realcard.format()
        print '-- fake --'
        print card.format()
        print '-- stats --'
        perp_per = stats['ngram']['perp_per'][i]
        perp_max = stats['ngram']['perp_max'][i]
        print dist
        print perp_per
        print perp_max
        print '----'

    if not oname is None:
        with open(oname, 'wt') as ofile:
            ofile.write(utils.mse_prepend)
            for (i, card, realcard, dist) in final:
                name = realcard.name
                writecard(realcard, name, ofile)
                writecard(card, name, ofile)
            ofile.write('version control:\n\ttype: none\napprentice code: ')
            # Copy whatever output file is produced, name the copy 'set' (yes, no extension).
            if os.path.isfile('set'):
                print 'ERROR: tried to overwrite existing file "set" - aborting.'
                return
            shutil.copyfile(oname, 'set')
            # Use the freaky mse extension instead of zip.
            with zipfile.ZipFile(oname+'.mse-set', mode='w') as zf:
                try:
                    # Zip up the set file into oname.mse-set.
                    zf.write('set') 
                finally:
                    if verbose:
                        print 'Made an MSE set file called ' + oname + '.mse-set.'
                    # The set file is useless outside the .mse-set, delete it.
                    os.remove('set')