I need clarification on pads in Maxpool. In the example here (maxpool_2d_pads) pads are mentioned as pad_bottom , pad_top , pad_right , pad_left, and in the attached screenshot pads are (0,0,1,1). Are the pads mentioned in the format (pad_bottom , pad_top , pad_right , pad_left)? If not, what is the right interpretation?
From the definition of the pads for MaxPool here
pads : list of ints ... pads format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. ...
So for your example, the pads are in the format [pad_top, pad_left, pad_bottom, pad_right]
This following part is copied from the answer from user2008981 below,
The pads are in order of the spatial axes of the X input. The X input has dimensions N x C x H x W when rank 4 (per the docs). So the spatial dimensions are x1=H (vertical) then x2=W (horizontal). Horizontal goes left to right, vertical goes top to bottom. x1_begin=top, x2_begin=left, x1_end=bottom, x2_end=right.
Related
I created a forest plot using metafor. The data I downloaded all has two significant figures after the decimal point for the study means and SDs, but when it uploads to the forest plot, these trailing zeros are dropped.
How can I keep these trailing zeros to make it look better?
The code for the forest plot is:
forest(meta2, showweights = TRUE, ilab.xpos=c(-24.5,-22, -19.5, -16, -13.75, -11),
ilab=cbind(bmi_awm$Intervention_n, bmi_awm$Intervention_mean, bmi_awm$Intervention_SD, bmi_awm$Comparison_n, bmi_awm$Comparison_mean, bmi_awm$Comparison_SD),(digits=2),
ilab.pos = 4,
rows=c(48), ylim=c(-1, 51.5), xlim=c(-35.5, 14), at=(c(-7, 0, 7))
enter image description here
See the documentation of the forest() function:
https://wviechtb.github.io/metafor/reference/forest.rma.html
digits: integer to specify the number of decimal places to which the tick mark labels of the x-axis and the annotations should be rounded (the default is 2L). Can also be a vector of two integers, the first to specify the number of decimal places for the annotations, the second for the x-axis labels. When specifying an integer (e.g., 2L), trailing zeros after the decimal mark are dropped for the x-axis labels. When specifying a numeric value (e.g., 2), trailing zeros are retained.
The problem in your code is that you have digits=2 wrapped in parentheses. Get rid of those and the training zeros should be retained.
I have a 5x5 grid which is described by max_size(5, 5). I need to generate a list of all cells from that description using DCG.
Here's the code I have so far:
:- use_module(library(clpfd)).
map_size(5, 5).
natnum(0).
natnum(X) :-
X #= X0 + 1,
natnum(X0).
list_all_cells(Visited) -->
{ length(Visited, 25) },
[].
list_all_cells(Visited) -->
[X-Y],
{ map_size(X_max, Y_max),
natnum(X), natnum(Y),
X #< X_max, Y #< Y_max,
maplist(dif(X-Y), Visited) },
list_all_cells([X-Y|Visited]).
However, it doesn't generate a list and outputs only 4 pairs.
A possible query to the DCG looks like list_all_cells([]) which is supposed to list all cells on the grid. For example, it's gonna be [0-0, 1-0, 1-1, 0-1] for a 2x2 grid (order doesn't matter).
In fact, I need this predicate to build another one called available_steps/2 that would generate a list of all possible moves for a given position. Having available_steps(CurrentPos, Visited), I will be able to brute-force Hunt the Wumpus game and find all possible routes to gold.
list_all_cells(Cells) :-
bagof(C,cell(C),Cells).
cell(X-Y) :-
between(0,4,X),
between(0,4,Y).
Example run:
?- list_all_cells(Cells); true.
Cells= [0-0, 0-1, 0-2, 0-3, 0-4, 1-0, 1-1, 1-2, ... - ...|...] [write] % The letter w was pressed.
Cells= [0-0, 0-1, 0-2, 0-3, 0-4, 1-0, 1-1, 1-2, 1-3, 1-4, 2-0, 2-1, 2-2, 2-3, 2-4, 3-0, 3-1, 3-2, 3-3, 3-4, 4-0, 4-1, 4-2, 4-3, 4-4] ;
true.
I have 3 related questions for plots in spatstat:
How do I label the segment of a linnet. for example just the id of the element
How do I label co-variate attached to segment of linnet on a plot
How to control width of an segment of linnet in a plot based on: a covariate or for example I want the thickness of the segment proportional to number of points realized on that segment from a point process on a network. So if a process generates 10 points on a line segment and 5 points on second segment, I would like to plot first segment twice wider than second segment.
I found examples in the book - Spatial Point Patterns - but they indicate use of image or kernel density to control the width of a segment. I am using linfun for a inhomogenous process and I did not find a method to color or control line width in my plot or to label the plot.
An example of small square:
library(spatstat)
v<-ppp(x=c(50,100,100,50), y=c(50,50,100,100),c(0,150), c(0,150)) #vertices
edg<-matrix(c(1,2,3,4,2,3,4,1), ncol=2) #edges
L<-linnet(v, edges=edg) #create a linnet
z<-c(11,22,33,44) # create covariate
Zfun <- linfun(function(x,y,seg,tp) { seg }, L)
plot(Zfun)
# I added some marks
marks(x) <- runif(npoints(x), 3, 4)
Thank you
You can do everything by creating a suitable function of class linfun.
As an example, take the network L <- simplenet.
For question 1:
f <- linfun(function(x,y,seg,tp) { seg }, L)
plot(f)
The function f returns the segment ID number of the segment containing the specified point. This number runs from 1 to nsegments(L).
For question 2, suppose you have a vector Z giving the value of a covariate for each segment of the network (assuming the covariate value is constant on each segment). I'll take the example Z <- runif(nsegments(L)). Then
g <- linfun(function(x,y,seg,tp) { Z[seg] }, L)
plot(g)
For question 3,
plot(g, style="width")
See help(plot.linfun) and help(plot.linim) (basically plot.linfun converts the function to a pixel image, and then calls plot.linim).
please , see following image, here you can see blue rectangle is custom shape bounds and custom shape is shoe , i want to find area of a portion written in image and i want that area in form of rectangle
do is there any path iterator concept ?
Note
custom shape i derived from image of the same size.
I would do it like this:
1.create table for all bounding box-rect perimeter lines
each value in it will represent the empty space length form border line to shape
something like this:
the values are found by simple image scanning until first non space color found
2.now bruteforce find the biggest rectangle area
x,y = top left corner
for xs = 1 to bounding box width
now scan the max valid height of rectangle from x to x + xs (x grows to the right)
// it should be the min y0[x..x+xs]
remember the biggest valid area/size combination
do this for all 4 combinations (star from the other corners)
I now Brute-force is slow but
you can divide perimeter lines not by pixels but with some step instead
also I am sure this can be optimized somehow
for example by derivation of perimeter find the extremes and check from them backwards
when the size will start shrinking then stop ...
of course take in mind that on complicated shapes this optimization will not work ...
I'm trying to fill in a structured grid with an analytical field, but despite reading the vtk docs, I haven't found out how to actually set scalar values at the grid points or the set the spacing/origin info of the grid. Starting from the code below, how do I
associate spatial information with the grid (ie cell 0,0,0 is at coordinates 0,0,0, the spacing is dx in every direction)
associate scalar values with each grid point. To start, I just need one, but eventually I'd like to store 3 pieces of data at each point (not a vector, 3 distinct scalars).
grid = vtk.vtkStructuredGrid()
numPoints = int((maxGrid - minGrid)/dx)
grid.SetDimensions(numPoints, numPoints, numPoints)
In VTK there are 3 types of "structured" grids, vtkImageData (vtkUniformGrid derives from this), vtkRectilinearGrid, and vtkStructuredGrid. They are all structured in the sense that the topology is set. vtkImageData has constant spacing between points and is axis aligned, vtkRectilinearGrid is axis aligned but can vary the spacing in each axis direction, and vtkStructuredGrid has arbitrarily located points (cells may not be valid though).
For what you want to do you should do:
from vtk import *
dx = 2.0
grid = vtkImageData()
grid.SetOrigin(0, 0, 0) # default values
grid.SetSpacing(dx, dx, dx)
grid.SetDimensions(5, 8, 10) # number of points in each direction
# print grid.GetNumberOfPoints()
# print grid.GetNumberOfCells()
array = vtkDoubleArray()
array.SetNumberOfComponents(1) # this is 3 for a vector
array.SetNumberOfTuples(grid.GetNumberOfPoints())
for i in range(grid.GetNumberOfPoints()):
array.SetValue(i, 1)
grid.GetPointData().AddArray(array)
# print grid.GetPointData().GetNumberOfArrays()
array.SetName("unit array")