LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
data_reader_synthetic.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
25 //
27 
28 #ifndef LBANN_DATA_READER_SYNTHETIC_HPP
29 #define LBANN_DATA_READER_SYNTHETIC_HPP
30 
31 #include "data_reader.hpp"
33 
34 // Forward declaration
35 class DataReaderSyntheticWhiteboxTester;
36 
37 namespace lbann {
38 
44 {
45 public:
46  // TODO: add what data distribution to use
47  data_reader_synthetic(int num_samples, int num_features, bool shuffle = true);
48  data_reader_synthetic(int num_samples,
49  std::vector<El::Int> dims,
50  int num_labels,
51  bool shuffle = true);
52  data_reader_synthetic(int num_samples,
53  std::vector<El::Int> dims,
54  std::vector<El::Int> response_dims,
55  bool shuffle = true);
56  data_reader_synthetic(int num_samples,
57  std::map<data_field_type, std::vector<El::Int>> data_fields,
58  bool shuffle = true);
61  ~data_reader_synthetic() override {}
62  data_reader_synthetic* copy() const override
63  {
64  return new data_reader_synthetic(*this);
65  }
66  std::string get_type() const override { return "data_reader_synthetic"; }
67 
68  void load() override;
69 
70  int get_linearized_size(data_field_type const& data_field) const override
71  {
72  auto iter = m_synthetic_data_fields.find(data_field);
73  if (iter == end(m_synthetic_data_fields)) {
74  LBANN_ERROR("Unknown data field ", data_field);
75  }
76  return get_linear_size(iter->second);
77  }
78 
79  int get_linearized_data_size() const override
80  {
82  }
83  int get_linearized_label_size() const override { return m_num_labels; }
84  int get_linearized_response_size() const override
85  {
87  }
88 
89  const std::vector<El::Int> get_data_dims() const override { return m_dimensions; }
90 
91  int get_num_labels() const override { return m_num_labels; }
92  int get_num_responses() const override
93  {
95  }
96 
97 protected:
98  bool fetch_data_field(data_field_type data_field,
99  CPUMat& Y,
100  int data_id,
101  int mb_idx) override;
102  bool fetch_datum(CPUMat& X, int data_id, int mb_idx) override;
103  bool fetch_label(CPUMat& Y, int data_id, int mb_idx) override;
104  bool fetch_response(CPUMat& Y, int data_id, int mb_idx) override;
105 
106  // Designate a whitebox testing friend
107  friend class ::DataReaderSyntheticWhiteboxTester;
108 
109 private:
115  std::vector<El::Int> m_dimensions;
117  std::vector<El::Int> m_response_dimensions;
118 
119  std::map<data_field_type, std::vector<El::Int>> m_synthetic_data_fields;
120 };
121 
122 } // namespace lbann
123 
124 #endif // LBANN_DATA_READER_SYNTHETIC_HPP
int get_linearized_response_size() const override
Get the linearized size (i.e. number of elements) in a response.
const std::vector< El::Int > get_data_dims() const override
Get the dimensions of the data.
auto get_linear_size(std::vector< T > const &dims)
Definition: dim_helpers.hpp:59
int get_linearized_size(data_field_type const &data_field) const override
get the linearized size of what is identified by desc.
std::vector< El::Int > m_response_dimensions
#define LBANN_ERROR(...)
Definition: exception.hpp:37
int get_num_responses() const override
Return the number of responses in this dataset.
data_reader_synthetic(int num_samples, int num_features, bool shuffle=true)
bool fetch_datum(CPUMat &X, int data_id, int mb_idx) override
bool fetch_data_field(data_field_type data_field, CPUMat &Y, int data_id, int mb_idx) override
Called by fetch_data, fetch_label, fetch_response.
bool fetch_label(CPUMat &Y, int data_id, int mb_idx) override
El::Matrix< DataType, El::Device::CPU > CPUMat
Definition: base.hpp:116
std::string get_type() const override
data_reader_synthetic & operator=(const data_reader_synthetic &)=default
bool fetch_response(CPUMat &Y, int data_id, int mb_idx) override
int get_linearized_label_size() const override
Get the linearized size (i.e. number of elements) in a label.
std::map< data_field_type, std::vector< El::Int > > m_synthetic_data_fields
std::string data_field_type
int get_num_labels() const override
Return the number of labels (classes) in this dataset.
int get_linearized_data_size() const override
Get the linearized size (i.e. number of elements) in a sample.
data_reader_synthetic * copy() const override