Example #1
0
    def setPlayerLayout(self, ind, playerName, topPanelXY, topPanelWH):
        baseWH = [600, 600]
        remainingSubWidth = (glb.wh[0] - baseWH[0] * 2) // 4
        if ind: pXY = [remainingSubWidth * 3 + baseWH[0], 10]
        else: pXY = [remainingSubWidth, 10]

        quadXY = [pXY[0], topPanelXY[1]]
        quadWH = [reduceTo(baseWH[0], 50), topPanelWH[1]]
        mdl.label(quadXY,
                  quadWH,
                  playerName,
                  51,
                  batch=self.batch,
                  group=gHeaderText,
                  xyPercInside=[10, 30])
        mdl.quad(quadXY,
                 quadWH, [0, 159, 217, 150],
                 self.batch,
                 group=gHeaderQuad,
                 blend=True)

        lblXY = [quadXY[0] + quadWH[0] + 20, quadXY[1]]
        self.turnLbl[ind] = mdl.label(lblXY,
                                      quadWH,
                                      'Turn !',
                                      51,
                                      batch=self.batch,
                                      group=gHeaderText,
                                      xyPercInside=[10, 30])
        self.lblSize = self.turnLbl[ind].font_size
        self.player[ind] = Player.Player(pXY,
                                         baseWH,
                                         batch=self.batch,
                                         group=gPlayer)
Example #2
0
def to_libfm(examples, libfm_filename):
    libfm_file = open(libfm_filename, 'w')
    for example in examples:
        x_i = model.represent(example)[:-1]
        y_i = model.label(example)
        user_id = example['user']
        user_id_feature = "%d:1" % (len(x_i)+user_id)
        libfm_file.write("%d %s %s\n" % (y_i, sp_vector(x_i), user_id_feature))
    libfm_file.close()
Example #3
0
def to_libfm(examples, libfm_filename):
    libfm_file = open(libfm_filename, 'w')
    for example in examples:
        x_i = model.represent(example)[:-1]
        y_i = model.label(example)
        user_id = example['user']
        user_id_feature = "%d:1" % (len(x_i) + user_id)
        libfm_file.write("%d %s %s\n" % (y_i, sp_vector(x_i), user_id_feature))
    libfm_file.close()
Example #4
0
    def setLabels( self, optionList ) :
        self.optionList = optionList
        if self.optionLabels :
            for lbl in self.optionLabels : lbl.delete()
        self.optionLabels = [ ]
        wh = self.subWH ; wh[1] = reduceTo( wh[1], 70 )

        for i in range( len( optionList ) ) :
            if len( optionList[i] ) :
                xy = self.indexToXY( [i,0] )
                self.optionLabels.append(
                     mdl.label( xy, wh, optionList[i][0], size = 36,  batch = self.batch, group = self.group + gText, xyPercInside = [2,45] )
                )
Example #5
0
    def victoryStuffs(self):
        self._status = VICTORY
        self.turnLbl[self.ind].text = 'Victory !'
        self.player[self.ind].makeShipsVisible()
        self.player[not self.ind].makeShipsVisible()

        pXY = self.player[self.ind].xy
        pWH = self.player[self.ind].wh
        wh = [reduceTo(pWH[0], 50), self.topPanelXY[1] - pXY[1] - pWH[1] - 10]
        xy = [(glb.wh[0] - wh[0]) // 2, pXY[1] + pWH[1] + 5]

        self.mainMenuButton = GameModel.GameModel(xy,
                                                  wh, [1, 1],
                                                  self.batch,
                                                  gPlayer,
                                                  mouseOverAud=True)
        mXY = self.mainMenuButton.xy
        mWH = self.mainMenuButton.wh

        mdl.quad(mXY,
                 mWH, [0, 159, 217, 180],
                 self.batch,
                 gFullQuad,
                 blend=True)
        mdl.quad([0, 0],
                 glb.wh, [0, 0, 0, 150],
                 self.batch,
                 gFullQuad,
                 blend=True)

        wh[1] = reduceTo(wh[1], 85)
        mdl.label(xy,
                  wh,
                  'Main Menu',
                  size=49,
                  batch=self.batch,
                  group=gHeaderText,
                  xyPercInside=[5, 20])
def get_test_examples():
    global test_X
    global test_y
    if not test_X:
        print "Loading test examples"
        _log_time()
        test_examples = music.load_examples("data/test_40k_10k.pkl")
        _print_time_diff()
        print "Obtaining X and y values"
        _log_time()
        test_X = [model.represent(example) for example in test_examples]
        _print_time_diff()
        _log_time()
        test_y = [model.label(example) for example in test_examples]
        _print_time_diff()
    return test_X, test_y
    _print_time_diff()
    _draw_separator()


print "Start loading examples"
_log_time()
examples = music.load_examples("data/train.pkl")
_print_time_diff()
_draw_separator()

print "Obtaining all x and y values"
_log_time()
all_X = [model.represent(example) for example in examples]
_print_time_diff()
_log_time()
all_y = [model.label(example) for example in examples]
_print_time_diff()
_draw_separator()


def print_consolidated_scores(scores):
    _draw_separator(".", 5)
    print "%0.6f (+/- %0.6f)" % (scores.mean(), scores.std() / 2)
    _draw_separator("`", 5)


def _get_mean_score(scores):
    return "%0.6f" % (scores.mean())


test_X = None
def contains_named_entities(sentence):
    pred = model.label(sentence)
    if 'DOS' in pred or 'UNIT' in pred:
        return True
Example #9
0
 def setHeader( self, text, quadColor ) :
     self.headerXY = xy = [0, reduceTo( self.sidePanelWH[1], 80) ]
     wh = [ self.sidePanelWH[0], reduceTo( self.sidePanelWH[1], 12) ]
     mdl.quad( xy, wh, quadColor, self.batch, self.group + gQuad, blend = True )
     wh[1] = reduceTo( wh[1], 90 ) 
     self.headerLbl = mdl.label( xy, wh, text, size = 54, batch = self.batch, group = self.group + gText , xyPercInside = [4,25] )
Example #10
0
    return scores


if __name__ == "__main__":
    import music

    train_examples = music.load_examples('data/train.pkl')
    # poly = PolynomialNetworkRegressor(degreex=3, n_components=2, tol=1e-3, warm_start=True, random_state=0)
    fm = pylibfm.FM(num_iter=10,
                    verbose=True,
                    task="regression",
                    initial_learning_rate=0.001,
                    learning_rate_schedule="optimal")
    v = DictVectorizer()
    X = np.asarray([model.represent(example) for example in train_examples])
    y = np.asarray([model.label(example) for example in train_examples])
    # fm.fit(sparse.csr_matrix(X), y)
    # svr_rbf.fit(X, y)
    # pca = PCA(n_components=100)
    # pca.fit(X)
    # X_fit = pca.transform(X)
    # print "pca done"
    # xs = [x[0] for x in X_fit]
    # ys = [x[1] for x in X_fit]
    # plt.scatter(xs, ys)
    # plt.show()
    # print v.fit_transform(X)
    # print X_fitM
    y_np = np.asarray(y)
    plt.hist(y_np, bins=np.arange(y_np.min(), y_np.max() + 1))
    # plt.title("Frequency of ratings")