Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Python implementation of the conjugate prior table for Bayesian Statistics
See wikipedia page:
https://en.wikipedia.org/wiki/Conjugate_prior#Table_of_conjugate_distributions
pip install conjugate-prior
BetaBinomial
- Useful for independent trials such as click-trough-rate (ctr), web visitor conversion.BetaBernoulli
- Same as above.GammaExponential
- Useful for churn-rate analysis, cost, dwell-time.GammaPoisson
- Useful for time passed until event, as above.NormalNormalKnownVar
- Useful for modeling a centralized distribution with constant noise.NormalLogNormalKnownVar
- Useful for modeling a Length of a support phone call.InvGammaNormalKnownMean
- Useful for modeling the effect of a noise.InvGammaWeibullKnownShape
- Useful for reasoning about particle sizes over time.DirichletMultinomial
- Extension of BetaBinomial to more than 2 types of events (Limited support).model = GammaExponential(a, b)
- A Bayesian model with an Exponential
likelihood, and a Gamma
prior. Where a
and b
are the prior parameters.model.pdf(x)
- Returns the probability-density-function of the prior function at x
.model.cdf(x)
- Returns the cumulative-density-function of the prior function at x
.model.mean()
- Returns the prior mean.model.plot(l, u)
- Plots the prior distribution between l
and u
.model.posterior(l, u)
- Returns the credible interval on (l,u)
(equivalent to cdf(u)-cdf(l)
).model.update(data)
- Returns a new model after observing data
.model.predict(x)
- Predicts the likelihood of observing x
(if a posterior predictive exists).model.sample()
- Draw a single sample from the posterior distribution.from conjugate_prior import BetaBinomial
heads = 95
tails = 105
prior_model = BetaBinomial() # Uninformative prior
updated_model = prior_model.update(heads, tails)
credible_interval = updated_model.posterior(0.45, 0.55)
print ("There's {p:.2f}% chance that the coin is fair".format(p=credible_interval*100))
predictive = updated_model.predict(50, 50)
print ("The chance of flipping 50 Heads and 50 Tails in 100 trials is {p:.2f}%".format(p=predictive*100))
Assume we have 10
creatives (variants) we can choose for our ad campaign, at first we start with the uninformative prior.
After getting feedback (i.e. clicks) from displaying the ads, we update our model.
Then we sample the DirrechletMultinomial
model for the updated distribution.
from conjugate_prior import DirichletMultinomial
from collections import Counter
# Assuming we have 10 creatives
model = DirichletMultinomial(10)
mle = lambda M:[int(r.argmax()) for r in M]
selections = [v for k,v in sorted(Counter(mle(model.sample(100))).most_common())]
print("Percentage before 1000 clicks: ",selections)
# after a period of time, we got this array of clicks
clicks = [400,200,100,50,20,20,10,0,0,200]
model = model.update(clicks)
selections = [v for k,v in sorted(Counter(mle(model.sample(100))).most_common())]
print("Percentage after 1000 clicks: ",selections)
from conjugate_prior import BetaBinomialRanker ranker = BetaBinomialRanker(prior=0.1) # 10% click-through-rate ranker["cmpgn1"]+=(1,9) # 1 click, 9 skips ranker["cmpgn2"]+=(10,90) # 10 click, 90 skips ranker["cmpgn3"]+=(1,2) # 1 click, 3 skips
print(ranker.rank_by_ucb())
FAQs
Bayesian Statistics conjugate prior distributions
We found that conjugate-prior demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.