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
abstract class TaskProvider { | |
def abstract nextTask() | |
def abstract runTask(task) | |
def beforeExecution(int parallelismFactor) {} | |
def afterExecution() {} | |
// callbacks can be used to update statistics | |
// and change behavior of nextTask() dynamically | |
def onStart(task) {} |
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 org.infinispan.Cache; | |
import org.infinispan.configuration.cache.CacheMode; | |
import org.infinispan.configuration.cache.Configuration; | |
import org.infinispan.configuration.cache.ConfigurationBuilder; | |
import org.infinispan.configuration.cache.FileCacheStoreConfigurationBuilder; | |
import org.infinispan.configuration.global.GlobalConfigurationBuilder; | |
import org.infinispan.eviction.EvictionStrategy; | |
import org.infinispan.io.GridFile; | |
import org.infinispan.io.GridFilesystem; | |
import org.infinispan.manager.DefaultCacheManager; |
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 com.caucho.hessian.io.Deflation; | |
import com.caucho.hessian.io.Hessian2Input; | |
import com.caucho.hessian.io.Hessian2Output; | |
import java.io.*; | |
public class HessianSerializer { | |
public static byte[] toByteArray(Serializable o, boolean deflate, int expectedBytesCount) throws IOException { | |
return toOutputStream(new ByteArrayOutputStream(expectedBytesCount), o, deflate).toByteArray(); |
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
def linear(a, b, x): | |
return b + a*x | |
# a linear demand function is generated for every | |
# pair of coefficients in vectors a_vec and b_vec | |
def demand_hypotheses(a_vec, b_vec): | |
for a, b in itertools.product(a_vec, b_vec): | |
yield { | |
'd': functools.partial(linear, a, b), | |
'p_opt': -b/(2*a) |
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
T = 24 * 1 # time step is one hour, flash offering for 1 day | |
m = 4 # not more than 4 price updates | |
def logx(x, n): # iterative logarithm function | |
for i in range(0, n): x = math.log(x) if x > 0 else 0 | |
return x | |
def intervals(m, T, scale): # generate a price schedule vector | |
mask = [] | |
for i in range(1, m): |
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
# parameters | |
prices = [1.99, 2.49, 2.99, 3.49, 3.99, 4.49] | |
alpha_0 = 30.00 # parameter of the prior distribution | |
beta_0 = 1.00 # parameter of the prior distribution | |
# parameters of the true (unknown) demand model | |
true_slop = 50 | |
true_intercept = -7 | |
# prior distribution for each price |
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
# prices - k-dimensional vector of allowed price levels | |
# demands - n x k matrix of demand predictions | |
# c - required sum of prices | |
# where k is the number of price levels, n is number of products | |
def optimal_prices_category(prices, demands, c): | |
n, k = np.shape(demands) | |
# prepare inputs | |
r = np.multiply(np.tile(prices, n), np.array(demands).reshape(1, k*n)) |
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 pymc3 as pm | |
d0 = [20, 28, 24, 20, 23] # observed demand samples | |
with pm.Model() as m: | |
d = pm.Gamma('theta', 1, 1) # prior distribution | |
pm.Poisson('d0', d, observed = d0) # likelihood | |
samples = pm.sample(10000) # draw samples from the posterior | |
seaborn.distplot(samples.get_values('theta'), fit=stats.gamma) |
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
p0 = [15, 14, 13, 12, 11] # offered prices | |
d0 = [20, 28, 35, 50, 65] # observed demands (for each offered price) | |
with pm.Model() as m: | |
# priors | |
log_b = pm.Normal('log_b', sd = 5) | |
a = pm.Normal('a', sd = 5) | |
log_d = log_b + a * np.log(p0) # demand model | |
pm.Poisson('d0', np.exp(log_d), observed = d0) # likelihood |
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
p = np.linspace(10, 16) # price range | |
d_means = np.exp(s.log_b + s.a * np.log(p).reshape(-1, 1)) | |
plt.plot(p, d_means, c = 'k', alpha = 0.01) | |
plt.plot(p0, d0, 'o', c = 'r') | |
plt.show() |
OlderNewer