Algorithm keystroke dynamics - algorithm

I have a third party keyboard app who's algorithm I'm trying to understand from a key map data file I have. It monitors the way you tap on your keyboard and then it adjusts the tappable area behind the scenes so as to accept user input more accurately. I'm now trying to similarly mimick this keyboard concept for a small game I am making.
This is the tappable character map the keyboard app rendered:
Here's an example of a character map for the keyboard letter V
{
"v" :
{
"characters" : [ "v" ],
"feature-threshold-multiplier" : 1.0,
"initial-scale-multiplier" : 1.0,
"mean" :
{
"dof" : 40,
"mode" : [ 210.0367889404297, 138.3223266601562 ]
},
"precision" :
{
"dof" : 40,
"mode" :
[
0.003064915072172880,
-0.0009184600203298032,
-0.0009184600203298032,
0.006329041905701160
]
},
"prior-mean" : [ 207.0, 142.50 ],
"prior-precision" : [ 0.004667554982006550, 0.0, 0.0, 0.004667554982006550 ]
}
}
Question
What I'm trying to figure out now is which part of the data set determines the size of the tappable area and which part determines the rotation.
My findings
Some things I have noticed which may help others in helping me understand what the keys and their values actually relate to:
I have found that precision -> mode contains two values which are always the same for every single character map.
I have noticed that there is a dof key for both the mean and
mode array, and they are always the same.
So far a friend has been able to figure out what one of the key values mean which contribute to the positioning of each tappable key.
The mean -> modecontains the x and y position.
This link shows a code output rendering of the character dataset given.
http://codepen.io/martinlindhe/pen/yebpgO
You'll notice that the output matches the exact positioning of the tappable key map shown below.

I can only guess here but my bet is:
pos = 210.0367889404297, 138.3223266601562
is position (corner or center) and
0.0030649150721728800,-0.0009184600203298032
-0.0009184600203298032, 0.0063290419057011600
are 2 x 2D basis vectors (so size and orientation of your tapping area) and size = 40 (which more or less matches position). I see 2 possible layouts (row-major or column-major) but your data is symmetric so no way to tell which one it is as both are:
u = 40 * ( 0.0030649150721728800,-0.0009184600203298032)
v = 40 * (-0.0009184600203298032, 0.0063290419057011600)
As you did not provide any info about coordinate system and also the position does not match the image at all (you post most likely scaled image) I can not verify any of them. The only thing that is visible is u is ~2 times the size of v and as this is for a V key (I assume) then I see it like this (infered from all data you provided):
as you can see the u vector is mirrored (god knows why).
To verify you should check/compare more than just single key. To get the scaling I would chose W,Z,M,O as they form almost a rectangle covering almost whole keyboard... And also check differently rotated keys to verify the weird mirroring.

Related

Trying to understand match_template from skimage.feature

I'm trying to understand someone's code from match_template, but I couldn't understand the below process. Let's say there's a picture he's going to chop several parts. The picture is saved in:
ImagenTotal = np.asarray(Image.open('./redmangos.jpg'))
Then he selects 2 places on that picture and the coordinates are:
puntosinteres = [[189.7038558467742, 111.99546370967738],[211.1748235887097, 187.9696572580645]]
Since match_template needs two arguments - one is the original picture and another is what he's going to use to compare. Then the following process looks like this:
xinteres = int(puntosinteres[0][0])
yinteres = int(puntosinteres[0][1])
radio = 10
imagenband = ImagenTotal[:,:,0]
templateband = ImagenTotal[yinteres - radio : yinteres + radio, xinteres - radio : xinteres + radio, 0]
result= match_template(imagenband, templateband)
result = np.where(result>0.8)
I don't know what he's trying to do on imagenband and templateband. Could someone point me to a direction?
Thank you!
imagenband grabs the 0th channel from ImagenTotal, to get a single grayscale image. templateband grabs a small, 20x20 rectangle from yinteres - radio (radius in Spanish) to yinteres + radio on the rows axis and xinteres - radio to xinteres + radio on the columns axis.
To read more on how indexing works for numpy arrays, you can read the official documentation on indexing here:
https://numpy.org/doc/stable/user/basics.indexing.html#basics-indexing
There are links there for more advanced indexing topics.

pentaho CDE conditional formatting of bubble chart

I have used CCC Heat Grid in CDE to create a bubble chart with bubbles of different colors. My data set has only 6 values: (1, 1.1, 2, 2.1, 3, 3.1). I have sizeRole property to "value" so that the size of the bubble varies based on the magnitude of these six values. Alternative, I could have set colorRole property to "value". I have set three colors: green (1), yellow (2) and red (3).
Now, what I want to have 1 as green, 2 as yellow and 3 as red; and biggest constant size for 1.1, 2.1 and 3.1. The values 1.1, 2.1 and 3.1 represent alarms in my data set, so I want them to be of biggest size bubble or some other differentiating visual element.
I tried the following in pre-execution but no luck
function changeBubbles(){
var cccOptions = this.chartDefinition;
// For changing extension points, a little more work is required:
var eps = Dashboards.propertiesArrayToObject(cccOptions.extensionPoints);
// add extension points:
eps.bar_shape = function getShape(){
var val = this.scene.vars.value.value;
if(val == 1.1 || val == 2.1 || val == 3.1){
return 'cross';
}
else {}
};
// Serialize back eps into cccOptions
cccOptions.extensionPoints = Dashboards.objectToPropertiesArray(eps);
}
How can we achieve this?
I hope the answer is still relevant, given that this is a late response.
To use bubbles you should have useShapes: true.
You can set a different constant shape by using the shape option. For example, shape: "cross".
To have the bubble size be constant, you should set the "sizeRole" to null: sizeRole: null. Bubbles will take all of the available "cell" size.
Then, the "value" column should be picked up by the "colorRole", but to be explicit, specify: colorRole: "value".
By default, because the color role will be bound to a continuous dimension ("value"), the color scale will be continuous as well.
To make it a discrete scale, change the "value" dimension to be discrete:
dimensions: {
"value": {isDiscrete: true}
}
Finally, to ensure that the colors are mapped to the desired values, specify the "colorMap" option:
colorMap: {
"1": "green",
"2": "yellow",
"3": "red"
}
That's it. I hope this just works :-)

D3 circle packing diameter calculation

I am using the pack layout for packing different no of equal sized circles. I have a group of clusters to be visualized. So I am calling pack function for each cluster of circles. In all the d3 examples the diameter is either calculated with the given size or fixed diameter. I would like to calculate it according to the no of circles to be packed. So how do I calculate the packing circle diameter?
is there any formula so that I can pack the circles without wasting the space.
If you truly don't care about relative sizing of the circles, then you could make your JSON file represent only the data you care about(say, names) and feed your packing function a dummy value that the 'value' accessor function is expecting.
For instance:
var circleChildren = [{
"value": 1
}, {
"value": 1
}, {
"value": 1
}, {
"value": 1
}];
would give you a JSON object that you can use as children for your packing function:
var circleInput = Object();
circleInput.children = circleChildren;
You can verify that in your console by running:
bubble.nodes(circleInput)
.filter(function (d) {
return !d.children; //we're flattening the 'parent-child' node structure
})
where bubble is your D3 packing bubble variable.
Here's a fiddle that demonstrates that. It may have some extra things but it implements what you're looking for. In addition, you can play around with the number of circles by adding more dummies in the JSON file, as well as changing the SVG container size in the diameter variable. Hope that helps!
EDIT: The size of your layout(in this case, a misnomer of the 'diameter' variable) directly determines the size and diameter of your circles within. At some point you have to assign the pack.size() or pack.radius() value in order for your circles to display within a layout(documentation ):
If size is specified, sets the available layout size to the specified two-element array of numbers representing x and y. If size is not specified, returns the current size, which defaults to 1×1.
Here you have several options:
If you want your circles to be 'dynamically' sized to your available element's width (that is, if you want them to cover up all the element width available) then I'd recommend you get your element's width beforehand, and then apply in your pack() function. The problem is then you have to think about resizing, etc.
If you want to keep the maximum sizing available, then you have to make your viz responsive. There's a really good question already in SO that deals with that.
I know this isn't the full solution but hopefully that points you in the right direction for what you're trying to do.
FURTHER EDIT:
All of a sudden, another idea came to mind. Kind of an implementation of my previous suggestion, but this would ensure you're using the maximum space available at the time for your circle drawing:
zone = d3.select("#myDiv");
myWidth = zone.style("width").substring(0, zone.style("width").length - 2);

Why does the locator look semi-transparent in this Dynamic graphic?

I want a position a locator on a graphic, and update its position based on the mouse position. Here is some sample code:
Show[{
Graphics[{Yellow, Rectangle[]}],
Graphics[Dynamic[
With[{pt = MousePosition[{"Graphics", Graphics}]},
{ If[pt===None, ,Locator[pt^2]], Text[pt, {0,0}, {-1,-1}] }
]
]]
}, PlotRange -> {{-.2, 1.2},{-.2, 1.2}}]
The weird thing is that sometimes the locator displays normally, sometimes it displays at what looks like half opacity. It flips from normal to half-opacity as I move the mouse around.
Why is this, and what can I do to fix it?
I'm using Mathematica 8 on OSX.

Finding area of the image

I used connected component labeling algorithm (bwconncomp) to label the different parts of a binary image (MATLAB). Now i need to calculate the area of different labels and remove the labels with smaller area. Can i use the default area finding command or is there any specific commands for that in matlab...Help..
From the documentation:
CC = bwconncomp(BW) returns the connected components CC found in BW.
The binary image BW can have any dimension. CC is a structure with
four fields...
The final field in CC is PixelIdxList, which is:
[a] 1-by-NumObjects cell array where the kth element in the cell array is
a vector containing the linear indices of the pixels in the kth object.
You can find the area of each label by looking at the length of the corresponding entry in the cell array. Something like:
areas_in_pixels = cellfun(#length, CC.PixelIdxList);
The PixelIdxList is a cell array, each member of which contains the linear indexes of the pixels present in that connected component. The line of code above finds the length of each cell in the cell array - i.e. the number of pixels in each connected component.
I've used cellfun to keep the code short and efficient. A different way of writing the same thing would be something like:
areas_in_pixels = nan(1, length(CC.PixelIdxList);
for i = 1:length(CC.PixelIdxList)
areas_in_pixels(i) = length(CC.PixelIdxList{i});
end
For each connected component, you can then find the size of that component in pixels by accessing an element in areas_in_pixels:
areas_in_pixels(34) %# area of connected component number 34
If you don't want to write lots of code like above just use built-in functions of MATLAB to detect the area. Label your components and from the properties of the component you can find out the area of that component. Suppose Bw is the binary image:
[B,L] = bwboundaries(Bw,'noholes');
stats = regionprops(L,'Area','perimeter');
for k = 1:length(B)
area(k)=stats.Area;
end
You can make this better still by avoiding the for loop with the following:
[B,L] = bwboundaries(Bw,'noholes');
stats = regionprops(L,'Area','perimeter');
area = [stats.Area];
Best,
-Will

Resources