virtual const Covariance& covariance() const { Mean mu = mean(); cov_ = Covariance::Zero(dimension(), dimension()); for(int i = 0; i < locations_.size(); i++) { Mean delta = (locations_[i].template cast<Real>()-mu); cov_ += prob_mass(i) * delta * delta.transpose(); } return cov_; }
int main(void) { int array[] = { 10, 2, 3, 34, 3, 4, 45, 99 }; int array_size = sizeof( array ) / sizeof( array[0] ); Mean< int > mean; for ( unsigned int i = 0; i < array_size; ++i ) { mean( array[i] ); } std::cout << "mean: " << mean.value() << std::endl; return 0; }
NormalDistribution::NormalDistribution(const Mean& m, const StdDeviation& sigma) : DistributionBase(), mean_(m.value()), stdDev_(sigma.value()) { if(stdDev_ < 0.0) throw runtime_error("NormalDistribution : in ctor, sigma must be positive."); lower_ = mean_ - stdDev_*2; upper_ = mean_ + stdDev_*2; pLower_ = getUntruncatedCDF(lower_); pUpper_ = getUntruncatedCDF(upper_); }
NormalDistribution::NormalDistribution(const Mean& m, const StdDeviation& sigma, double numDeviations) : DistributionBase(), mean_(m.value()), stdDev_(sigma.value()) { if(stdDev_ < 0.0) throw std::runtime_error("NormalDistribution : in ctor, sigma must be positive."); if(numDeviations < 0.0) throw runtime_error("NormalDistribution : in ctor, numDevations must be positive."); lower_ = mean_ - numDeviations*stdDev_; upper_ = mean_ + numDeviations*stdDev_; pLower_ = getUntruncatedCDF(lower_); pUpper_ = getUntruncatedCDF(upper_); }
/** * Record performance measures */ void record(uint time, const Model& model, double control = 1){ //uint year = IOSKJ::year(time); uint quarter = IOSKJ::quarter(time); times.append(); // Catch magnitude auto catch_total = model.catches_taken(sum); catches_total.append(catch_total); auto catches_by_method = model.catches_taken(sum,by(methods)); catches_ps.append(catches_by_method(PS)); catches_pl.append(catches_by_method(PL)); catches_gn.append(catches_by_method(GN)); // Years catch goes below baseline catches_lower.append(catch_total < 425000/4.0); // Catch variability if(quarter == 0 and catch_total>0){ catches_var.append(catch_total); catches_mapc.append(catch_total); } // Shutdown defined as quarterly catches <10% of recent average // catches of about 400000t catches_shut.append(catch_total<1000); // Changes in MP control e.g. catch or effort limit if (quarter == 0) { if (std::isfinite(control_last_)) { control_ups.append(control>control_last_); control_downs.append(control<control_last_); } control_last_ = control; } // Stock status relative to unfished auto status = model.biomass_status(); status_mean.append(status); status_b10.append(status<0.1); status_b20.append(status<0.2); // Biomass relative to B40 auto b = model.biomass_spawners(sum)/model.biomass_spawners_40; b_ratio.append(b); // F relative to F40 auto f = model.fishing_mortality_get()/model.f_40; f_ratio.append(f); // Kobe plot // Determine quadrant char quadrant; if(b>=1){ if(f<=1) quadrant = 'a'; else quadrant = 'b'; } else { if(f<=1) quadrant = 'c'; else quadrant = 'd'; } // Update performance measures for proportion of time spent in each quadrant kobe_a.append(quadrant=='a'); kobe_b.append(quadrant=='b'); kobe_c.append(quadrant=='c'); kobe_d.append(quadrant=='d'); // Update performance measure for time taken to get back into quadrant A if(quadrant=='a'){ // If previously outside of A then append the time that // have been outside to the mean and reset time counter to zero. if(kobe_out_a>0){ kobe_to_a.append(kobe_out_a); kobe_out_a = 0; } } else { // Outside of A so increment time counter. kobe_out_a++; } // Catch rates // Use vulnerable (i.e. selected) biomass for the three main regions/gears // relative to the start year as a measure of catch rates (CPUE) if(times==1){ // Record baselines for(auto region : regions){ for(auto method : methods){ cpue_baseline(region,method) = model.biomass_vulnerable(region,method); } } } else { // Record relative to baseline for(auto region : regions){ for(auto method : methods){ cpue_mean(region,method).append( model.biomass_vulnerable(region,method)/cpue_baseline(region,method) ); } } } }