def test_safe_idx_sequence_from_idx(data, idx=None, data_seq=1, target_seq=0, target_shift=0): safe_idx = get_safe_idx(data, idx=idx, data_seq=data_seq, target_seq=target_seq, target_shift=target_shift) print_ndarray( f'safe_idx = get_safe_idx({np.shape(data)}, idx={idx}, data_seq={data_seq}, target_seq={target_seq}, target_shift={target_shift})', safe_idx) x, y = sequence_from_idx(data, data, safe_idx, data_seq=data_seq, target_seq=target_seq, target_shift=target_shift) print_ndarray( f'x, _ = sequence_from_idx({np.shape(data)}, {np.shape(data)}, safe_idx, data_seq={data_seq}, target_seq={target_seq}, target_shift={target_shift})', x) print_ndarray( f'_, y = sequence_from_idx({np.shape(data)}, {np.shape(data)}, safe_idx, data_seq={data_seq}, target_seq={target_seq}, target_shift={target_shift})', y) pass # test_safe_idx_batch_from_seq()
def test_prep(data, config, idx=[28799, 35999], data_seq=0, target_seq=0, target_shift=0): data.set_params(data_seq=data_seq, target_seq=target_seq, target_shift=target_shift) print(data) x, y = data.get_dataset(idx) print_ndarray('\nx = data.get_dataset({})'.format(idx), x, 10, frm='8.3f') print_ndarray('y = data.get_dataset({})\n'.format(idx), y, 10, frm='8.3f') nbins = 15 p_range = [5, 95] treshold = 0.050 if not tf.executing_eagerly(): data_shape = np.shape(x)[1:] model = Preproces.build(data_shape, name=model_name, config=config, nbins=nbins, p_range=p_range, treshold=treshold) logdir = 'C:\logs' tf.compat.v1.summary.FileWriter( logdir, graph=tf.compat.v1.get_default_graph()).close() assert False, 'write graph' output = prep(x, config, nbins=nbins, p_range=p_range, treshold=treshold) print_ndarray('\noutput\n', output, 0) # (2,16,16,36) return output
if __name__ == "__main__": import numpy as np from mylib import print_ndarray print('\ntensorflow helper functions') print('tensorflow version: {0}'.format(tf.__version__)) print('tf.executing_eagerly(): {0}'.format(tf.executing_eagerly())) # define test random array np.random.seed(seed=111) mu = np.array([0, 2, 5, -5], dtype=np.float32).reshape(-1, 1) mu = np.array([0, 0, 0, 0], dtype=np.float32).reshape(-1, 1) sigma = np.array([1, 2, 3, 3], dtype=np.float32).reshape(-1, 1) logvar = np.log(np.square(sigma)) print_ndarray('mu', mu) print_ndarray('sigma', sigma) a_shape = (4, 11000) n = a_shape[0] a = np.random.normal(size=a_shape) * sigma + mu print_ndarray('a = np.random.normal(size={}) * sigma + mu'.format(a.shape), a) a = np.cumsum(a, axis=1) print_ndarray('a = np.cumsum(a, np.float32)'.format(a.shape), a, frm='8.2f') q = [25, 50, 75] percentile = np.percentile(a, q, axis=-1)
print(details['device_name']) print('---\n') input_shape = (16, 16, 36) config = get_mixer_s4_config() if not tf.executing_eagerly(): logdir = 'C:\logs' m = MlpMix2.build(input_shape, config, name='test_model') tf.compat.v1.summary.FileWriter( logdir, graph=tf.compat.v1.get_default_graph()).close() assert False, 'write graph' m = MlpMix2.build(input_shape, config) size = (1024, 16, 16, 36) x = np.random.normal(size=size) print_ndarray(f'x = np.random.normal(size={size})', x) log_prob, value, feature = m(x) print_ndarray('log_prob', log_prob) print_ndarray('value', value) print_ndarray( 'feature, mean, var', np.concatenate([ feature, np.mean(feature, axis=-1, keepdims=True), np.var(feature, axis=-1, keepdims=True) ], axis=-1))
tf.math.exp(hard_positives - hard_negatives)) else: triplet_loss = tf.maximum(hard_positives - hard_negatives + margin, 0.0) return triplet_loss # tf.reduce_mean(triplet_loss) if __name__ == "__main__": import numpy as np from mylib import print_ndarray size = (128, 128) labels = np.random.randint(0, high=2, size=size[0]) feature = np.random.normal(loc=1, scale=1, size=size) print_ndarray(f'\nlabels (y_true)', labels) print_ndarray(f'feature (y_pred)', feature) angular_dist = angular_distance(feature) print_ndarray(f'angular_dist', angular_dist) pairwise_dist = pairwise_distance(feature, squared=False) print_ndarray(f'pairwise_dist', pairwise_dist) pairwise_dist = pairwise_distance(feature, squared=False, L2_normalize=True) print_ndarray(f'pairwise_dist', pairwise_dist) t = triplet_semihard_loss( labels,
output = test_prep(dr_train, config256, idx=idx, data_seq=256, target_seq=0, target_shift=0) for image in output: draw_img(image, n_cols=9, n_rows=4) # test prepare_data() x, y = dr_train.get_dataset(idx, data_seq=7200, target_seq=0, target_shift=0) print_ndarray('\nx = .get_dataset({})'.format(idx), x, 20, frm='8.3f') y = x[0, :, :4] a = prepare_data(y, config256) print_ndarray(' = .prepare_data({})'.format(np.shape(y)), a, 20, frm='8.3f') #data_list = ['Open', 'High', 'Low', 'Close', 'AD1', 'AH4', 'AH1', 'AM15', 'AM5', 'LVW1', 'LVD1', 'LVH4', 'LVH1', 'LVM15', 'LVM5', 'LVM2', 'Idx'] config1024 = get_prep1024_config(data_file='hilo66_logvar_2020.csv', target_file='reward_100_2020~.csv') dr_train = get_data(config1024, data_path=data_path) output = test_prep(dr_train, config1024,
target_seq=target_seq, target_shift=target_shift) print_ndarray( f'x, _ = sequence_from_idx({np.shape(data)}, {np.shape(data)}, safe_idx, data_seq={data_seq}, target_seq={target_seq}, target_shift={target_shift})', x) print_ndarray( f'_, y = sequence_from_idx({np.shape(data)}, {np.shape(data)}, safe_idx, data_seq={data_seq}, target_seq={target_seq}, target_shift={target_shift})', y) pass # test_safe_idx_batch_from_seq() size = 12 data = np.arange(size, dtype=np.float32) data = np.reshape(data, (-1, 1)) data = np.concatenate([data + 0.1, data + 0.2], axis=-1) print_ndarray('data', data) test_safe_idx_sequence_from_idx(data, idx=None, data_seq=0, target_seq=0, target_shift=0) test_safe_idx_sequence_from_idx(data, idx=None, data_seq=1, target_seq=0, target_shift=0) test_safe_idx_sequence_from_idx(data, idx=None, data_seq=2, target_seq=0,
if __name__ == "__main__": import numpy as np from mylib import print_ndarray print('\nnumpy helper functions') print('numpy version: {0}'.format(np.__version__)) # define test random array np.random.seed(seed=111) mu = np.array([0, 2, 5, -5], dtype=np.float32).reshape(-1, 1) mu = np.array([0, 0, 0, 0], dtype=np.float32).reshape(-1, 1) sigma = np.array([1, 2, 3, 3], dtype=np.float32).reshape(-1, 1) logvar = np.log(np.square(sigma)) print_ndarray('mu', mu) print_ndarray('sigma', sigma) a_shape = (4, 11000) n = a_shape[0] a = np.random.normal(size=a_shape) * sigma + mu a = np.asarray(a, dtype=np.float32) print_ndarray('a = np.random.normal(size={}) * sigma + mu'.format(a.shape), a) a = np.cumsum(a, axis=1) print_ndarray('a = np.cumsum(a, np.float32)'.format(a.shape), a, frm='8.2f') q = [25, 50, 75]