Variable names of unordered set items without implied structure - binary

This question will be asked in a specific form, but applies to a more general question, how to name unordered set items without implying any sort of structure.
In terms of graph theory, a connected, undirected graph will contain vertices that are connected via edges.
When creating an edge class with two member variables that are vertices, representing the two vertices that the edge connects, there was a difficulty in describing the two variables that did not include some form of implied structure.
Consider
class Edge{
Vertex v1;
Vertex v2;
}
or
class Edge{
Vertex left;
Vertex right;
}
or
class Edge{
Vertex a;
Vertex b;
}
{v1, v2} implies order and a larger possible size than two, though an edge only has two ends.
{a, b} is similar to {v1,v2}, only substiting different symbols.
{left, right} or {up, down} imply direction, which may be counter-intuitive when there is not necessarily any spatial reference to the graph, since raw graphs are pure abstractions.
{start, end} would work for a directed graph but seems arbitrary in an undirected graph.
The closest that I can consider is:
class Edge{
Vertex oneEnd;
Vertex otherEnd;
}
but that feels kludgey.
What name complies with good practice for such variables without implying any form of direction, ordering, or structure?

I'd go with Edge { Vertex v1; Vertex v2; }. I don't think that the user of your code will interpret the numerical suffixes as the order, but simply as differentiators. What if your unordered set contained 10 or 100 items, as could be the case with for example a polygon structure? I'm sure the most intuitive solution would be to use numerical indices/suffixes when naming the items.

Related

How to get the nth element of list using neural network?

I would like to add a neural network layer that takes as input from a output of another layer in the neural network and another separate number k and outputs the kth element of the list. This layer is supposed to be part a bigger deep network that supplies only the k element to succeeding layer.
The way i think is to dynamically change weights dynamically to a one hot array with only kth element = 1 rest all zeros.
Second way would be to freeze weights and mutliply the previous layer out with the one hot output and input it to next layer. But I am not sure how to do this.
You can just compose top-k modules from any library:
just_kth_element(x, k) := -topk(-topk(x, k=k), k=1)
Since kth element is nothing but smallest element in topK elements.
Or equivalent
just_kth_element(x, k) := min(topk(x, k=k))

Quadtrees: a common intersect method failing to handle a simple case

I am writing a simple GUI library and am using quadtrees to determine which, if any, objects are interacted with during a mouse event. I was looking through a number of quadtree libraries on github and they all contained a method for adding a rectangular object to a quadtree.
The method, in all cases, simply checked to see if the rectangle intersected with the given quadtree:
return quadtree.x2 >= rect.x1
and quadtree.x1 <= rect.x2
and quadtree.y2 >= rect.y1
and quadtree.y1 <= rect.y2
However, this gives an unwanted result in one of the simplest cases: Imagine a 100x100 square area. I place four 50x50 square objects into the area with coordinates (0,0), (0,50), (50,0), and (50,50). If these objects had been placed into a 100x100 quadtree with a maximum capacity of one object, I would (visually) expect that the first layer of the quadtree would split and that the four resulting trees would each exactly contain one of the squares.
If I use the above method to determine which tree the squares are placed into, though, I find that each object intersects with all four trees. This would cause each of the trees to rapidly split until the maximum depth is reached.
The only way I see to avoid this is to use two checks:
return (quadtree.x2 > rect.x1
and quadtree.x1 < rect.x2
and quadtree.y2 > rect.y1
and quadtree.y1 < rect.y2)
or (quadtree.x2 == rect.x1
and quadtree.x1 == rect.x2
and quadtree.y2 == rect.y1
and quadtree.y1 == rect.y2)
(in the simplest case. Larger objects would have to be viewed within a bounding box since, for example, an object with coordinates (0,0), w=100, h=100 would belong in the upper-left quadtree as well.)
I could also calculate the overlap between the rectangles and the quadtrees to see if it's non-zero.
Am I missing something? It seems like this should be an ideal situation for a quadtree, yet, in most implementations, it's a huge mess.
I wouldn't call this an ideal situation, because the four rectangles overlap by a fractional amount. For example, if we assume a (fictional) floating precision of 10^(-10), every 'point' is actually a small rectangle with 10^(-10) length, and thus the rectangles overlap by 10^(-10). This is why you get the deep tree.
But I also think the tree could be improved with a slightly modified overlap checking. With your code, the sub-nodes all overlap by a tiny amount. It would work better with excluding the minimum (or maximum values), for example:
return quadtree.x2 >= rect.x1
and quadtree.x1 < rect.x2
and quadtree.y2 >= rect.y1
and quadtree.y1 < rect.y2
So the lower left coordinate of a node is actually outside of that node. This would at least avoid points turning up in several nodes (such as the point (50,50)), and the lower left rectangle would be stored in only one node.

Rapidminer Classification

I am trying to solve a simple classification problem where the label has 12 different levels and need to classify each example into one of these 12. However, I want my output to look like refer the image:
http://i.stack.imgur.com/49USG.png
Here; assuming that I set a confidence threshold of 20%; I want my output to contain all the labels for each id which are above 20% and ordered (highest confidence first). If none of the labels are above 20%; then a default label.
More specifically, are there any existing operators in Rapidminer which could give such an output?
Whenever the Apply Model operator runs, it produces new special attributes corresponding to confidences for the individual values of the label attribute. So if the label has values one, two, three, three new attributes will be created confidence(one), confidence(two), confidence(three). It would be possible to use the Generate Attributes operator to work out some logic to decide how to really classify each example. It would also be possible to use the Apply Threshold operator (with Create Threshold) to do something similar. It's impossible to give any more guidance unless you post a representative example with data.

Turtles with size in Netlogo

I need to create turtles that have a certain dimension and check for overlap.
Since turtles per definition have no extension, I thought maybe the gis extension could be useful.
There is a way of associating an envelope with a turtle like
let gis:envelope-of self (list (xcor - 2 ) (xcor + 2) (ycor - 2) (ycor + 2))
But I don't know how to use this to draw the envelope and to check for overlaps.
Another way could be to give up the idea of one turtle having dimensions and to create a gis dataset from turtles by using
gis:turtle-dataset turtle-set
But I don't know how to create a polygon with this :-(
Any ideas?
Updated for Seth's comment to make explicit the different approaches for circles and others.
If the turtles are circles, then there is an overlap if the sum of the sizes of the two turtles < distance between them / 2, using the distance primitive as in Seth's comment.
However, if you have squares or other shapes, then you will have to do some fancy stuff with heading and the various trigonometry functions, and will need the differences of positions in the x and y direction (differences in xcor and ycor respectively. Something like this will get you started:
to-report xdiff [ turt1 turt2 ]
report [xcor] of turt1 - [xcor] of turt2
end
In the end I took an easy way out:
Since my objects don't have to move, I use adjacent patches to form a block of the needed size. Before I occupy a new patch, I check if it is already used and if so I delete all newly occupied patches.
Not very versatily, but it does the job for me so far.

What explains the term orthogonal in a more non-nerd fashion?

For example:
Cardinality and optionality are
orthogonal properties of a
relationship. You can specify that a
relationship is optional, even if you
have specified upper and/or lower
bounds. This means that there do not
have to be any objects at the
destination, but if there are then the
number of objects must lie within the
bounds specified.
What exactly does "orthogonal" mean? I bet it's just a fancy soundig nerd-style word for something that could be expressed a lot easier to understand for average people ;)
From wikipedia:
In mathematics, two vectors are
orthogonal if they are perpendicular,
i.e., they form a right angle. The
word comes from the Greek ὀρθός
(orthos), meaning "straight", and
γωνία (gonia), meaning "angle".
Anyone?
In the quoted context above you could substitute the word "independent" or "unrelated" for "orthogonal".
Items/concepts/values etc.. that are Orthogonal means that one does not constrain the other, so you can establish one item/concept/value without regards for how other orthogonal items are set.
Loosely speaking, orthogonal means independent.
Specifically in 2d space an orthogonal line is one with bends at 90 degrees to each other.