Code may not be quite correct.
a = np.array([1,2,3,4,5]) b = np.array([1,2,3,4,5]) # Method 1: Array at a time c = a + b # Method 2: Numba vectorize @numba.vectorize def vsum(a, b): return a + b # a and b are just single values! c = vsum(a, b) # Method 3: Manual parallel loop @numba.njit(parallel=True) def jsum(a, b): c = np.empty_like(a) for i in numba.prange(len(a)): c[i] = a[i] + b[i]
from numba import njit, prange import numpy as np @njit(parallel=True) def two_d_array_reduction_prod(n): shp = (13, 17) result1 = 2 * np.ones(shp, np.int_) tmp = 2 * np.ones_like(result1) for i in prange(n): result1 *= tmp return result1
This is for energy values for a detector that had multiple tiles, each tile is in a sector and there are two sectors (East and West). It is for runs over multiple days, so each row corresponds to a tile in the form:
[Day, East/West, Sector, Tile, Energy, Error]
Just to make it more clear what I was saying above. My goal is to get a graph for a particular tile over all the range of days, with error bars showing, and then to get an average value from that tile (again, with the associated error). I'm having trouble getting started; the standard code of:
import matplotlib.pyplot as plt plt.errorbar(x,y,xerr,yerr)
I'm not able to use well; I don't really know what should go in where (I've tried a few things without much success). Anyone perhaps have a link to a relevant tutorial or some other such?
prangeis a function in the
numba.prange(...)is required if you only import the
numbamodule. If you use
from numba import prange(which you do) then you have the
prange(...)function available without having to tell python that you want it from the
numbamodule (since you already imported it)
scipy.optimizemodule fitting functions
scipy.optimize.curve_fitshows an example with some plotting
We are pleased to announce the second "Python in HEP" workshop organised by the HEP Software Foundation (HSF). The PyHEP, "Python in HEP", workshops aim to provide an environment to discuss and promote the usage of Python in the HEP community at large.
PyHEP 2019 will be held in Abingdon, near Oxford, United Kingdom, from 16-18 October 2019.
The workshop will be a forum for the participants and the community at large to discuss developments of Python packages and tools, exchange experiences, and steer where the community needs and wants to go. There will be ample time for discussion.
The agenda will be composed of plenary sessions, a highlight of which is the following:
1) A keynote presentation from the Data Science domain.
2) A topical session on histogramming including a talk and a hands-on tutorial.
3) Lightning talks from participants.
4) Presentations following up from topics discussed at PyHEP 2018.
We encourage community members to propose presentations on any topic (email: firstname.lastname@example.org). We are particularly interested in new(-ish) packages of broad relevance.
The agenda will be made available on the workshop indico page (https://indico.cern.ch/event/833895/) in due time. It is also linked from the PyHEP WG homepage http://hepsoftwarefoundation.org/activities/pyhep.html.
Registration will open very soon, and we will provide detailed travel and accommodation information at that time.
Travel funds may be available at a modest level. To be confirmed once registration opens.
You are encouraged to register to the PyHEP WG Gitter channel (https://gitter.im/HSF/PyHEP) and/or to the HSF forum (https://groups.google.com/forum/#!forum/hsf-forum) to receive further information concerning the organisation of the workshop.
Looking forward to your participation!
Eduardo Rodrigues & Ben Krikler, for the organising committee
plt.hist2d(nMIP, refMult, bins=[150, 50], cmap=plt.cm.jet)
All right, next problem (sorry if I'm overly bugging you all): histogram fitting. I can do this fairly easily on ROOT, but I'm having a lot of trouble on Python. For whatever reason, I can't seem to find a tutorial that includes this. All the fitting tutorials give errors when I try to fit a 2D histogram. I'm making the histogram as I did in the above post:
plt.hist2d(mipVref, mipVref, bins=[150, 50], cmap=plt.cm.get_cmap("afmhot"))
I've tried curve_fit and Model, but to no avail. Any pointers to a specific method to fit 2D histos? Thanks!
I checked out a few things, and am hitting a snag when it comes to getting the function portion down. Here's my relevant code (much of which I adapted from others on Stack Exchange):
H, xedges, yedges = np.histogram2d(mipVref, mipVref, bins=[100, 100]) def centers(edges): return edges[:-1] + np.diff(edges[:2])/2 xcenters = centers(xedges) ycenters = centers(yedges) pdf = interp2d(xcenters, ycenters, H) plt.pcolor(xedges, yedges, pdf(xedges, yedges), cmap=plt.cm.get_cmap("hot"))
Sorry for the long post!
New question: I have a working model using Keras with Tensorflow background. My goal is to get the final function coded into ROOT as that's what we would need for the metric we're making. So, how do I make sense of the weights? Here's the relevant code:
model = Sequential() model.add(Dense(16, input_dim=16, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) model.fit(data[:, 1:], data[:, 0], epochs=30, batch_size=50)
I'm trying it with only one relu layer with 2 neurons in order to get a feel for how it all works, and it returns the following array sizes:
(16, 16), (1, 16), (16, 1), (1, 1)
Just from dimensional analysis (I'm using 16 inputs to get 1 output), I would think that the 16 inputs will combine with the (16, 16) array to give a (1, 16) array which adds the (16, 1) array elements and then the last (16, 1) gives a single element to use in the sigmoid (with the (1, 1) value being the additional term). Taking weights times inputs as w.x, and added to their modifiers. So this would be:
w1.x+b1 = x1, for all b1 indexed
w1 -> (16, 16), b1 -> (1, 16)
w2 -> (16, 1), b2 -> (1, 1)
Do I understand this correctly? I'm trying to hand-reproduce the final predictions from the model so I can run them in ROOT.
@henryiii I think that's what I'm looking for; I was trying to reconstruct the mathematics of the handoffs, but I think I was missing a layer or two in the exchange. It seems it's not quite as simple as I had it (thought reLU would be like a delta plus and sigmoid like a Boltzman). I'm reading through that git now. Thanks!
@tunnell It's not nearly as ambitious as running TensorFlow on ROOT; I'm just looking for a way to execute the prediction model that was generated. I thought it could be exported in a simple, mathematical formula (as all it's doing, in the end, is putting weights on inputs and using those for an output). I have the shape and weights printed out; basically, I'm looking to reconstruct the prediction algorithm (not further refine it or anything like that; I'm considering all training done once I get out of Python) for use in ROOT. If it's just a mathematical formula, which I should think it would have to be, it ought to be readily programmable to any language without much fuss, no?