41 #ifndef SHARK_DATA_SPARSEDATA_H 42 #define SHARK_DATA_SPARSEDATA_H 66 LabeledData<RealVector, unsigned int>& dataset,
68 unsigned int highestIndex = 0,
79 LabeledData<RealVector, RealVector>& dataset,
81 unsigned int highestIndex = 0,
92 LabeledData<CompressedRealVector, unsigned int>& dataset,
94 unsigned int highestIndex = 0,
105 LabeledData<CompressedRealVector, RealVector>& dataset,
106 std::istream& stream,
107 unsigned int highestIndex = 0,
118 LabeledData<RealVector, unsigned int>& dataset,
120 unsigned int highestIndex = 0,
131 LabeledData<RealVector, RealVector>& dataset,
133 unsigned int highestIndex = 0,
144 LabeledData<CompressedRealVector, unsigned int>& dataset,
146 unsigned int highestIndex = 0,
157 LabeledData<CompressedRealVector, RealVector>& dataset,
159 unsigned int highestIndex = 0,
170 template<
typename InputType>
175 std::vector< KeyValuePair<unsigned int, std::pair<std::size_t, std::size_t> > > order;
178 auto batch = dataset.
batch(b);
179 for (std::size_t i=0; i<
batchSize(batch); i++)
181 order.emplace_back(
getBatchElement(batch, i).label, std::make_pair(b, i));
186 std::sort(order.begin(), order.end());
189 for (
auto const& p : order)
193 if (oneMinusOne) stream << 2*int(element.label)-1 <<
" ";
195 else stream << element.label+1 <<
" ";
197 for (
auto it = element.input.begin(); it != element.input.end(); ++it)
199 stream <<
" " << it.index()+1 <<
":" << *it;
212 template<
typename InputType>
218 if (append ==
true) {
219 ofs.open (fn.c_str(), std::fstream::out | std::fstream::app );
221 ofs.open (fn.c_str());
232 template<
typename InputType>
237 auto batch = dataset.
batch(b);
238 for (std::size_t i=0; i<
batchSize(batch); i++)
242 stream << element.label(0);
243 for (
auto it = element.input.begin(); it != element.input.end(); ++it)
245 stream <<
" " << it.index()+1 <<
":" << *it;
257 template<
typename InputType>
263 if (append ==
true) {
264 ofs.open (fn.c_str(), std::fstream::out | std::fstream::app );
266 ofs.open (fn.c_str());