def log_likelihood(self, value: float) -> float:
     logK, loc, logScale = self.params['logK'], self.params['loc'], self.params['logScale']
     K = math.exp(logK)
     scale = math.exp(logScale)
     if self.state['anchor'] is None or np.isnan(value):
         return 0.0
     else:
         x = value - self.state['anchor']
         return math.log(
             exponnorm.pdf(x, K=K, loc=loc, scale=scale) + exponnorm.pdf(-x, K=K, loc=loc, scale=scale) + 0.001)
示例#2
0
文件: models.py 项目: jpierel14/sntd
    def _param_flux(self, phase):
        temp = exponnorm.pdf(
            phase, self._parameters[1], scale=self._parameters[2])
        if np.max(temp) == 0:
            return(np.zeros(len(phase)))
        pierelFlux = self._parameters[0]*exponnorm.pdf(phase, self._parameters[1], loc=-phase[temp == np.max(
            temp)], scale=self._parameters[2])/np.max(temp)+self._parameters[3]

        # print(phase[0],self._parameters[4])
        if np.inf in pierelFlux or np.any(np.isnan(pierelFlux)):
            # print(self._parameters)
            return(np.zeros(len(phase)))
        return(pierelFlux)
示例#3
0
    def apply(self, solution, mu=0.25, sigma=0.05, rate=5):

        corr = solution.corr
        err = solution.err
        m = solution.model
        cond = solution.conditions
        undec = solution.undec
        evolution = solution.evolution

        mixturecoef = getattr(self, 'mixture{}'.format(cond['reward']))
        assert mixturecoef >= 0 and mixturecoef <= 1
        assert isinstance(solution, Solution)

        # To make this work with undecided probability, we need to
        # normalize by the sum of the decided density.  That way, this
        # function will never touch the undecided pieces.

        norm = np.sum(corr)  #+ np.sum(err)
        K = 1 / (sigma * rate)
        X = m.dt * np.arange(0, len(corr))
        # X = np.linspace(0,5,1000)
        Y = exponnorm.pdf(X, K, loc=mu, scale=sigma)
        Y /= np.sum(Y)
        # plt.plot(X,Y)
        corr = corr * (
            1 - mixturecoef
        ) + mixturecoef * Y * norm  # Assume numpy ndarrays, not lists

        return Solution(corr, err, m, cond, undec, evolution)
示例#4
0
def compute_likeness(A, B, masks):
    """ Predicts the likelihood that each pixel in B belongs to a phase based
    on the histogram of A.

    Parameters
    ------------
    A : ndarray
    B : ndarray
    masks : list of ndarrays

    Returns
    --------------
    likelihoods : list of ndarrays
    """
    # generate the pdf or pmf for each of the phases
    pdfs = []
    for m in masks:
        K, mu, std = exponnorm.fit(np.ravel(A[m > 0]))
        print((K, mu, std))
        # for each reconstruciton, plot the likelihood that this phase
        # generates that pixel
        pdfs.append(exponnorm.pdf(B, K, mu, std))

    # determine the probability that it belongs to its correct phase
    pdfs_total = sum(pdfs)
    return pdfs / pdfs_total
 def lt_pdf_extincted_color(self, mag):
     """
     approximate pdf of the extincted color distribution
     """
     mean_colors = self.param_dict['color_mu_1']
     scatters = self.param_dict['color_sigma_1']
     ks = 1.0 / (scatters * 7.1765)
     return exponnorm.pdf(mag, ks, loc=mean_colors, scale=scatters)
示例#6
0
def main():
	symbol = 'BTCUSDT'
	start = int(datetime.datetime.timestamp(datetime.datetime(2019, 6, 1))) * 1000 - 365 * 24 * 60 * 60 * 1000
	previous = start
	trades = []
	total_trades = 0
	max_trades = 0
	time_step = 1
	with open('../Binance/' + symbol + '.csv', 'r') as csvfile:
		reader = csv.DictReader(csvfile)
		for line in reader:
			if int(line['Timestamp']) > previous + time_step * 60 * 60 * 1000:
				previous += time_step * 60 * 60 * 1000
				trades.append(total_trades)
				if max_trades < total_trades:
					max_trades = total_trades
				total_trades = 0
			total_trades += 1

	mean = np.mean(trades)
	print(mean)

	trades = [t for t in trades if t != 1]

	#mean, scale = norm.fit(np.log(trades))
	a, loc, scale = skewnorm.fit(np.log(trades))
	loc_n, scale_n = norm.fit(np.log(trades))

	k, loc_ne, scale_ne = exponnorm.fit(np.log(trades))

	plt.hist(np.log(trades), bins=100, density=True)
	x = np.linspace(6, 12, 100)
	plt.plot(x, skewnorm.pdf(x, a, loc=loc, scale=scale), label='skewnorm')
	plt.plot(x, norm.pdf(x, loc=loc_n, scale=scale_n), label='norm')
	plt.plot(x, exponnorm.pdf(x, k, loc=loc_n, scale=scale_n), label='Exponentially modified Gaussian')

	plt.xlabel('Log Trades')
	plt.ylabel('Density')

	plt.legend()

	#plt.plot([i for i in range(1, max_trades)], poisson_density(np.array([i for i in range(1, max_trades)]), mean))
	#plt.plot([i for i in range(0, max_trades)], norm.pdf([i for i in range(max_trades)], loc=mean, scale=np.sqrt(mean)))
	plt.savefig(symbol + ' log Trades')

	plt.show()
示例#7
0
def xGaussPDF(x, k, loc, scale, amp):
    """ amp=overall multip factor, loc=mu, sc=sigma, k=tau """
    from scipy.stats import exponnorm
    return amp * exponnorm.pdf(x, k, loc, scale)
示例#8
0
 def mode(param):
     x = np.linspace(0, 10, 10000)
     model = exponnorm.pdf(x, *param)
     index = np.argmax(model)
     mode = x[index]
     return mode
示例#9
0
 def to_minimize(x, param):
     return -exponnorm.pdf(x, *param)
示例#10
0
from scipy.stats import exponnorm
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

K = 1.5
mean, var, skew, kurt = exponnorm.stats(K, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(exponnorm.ppf(0.01, K),
                exponnorm.ppf(0.99, K), 100)
ax.plot(x, exponnorm.pdf(x, K),
       'r-', lw=5, alpha=0.6, label='exponnorm pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = exponnorm(K)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = exponnorm.ppf([0.001, 0.5, 0.999], K)
np.allclose([0.001, 0.5, 0.999], exponnorm.cdf(vals, K))
# True
示例#11
0
from scipy.stats import exponnorm
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

K = 1.5
mean, var, skew, kurt = exponnorm.stats(K, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(exponnorm.ppf(0.01, K), exponnorm.ppf(0.99, K), 100)
ax.plot(x, exponnorm.pdf(x, K), 'r-', lw=5, alpha=0.6, label='exponnorm pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = exponnorm(K)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = exponnorm.ppf([0.001, 0.5, 0.999], K)
np.allclose([0.001, 0.5, 0.999], exponnorm.cdf(vals, K))
# True

# Generate random numbers: