Muster
 All Classes Namespaces Files Functions Variables Typedefs Macros
trial.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2010, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory
4 // LLNL-CODE-433662
5 // All rights reserved.
6 //
7 // This file is part of Muster. For details, see http://github.com/tgamblin/muster.
8 // Please also read the LICENSE file for further information.
9 //
10 // Redistribution and use in source and binary forms, with or without modification, are
11 // permitted provided that the following conditions are met:
12 //
13 // * Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the disclaimer below.
15 // * Redistributions in binary form must reproduce the above copyright notice, this list of
16 // conditions and the disclaimer (as noted below) in the documentation and/or other materials
17 // provided with the distribution.
18 // * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse
19 // or promote products derived from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
22 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24 // LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 ///
33 /// @file trial.h
34 /// @author Todd Gamblin tgamblin@llnl.gov
35 /// @brief Data structure representing a trial run of a partitioned clustering algorithm.
36 ///
37 #ifndef TRIAL_H
38 #define TRIAL_H
39 
40 #include <cstdlib>
41 
42 namespace cluster {
43 
44  ///
45  /// This struct represents parameters for a single trial run of kmedoids.
46  /// We generate a bunch of these to farm all the trials out to processes when doing
47  /// parallel clustering.
48  ///
49  /// Each trial has a particular <i>k</i> (number of clusters), sample size, and
50  /// repetition number (for successive samples with the same k).
51  ///
52  struct trial {
53  size_t k;
54  size_t rep;
55  size_t sample_size;
56 
57  trial() { }
58 
59  trial(size_t _k, size_t _rep, size_t _sample_size)
60  : k(_k), rep(_rep), sample_size(_sample_size) { }
61 
62  trial(const trial& other)
63  : k(other.k), rep(other.rep), sample_size(other.sample_size) { }
64  };
65 
66  ///
67  /// Class to generate a set of trials for clustering. This packages up state for the main
68  /// trial loop and allows work to be farmed out to worker processes.
69  ///
70  class trial_generator {
71  public:
72  ///
73  /// Constructor to generate trials from 1 to max_k.
74  ///
75  trial_generator(size_t _max_k, size_t _max_reps, size_t _init_size, size_t _num_objects);
76 
77  ///
78  /// Constructor to generate trials from min_k to max_k.
79  ///
80  trial_generator(size_t min_k, size_t _max_k,
81  size_t _max_reps, size_t _init_size, size_t _num_objects);
82 
83  size_t count() const; ///< return iterations so far.
84  bool has_next() const; ///< whether there are trials remaining.
85  trial next(); ///< return parameters for next trial
86  void reset(); ///< return to initial state
87  size_t num_trials(); ///< Return total number of trials this will generate.
88 
89  const size_t max_k; ///< maximum k to try
90  const size_t max_reps; ///< max number of repetitions per k
91  const size_t init_size; ///< initial size for samples before factoring in k, as per CLARA paper.
92  const size_t num_objects; ///< number of elements in the data set; determines maximum sample size.
93 
94  private:
95  trial cur_trial; ///< current state of the iterator.
96  size_t number_of_trials; ///< memoized total number of trials in this generator
97  size_t iterations; ///< number of iterations so far
98 
99  /// size of the sample to cluster for particular k
100  size_t get_sample_size(size_t k);
101  };
102 
103 } // namespace cluster
104 
105 #endif // TRIAL_H
bool has_next() const
whether there are trials remaining.
Definition: trial.cpp:79
const size_t max_k
maximum k to try
Definition: trial.h:89
size_t count() const
return iterations so far.
Definition: trial.cpp:105
trial next()
return parameters for next trial
Definition: trial.cpp:84
const size_t init_size
initial size for samples before factoring in k, as per CLARA paper.
Definition: trial.h:91
const size_t max_reps
max number of repetitions per k
Definition: trial.h:90
size_t k
Definition: trial.h:53
size_t num_trials()
Return total number of trials this will generate.
Definition: trial.cpp:101
trial(size_t _k, size_t _rep, size_t _sample_size)
Definition: trial.h:59
trial(const trial &other)
Definition: trial.h:62
trial_generator(size_t _max_k, size_t _max_reps, size_t _init_size, size_t _num_objects)
Constructor to generate trials from 1 to max_k.
Definition: trial.cpp:54
size_t rep
Definition: trial.h:54
const size_t num_objects
number of elements in the data set; determines maximum sample size.
Definition: trial.h:92
Class to generate a set of trials for clustering.
Definition: trial.h:70
void reset()
return to initial state
This struct represents parameters for a single trial run of kmedoids.
Definition: trial.h:52
size_t sample_size
Definition: trial.h:55
Muster. Copyright © 2010, Lawrence Livermore National Laboratory, LLNL-CODE-433662.
Distribution of Muster and its documentation is subject to terms of the Muster LICENSE.
Generated on Thu Sep 1 2016 using Doxygen 1.8.5