Skip to content

Commit

Permalink
add t-distribution to SpatialKernel, fix up kernel code
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Sep 13, 2023
1 parent 333cccc commit d71d392
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 101 deletions.
4 changes: 4 additions & 0 deletions QtSLiM/QtSLiMTablesDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ QVariant QtSLiMInteractionTypeTableModel::data(const QModelIndex &p_index, int r
case SpatialKernelType::kExponential: return QVariant(QString("exp"));
case SpatialKernelType::kNormal: return QVariant(QString("normal"));
case SpatialKernelType::kCauchy: return QVariant(QString("Cauchy"));
case SpatialKernelType::kStudentsT: return QVariant(QString("Student's t"));
}
}
else if (p_index.column() == 3)
Expand All @@ -935,6 +936,9 @@ QVariant QtSLiMInteractionTypeTableModel::data(const QModelIndex &p_index, int r
case SpatialKernelType::kCauchy:
paramString += QString(", γ=%1").arg(interactionType->if_param2_, 0, 'f', 3);
break;
case SpatialKernelType::kStudentsT:
paramString += QString(", ν=%1, σ=%2").arg(interactionType->if_param2_, 0, 'f', 3).arg(interactionType->if_param3_, 0, 'f', 3);
break;
}

return QVariant(paramString);
Expand Down
10 changes: 5 additions & 5 deletions QtSLiM/help/SLiMHelpClasses.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
<p class="p6">Returns the number of individuals in <span class="s1">exerterSubpop</span> that are within the maximum interaction distance according to the distance metric of the <span class="s1">InteractionType</span>.<span class="Apple-converted-space">  </span>The subpopulation may be supplied either as an <span class="s1">integer</span> ID, or as a <span class="s1">Subpopulation</span> object.<span class="Apple-converted-space">  </span>The <span class="s1">evaluate()</span> method must have been previously called for <span class="s1">exerterSubpop</span>, and positions saved at evaluation time will be used.<span class="Apple-converted-space">  </span>If the <span class="s1">InteractionType</span> is non-spatial, this method may not be called.</p>
<p class="p6">This method is similar to <span class="s1">nearestNeighborsOfPoint()</span> (when passed a large count so as to guarantee that all neighbors are returned), but this method returns only a count of the individuals, not a vector containing the individuals.</p>
<p class="p3">– (void)setInteractionFunction(string$ functionType, ...)</p>
<p class="p4">Set the function used to translate spatial distances into interaction strengths for an interaction type.<span class="Apple-converted-space">  </span>The <span class="s1">functionType</span> may be <span class="s1">"f"</span>, in which case the ellipsis <span class="s1">...</span> should supply a <span class="s1">numeric$</span> fixed interaction strength; <span class="s1">"l"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength for a linear function; <span class="s1">"e"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength and a <span class="s1">numeric$</span> lambda (shape) parameter for a negative exponential function; <span class="s6">; </span><span class="s7">"n"</span><span class="s6">, in which case the ellipsis should supply a </span><span class="s7">numeric$</span><span class="s6"> maximum strength and a </span><span class="s7">numeric$</span><span class="s6"> sigma (standard deviation) parameter for a Gaussian function; or </span><span class="s7">"c"</span><span class="s6">, in which case the ellipsis should supply a </span><span class="s7">numeric$</span><span class="s6"> maximum strength and a </span><span class="s7">numeric$</span><span class="s6"> scale parameter for a Cauchy distribution function</span>.<span class="Apple-converted-space">  </span>Non-spatial interactions must use function type <span class="s1">"f"</span>, since no distance values are available in that case.</p>
<p class="p6">Set the function used to translate spatial distances into interaction strengths for an interaction type.<span class="Apple-converted-space">  </span>The <span class="s1">functionType</span> may be <span class="s1">"f"</span>, in which case the ellipsis <span class="s1">...</span> should supply a <span class="s1">numeric$</span> fixed interaction strength; <span class="s1">"l"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength for a linear function; <span class="s1">"e"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength and a <span class="s1">numeric$</span> lambda (shape) parameter for a negative exponential function; <span class="s1">"n"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength and a <span class="s1">numeric$</span> sigma (standard deviation) parameter for a Gaussian function; <span class="s1">"c"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength and a <span class="s1">numeric$</span> scale parameter for a Cauchy distribution function; or <span class="s1">"t"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> maximum strength, a <span class="s1">numeric$</span> degrees of freedom, and a <span class="s1">numeric$</span> scale parameter for a <i>t</i>-distribution function.<span class="Apple-converted-space">  </span>Non-spatial interactions must use function type <span class="s1">"f"</span>, since no distance values are available in that case.</p>
<p class="p6">The interaction function for an interaction type is normally a constant in simulations; in any case, it cannot be changed when an interaction has already been evaluated, so either it should be set prior to evaluation, or <span class="s1">unevaluate()</span> should be called first.</p>
<p class="p5">– (float)strength(object&lt;Individual&gt;$ receiver, [No&lt;Individual&gt; exerters = NULL])</p>
<p class="p6">Returns a vector containing the interaction strengths exerted upon <span class="s1">receiver</span> by the individuals in <span class="s1">exerters</span>.<span class="Apple-converted-space">  </span>If <span class="s1">exerters</span> is <span class="s1">NULL</span> (the default), then a vector of the interaction strengths exerted by all individuals in the subpopulation of <span class="s1">receiver</span> (including <span class="s1">receiver</span> itself) is returned; this case may be handled much more efficiently than if a vector of all individuals in the subpopulation is explicitly provided.<span class="Apple-converted-space">  </span>Otherwise, all individuals in <span class="s1">exerters</span> must belong to a single subpopulation (but not necessarily the same subpopulation as <span class="s1">receiver</span>).<span class="Apple-converted-space">  </span>The <span class="s1">evaluate()</span> method must have been previously called for the receiver and exerter subpopulations, and positions saved at evaluation time will be used.</p>
Expand Down Expand Up @@ -735,11 +735,11 @@
<p class="p6">Note that unlike <span class="s1">sampleNearbyPoint()</span>, this method requires that all map values are non-negative.</p>
<p class="p5">– (float)sampleNearbyPoint(float point, float$ maxDistance, string$ functionType, ...)</p>
<p class="p6">For a spatial point supplied in <span class="s1">point</span>, returns a nearby point sampled from a kernel weighted by the spatial map’s values.<span class="Apple-converted-space">  </span>Only points within the maximum distance of the kernel, <span class="s1">maxDistance</span>, will be chosen, and the probability that a given point is chosen will be proportional to the density of the kernel at that point multiplied by the value of the map at that point (interpolated, if interpolation is enabled for the map).<span class="Apple-converted-space">  </span>Negative values of the map will be treated as zero.</p>
<p class="p6">The kernel is specified with a kernel shape, <span class="s1">functionType</span>, followed by zero or more ellipsis arguments; see <span class="s1">smooth()</span> for further information.<span class="Apple-converted-space">  </span>For this method, at present only a flat kernel (type <span class="s1">"f"</span>) or a Gaussian kernel (type <span class="s1">"n"</span>) are supported.</p>
<p class="p6">This method can be used to find points in the vicinity of individuals that are favorable – possessing more resources, or better environmental conditions, etc.<span class="Apple-converted-space">  </span>It can also be used to guide the dispersal or foraging behavior of individuals.</p>
<p class="p6">The kernel is specified with a kernel shape, <span class="s1">functionType</span>, followed by zero or more ellipsis arguments; see <span class="s1">smooth()</span> for further information.<span class="Apple-converted-space">  </span>For this method, at present only kernel types <span class="s1">"f"</span>, <span class="s1">"l"</span>, <span class="s1">"e"</span>, <span class="s1">"n"</span>, and <span class="s1">"t"</span> are supported, and type <span class="s1">"t"</span> is not presently supported for 3D kernels.</p>
<p class="p6">This method can be used to find points in the vicinity of individuals that are favorable – possessing more resources, or better environmental conditions, etc.<span class="Apple-converted-space">  </span>It can also be used to guide the dispersal or foraging behavior of individuals.<span class="Apple-converted-space">  </span>See <span class="s1">sampleImprovedNearbyPoint()</span> for a variant that may be useful for directed movement across a landscape.</p>
<p class="p5">– (object&lt;SpatialMap&gt;$)smooth(float$ maxDistance, string$ functionType, ...)</p>
<p class="p6">Smooths (or blurs, one could say) the values of the spatial map by convolution with a kernel.<span class="Apple-converted-space">  </span>The kernel is specified with a maximum distance <span class="s1">maxDistance</span> (beyond which the kernel cuts off to a value of zero), a kernel type <span class="s1">functionType</span> that should be <span class="s1">"f"</span>, <span class="s1">"l"</span>, <span class="s1">"e"</span>, <span class="s1">"n"</span>, or <span class="s1">"c"</span>, and additional parameters in the ellipsis <span class="s1">...</span> that depend upon the kernel type and further specify its shape.<span class="Apple-converted-space">  </span>The target spatial map is returned, to allow easy chaining of operations.</p>
<p class="p6">The kernel specification is similar to that for the <span class="s1">setInteractionType()</span> method of <span class="s1">InteractionType</span>, but omits the maximum value of the kernel.<span class="Apple-converted-space">  </span>Specifically, <span class="s1">functionType</span> may be <span class="s1">"f"</span>, in which case no ellipsis arguments should be supplied; <span class="s1">"l"</span>, similarly with no ellipsis arguments; <span class="s1">"e"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> lambda (shape) parameter for a negative exponential function; <span class="s1">"n"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> sigma (standard deviation) parameter for a Gaussian function; or <span class="s1">"c"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> scale parameter for a Cauchy distribution function.<span class="Apple-converted-space">  </span>See the <span class="s1">InteractionType</span> class documentation for discussions of these kernel types.</p>
<p class="p6">Smooths (or blurs, one could say) the values of the spatial map by convolution with a kernel.<span class="Apple-converted-space">  </span>The kernel is specified with a maximum distance <span class="s1">maxDistance</span> (beyond which the kernel cuts off to a value of zero), a kernel type <span class="s1">functionType</span> that should be <span class="s1">"f"</span>, <span class="s1">"l"</span>, <span class="s1">"e"</span>, <span class="s1">"n"</span>, <span class="s1">"c"</span>, or <span class="s1">"t"</span>, and additional parameters in the ellipsis <span class="s1">...</span> that depend upon the kernel type and further specify its shape.<span class="Apple-converted-space">  </span>The target spatial map is returned, to allow easy chaining of operations.</p>
<p class="p6">The kernel specification is similar to that for the <span class="s1">setInteractionType()</span> method of <span class="s1">InteractionType</span>, but omits the maximum value of the kernel.<span class="Apple-converted-space">  </span>Specifically, <span class="s1">functionType</span> may be <span class="s1">"f"</span>, in which case no ellipsis arguments should be supplied; <span class="s1">"l"</span>, similarly with no ellipsis arguments; <span class="s1">"e"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> lambda (shape) parameter for a negative exponential function; <span class="s1">"n"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> sigma (standard deviation) parameter for a Gaussian function; <span class="s1">"c"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> scale parameter for a Cauchy distribution function; or <span class="s1">"t"</span>, in which case the ellipsis should supply a <span class="s1">numeric$</span> degrees of freedom and a <span class="s1">numeric$</span> scale parameter for a <i>t</i>-distribution function.<span class="Apple-converted-space">  </span>See the <span class="s1">InteractionType</span> class documentation for discussions of these kernel types.</p>
<p class="p6">Distance metrics specified to this method, such as <span class="s1">maxDistance</span> and the additional kernel shape parameters, are measured in the distance scale of the spatial map – the same distance scale in which the spatial bounds of the map are specified.<span class="Apple-converted-space">  </span>The operation is performed upon the grid values of the spatial map; distances are internally translated into the scale of the value grid.<span class="Apple-converted-space">  </span>Clipping at the edge of the spatial map is done; in particular, the weights of edge and corner grid values are adjusted for their partial (one-half and one-quarter) coverage.</p>
<p class="p6">The density scale of the kernel has no effect and will be normalized; this is the reason that <span class="s1">smooth()</span>, unlike <span class="s1">InteractionType</span>, does not require specification of the maximum value of the kernel.<span class="Apple-converted-space">  </span>This normalization prevents the kernel from increasing or decreasing the average spatial map value (apart from possible edge effects).</p>
<p class="p5">– (object&lt;SpatialMap&gt;$)subtract(ifo&lt;SpatialMap&gt;$ x)</p>
Expand Down
Loading

0 comments on commit d71d392

Please sign in to comment.