13 namespace alps {
namespace alea {
15 template <
typename T,
typename Str>
23 template <
typename T,
typename Str>
32 template <
typename T,
typename Str>
37 data2_ -= count_ * data_.cwiseAbs2();
42 const double nunbiased = count_ - count2_/count_;
44 data2_ = data2_.array().isNaN().select(data2_, INFINITY);
47 data2_ = data2_ / nunbiased;
51 template <
typename T,
typename Str>
61 const double nunbiased = count_ - count2_/count_;
63 data2_ = data2_.array().isNaN().select(data2_, 0);
65 data2_ = data2_ * nunbiased;
67 data2_ += count_ * data_.cwiseAbs2();
76 template <
typename T,
typename Str>
79 , current_(size, batch_size)
83 template <
typename T,
typename Str>
85 : store_(other.store_ ? new
var_data<T,Str>(*other.store_) : nullptr)
86 , current_(other.current_)
89 template <
typename T,
typename Str>
92 store_.reset(other.store_ ?
new var_data<T,Str>(*other.store_) :
nullptr);
93 current_ = other.current_;
97 template <
typename T,
typename Str>
107 template <
typename T,
typename Str>
115 template <
typename T,
typename Str>
123 template <
typename T,
typename Str>
135 template <
typename T,
typename Str>
146 store_->data() += other_store.
data();
147 store_->data2() += other_store.
data2();
148 store_->count() += other_store.
count();
149 store_->count2() += other_store.
count2();
154 template <
typename T,
typename Str>
163 template <
typename T,
typename Str>
171 template <
typename T,
typename Str>
178 if (current_.
count() != 0)
182 result.store_.reset();
183 result.store_.swap(store_);
186 result.store_->convert_to_mean();
189 template <
typename T,
typename Str>
195 store_->data().noalias() += current_.
sum();
196 store_->data2().noalias() += current_.
sum().unaryExpr(abs2) / current_.
count();
197 store_->count() += current_.
count();
198 store_->count2() += current_.
count() * current_.
count();
201 if (cascade !=
nullptr)
212 template <
typename T,
typename Str>
214 : store_(other.store_ ? new
var_data<T,Str>(*other.store_) : nullptr)
217 template <
typename T,
typename Str>
220 store_.reset(other.store_ ?
new var_data<T,Str>(*other.store_) :
nullptr);
224 template <
typename T,
typename Strategy>
238 const var_result<std::complex<double>, circular_var> &r2);
240 const var_result<std::complex<double>, elliptic_var> &r2);
242 template <
typename T,
typename Str>
249 template <
typename T,
typename Str>
254 store_->convert_to_sum();
255 r.
reduce(
view<T>(store_->data().data(), store_->data().rows()));
260 if (pre_commit && post_commit) {
266 store_->convert_to_mean();
277 template <
typename T,
typename Str>
283 serialize(s,
"@size",
self.store_->data_.size());
284 serialize(s,
"count",
self.store_->count_);
285 serialize(s,
"count2",
self.store_->count2_);
287 serialize(s,
"value",
self.store_->data_);
290 serialize(s,
"var",
self.store_->data2_);
293 template <
typename T,
typename Str>
302 if (!
self.
valid() ||
self.
size() != new_size)
324 template <
typename T,
typename Str>
325 std::ostream &operator<<(std::ostream &str, const var_result<T,Str> &
self)
333 str <<
self.mean() <<
" +- " <<
self.stderror();
337 template std::ostream &operator<<(std::ostream &, const var_result<double, circular_var> &);
338 template std::ostream &operator<<(std::ostream &, const var_result<std::complex<double>, circular_var> &);
339 template std::ostream &operator<<(std::ostream &, const var_result<std::complex<double>, elliptic_var> &);
void finalize_to(var_result< T, Strategy > &result, var_acc *cascade)
var_result< T, Strategy > result() const
column< var_type > stderror() const
void check_valid(const Acc &acc)
const column< value_type > & data() const
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
const var_data< T, Strategy > & store() const
size_t batch_size() const
void set_size(size_t size)
void add_bundle(var_acc *cascade)
var_result & operator=(const var_result &other)
var_result< T, Strategy > finalize()
void reduce(const reducer &r)
friend void serialize(serializer &, const std::string &, const var_result &)
void add(const computed< T > &source, size_t count, var_acc *cascade)
virtual void commit() const =0
bind< Strategy, T >::var_type var_type
const column< var_type > & data2() const
T & get_format(std::ios_base &stream, T initial_value=T())
var_acc & operator=(const var_acc &other)
var_acc(size_t size=1, size_t batch_size=1)
virtual void read(const std::string &key, ndview< double >)=0
virtual void add_to(view< T > out) const =0
friend void deserialize(deserializer &, const std::string &, var_result &)
bool operator==(const autocorr_result< T > &r1, const autocorr_result< T > &r2)
virtual reducer_setup get_setup() const =0
virtual void enter(const std::string &group)=0
T r(T x, T y=T(), T z=T())
eigen_adapter< typename Derived::Scalar, Derived > make_adapter(const Eigen::DenseBase< Derived > &in)
var_acc & operator<<(const computed< T > &src)
virtual void reduce(view< double > data) const =0
virtual void enter(const std::string &group)=0
double observations() const
void set_batch_size(size_t batch_size)