virtual void
 w(const dipvector_t &diploids, gcont_t &gametes,
   const mcont_t &mutations)
 {
     auto N_curr = diploids.size();
     if (fitnesses.size() < N_curr)
         fitnesses.resize(N_curr);
     wbar = 0.;
     for (size_t i = 0; i < N_curr; ++i)
         {
             gametes[diploids[i].first].n
                 = gametes[diploids[i].second].n = 0;
             fitnesses[i] = diploids[i].w;
             wbar += diploids[i].w;
         }
     wbar /= double(N_curr);
     lookup = KTfwd::fwdpp_internal::gsl_ran_discrete_t_ptr(
         gsl_ran_discrete_preproc(N_curr, &fitnesses[0]));
 }
Exemple #2
0
    sep_sample_t
    ms_sample_separate_single_deme( const mcont_t & mutations,
				    const gcont_t & gametes,
				    const dipvector_t & diploids,
				    const std::vector<unsigned> & diplist,
				    const unsigned & n,
				    const bool & remove_fixed )
    {
      sep_sample_t rv;
      sample_t::iterator itr;

      std::function<bool(const sample_site_t &, const double &)> sitefinder = [](const sample_site_t & site,
										 const double & d )
	{
	  return std::fabs(site.first-d) <= std::numeric_limits<double>::epsilon();
	};

      for( size_t i = 0 ; i < diplist.size() ; ++i )
	{
	  typename dipvector_t::difference_type ind = diplist[i];
	  assert(ind>=0);
	  assert( unsigned(ind) < diploids.size() );
	  fwdpp_internal::update_sample_block( rv.first,gametes[diploids[ind].first].mutations,mutations,i,2*diplist.size(),sitefinder);
	  fwdpp_internal::update_sample_block( rv.first,gametes[diploids[ind].second].mutations,mutations,i,2*diplist.size(),sitefinder,1);
	  fwdpp_internal::update_sample_block( rv.second,gametes[diploids[ind].first].smutations,mutations,i,2*diplist.size(),sitefinder);
	  fwdpp_internal::update_sample_block( rv.second,gametes[diploids[ind].second].smutations,mutations,i,2*diplist.size(),sitefinder,1);
	}
      if(remove_fixed&&!rv.first.empty())
	{
	  remove_fixed_variants_from_sample(rv.first,2*diplist.size());
	}
      if(!rv.first.empty())
	{
	  std::sort(rv.first.begin(),rv.first.end(),
		    [](const sample_site_t & lhs,
		       const sample_site_t & rhs) { return lhs.first < rhs.first; });
	}
      if(remove_fixed&&!rv.second.empty())
	{
	  remove_fixed_variants_from_sample(rv.second,2*diplist.size());
	}
      if(!rv.second.empty())
	{
	  std::sort(rv.second.begin(),rv.second.end(),
		    [](const sample_site_t & lhs,
		       const sample_site_t & rhs) { return lhs.first < rhs.first; });
	}
      //Deal w/odd sample sizes
      if(n%2 != 0.)
	{
	  trim_last(&rv.first);
	  trim_last(&rv.second);
	}
      assert(std::is_sorted(rv.first.begin(),rv.first.end(),
			    [](const sample_site_t & a,
			       const sample_site_t & b) noexcept {
			      return a.first<b.first;
			    }));
      assert(std::is_sorted(rv.second.begin(),rv.second.end(),
			    [](const sample_site_t & a,
			       const sample_site_t & b) noexcept {
			      return a.first<b.first;
			    }));
      return rv;
    }
Exemple #3
0
    std::vector<sep_sample_t >
    ms_sample_separate_mlocus( const mcont_t & mutations,
			       const gcont_t & gametes,
			       const dipvector_t & diploids,
			       const std::vector<unsigned> & diplist,
			       const unsigned & n,
			       const bool & remove_fixed)
    {
      using rvtype = std::vector<sep_sample_t>;
      //using genotype = typename dipvector_t::value_type;

      rvtype rv( diploids.size() );

      std::function<bool(const sample_site_t &, const double &)> sitefinder = [](const sample_site_t & site,
										 const double & d )
	{
	  return std::fabs(site.first-d) <= std::numeric_limits<double>::epsilon();
	};

      //Go over each indidivual's mutations and update the return value
      //typename dipvector_t::const_iterator dbegin = diploids->begin();
      for( unsigned ind = 0 ; ind < diplist.size() ; ++ind )
	{
	  unsigned rv_count=0;
	  for (const auto & locus : diploids[diplist[ind]] )
	    {
	      //finally, we can go over mutations
	      fwdpp_internal::update_sample_block(rv[rv_count].first,gametes[locus.first].mutations,mutations,ind,2*diplist.size(),sitefinder);
	      fwdpp_internal::update_sample_block(rv[rv_count].second,gametes[locus.first].smutations,mutations,ind,2*diplist.size(),sitefinder);
	      fwdpp_internal::update_sample_block(rv[rv_count].first,gametes[locus.second].mutations,mutations,ind,2*diplist.size(),sitefinder,1);
	      fwdpp_internal::update_sample_block(rv[rv_count].second,gametes[locus.second].smutations,mutations,ind,2*diplist.size(),sitefinder,1);
	      ++rv_count;	      
	    }
	}

      if( remove_fixed )
	{
	  for( unsigned i = 0 ; i < rv.size() ; ++i )
	    {
	      remove_fixed_variants_from_sample(rv[i].first,2*diplist.size());
	      remove_fixed_variants_from_sample(rv[i].second,2*diplist.size());
	    }
	}
      //sort on position
      for( unsigned i = 0 ; i < rv.size() ; ++i )
	{
	  std::sort(rv[i].first.begin(),rv[i].first.end(),
		    [](const sample_site_t & lhs,
		       const sample_site_t & rhs) { return lhs.first < rhs.first; });
	  std::sort(rv[i].second.begin(),rv[i].second.end(),
		    [](const sample_site_t & lhs,
		       const sample_site_t & rhs) { return lhs.first < rhs.first; });
	  //Deal w/odd sample sizes
	  if(n%2!=0.)
	    {
	      trim_last(&rv[i].first);
	      trim_last(&rv[i].second);
	    }
	}
#ifndef NDEBUG
      for(const auto & rvi : rv )
	{
	  assert(std::is_sorted(rvi.first.begin(),rvi.first.end(),
				[](const sample_site_t & a,
				   const sample_site_t & b) noexcept {
				  return a.first<b.first;
				}));
	  assert(std::is_sorted(rvi.second.begin(),rvi.second.end(),
				[](const sample_site_t & a,
				   const sample_site_t & b) noexcept {
				  return a.first<b.first;
				}));
	}
#endif
      return rv;
    }