Skip to content

Handle cases where no males/females exist in a *virtual* subpopulation? #35

@ashander

Description

@ashander

I'm attempting to deal with virtual subpopulations where there are no male or females using an approach similar to your suggestion in #15 and running into problems (related to weighting; see also #12 ).

Essentially, I can control the next generation size (as here with demoModel) and even the offspring number and sequencing (although here that is static) but when multiple virtual subpopulations exist in the same physical subpop, I'm running into issues due to weighting --- the virtual subpopulation with no females still attempts to produce offspring because weights are assigned based on current size (see debug output below) and so assigns one offspring to each VSP (VSP sizes in subpop 0 is 1, 1).

Is there some weighting scheme (or other strategy) that will work to assign zero offspring to VSPs with no males/females?

import simuPOP as sim
numoff = 1  # Global used in in demoModel and evolve

def demoModel(pop):
    sim.stat(pop, numOfMales=True, vars=['numOfMales_sp', 'numOfFemales_sp'])
    m_f = [(pop.dvars(i).numOfMales, pop.dvars(i).numOfFemales) for i in range(pop.numSubPop())]
    return [f * numoff if m > 0 else 0 for m,f in m_f]

sim.turnOnDebug('DBG_ALL')
sim.setOptions(seed=112)
initial_size = 7
p = sim.Population(initial_size, infoFields=['mark'])
sim.initInfo(p, [1, 1, 1, 2, 2, 2, 2], infoFields='mark')
sim.initSex(p, sex=[sim.MALE, sim.FEMALE, sim.FEMALE, sim.MALE, sim.MALE, sim.MALE, sim.MALE, ])
p.setVirtualSplitter(sim.InfoSplitter('mark', ranges=((1, 2), (2, 3))))
p.evolve(
    preOps=sim.Dumper(structure = False),
    matingScheme=sim.HeteroMating(
        [sim.HomoMating(
            chooser = sim.CombinedParentsChooser(
                sim.RandomParentChooser(replacement=True, sexChoice=sim.MALE_ONLY),
                sim.SequentialParentChooser(sexChoice=sim.FEMALE_ONLY),
            ),
            generator = sim.OffspringGenerator( ops = [
                sim.MendelianGenoTransmitter(),
            ],
                numOffspring=numoff),
            subPops=[(sim.ALL_AVAIL, 0), (sim.ALL_AVAIL, 1)],
            weight=1,
        )],
        subPopSize=demoModel,
    ),
    postOps=sim.Dumper(structure = False),
    gen=1,
)

Output

::::::::::::::::::::::::::::::::--
Constructor of population is called
Inc ref of 2 to 9
individual size is 24+1*0
, infoPtr: 8, GenoPtr: 8, Flag: 1, plus genoStru
genoSize 0
Analyzed string is >
Filename is 
Analyzed string is >
Filename is 
Creating Simulator 
Constructor of population is called
Inc ref of 1 to 6
individual size is 24+1*0
, infoPtr: 8, GenoPtr: 8, Flag: 1, plus genoStru
genoSize 0
Constructor of population is called
Inc ref of 1 to 7
individual size is 24+1*0
, infoPtr: 8, GenoPtr: 8, Flag: 1, plus genoStru
genoSize 0
Simulator created
Start evolution.: 2e-06
SubPopulation 0 (), 7 Individuals:
   0: MU  |  |  1
   1: FU  |  |  1
   2: FU  |  |  1
   3: MU  |  |  2
   4: MU  |  |  2
   5: MU  |  |  2
   6: MU  |  |  2

Applied <simuPOP.Dumper>: 0.000186
Start mating at generation 0: 1.3e-05
Dec ref of 1 to 6
Inc ref of 2 to 10
New subpop size 2
Positive mating scheme weights: 1, 1
Negative mating scheme weights: 0, 0
VSP sizes in subpop 0 is 1, 1
Mating is done in single-thread mode
Mating scheme 1 in subpopulation 0 failed to produce 1 offspring.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions