This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as stats | |
def Cucconi (x, y): | |
# Calculates the test statistic for the Cucconi two-sample location-scale test | |
# assume x is smallest, swap as needed | |
m = len(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.spatial.distance import pdist, squareform | |
import numpy as np | |
import copy | |
def distcorr(Xval, Yval, pval=True, nruns=500): | |
""" Compute the distance correlation function, returning the p-value. | |
Based on Satra/distcorr.py (gist aa3d19a12b74e9ab7941) | |
>>> a = [1,2,3,4,5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Basic Statistic | |
P(Success) = 1/N | |
Add a corrector, Make it difference between theorical probability and observation | |
P(Success) = 1/N + Corrector | |
P(Success) = 1/N + (1/N - SucessCount / TotalCount ) | |
Adjust for initial phase: | |
Prevent Division per zero & reduce the strength for small count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample from a normal distribution, truncated between -1 and 1 | |
double MultiObjectiveCompactDifferentialEvolution::sampleValue(double mu, double sigma) { | |
if (sigma < 1e-8) // Should avoid infinity error below | |
return mu; | |
try { | |
double sqrt2Sigma = SQRT_2 * sigma; | |
double erfMuNeg = boost::math::erf((mu - 1) / sqrt2Sigma); | |
double erfMuPlus = boost::math::erf((mu + 1) / sqrt2Sigma); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function IndexStore() { | |
// Main structure | |
// Format is dict key => array of item indices | |
this.indicesForKey = {}; | |
// List of indexed items. | |
this.items = []; | |
// Helper to prevent duplicate on items. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See http://jonisalonen.com/2012/converting-decimal-numbers-to-ratios/ | |
// Also https://en.wikipedia.org/wiki/Diophantine_approximation | |
// or french https://fr.wikipedia.org/wiki/Fraction_continue_et_approximation_diophantienne | |
function float2rat(x) { | |
var tolerance = 1.0E-6; | |
var max_iter = 100; // Limit on the amount of work we want to do | |
var max_den = 1000; // When is a fraction not really more helpfull than decimal ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Explore very small and very large, positive and negative numbers. | |
// | |
// Spend about 50% of time in + and 50% in - region. (Or fix m to 1 fo positive only) | |
// Spend about 50% of time in +- 10^N and 50% in +- 10^-N region. | |
// Spend about 50% of time between +-[1/1000, 1000] range and 50% of time outside of it, without limit. | |
// | |
// More precisely 50% of values are in [3^-s, 3^s] with "s" is the power of "q". | |
// As a guideline q^6: 1/1000..1000, q^4: 1/100..100, q^2: 1/10..10 | |
// One may notice than 3^6=729<1000, | |
// In practice what this mean is that 1000 is in the 60% most likely outcomes instead of 50%. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert uniform random [0,1] to normal random ~ N(0,1) | |
// norm_rnd = Probit( random() ) | |
// | |
// Probit(p) ~= logit(p)*sqrt(pi/8) | |
// logit(p) = log( p / (1-p) ) | |
// | |
Function RandomNormal(){ | |
var c = 0.626657068657750125603941 // sqrt(pi/8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Select the n-th item with probability `1/n`. | |
// Return an 0 based index (`i = n-1`) | |
// | |
// If parameter `a` is given, we select from probability `1/(n^a)` | |
// In particular, if a negative value of `a` is given, we select with probability `n^y, y = -a`; | |
// | |
// The code use the inverse of the cumulative probability function, to map the uniform distribution to the power distribution. | |
// | |
// Caveat: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SendGridDeliveryServices | |
{ | |
private static string _sendGridApiKey = "..."; | |
public static bool SendMailToCustomerServices(string name, string email, string subject, string body) | |
{ | |
var from = new EmailAddress("system@xyz.com", name); | |
var reply = new EmailAddress(email, name); |
NewerOlder