Skip to content

Commit b07e36f

Browse files
committed
improve control over prng in hydra::unweight, change hydra::Exponential
1 parent 7875dc9 commit b07e36f

File tree

9 files changed

+335
-191
lines changed

9 files changed

+335
-191
lines changed

examples/random/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ ADD_HYDRA_EXAMPLE(fill_basic_distributions BUILD_CUDA_TARGETS BUILD_TBB_TARGETS
88
ADD_HYDRA_EXAMPLE(sample_distribution BUILD_CUDA_TARGETS BUILD_TBB_TARGETS BUILD_OMP_TARGETS BUILD_CPP_TARGETS)
99
ADD_HYDRA_EXAMPLE(booststrapping BUILD_CUDA_TARGETS BUILD_TBB_TARGETS BUILD_OMP_TARGETS BUILD_CPP_TARGETS)
1010
ADD_HYDRA_EXAMPLE(sobol_quasirandom BUILD_CUDA_TARGETS BUILD_TBB_TARGETS BUILD_OMP_TARGETS BUILD_CPP_TARGETS)
11+
ADD_HYDRA_EXAMPLE(unweight_sample BUILD_CUDA_TARGETS BUILD_TBB_TARGETS BUILD_OMP_TARGETS BUILD_CPP_TARGETS)

examples/random/basic_distributions.inl

Lines changed: 2 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -33,165 +33,6 @@
3333
*
3434
*/
3535

36-
/*
37-
#include <iostream>
38-
#include <assert.h>
39-
#include <time.h>
40-
#include <chrono>
41-
42-
//command line
43-
#include <tclap/CmdLine.h>
44-
45-
//this lib
46-
#include <hydra/device/System.h>
47-
#include <hydra/host/System.h>
48-
#include <hydra/Function.h>
49-
#include <hydra/Lambda.h>
50-
#include <hydra/Random.h>
51-
#include <hydra/Algorithm.h>
52-
*/
53-
/*-------------------------------------
54-
* Include classes from ROOT to fill
55-
* and draw histograms and plots.
56-
*-------------------------------------
57-
*/
58-
/*
59-
#ifdef _ROOT_AVAILABLE_
60-
61-
#include <TROOT.h>
62-
#include <TH1D.h>
63-
#include <TApplication.h>
64-
#include <TCanvas.h>
65-
66-
#endif //_ROOT_AVAILABLE_
67-
68-
69-
70-
int main(int argv, char** argc)
71-
{
72-
size_t nentries = 0;
73-
74-
try {
75-
76-
TCLAP::CmdLine cmd("Command line arguments for ", '=');
77-
78-
TCLAP::ValueArg<size_t> EArg("n", "number-of-events","Number of events", true, 10e6, "size_t");
79-
cmd.add(EArg);
80-
81-
// Parse the argv array.
82-
cmd.parse(argv, argc);
83-
84-
// Get the value parsed by each arg.
85-
nentries = EArg.getValue();
86-
87-
}
88-
catch (TCLAP::ArgException &e) {
89-
std::cerr << "error: " << e.error() << " for arg " << e.argId()
90-
<< std::endl;
91-
}
92-
93-
94-
//generator
95-
hydra::Random<>
96-
Generator( std::chrono::system_clock::now().time_since_epoch().count() );
97-
98-
99-
//device
100-
//------------------------
101-
#ifdef _ROOT_AVAILABLE_
102-
103-
TH1D hist_uniform_d("uniform_d", "Uniform", 100, -6.0, 6.0);
104-
TH1D hist_gaussian_d("gaussian_d", "Gaussian", 100, -6.0, 6.0);
105-
TH1D hist_exp_d("exponential_d", "Exponential", 100, 0.0, 5.0);
106-
TH1D hist_bw_d("breit_wigner_d", "Breit-Wigner",100, 0.0, 5.0);
107-
108-
#endif //_ROOT_AVAILABLE_
109-
110-
{
111-
//1D device buffer
112-
hydra::device::vector<double> data_d(nentries);
113-
hydra::host::vector<double> data_h(nentries);
114-
115-
//-------------------------------------------------------
116-
//uniform
117-
Generator.Uniform(-5.0, 5.0, data_d.begin(), data_d.end());
118-
hydra::copy(data_d, data_h);
119-
120-
for(size_t i=0; i<10; i++)
121-
std::cout << "< Random::Uniform > [" << i << "] :" << data_d[i] << std::endl;
122-
123-
#ifdef _ROOT_AVAILABLE_
124-
for(auto value : data_h)
125-
hist_uniform_d.Fill( value);
126-
#endif //_ROOT_AVAILABLE_
127-
128-
//-------------------------------------------------------
129-
//gaussian
130-
Generator.Gauss(0.0, 1.0, data_d.begin(), data_d.end());
131-
hydra::copy(data_d, data_h);
132-
133-
for(size_t i=0; i<10; i++)
134-
std::cout << "< Random::Gauss > [" << i << "] :" << data_d[i] << std::endl;
135-
136-
#ifdef _ROOT_AVAILABLE_
137-
for(auto value : data_d)
138-
hist_gaussian_d.Fill( value);
139-
#endif //_ROOT_AVAILABLE_
140-
141-
//-------------------------------------------------------
142-
//exponential
143-
Generator.Exp(1.0, data_d);
144-
hydra::copy(data_d, data_h);
145-
146-
for(size_t i=0; i<10; i++)
147-
std::cout << "< Random::Exp > [" << i << "] :" << data_d[i] << std::endl;
148-
149-
#ifdef _ROOT_AVAILABLE_
150-
for(auto value : data_h)
151-
hist_exp_d.Fill( value);
152-
#endif //_ROOT_AVAILABLE_
153-
154-
//-------------------------------------------------------
155-
//breit-wigner
156-
Generator.BreitWigner(2.0, 0.2, data_d.begin(), data_d.end());
157-
hydra::copy(data_d, data_h);
158-
159-
for(size_t i=0; i<10; i++)
160-
std::cout << "< Random::BreitWigner > [" << i << "] :" << data_d[i] << std::endl;
161-
162-
#ifdef _ROOT_AVAILABLE_
163-
for(auto value : data_h)
164-
hist_bw_d.Fill( value);
165-
#endif //_ROOT_AVAILABLE_
166-
}
167-
168-
169-
170-
171-
#ifdef _ROOT_AVAILABLE_
172-
TApplication *myapp=new TApplication("myapp",0,0);
173-
174-
//draw histograms
175-
TCanvas canvas_d("canvas_d" ,"Distributions - Device", 1000, 1000);
176-
canvas_d.Divide(2,2);
177-
canvas_d.cd(1); hist_uniform_d.Draw("hist");
178-
canvas_d.cd(2); hist_gaussian_d.Draw("hist");
179-
canvas_d.cd(3); hist_exp_d.Draw("hist");
180-
canvas_d.cd(4); hist_bw_d.Draw("hist");
181-
182-
183-
184-
myapp->Run();
185-
186-
#endif //_ROOT_AVAILABLE_
187-
188-
return 0;
189-
190-
191-
192-
}
193-
194-
*/
19536
#include <iostream>
19637
#include <assert.h>
19738
#include <time.h>
@@ -262,17 +103,9 @@ auto data = hydra::device::vector< double>(10, .0);
262103
//Parameters
263104
auto mean = hydra::Parameter::Create("mean" ).Value(0.0);
264105
auto sigma = hydra::Parameter::Create("sigma").Value(0.25);
106+
auto gauss = hydra::Gaussian<xvar>(mean, sigma);
265107

266-
auto gauss = hydra::Gaussian<xvar>(mean, sigma);
267-
268-
for(auto x: data)
269-
std::cout << ">>>>>>>>>"<<hydra::detail::is_valid_type_pack<hydra_thrust::tuple<xvar> , decltype(x) >::value << std::endl;
270-
//x.dummy;
271-
//std::cout << gauss(x) << std::endl;
272-
273-
274-
275-
//LogNormal distribution
108+
//LogNormal distribution
276109
auto lognormal = hydra::LogNormal<xvar>(mean, sigma);
277110

278111

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*----------------------------------------------------------------------------
2+
*
3+
* Copyright (C) 2016 - 2020 Antonio Augusto Alves Junior
4+
*
5+
* This file is part of Hydra Data Analysis Framework.
6+
*
7+
* Hydra is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Hydra is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Hydra. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*---------------------------------------------------------------------------*/
21+
22+
/*
23+
* unweight_sample.cpp
24+
*
25+
* Created on: 21/10/2020
26+
* Author: Antonio Augusto Alves Junior
27+
*/
28+
29+
#include <examples/random/unweight_sample.inl>

examples/random/unweight_sample.cu

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*----------------------------------------------------------------------------
2+
*
3+
* Copyright (C) 2016 - 2020 Antonio Augusto Alves Junior
4+
*
5+
* This file is part of Hydra Data Analysis Framework.
6+
*
7+
* Hydra is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Hydra is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Hydra. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*---------------------------------------------------------------------------*/
21+
22+
/*
23+
* unweight_sample.cu
24+
*
25+
* Created on: 21/10/2020
26+
* Author: Antonio Augusto Alves Junior
27+
*/
28+
29+
#include <examples/random/unweight_sample.inl>

0 commit comments

Comments
 (0)