persp3d - main title that doesn't rotate? [duplicate] - r

This question already has answers here:
Put a fixed title in an interactive 3D plot using rgl package, R
(4 answers)
Closed 9 years ago.
Editing to provide more code and a runnable example.
If I open a 3D plot using the following code:
library(rgl)
GainTargets = seq(from=1, to=12, by=1)
PredBarTargets = seq(from=3, to=16, by=1)
data=structure(c(1176.18, 1379.34, 1280.67, 1149.02, 1034.01, 1028.74,
944.06, 807.54, 715.39, 691.08, 679.14, 644.02, 642.98, 577.61,
1004.22, 1238.13, 1216.16, 1104.92, 1032.46, 1038.11, 919.98,
855.47, 706.54, 668.51, 665.67, 689.57, 686, 623.82, 729.61,
1127.32, 1137.55, 1084.25, 955.15, 1005.86, 955.6, 881.66, 839.93,
767.45, 731.49, 727.19, 696.45, 634.52, 377.81, 917.08, 1087.57,
1036.17, 920.88, 993.75, 964.35, 848.94, 874.95, 780.58, 725.08,
695.12, 709.32, 663.93, 227, 787.53, 949.31, 972.59, 950.3, 946.22,
876.33, 881.49, 827.44, 767.66, 755.26, 731.71, 744.37, 692.86,
32.65, 404.91, 514.82, 652.8, 697.77, 859.85, 808.12, 794.15,
746.61, 719.72, 709.59, 662.36, 695.06, 687.76, 0, 262.09, 347.17,
442.35, 453.76, 684.06, 638.13, 664.69, 721.68, 688.32, 653.87,
665.21, 680.52, 685.13, 0, 38.77, 264.4, 432.8, 408.33, 457.38,
474.23, 453.76, 570.74, 591.96, 593.7, 636.75, 585.43, 577.72,
0, 0, 92.65, 255.08, 388.66, 432.73, 418.19, 425.02, 436.3, 452.17,
489.17, 499.27, 500.93, 495.26, 0, 0, 0, 90.28, 309.44, 324.99,
357.05, 376.11, 412.2, 337.4, 338.54, 370.11, 389.95, 501.99,
0, 0, 0, 0, 106.55, 190.84, 216.41, 322.11, 337.05, 313.99, 325.03,
356.98, 381.47, 373.77, 0, 0, 0, 0, 0, 198.84, 120.76, 204.33,
146.22, 289.93, 284.82, 337.22, 347.41, 337.29), .Dim = c(14L,
12L))
Points<-as.matrix(data)
open3d()
persp3d(x=PredBarTargets, y=GainTargets, z=Points,
col="green3", main="Total Points")
then I do get a title on the plot, but unfortunately the title moves around with mouse actions.
Does anyone know how to get the title text "Total Points" to be fixed at the top of the window such that it doesn't move? Also, if there's a way to associate the axis text with the axis that that has the numbers on it then that might be more readable.
Thanks

This cannot be done in rgl at the moment. You can only place text in 3d coordinates and have it rotate with the plot. Why not contact the maintainer of rgl and put this on a feature request list.
Note this Q is a duplicate of another question on SO.

Related

"You have to specify either input_ids or inputs_embeds", but I did specify the input_ids

I trained a BERT based encoder decoder model (EncoderDecoderModel) named ed_model with HuggingFace's transformers module.
I used the BertTokenizer named as input_tokenizer
I tokenized the input with:
txt = "Some wonderful sentence to encode"
inputs = input_tokenizer(txt, return_tensors="pt").to(device)
print(inputs)
The output clearly shows that a input_ids is the return dict
{'input_ids': tensor([[ 101, 5660, 7975, 2127, 2053, 2936, 5061, 102]], device='cuda:0'), 'token_type_ids': tensor([[0, 0, 0, 0, 0, 0, 0, 0]], device='cuda:0'), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1]], device='cuda:0')}
But when I try to predict, I get this error:
ed_model.forward(**inputs)
ValueError: You have to specify either input_ids or inputs_embeds
Any ideas ?
Well, apparently this is a known issue, for example: This issue of T5
The problem is that there's probably a renaming procedure in the code, since we use a encoder-decoder architecture we have 2 types of input ids.
The solution is to explicitly specify the type of input id
ed_model.forward(decoder_input_ids=inputs['input_ids'],**inputs)
I wish it was documented somewhere, but now you know :-)

Is there a way to normalize data with high kurtosis?

I have a vector that has a kurtosis of 2.95 (which is pretty high, Leptokurtic). Following is a sample of that data:
x = c(6.819, 8.948, 0, 67.556, -40.785, -18.951, -29.151, 1.008,
0, 18.034, -6.631, 6.294, 0.643, -28.921, 0, -2.133, -44.348,
-87.488, 7.063, 0, -74.428, -16.361, 50.963, -32.431, -82.233,
-26.953, -48.475, 64.043, 0, 1.576, -2.728, -5.9, -63.059, -1.061,
-15.018, -58.119, -32.092, 5.329, -19.968, 38.822, 66.897, 0,
-2.579, 82.696, 42.745, 79.677, 2.522, -11.475, 1.019, 2.719,
-3.634, -7.975, 0, 1.873, 21.732, -10.217, -24.002, -76.049,
35.045, 27.22, -71.366, 16.293, -48.762, 65.481, 66.615, -19.616,
6.016, 59.722, 88.235, 10.1, 0, -4.598, 5.446, 56.909, 0, -24.827,
0, 6.487, 0, 63.315, 28.397, 9.433, 19.085, 0, 6.591, -22.643,
32.235, -12.535, -1.787, 56.157, 68.819, 0, -21.936, 38.695,
-79.006, 24.888, -5.187, 10.368, -68.191, 0, -22.171, -78.783,
-14.119, 54.084, -13.597, 26.669, 0, -18.402, 80.309, -12.652,
1.801, -69.946, -87.67, -19.586, 38.085, -21.031, -36.957, 1.357,
0.17, 47.407, -59.598, 66.125, 10.97, 6.33, -38.837, 1.868, 38.169,
-46.662, -32.255, 25.816, 14.432, -18.57, -0.456, -0.638, 31.07,
72.794, 52.957, 13.858, -18.885, 0, -13.488, 11.689, 1.618, 19.373,
-57.526, 0, -0.655, 36.308, 50.231, 0.048, -80.157, 0, -64.805,
-70.864, 0.813, 52.143, -4.989, 42.166, 7.397, 87.437, -17.897,
-0.877, 68.363, 47.315, -2.181, 2.699, 36.278, 0, -2.924, 71.56,
74.406, -46.071, 56.158, 1.44, 0, 0, 0, -3.233, 37.084, -85.189,
0, -16.137, -84.499, -12.67, -14.117, 0, 23.757, -58.299, -34.956,
0.402, 0, -67.585, -14.314, -73.426, 23.158, 1.782, 0, 4.399,
18.871, -6.929)
Is there a way to normalize this data?
Since this data range between -90 to 90, the normalized data should be in a similar range and should not change vastly, i.e. the range should not be changed to -1 to 1 or -20 to 20 etc...
I have tried using atan(X), 1/x, log(x), and many other transformational techniques but they all tend to increase the skewness. Is there a way to normalize this data without skewing it?
I am sure there must be an easy solution to this.
It may not be what you want but you can almost always perfectly normalize a distribution (if there are no ties) using a normal scores transformation:
xq <- qnorm(rank(x)/(length(x)+1), mean=mean(x), sd=sd(x))
plot(sort(x),sort(xq))
hist(xq)
qqnorm(xq)
The new range is (-99.2, 99.6) (the old range was +/- 88).
If you need to change the range you could do it as follows:
newmin + (newmax-newmin)*scale(xq, center=min(qx), scale=diff(range(xq)))
but as suggested in the comments this may not actually be the right approach to solve your broader problem.

Is this the best way of getting tomorrow 09:00? [duplicate]

This question already has an answer here:
How to get specific time from next day
(1 answer)
Closed 2 years ago.
I want to get a datetime object for tomorrow morning 09:00 in Go. My current take is this:
now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.UTC).AddDate(0, 0, 1))
It seems oddly verbose though. Isn't there a simpler way of doing this?
Simplify by adding 1 to the day directly.
now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day() + 1, 9, 0, 0, 0, time.UTC)
Run it on the playground.
The time.Date function normalizes the day.

How to center all elements from top to bottom in a GridPane

GridPane.setConstraints(button1,0,0);
GridPane.setConstraints(button2,0,1);
GridPane.setConstraints(button3,0,2);
gridPane.getChildren().addAll(button1,button2,button3);
I have some buttons in a GridPane as they are shown above, and I want to
center them all in gridPane;
center each button's label within
their button boundary (optional).
Currently the buttons are aligned to the left and they don't look so good. Can someone please tell me what to do? Thanks
You can set the vertical and horizontal alignments of each cell by using other constraint options:
GridPane.setConstraints( b1, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER );
GridPane.setConstraints( b2, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER );
GridPane.setConstraints( b3, 0, 2, 1, 1, HPos.CENTER, VPos.CENTER );
You may also set the gaps between the cells with:
gridPane.setVgap( 10 );
gridPane.setHgap( 10 );
to debug those values visually use:
gridPane.setGridLinesVisible( true );

QGraphicsRectItem::pos() function returns something that is not expected?

I have this simple piece of code in a class constructor which is inherited from QGraphicsScene :
setSceneRect(0,0,800,800);
addRect(sceneRect());
QGraphicsRectItem*r1 = addRect(200, 0, 5, 5);
qDebug()<<r1->pos();
Here I add a rect at pos(200,0) but qDebug() prints QPointF(0, 0)! I'm totally confused.
Even scenePos returns (0,0)! Is it true?!
The rect is at position (200, 0) inside the item's coordinate system, but the item itself is at (0,0) in its parent's coordinate system.
The QGraphicsScene::addRect() documentation explains this:
Note that the item's geometry is provided in item coordinates, and its position is initialized to (0, 0). For example, if a QRect(50, 50, 100, 100) is added, its top-left corner will be at (50, 50) relative to the origin in the items coordinate system.
Alternatively, you can add a rectangle at 0, 0, 5, 5) and move the item afterwards, to get the result you expected:
QGraphicsRectItem* r1 = addRect(0, 0, 5, 5);
r1->setPos(200, 0);

Resources