def main(): S = np.linspace(0, 200, 200 * 8 + 1) Sl = 0 Su = 250 N = 128 * T K = 8 * (Su - Sl) Sk = (K * (S - Sl) / (Su - Sl)).astype(int) legend = [] label = "$\\Omega^v = [%i, 5]$" model = FDEModel(N, dS, payoff) fig = plt.figure() fig.set_figwidth(1.8 * fig.get_figwidth()) ax = fig.add_subplot(1, 2, 1) for i in range(1, 5): Conv.times = [(i, 5)] ax.plot(S, model.price(Sl, Su, K).V[0][Sk]) legend.append(label % i) plt.xlabel("Stock Price") plt.ylabel("Convertible Bond Price") plt.legend(legend) ax = fig.add_subplot(1, 2, 2, projection="3d") plot_model(ax, dS, payoff)
def analyze(data, neuron, args=None, confs=None): if args is None: args = DEFAULT_ARGS if confs is None: confs = DEFAULT_CONFS firing_rates = transform_spikes(neuron, filter_width=50) data, neuron, firing_rates = remove_nans(data, neuron, firing_rates) create_model = lambda: Model(PoissonRegressor(), spikes=neuron, n_folds=10) create_model = lambda: Model(LinearRegression(), spikes=neuron, n_folds=10) best_model = create_model() subset = data.columns.to_list() # starting with all columns data_ = transform_data(data[subset], args['bins']) best_model(data_, firing_rates) plot_model(data_, neuron, firing_rates, best_model, subset) # return bins = args['bins'] # naive estimation of SHAP values # a real calculation will require 2^k (k=no. features) models, and to avg them with different weights (N choose k) features_to_remove = get_one_dim_feature_names( ) + get_two_dim_feature_names() for feature_to_remove in features_to_remove: if isinstance(feature_to_remove, str): # 1D feature feature_to_remove = [feature_to_remove] model = create_model() new_subset = [col for col in subset if col not in feature_to_remove] print(new_subset, feature_to_remove) new_bins = bins.copy() [new_bins.pop(x) for x in feature_to_remove] data_ = transform_data(data[new_subset], new_bins) print(data_.shape) model(data_, firing_rates) if model > best_model: subset = new_subset best_model = model bins = new_bins get_avg_ll = lambda m: np.mean( [x.results.likelihood for x in m.CVfolds]) print(feature_to_remove, get_avg_ll(model)) # shuffles_results = run_shuffles(best_model) plot_model(data_, neuron, firing_rates, model, subset)
def main(): S = np.linspace(0, 200, 200 * 8 + 1) Sl = 0 Su = 250 N = 128 * T K = 8 * (Su - Sl) Sk = (K * (S - Sl) / (Su - Sl)).astype(int) model = FDEModel(N, dS, payoff) fig = plt.figure() fig.set_figwidth(1.8 * fig.get_figwidth()) ax = fig.add_subplot(1, 2, 1) ax.plot(S, model.price(Sl, Su, K).V[0][Sk]) C.times = [2] ax.plot(S, model.price(Sl, Su, K).V[0][Sk]) plt.xlabel("Stock Price") plt.ylabel("Convertible Bond Price") plt.legend(["$\\Omega^c = [2, 5)$", "$\\Omega^c = \\{2\\}$"]) ax = fig.add_subplot(1, 2, 2, projection="3d") plot_model(ax, dS, payoff)
def main(): S = np.linspace(0, 200, 200 * 8 + 1) Sl = 0 Su = 250 N = 128 * T K = 8 * (Su - Sl) Sk = (K * (S - Sl) / (Su - Sl)).astype(int) model = FDEModel(N, dS, payoff) fig = plt.figure() fig.set_figwidth(1.8 * fig.get_figwidth()) ax = fig.add_subplot(1, 2, 1) ax.plot(S, model.price(Sl, Su, K).V[0][Sk]) A.N = -A.C ax.plot(S, model.price(Sl, Su, K).V[0][Sk]) plt.xlabel("Stock Price") plt.ylabel("Convertible Bond Price") plt.legend(["$R = 104$", "$R = 0$"]) ax = fig.add_subplot(1, 2, 2, projection="3d") plot_model(ax, dS, payoff)
def main(): fig = plt.figure() ax = fig.add_subplot(111, projection="3d") plot_model(ax, dS, payoff)
avg_reward_hist.append(r_total/t) model_log.append(agent.model) return avg_reward_hist, agent.model_hist np.random.seed(10) number_arms = 20 testbed = Arms(number_arms) iters_test = 10000 print(testbed) print('\nMODELS OF VARIOUS AGENTS:') agent1 = Agent(number_arms, epsilon=0, Q_0=0) # -1 epsilon will never explore reward1, model1 = test_agent(testbed, agent1, iters_test) plot_model(model1, iters_test, testbed.arms, name="agent1") agent2 = Agent(number_arms, epsilon=0.01, Q_0=0) reward2, model2 = test_agent(testbed, agent2, iters_test) plot_model(model2, iters_test, testbed.arms, name="agent2") agent3 = Agent(number_arms, epsilon=0.1, Q_0=0) reward3, model3 = test_agent(testbed, agent3, iters_test) plot_model(model3, iters_test, testbed.arms, name="agent3") agent4 = Agent(number_arms, epsilon=1) reward4, model4 = test_agent(testbed, agent4, iters_test) plot_model(model4, iters_test, testbed.arms, name="agent4") compare_avg_performance([agent1, agent2, agent3, agent4], iters_test, [reward1, reward2, reward3, reward4],