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

Analytic initialisation #41

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Analytic initialisation #41

wants to merge 23 commits into from

Conversation

J-M-Moore
Copy link
Collaborator

This PR adds the option to initialise the simu parameters to their analytic minimum. Currently uses the analytic minimum of the chi2 evaluated on the experimental dataset, but allows for any user-defined PDF set to produce the predictions (which can be different from the fixed PDF used in a fixed PDF fit).

@ElieHammou
Copy link
Collaborator

It looks like if only one operator is used in the fit and the analytic initialisation is used, the code is not working. I get the error message

Traceback (most recent call last):
  File "/home/eh651/rds/hpc-work/miniconda3/envs/simunet/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 1853, in _create_c_op
    c_op = pywrap_tf_session.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Index out of range using input dim 0; input has only 0 dims for '{{node combine_cfac_layer/strided_slice}} = StridedSlice[Index=DT_INT32, T=DT_FLOAT, begin_mask=1, ellipsis_mask=0, end_mask=1, new_axis_mask=2, shrink_axis_mask=0](combine_cfac_layer/ReadVariableOp, combine_cfac_layer/strided_slice/stack, combine_cfac_layer/strided_slice/stack_1, combine_cfac_layer/strided_slice/stack_2)' with input shapes: [], [2], [2], [2] and with computed input tensors: input[3] = <1 1>.

Things are fine if I run with a different initialisation.

@J-M-Moore
Copy link
Collaborator Author

It looks like if only one operator is used in the fit and the analytic initialisation is used, the code is not working. I get the error message

Traceback (most recent call last):
  File "/home/eh651/rds/hpc-work/miniconda3/envs/simunet/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 1853, in _create_c_op
    c_op = pywrap_tf_session.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Index out of range using input dim 0; input has only 0 dims for '{{node combine_cfac_layer/strided_slice}} = StridedSlice[Index=DT_INT32, T=DT_FLOAT, begin_mask=1, ellipsis_mask=0, end_mask=1, new_axis_mask=2, shrink_axis_mask=0](combine_cfac_layer/ReadVariableOp, combine_cfac_layer/strided_slice/stack, combine_cfac_layer/strided_slice/stack_1, combine_cfac_layer/strided_slice/stack_2)' with input shapes: [], [2], [2], [2] and with computed input tensors: input[3] = <1 1>.

Things are fine if I run with a different initialisation.

Fixed now!

@LucaMantani
Copy link
Member

@J-M-Moore I am getting a KeyError:

  File "/auto/home/users/l/m/lmantani/applications/SIMUnet/simunet_release/n3fit/src/n3fit/performfit.py", line 208, in performfit
    exp_data = exp_data.loc[groups_index]
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1073, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1301, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1239, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1432, in _get_listlike_indexer
    keyarr, indexer = ax._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2626, in _get_indexer_strict
    return super()._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6070, in _get_indexer_strict
    self._raise_if_missing(keyarr, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2646, in _raise_if_missing
    return super()._raise_if_missing(key, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6133, in _raise_if_missing
    raise KeyError(f"{not_found} not in index")
KeyError: "[('ATLAS', 'ATLAS_TTBAR_13TEV_HADRONIC_2D_TTM_ABSYTTNORM', 10), ('ATLAS', 'ATLAS_TTBAR_13TEV_TTMNORM', 8), ('ATLAS', 'ATLAS_TTBARZ_13TEV_PTZNORM', 5), ('CMS', 'CMS_TTB_DIFF_13TEV_2016_2L_TTMNORM', 5), ('CMS', 'CMS_TTBAR_13TEV_TTMNORM', 14), ('CMS', 'CMS_TTBARZ_13TEV_PTZNORM', 3)] not in index"

Do you know what is going on?

@J-M-Moore
Copy link
Collaborator Author

@J-M-Moore I am getting a KeyError:

  File "/auto/home/users/l/m/lmantani/applications/SIMUnet/simunet_release/n3fit/src/n3fit/performfit.py", line 208, in performfit
    exp_data = exp_data.loc[groups_index]
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1073, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1301, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1239, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1432, in _get_listlike_indexer
    keyarr, indexer = ax._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2626, in _get_indexer_strict
    return super()._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6070, in _get_indexer_strict
    self._raise_if_missing(keyarr, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2646, in _raise_if_missing
    return super()._raise_if_missing(key, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6133, in _raise_if_missing
    raise KeyError(f"{not_found} not in index")
KeyError: "[('ATLAS', 'ATLAS_TTBAR_13TEV_HADRONIC_2D_TTM_ABSYTTNORM', 10), ('ATLAS', 'ATLAS_TTBAR_13TEV_TTMNORM', 8), ('ATLAS', 'ATLAS_TTBARZ_13TEV_PTZNORM', 5), ('CMS', 'CMS_TTB_DIFF_13TEV_2016_2L_TTMNORM', 5), ('CMS', 'CMS_TTBAR_13TEV_TTMNORM', 14), ('CMS', 'CMS_TTBARZ_13TEV_PTZNORM', 3)] not in index"

Do you know what is going on?

I think it is to do with cuts, I will fix it

@J-M-Moore
Copy link
Collaborator Author

@J-M-Moore I am getting a KeyError:

  File "/auto/home/users/l/m/lmantani/applications/SIMUnet/simunet_release/n3fit/src/n3fit/performfit.py", line 208, in performfit
    exp_data = exp_data.loc[groups_index]
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1073, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1301, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1239, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexing.py", line 1432, in _get_listlike_indexer
    keyarr, indexer = ax._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2626, in _get_indexer_strict
    return super()._get_indexer_strict(key, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6070, in _get_indexer_strict
    self._raise_if_missing(keyarr, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/multi.py", line 2646, in _raise_if_missing
    return super()._raise_if_missing(key, indexer, axis_name)
  File "/home/ucl/cp3/lmantani/miniconda3/envs/simunet/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 6133, in _raise_if_missing
    raise KeyError(f"{not_found} not in index")
KeyError: "[('ATLAS', 'ATLAS_TTBAR_13TEV_HADRONIC_2D_TTM_ABSYTTNORM', 10), ('ATLAS', 'ATLAS_TTBAR_13TEV_TTMNORM', 8), ('ATLAS', 'ATLAS_TTBARZ_13TEV_PTZNORM', 5), ('CMS', 'CMS_TTB_DIFF_13TEV_2016_2L_TTMNORM', 5), ('CMS', 'CMS_TTBAR_13TEV_TTMNORM', 14), ('CMS', 'CMS_TTBARZ_13TEV_PTZNORM', 3)] not in index"

Do you know what is going on?

I think it is to do with cuts, I will fix it

It was to do with cuts, it is fixed now :)

@comane
Copy link
Member

comane commented Dec 19, 2023

[ERROR]: Bad configuration encountered:
A parameter is required: analytic_check.
This is needed to process:

  • performfit

@comane
Copy link
Member

comane commented Dec 19, 2023

I think it is important that we can still run a standard runcard on this branch without having to specify anything on analytic initialisation. So I think there should be some default values used when things like analytic_check are not specified

@LucaMantani
Copy link
Member

Something is wrong with the scales, if they are different from 1.0, they affect both the initialisation and the final writing, making the automatic initialisation not usable.

@LucaMantani
Copy link
Member

LucaMantani commented Dec 19, 2023

I pushed a small fix, in which the scales multiply the initialisation values, not divide. I think this was the source of the problem as now things seem to be working no matter the value of the scales.

If the values from the table are divided by the scale, the Wilson coefficient needs to be multiplied, so that the theoretical prediction given by
c * lin = (c * scale) * (lin / scale) = c' * lin'

This was not introduced in this PR, when initialising in 0 we were not noticing the problem, other kind of initialisation were affected.

Comment on lines +69 to +75
if num_initial > 0:
initial_values = tf.concat(initial_values, 0)
initial_values = tf.math.divide(initial_values, self.scales)
initial_values = tf.math.multiply(initial_values, self.scales)

if num_initial > 0:
initial_values = tf.concat(initial_values, 0)
initial_values = tf.reshape(initial_values, (num_initial,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why here there is the same if statement done twice, can't it all be done in one single if?

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

Successfully merging this pull request may close these issues.

5 participants