-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
QtSLiM/recipes/Recipe 22.7 - Parallelizing nonWF reproduction and spatial interactions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
initialize() { | ||
initializeSLiMModelType("nonWF"); | ||
initializeSLiMOptions(dimensionality="xy"); | ||
defineConstant("K", 100000); // carrying-capacity density | ||
defineConstant("S", 0.005); // sigma_S, the spatial interaction width | ||
defineConstant("M", 0.025); // sigma_M, the spatial mating width | ||
|
||
initializeMutationType("m1", 0.5, "f", 0.0); | ||
m1.convertToSubstitution = T; | ||
|
||
initializeGenomicElementType("g1", m1, 1.0); | ||
initializeGenomicElement(g1, 0, 1e8 - 1); | ||
initializeMutationRate(1e-7); | ||
initializeRecombinationRate(1e-8); | ||
|
||
// competition kernel | ||
initializeInteractionType(1, "xy", reciprocal=T, maxDistance=S * 2); | ||
i1.setInteractionFunction("n", 1.0, S); | ||
|
||
// mating kernel | ||
initializeInteractionType(2, "xy", reciprocal=T, maxDistance=M * 2); | ||
i1.setInteractionFunction("n", 1.0, M); | ||
} | ||
2: first() { | ||
i2.evaluate(p1); | ||
} | ||
reproduction() { | ||
inds = p1.individuals; | ||
mates = i2.drawByStrength(inds, 1, returnDict=T); | ||
order = mates.compactIndices(); | ||
inds = inds[order]; | ||
num = rpois(size(inds), 5); | ||
nonzero_indices = which(num > 0); | ||
|
||
for (i in nonzero_indices) | ||
{ | ||
ind = inds[i]; | ||
offspring = p1.addCrossed(ind, mates.getValue(i), count=num[i], defer=T); | ||
offspring.setSpatialPosition(ind.spatialPosition); | ||
} | ||
|
||
self.active = 0; | ||
} | ||
1 early() { | ||
sim.addSubpop("p1", K); | ||
p1.individuals.setSpatialPosition(p1.pointUniform(K)); | ||
} | ||
early() { | ||
// deviate offspring from their maternal positions | ||
newborns = p1.subsetIndividuals(maxAge=0); | ||
old_pos = newborns.spatialPosition; | ||
new_pos = p1.pointReflected(old_pos + rnorm(size(old_pos), 0, 0.02)); | ||
newborns.setSpatialPosition(new_pos); | ||
} | ||
early() { | ||
// spatial competition | ||
i1.evaluate(p1); | ||
inds = p1.individuals; | ||
competition = i1.localPopulationDensity(inds); | ||
inds.fitnessScaling = K / competition; | ||
} | ||
100 late() { } |
62 changes: 62 additions & 0 deletions
62
SLiMgui/Recipes/Recipe 22.7 - Parallelizing nonWF reproduction and spatial interactions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
initialize() { | ||
initializeSLiMModelType("nonWF"); | ||
initializeSLiMOptions(dimensionality="xy"); | ||
defineConstant("K", 100000); // carrying-capacity density | ||
defineConstant("S", 0.005); // sigma_S, the spatial interaction width | ||
defineConstant("M", 0.025); // sigma_M, the spatial mating width | ||
|
||
initializeMutationType("m1", 0.5, "f", 0.0); | ||
m1.convertToSubstitution = T; | ||
|
||
initializeGenomicElementType("g1", m1, 1.0); | ||
initializeGenomicElement(g1, 0, 1e8 - 1); | ||
initializeMutationRate(1e-7); | ||
initializeRecombinationRate(1e-8); | ||
|
||
// competition kernel | ||
initializeInteractionType(1, "xy", reciprocal=T, maxDistance=S * 2); | ||
i1.setInteractionFunction("n", 1.0, S); | ||
|
||
// mating kernel | ||
initializeInteractionType(2, "xy", reciprocal=T, maxDistance=M * 2); | ||
i1.setInteractionFunction("n", 1.0, M); | ||
} | ||
2: first() { | ||
i2.evaluate(p1); | ||
} | ||
reproduction() { | ||
inds = p1.individuals; | ||
mates = i2.drawByStrength(inds, 1, returnDict=T); | ||
order = mates.compactIndices(); | ||
inds = inds[order]; | ||
num = rpois(size(inds), 5); | ||
nonzero_indices = which(num > 0); | ||
|
||
for (i in nonzero_indices) | ||
{ | ||
ind = inds[i]; | ||
offspring = p1.addCrossed(ind, mates.getValue(i), count=num[i], defer=T); | ||
offspring.setSpatialPosition(ind.spatialPosition); | ||
} | ||
|
||
self.active = 0; | ||
} | ||
1 early() { | ||
sim.addSubpop("p1", K); | ||
p1.individuals.setSpatialPosition(p1.pointUniform(K)); | ||
} | ||
early() { | ||
// deviate offspring from their maternal positions | ||
newborns = p1.subsetIndividuals(maxAge=0); | ||
old_pos = newborns.spatialPosition; | ||
new_pos = p1.pointReflected(old_pos + rnorm(size(old_pos), 0, 0.02)); | ||
newborns.setSpatialPosition(new_pos); | ||
} | ||
early() { | ||
// spatial competition | ||
i1.evaluate(p1); | ||
inds = p1.individuals; | ||
competition = i1.localPopulationDensity(inds); | ||
inds.fitnessScaling = K / competition; | ||
} | ||
100 late() { } |