VS Code changes indentation on copy/paste - visual-studio-code

I use Python. According to the PEP 8 Style Guide, both of these are acceptable -
my_list = [
1, 2, 3,
4, 5, 6,
]
my_list = [
1, 2, 3,
4, 5, 6,
]
I prefer the former. However, if I copy and paste a block like this, VS Code changes the indentation like this -
my_list = [
1, 2, 3,
4, 5, 6,
]
my_list = [
1, 2, 3,
4, 5, 6,
]
Is there a setting to change this behaviour?

Related

I can't join a table on a jsonb value - Postgresql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I can't quitely understand what's others solution in others question, I hope you guys can elaborate more
I have this query and it works like I want it to.
SELECT
stu.fname || ' ' || stu.lname AS "name",
sch."name" AS school_name,
stu.custom_school_name,
tr.created_at,
tr.weights::JSON->0->>'ctgr' AS first_char,
tr.weights::JSON->1->>'ctgr' AS second_char,
tr.weights::JSON->2->>'ctgr' AS third_char
FROM
tmb_result tr
JOIN students stu ON stu."id" = tr.student_id
JOIN schools sch ON sch."id" = stu.school_id
WHERE
tr.created_at BETWEEN '2022-11-24 00:00:00+07' AND '2022-11-30 24:00:00+07';
+------------+-------------+------------+
| first_char | second_char | third_char |
+------------+-------------+------------+
| R | I | A |
| R | I | A |
| R | I | A |
+------------+-------------+------------+
but my senior wants me to change the first, second, and third_char data to this label_long data from this table based on this table code
how can I join them? this is the jsonb data from tr.weights
[
{
"ctgr": "R",
"sw_ct": 3,
"ksw_ct": 1,
"ssw_ct": 3,
"tsw_ct": 0,
"ctgr_ord": 1,
"total_wght": 23
},
{
"ctgr": "I",
"sw_ct": 4,
"ksw_ct": 1,
"ssw_ct": 2,
"tsw_ct": 0,
"ctgr_ord": 2,
"total_wght": 22
},
{
"ctgr": "A",
"sw_ct": 2,
"ksw_ct": 2,
"ssw_ct": 3,
"tsw_ct": 0,
"ctgr_ord": 3,
"total_wght": 22
},
{
"ctgr": "S",
"sw_ct": 3,
"ksw_ct": 0,
"ssw_ct": 2,
"tsw_ct": 2,
"ctgr_ord": 4,
"total_wght": 19
},
{
"ctgr": "E",
"sw_ct": 5,
"ksw_ct": 1,
"ssw_ct": 1,
"tsw_ct": 0,
"ctgr_ord": 5,
"total_wght": 21
},
{
"ctgr": "C",
"sw_ct": 3,
"ksw_ct": 3,
"ssw_ct": 1,
"tsw_ct": 0,
"ctgr_ord": 6,
"total_wght": 19
}
]

measure of how similar an object is to its own cluster or to other clusters

I have a set of samples. These samples are partitioned based on their values into several clusters (3 clusters).
df = pd.DataFrame({'samples': ['A', 'B', 'C', 'D', 'E'],
'values': [[5, 0, 2, 2],[1, 6, 0, 2],[7, 2, 0, 0],[3, 6, 0, 0],[7, 0, 0, 2]],
'cluster': [1, 0, 2, 0, 1]})
df
output:
samples values cluster
0 A [5, 0, 2, 2] 1
1 B [1, 6, 0, 2] 0
2 C [7, 2, 0, 0] 2
3 D [3, 6, 0, 0] 0
4 E [7, 0, 0, 2] 1
Assuming after a round, the value of sample (B) has changed from [1, 6, 0, 2] to [7, 1, 0, 2]
How could I measure whether sample (B) still belongs to its own cluster (0) or should move to other clusters?
samples values cluster
0 A [5, 0, 2, 2] 1
1 B [7, 1, 0, 2] ?
2 C [7, 2, 0, 0] 2
3 D [3, 6, 0, 0] 0
4 E [7, 0, 0, 2] 1
I could use silhouette index, but I looking for different methods such as math formulas, or other techniques.

Understanding Feature Maps in Convolutional Layers (PyTorch)

I've got this segment of code in a discriminator network for MNIST:
nn.Conv2d(1, 64, 4, 2, 1),
From my understanding, there is 1 input channel (the MNIST image), then we apply a 4x4 kernel to the image in strides of 2 to produce 64 feature maps. Does this mean that we actually have 64 kernels at this layer? Because in order to get 64 different feature maps, we would need 64 separate kernels to convolve over the image?
Then after some ReLu, we have another convolution:
nn.Conv2d(64, 128, 4, 2, 1),
How do we get from 64 to 128? From my understanding of the first example, we have 64 seperate kernels that can produce 64 seperate feature maps. But here we go from 64 feature maps to 128 feature maps? Does that mean that we only have two kernels?
I hope someone can shine some light on whether my understanding is correct!
Your understanding in the first example is correct, you have 64 different kernels to produce 64 different feature maps.
In case of the second example, so the number of input channels not beeing one, you still have as "many" kernels as the number of output feature maps (so 128), which each are trained on a linear combination of the input feature maps. So in your case each of these kernels would have 4x4x64 trainable weights.
All the input channels are connected to each output channel (if group = 1, as by default) by convolution with filters (kernels) -- one for each output channel. Each kernel though has sub-kernels for each input channel.
So in the first layer you have in_channels = 1 and out_channels = 64 meaning that there are 64 kernels (and sub-kernels). In the second layer you have in_channels = 64 and out_channels = 128 meaning that there are 128 kernels each having 64 * 128 sub-kernels.
Here's a simple example of one conv layer taken from cs231n for clarification:
And my implementation in Pytorch:
import torch
from torch import nn
cnn = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3,
stride=2, padding=1, bias=True, groups=1)
w0 = torch.FloatTensor([[[-1, -1, 0],
[ 1, 1, 1],
[ 1, 1, 0]],
[[ 1, 1, -1],
[ 0, 0, 0],
[ 1, 1, -1]],
[[ 0, -1, 0],
[-1, 0, -1],
[ 1, 0, 1]]])
b0 = torch.FloatTensor([1])
w1 = torch.FloatTensor([[[-1, 0, 0],
[ 1, 1, 1],
[-1, -1, 0]],
[[ 1, -1, -1],
[-1, 1, -1],
[ 1, -1, 0]],
[[ 1, -1, 0],
[ 0, 1, 1],
[ 1, 0, 1]]])
b1 = torch.FloatTensor([0])
cnn.weight = torch.nn.Parameter(torch.stack((w0, w1), 0))
cnn.bias = torch.nn.Parameter(torch.cat((b0, b1), 0))
inpt = torch.FloatTensor([[[ 1, 2, 0, 1, 2],
[ 1, 0, 2, 2, 0],
[ 2, 0, 0, 2, 2],
[ 0, 0, 2, 2, 0],
[ 2, 2, 2, 1, 2]],
[[ 2, 0, 0, 1, 1],
[ 1, 0, 2, 1, 2],
[ 2, 0, 2, 2, 1],
[ 0, 2, 0, 0, 1],
[ 1, 2, 1, 2, 0]],
[[ 0, 0, 2, 1, 2],
[ 0, 1, 0, 2, 0],
[ 1, 1, 0, 0, 2],
[ 0, 0, 0, 1, 1],
[ 0, 1, 2, 0, 2]]])
cnn(inpt.unsqueeze(0))
Output:
tensor([[[[ 7., 9., 10.],
[ 0., 6., 10.],
[ 2., 5., 2.]],
[[ 4., 4., 4.],
[ 5., 1., 2.],
[ 2., 6., 0.]]]])

Logical indexing with two conditions

I have a rankingMat which contains the rankings of equity tickers, where every column represents one ticker and every row represents a point in time. The ranking has been performed in a descending manner, i.e. a 1 in rankingMat identifies the highest rank for that time period (read: row). Ticker/column 4 represents a cash security. This will be important further down the road.
Now, I would like to identify in which equity tickers I am supposed to invest. There exists two conditions:
I only invest in tickers that have a rank less or equal to 3.
In addition, I only invest in tickers that are ranked higher or equal compared to cash (ticker/column 4).
I'm able to get a result that fulfills the first condition:
rankingMat = ...
[NaN, NaN, NaN, NaN, NaN, NaN; ...
1, 5, 2, 3, 6, 4; ...
4, 5, 2, 3, 6, 1; ...
4, 1, 2, 5, 6, 3; ...
6, 4, 5, 2, 1, 3; ...
2, 3, 4, 6, 1, 5; ...
3, 6, 4, 1, 2, 5; ...
2, 5, 6, 1, 4, 3];
portfolio = rankingMat <= 3;
The result looks like this:
portfolio = ...
[0, 0, 0, 0, 0, 0; ...
1, 0, 1, 1, 0, 0; ...
0, 0, 1, 1, 0, 1; ...
0, 1, 1, 0, 0, 1; ...
0, 0, 0, 1, 1, 1; ...
1, 1, 0, 0, 1, 0; ...
1, 0, 0, 1, 1, 0; ...
1, 0, 0, 1, 0, 1]
My problem is condition 2. In every row, I need to compare not only if the integer is less or equal to 3, I also need to make sure that it is less than the integer in column 4 in that particular row. I am looking for a solution that avoids a for-loop. I guess it is possible with indexing. So, any hint is highly appreciated.
The final result should look like this:
portfolio = ...
[0, 0, 0, 0, 0, 0; ...
1, 0, 1, 1, 0, 0; ...
0, 0, 1, 1, 0, 1; ...
0, 1, 1, 0, 0, 1; ...
0, 0, 0, 1, 1, 0; ...
1, 1, 0, 0, 1, 0; ...
0, 0, 0, 1, 0, 0; ...
0, 0, 0, 1, 0, 0]
% Prior to R2016b
portfolio = rankingMat <= 3 & ...
bsxfun(#lt, rankingMat, rankingMat(:,4));
% On or after R2016b
portfolio = rankingMat <= 3 & ...
rankingMat < rankingMat(:,4);

Facebook Graph empty data for likes, tags etc

1) I'm wondering why the Facebook Graph gives empty results for the following objects:
(Please keep in mind I have a token that has the correct permissions, moreover, extended permissions to access these objects).
tagged - https://graph.facebook.com/me/tagged or /{userid}/tagged
likes
activities
accounts
which produces:
{"data": []}
2) Did Facebook strip our permissions from accessing our own data?
3) Which objects cannot be accessed?
4) Here are my extended /permissions
<pre>
{
"data": [
{
"installed": 1,
"status_update": 1,
"publish_checkins": 1,
"photo_upload": 1,
"video_upload": 1,
"sms": 1,
"email": 1,
"create_event": 1,
"create_note": 1,
"export_stream": 1,
"share_item": 1,
"rsvp_event": 1,
"read_stream": 1,
"publish_stream": 1,
"read_mailbox": 1,
"ads_management": 1,
"read_friendlists": 1,
"manage_friendlists": 1,
"xmpp_login": 1,
"read_insights": 1,
"read_requests": 1,
"manage_notifications": 1,
"manage_pages": 1,
"publish_actions": 1,
"user_birthday": 1,
"user_religion_politics": 1,
"user_relationships": 1,
"user_relationship_details": 1,
"user_hometown": 1,
"user_location": 1,
"user_likes": 1,
"user_activities": 1,
"user_interests": 1,
"user_education_history": 1,
"user_work_history": 1,
"user_online_presence": 1,
"user_website": 1,
"user_groups": 1,
"user_events": 1,
"user_photos": 1,
"user_videos": 1,
"user_photo_video_tags": 1,
"user_notes": 1,
"user_checkins": 1,
"user_questions": 1,
"user_about_me": 1,
"user_status": 1,
"user_games_activity": 1,
"user_subscriptions": 1,
"friends_birthday": 1,
"friends_religion_politics": 1,
"friends_relationships": 1,
"friends_relationship_details": 1,
"friends_hometown": 1,
"friends_location": 1,
"friends_likes": 1,
"friends_activities": 1,
"friends_interests": 1,
"friends_education_history": 1,
"friends_work_history": 1,
"friends_online_presence": 1,
"friends_website": 1,
"friends_groups": 1,
"friends_events": 1,
"friends_photos": 1,
"friends_videos": 1,
"friends_photo_video_tags": 1,
"friends_notes": 1,
"friends_checkins": 1,
"friends_questions": 1,
"friends_about_me": 1,
"friends_status": 1,
"friends_games_activity": 1,
"friends_subscriptions": 1
}
]
}
</pre>
I've checked them, I don't see any tags (but not sure if I have been tagged in the last few days).
The other ones work perfectly for me when tested in the https://developers.facebook.com/tools/explorer. So are you sure your account has likes/activities and more then one account? Since I only see my 'pages' of which I am also owner.