Ejemplo n.º 1
0
    def estimate_log_likelihood(self, X):
        """
		Estimate the log-likelihood of the model with respect to a set of data samples.
		This method uses the L{Estimator} class.

		@type  X: array_like
		@param X: data points

		@rtype:  real
		@return: the average model log-likelihood in nats
		"""

        import estimator
        return estimator.Estimator(self).estimate_log_probability(X)[0].mean()
Ejemplo n.º 2
0
	def estimate_log_partition_function(self, num_ais_samples=100, beta_weights=[], layer=-1):
		"""
		Estimate the log of the partition function of the top layer. This method is
		a wrapper for the L{Estimator} class and is provided for convenience.

		@type  num_ais_samples: integer
		@param num_ais_samples: number of samples used to estimate the partition function

		@type  beta_weights: list
		@param beta_weights: annealing weights changing from zero to one

		@rtype:  real
		@return: log of the estimated partition function
		"""

		import estimator
		return estimator.Estimator(self).estimate_log_partition_function(num_ais_samples, beta_weights, layer)
Ejemplo n.º 3
0
	def estimate_log_likelihood(self, X, num_samples=200):
		"""
		Estimate the log probability of a set of data samples. This method uses
		the L{Estimator} class.

		@type  X: array_like
		@param X: data points

		@type  num_samples: integer
		@param num_samples: number of Monte Carlo samples used to estimate unnormalized
		probabilities

		@rtype:  real
		@return: the average model log-likelihood in nats
		"""

		import estimator
		return estimator.Estimator(self).estimate_log_probability(X, num_samples)[0].mean()
Ejemplo n.º 4
0
if not os.path.exists(PlotsDirectory):
    os.makedirs(PlotsDirectory)

names = ['highway', 'fall', 'traffic']
estimation_range = [np.array([1050, 1200]), np.array([1460, 1510]), np.array([950, 1000])]
prediction_range = [np.array([1201, 1350]), np.array([1511, 1560]), np.array([1001, 1050])]

for seq_index, seq_name in enumerate(names):

    print('computing ' + seq_name +' ...')

    [X_est, y_est] = load_data(data_path, seq_name, estimation_range[seq_index], grayscale=True)
    [X_pred, y_pred] = load_data(data_path, seq_name, prediction_range[seq_index], grayscale=True)

    g_estimator = estimator.Estimator()
    g_estimator.fit(X_est)

    y_pred = build_mask(y_pred)

    max_alpha = 15
    alphas = np.arange(0, max_alpha, 0.1)
    n_alpha = len(alphas)
    TP = np.zeros(n_alpha)
    TN = np.zeros(n_alpha)
    FP = np.zeros(n_alpha)
    FN = np.zeros(n_alpha)
    TF = np.zeros(n_alpha)
    F1 = np.zeros(n_alpha)
    Pr = np.zeros(n_alpha)
    Re = np.zeros(n_alpha)
Ejemplo n.º 5
0
    dropout = 0.1 * tf.cast(training, tf.float32)
    x = data["input"]
    x = layer1(x)
    x = tf.nn.dropout(x, rate=dropout)
    x = layer2(x)
    y = data["label"]
    loss = tf.keras.losses.binary_crossentropy(y, x)
    loss = tf.reduce_mean(loss)
    accuracy = tf.keras.metrics.binary_accuracy(y, x)
    accuracy = tf.reduce_mean(accuracy)
    metric = {"accuracy": accuracy}
    optimizer = tf.train.GradientDescentOptimizer(1e-3)
    trainable_variables = layer1.weights + layer2.weights
    model_spec = estimator.ModelSpec(loss=loss,
                                     optimizer=optimizer,
                                     trainable_variables=trainable_variables,
                                     metric=metric)
    return model_spec


run_config = estimator.RunConfig(
    train_steps_per_round=1000,
    eval_steps_per_round=20,
    model_dir="model_dir",
    save_every_rounds=40,
)

estm = estimator.Estimator(model_fn, data_fn, run_config)

estm.run(200)
Ejemplo n.º 6
0
    def selectEvent(self, event_id):
        # Now that we have the event_id, let's create the log manager for this process
        self.log = logmanager.LogManager(self.logs_directory, event_id)
        self.betapi.setLog(self.log)
        self.money = self.betapi.getAccountFunds()

        self.homeTeam, self.awayTeam = self.betapi.selectEvent(event_id)

        self.log.log("manager", "Home Team:", self.homeTeam)
        self.log.log("manager", "Away Team:", self.awayTeam)
        # Get main odds(to calculate probabilities)
        odds_dict = {}
        try:
            odds_dict['market_Full_Time'] = self.betapi.market_Full_Time()[0]
        except:
            pass
        try:
            odds_dict['market_Half_Time'] = self.betapi.market_Half_Time()[0]
        except:
            pass
        try:
            odds_dict['market_CorrectScore'] = self.betapi.market_CorrectScore(
            )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_0_5'] = self.betapi.market_Over_Under_0_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_1_5'] = self.betapi.market_Over_Under_1_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_2_5'] = self.betapi.market_Over_Under_2_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_3_5'] = self.betapi.market_Over_Under_3_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_4_5'] = self.betapi.market_Over_Under_4_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_5_5'] = self.betapi.market_Over_Under_5_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_6_5'] = self.betapi.market_Over_Under_6_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_7_5'] = self.betapi.market_Over_Under_7_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Over_Under_8_5'] = self.betapi.market_Over_Under_8_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Half_Time_Over_Under_0_5'] = self.betapi.market_Half_Time_Over_Under_0_5(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_Half_Time_Over_Under_1_5'] = self.betapi.market_Half_Time_Over_Under_1_5(
                )[0]
        except:
            pass
        try:
            odds_dict['market_HT_FT'] = self.betapi.market_HT_FT()[0]
        except:
            pass
        try:
            odds_dict[
                'market_Half_Time_Score'] = self.betapi.market_Half_Time_Score(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_CorrectScore2Home'] = self.betapi.market_CorrectScore2Home(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_CorrectScore2Away'] = self.betapi.market_CorrectScore2Away(
                )[0]
        except:
            pass
        try:
            odds_dict[
                'market_BothTeamsToScore'] = self.betapi.market_BothTeamsToScore(
                )[0]
        except:
            pass
        try:
            odds_dict['market_First_Goal'] = self.betapi.market_First_Goal()[0]
        except:
            pass
        try:
            odds_dict['market_Draw_No_Bet'] = self.betapi.market_Draw_No_Bet(
            )[0]
        except:
            pass

        # Create estimator (calculator of theoretical odds)
        self.estimator = estimator.Estimator(odds_dict=odds_dict,
                                             homeTeam=self.homeTeam,
                                             awayTeam=self.awayTeam,
                                             log=self.log)
        self.event_id = event_id