def main(): data_location = './data/lorenz_96.npy' data = generate(N=40, F=8.0) utils.save_as_numpy(data, data_location) data = utils.load_to_numpy(data_location) utils.plot(data)
def gen_spatial_heat_maps(q_spatial, decomposed_channel_num, spatial_factors, save_directory, attr_class, factorization_method, no_slash_layer_name, img, AM, model): if q_spatial is not None: for i_decomposed_channel_num in range(decomposed_channel_num): spatial_factors[i_decomposed_channel_num, ...] = spatial_factors[i_decomposed_channel_num, ...] * ( spatial_factors[i_decomposed_channel_num, ...] > np.quantile(spatial_factors[i_decomposed_channel_num, ...], q_spatial / 100)) index_saveimg = 0 for i_factor in range(spatial_factors.shape[0]): factor_resized = resize(spatial_factors[i_factor], (model.image_shape[0], model.image_shape[1]), order=1, mode='constant', anti_aliasing=False) imgtype_name1 = 'SpatialHM' plot(factor_resized, save_directory, attr_class, factorization_method, no_slash_layer_name, imgtype_name1, index_saveimg, xi=img, cmap2='seismic', alpha=0.3) index_saveimg = index_saveimg + 1 print('heat maps have been saved')
def main(): # numeric greeks example # default market environment market_env = MarketEnvironment() print(market_env) # define option style and type opt_style = "plain_vanilla" # "digital" opt_type = "call" # "call" option = option_factory(market_env, opt_style, opt_type) print(option) # numeric greeks instance NumGreeks = NumericGreeks(option) # underlying range at which compute greeks S_range = np.linspace(50, 150, 2000) # time-to-maturity range at which compute greeks tau_range = np.linspace(1e-4, 1.0, 1000) tau_range = homogenize(tau_range, reverse_order=True) # select greek for greek_type in ["delta", "theta", "gamma", "vega", "rho"]: # # greek Vs Underlying level S # # numeric greek calculation greek_numeric_Vs_S = greeks_factory(NumGreeks, greek_type)(S=S_range) # labels label_numeric_S = greeks_label_factory(greek_type, opt_type, kind="num") # plot title plot_title_S = greeks_title_factory(option, greek_type) # plot plot(x=S_range, f=greek_numeric_Vs_S, x_label=r"$S$", f_label=label_numeric_S, title=plot_title_S) # # greek Vs residual time to maturity tau # # numeric greek calculation greek_numeric_Vs_tau = greeks_factory(NumGreeks, greek_type)(tau=tau_range) # labels label_numeric_tau = greeks_label_factory(greek_type, opt_type, kind="num", underlying=r"\tau") # plot title plot_title_tau = greeks_title_factory(option, greek_type, underlying=r"\tau") # plot plot(x=tau_range, f=greek_numeric_Vs_tau, x_label=r"$\tau$", f_label=label_numeric_tau, title=plot_title_tau)
marker_size=9, symbol='square', )) trace_data.append( utils.scatter_trace( x, n_15, 'A', symbol='triangle-up', marker_size=9, )) utils.plot( trace_data, '', 'Kshitij', x_title=x_title, y_title='Test Error', x_scale='log', x_tickvals=x_tickvals, x_ticktext=x_ticktext, # y_tickvals=[0, 0.01, 0.02, 0.03, 0.4], # y_ticktext=y_ticktexts, # x_range=x_range, # y_range=[0, 0.04], # legend_x=legend_x, # legend_xanchor=legend_xanchor, legend_y=0.8, # legend_orientation='h', )
np.mean(episode_length_history[max(0, len(episode_length_history) - 100):])) if not episode % 20 and episode: print( "Episode {} over. Broken WR: {:.3f}. AVG reward: {:.3f}. Episode legth: {:.2f}." .format(episode, wr_array[-1], reward_history_avg[-1], episode_length_avg[-1])) if not episode % 1000 and episode: # Save model player.save_model(MODELS_DIR, episode) print("Model saved") # Update plot of the Winning Rate plot(wr_array, wr_array_avg, "WR history", "WR_history_training", PLOTS_DIR, ["WR", "100-episode average"]) # Update plot of the reward plot(reward_history, reward_history_avg, "Reward history", "reward_history_training", PLOTS_DIR, ["Reward", "100-episode average"]) # Update plot of the episode length plot(episode_length_history, episode_length_avg, "Episode length", "episode_length_training", PLOTS_DIR, ["Episode length", "100-episode average"]) episode += 1