GithubHelp home page GithubHelp logo

hep-mh / acropolis Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 27.99 MB

A library that enables the calculation of photodisintegration constraints for a variety of BSM scenarios

Home Page: https://acropolis.hepforge.org

License: GNU General Public License v3.0

Python 92.16% Shell 0.84% C 2.18% HTML 4.83%
light-elements bsm dark-matter bbn photodisintegration particle-physics physics cosmology dark-sectors decays

acropolis's Issues

Issue with the interpolator in `InputInterface::_interp_cosmo_data`

I have noticed that the code for the piecewise linear interpolation in InputInterface::_interp_cosmo_data does not work as intended. In particular the follwoing line is not doing what is intended

ix = np.argmin( np.abs( x - val_log ) )

Judging from the logic of the code, this line is supposed to return the index ix of the data point which is to the left of the point in question, but what it actually returns is the index of the data point which is the closest, which might also lie to the right of the point in question.

This will in general lead to discontinuities right in the middle between two data points (cf. plots below). Assuming that the x-values are in increasing order, it is also important to check whether the closest data point has a value x[ix] that is bigger than val. If so, ix has to be decreased by one. Note that this will automatically include the rather artificial decrease of ix when ix points to the end of the x-array. Therefore, it is sufficient to replace the line if ix == N - 1: by if x[ix] >= log_val:. In the case the initial x-array is not sorted in increasing order, both arrays x and y have to be sorted first.

Attached you will find plots that show the issue in a minimal working example. The red line denotes the original test function and the red dots refer to the discrete data points. The blue line shows the result of the buggy interpolation, whereas the yellow line shows the interpolation after the fix is applied.
For x in increasing order the plot is shown here, the corresponding plot for x in decreasing order is shown
here.

The code for this MWE can be found here (note to change the file type from .py.txt back to .py as github does not allow for .py files to be uploaded.

I suggest to fix this issue by changing

def _interp_cosmo_data(self, val, xc, yc):
    x = self._sCosmoDataLog[:,xc]
    y = self._sCosmoDataLog[:,yc]
    N = self._sCosmoDataShp[0]

    val_log = log10(val)
    # Extract the index corresponding to
    # the data entries above and below 'val'
    ix = np.argmin( np.abs( x - val_log ) )
    if ix == N - 1:
        ix -= 1

    m = (y[ix+1] - y[ix])/(x[ix+1] - x[ix])
    b = y[ix] - m*x[ix]

    return 10**(m*val_log + b)

to

def _interp_cosmo_data(self, val, xc, yc):
    x = self._sCosmoDataLog[:,xc]
    y = self._sCosmoDataLog[:,yc]
    N = self._sCosmoDataShp[0]

    # Sort x and y in increasing order
    o = np.argsort(x)
    x = x[o]
    y = y[o]

    val_log = log10(val)
    # Extract the index corresponding to
    # the data entries above and below 'val'
    ix = np.argmin( np.abs( x - val_log ) )
    if x[ix] >= val_log:
        ix -= 1

    m = (y[ix+1] - y[ix])/(x[ix+1] - x[ix])
    b = y[ix] - m*x[ix]

    return 10**(m*val_log + b)

in acropolis/input.py starting at line 98.

Note that as long as the original function is sampled well enough, this bug is not as severe, but it should be fixed anyway.

Cheers,
Patrick

Issues with vanishing decay rates

Occasionally some decay rates vanish, e.g. the Be7+a>He3+He4 rate is exactly 0 for low temperatures for the following parameter point (using the decay model)

3.17367 1.60439e+10 10 5.7220383e-10 0 1

I don't know how sensible these values are, but they are not unique, and many such points are easily reached in large parameter scans.

These decay rates are so small that are below the precision limit and are effectively set to 0, which causes problems down the line when setting up the interpolators using log scale, and acropolis fails with an NaN error. I don't think this is a conceptual problem, really small rates are possible as far as I can tell, so it should be just a computational problem on how to handle these really small rates. Locally I've just regularized all zeroes in the grids to the minimum float value of the system, which is enough for the log interpolator to work fine. This is my suggested fix to acropolis/utils.py

@@ -2,6 +2,8 @@
 from math import log, pow
 # numpy
 import numpy as np
+# sys
+import sys
 
 
 class LogInterp(object):
@@ -11,6 +13,9 @@ class LogInterp(object):
         self._sLogBase = log(self._sBase)
 
         self._sFillValue = fill_value
+ 
+        x_grid = [x if x > 0 else sys.float_info.min for x in x_grid]
+        y_grid = [y if y > 0 else sys.float_info.min for y in y_grid]
 
         self._sXLog = np.log(x_grid)/self._sLogBase
         self._sYLog = np.log(y_grid)/self._sLogBase

I hope this helps you with implementing a fix to this in this or any other way.

Cheers,
Tomas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.