Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Euler Sample Path does not work under TensorFlow 2.0 with Higher Dimension #14

Closed
jjchan121 opened this issue Nov 24, 2019 · 4 comments
Closed

Comments

@jjchan121
Copy link

When we specify the SDE with dimension greater than one and simulate under Euler Scheme, we will have the following errors.

~/anaconda/envs/py36dev/lib/python3.6/site-packages/tf_quant_finance/models/ito_process.py in step_fn(i, written_count, current_state, result)
332 dw = random.mv_normal_sample(
333 (num_samples,), mean=wiener_mean, random_type=random_type,
--> 334 seed=seed)
335 dw = dw * sqrt_dt[i]
336 dt_inc = dt[i] * self.drift_fn()(current_time, current_state) # pylint: disable=not-callable

~/anaconda/envs/py36dev/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/multivariate_normal.py in multivariate_normal(sample_shape, mean, covariance_matrix, scale_matrix, random_type, validate_args, seed, dtype, name, **kwargs)
170 name,
171 default_name='multivariate_normal',
--> 172 values=[sample_shape, mean, covariance_matrix, scale_matrix]):
173 if mean is not None:
174 mean = tf.convert_to_tensor(mean, dtype=dtype, name='mean')

TypeError: init() got an unexpected keyword argument 'default_name'

I'm using Tensorflow 2.0

@saxena-ashish-g
Copy link
Contributor

I have pushed a fix for this (we needed to replace tf.name_scope with tf.compat.v1.name_scope). Can you please give it another spin (against the head version and not the pip version) and let me know if it still doesn't work.

@jjchan121
Copy link
Author

Even worse, I can't import the library.

----> 1 import tf_quant_finance as tqf

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/init.py in
66
67 from tf_quant_finance import black_scholes
---> 68 from tf_quant_finance import math
69 from tf_quant_finance import models
70 from tf_quant_finance import rates

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/init.py in
23 from tf_quant_finance.math import pde
24 from tf_quant_finance.math import piecewise
---> 25 from tf_quant_finance.math import random_ops as random
26 from tf_quant_finance.math import root_search
27 from tf_quant_finance.math import segment_ops

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/init.py in
19
20 from tf_quant_finance.math.random_ops import halton
---> 21 from tf_quant_finance.math.random_ops import sobol
22 from tf_quant_finance.math.random_ops.multivariate_normal import multivariate_normal as mv_normal_sample
23 from tf_quant_finance.math.random_ops.multivariate_normal import RandomType

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/sobol/init.py in
18 from future import print_function
19
---> 20 from tf_quant_finance.math.random_ops.sobol.sobol_impl import sample
21
22 from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/sobol/sobol_impl.py in
223
224 (_PRIMITIVE_POLYNOMIAL_COEFFICIENTS,
--> 225 _INITIAL_DIRECTION_NUMBERS) = _load_sobol_data()

~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/sobol/sobol_impl.py in _load_sobol_data()
207 direction_numbers = np.zeros(shape=(18, 21200), dtype=np.int64)
208 index = 0
--> 209 with open(path) as f:
210 for line in f:
211 # Skip first line (header).

@matejr
Copy link
Contributor

matejr commented Nov 28, 2019

Hi @jjchan121,

we tried to reproduce your last error in an environment similar to yours (ubuntu, anaconda, latest pip package installed within anaconda). However, the "import tf_quant_finance as tqf" statement works in this environment.

Could you please provide more details about your environment? We would need the following information:

  • base operating system (e.g., ubuntu)
  • anaconda, python, pip and tensorflow versions
  • tf-quant-finance version (pip package version)
  • how did you install tf-quant-finance package (e.g., using pip install tf-quant-finance or did you build the pip package yourself)?
  • if you've build the pip package yourself: how did you build it?

Ideally, we would get a sequence of commands that can completely reproduce the environment in which the "import tf_quant_finance as tqf" statement fails.

As a temporary workaround, you could just comment out the line 224 (line with _load_sobol_data()) in ~/.conda/envs/idp36p/lib/python3.6/site-packages/tf_quant_finance/math/random_ops/sobol/sobol_impl.py

In this case, Sobol number generator won't work, but you can use other types of random numbers (e.g., Halton numbers or pseudorandom numbers).

@cyrilchim
Copy link
Contributor

All should be working now with TF 2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants