I have embedded some code in my Rmd file to perform t.test on a set of data. But weirdly, each time I click on 'Knit HTML', I see different outputs for p-value in the HTML file. But the same doesn't happen if I am running code in the console. Can somebody please help understand why it must be happening and how I can avoid it?
Below is that piece of code:
```{r, echo=TRUE}
tresults <- matrix(nrow = 4, ncol = 3)
for (i in 1:4){
options(scipen = 999) #Force are to not use exponential notation
tresult <- t.test(years[[i]][,11], years[[i]][,21], var.equal = T, alternative = "greater")
tresults[i,] <- as.numeric(c(tresult[[1]], tresult[[2]], tresult[[3]]))}
tresults <- format(round(tresults, 3), nsmall = 3) #round off to 3 decimal points
tresults <- cbind(c("2004-05", "2005-06", "2006-07", "2007-08"), tresults)
colnames(tresults) <- c("years", "t", "df", "p-value")
print(tresults)
```
Edit:
'years' is basically a list that contains data-frame corresponding to each year -
#List the datasets
years <- list(prod_data_0405, prod_data_0506, prod_data_0607, prod_data_0708)
I have created a sample of this list, converted it to data-frame for the convenience of sharing using following command:
years_sample <- as.data.frame(do.call(rbind, years_sample))
and saved it on this link. Please use it to test the code and let me know.
Edit 2
Here is the sample that I have created using dput(years)
list(structure(list(ID = c(1, 2, 3, 4, 5, 6), Area..acres. = c(4,
1, 2, 3, 1, 1), Cotton = c(2, 2.5, 2, 5, 3, 0), Pigeon.pea = c(0.33,
NaN, 0.5, 0.21, NaN, 0), Soyabean = c(4, NaN, NaN, 6, NaN, NaN
), Sorghum = c("", "", "", "6", "", ""), Other = c(NaN, NaN,
NaN, 1.6, NaN, NaN), Total.yield..Quintal. = c(6.33, 2.5, 5,
23.56, 3, 0), Gross.Income..Rs. = c(4695, 4750, 4612.5, 11531.67,
5700, 3800), Total.Expenditure..Rs. = c(1955, 1700, 2237, 3296.67,
1520, 2900), Net.Income..Rs. = c(2740, 3050, 2366.5, 235, 4180,
0), Area..acres..1 = c(1, 8, 2, 3, 5, 5), Cotton.1 = c("", "4.6",
"5", "", "2.33", "0"), Pigeon.pea.1 = c(NaN, 0.4, 0.5, 0.33,
0.2, 0), Soyabean.1 = c(NaN, 2, NaN, 0.23, 3, NaN), Sorghum.1 = c(4,
11, NaN, NaN, 4.5, 0), Other.1 = c(NaN, NaN, NaN, NaN, NaN, NaN
), Total.yield..Quintal..1 = c(4, 40, 11, 1.7, 15.1, 0), Gross.Income..Rs..1 = c(3200,
7603.12, 7612.5, 1013.33, 4705, 5980), Total.Expenditure..Rs..1 = c(1950,
3042.7, 2850, 1193.33, 2060, 4050), Net.Income..Rs..1 = c(1250,
4560.72, 4762.5, -150, 2645, 2852.5)), .Names = c("ID", "Area..acres.",
"Cotton", "Pigeon.pea", "Soyabean", "Sorghum", "Other", "Total.yield..Quintal.",
"Gross.Income..Rs.", "Total.Expenditure..Rs.", "Net.Income..Rs.",
"Area..acres..1", "Cotton.1", "Pigeon.pea.1", "Soyabean.1", "Sorghum.1",
"Other.1", "Total.yield..Quintal..1", "Gross.Income..Rs..1",
"Total.Expenditure..Rs..1", "Net.Income..Rs..1"), row.names = c(NA,
6L), class = "data.frame"), structure(list(ID = c(1, 2, 3, 4,
5, 6), Area..acres. = c(2, 1, 2, 6, 1, 1), Cotton = c(NaN, 6,
2, 1.75, NaN, NaN), Pigeon.pea = c(0.75, 2, NaN, 1, NaN, NaN),
Soyabean = c(4, NaN, 1.5, 2.75, 3, 3), Sorghum = c(1, NaN,
2, 1, NaN, NaN), Other = c(0.25, 0.1, NaN, NaN, NaN, NaN),
Total.yield..Quintal. = c(12, 8.1, 11, 18.5, 3, 3), Gross.Income..Rs. = c(6525,
3000, 5575, 4666.67, 3240, 3800), Total.Expenditure..Rs. = c(3785,
2290, 2270, 2450, 1950, 2900), Net.Income..Rs. = c(2740,
710, 3305, 2216.67, 1290, 900), Area..acres..1 = c(3, 2,
2, 5, 4, 5), Cotton.1 = c(2, 2.5, 2, NaN, 0.83, 3), Pigeon.pea.1 = c(0.75,
0.25, 1, NaN, 1, 0.62), Soyabean.1 = c("", "", "", "", "",
""), Sorghum.1 = c(4, 0.1, 4, 1.5, 2, 3), Other.1 = c(NaN,
0.1, NaN, NaN, NaN, NaN), Total.yield..Quintal..1 = c(9.5,
5.7, 7, 3, 7.5, 17.5), Gross.Income..Rs..1 = c(4433.33, 3500,
4275, 1275, 2900, 5980), Total.Expenditure..Rs..1 = c(3823.33,
3270, 2660, 2075, 2262.5, 3560), Net.Income..Rs..1 = c(610,
230, 1615, 800, 637.5, 2420)), .Names = c("ID", "Area..acres.",
"Cotton", "Pigeon.pea", "Soyabean", "Sorghum", "Other", "Total.yield..Quintal.",
"Gross.Income..Rs.", "Total.Expenditure..Rs.", "Net.Income..Rs.",
"Area..acres..1", "Cotton.1", "Pigeon.pea.1", "Soyabean.1", "Sorghum.1",
"Other.1", "Total.yield..Quintal..1", "Gross.Income..Rs..1",
"Total.Expenditure..Rs..1", "Net.Income..Rs..1"), row.names = c(NA,
6L), class = "data.frame"), structure(list(ID = c(1, 2, 3, 4,
5, 6), Area..acres. = c(2, 1.5, 2, 3, 2, 3), Cotton = c(NaN,
2, NaN, 2.66, NaN, NaN), Pigeon.pea = c(NaN, 0.33, 0.4, 0.53,
0.5, NaN), Soyabean = c(3.5, NaN, 2, NaN, 3, 2.66), Sorghum = c(NaN,
NaN, NaN, 0.25, 2, NaN), Other = c(NaN, NaN, NaN, 0.19, NaN,
NaN), Total.yield..Quintal. = c(NaN, 3.5, 4.8, 10.02, 11, 8),
Gross.Income..Rs. = c(4200, 4646.66, 5389, 6507.33, 6600,
3200), Total.Expenditure..Rs. = c("1670", "2060", "2385",
"2528.33", "3006.5", "1426.66"), Net.Income..Rs. = c(2530,
2586.66, 3004, 3979, 3592.5, 1773.34), Area..acres..1 = c(2,
1.5, 2, 7, 1.5, 7.5), Cotton.1 = c(2, 3.33, 3, 2.16, 2, 0.93
), Pigeon.pea.1 = c(1, 0.33, 0.4, 0.33, 0.26, 0.2), Soyabean.1 = c(NaN,
NaN, NaN, NaN, NaN, NaN), Sorghum.1 = c(NaN, NaN, NaN, 5,
NaN, 6), Other.1 = c(NaN, NaN, NaN, NaN, NaN, NaN), Total.yield..Quintal..1 = c(6,
5.5, 6.8, 20, 3.4, 14.5), Gross.Income..Rs..1 = c(5930, 7500,
6920, 5100, 4666, 2822.66), Total.Expenditure..Rs..1 = c(3225,
3400, 3610, 3654.28, 5600, 1754.66), Net.Income..Rs..1 = c(2705,
4100, 3310, 1445.72, -934, 1068)), .Names = c("ID", "Area..acres.",
"Cotton", "Pigeon.pea", "Soyabean", "Sorghum", "Other", "Total.yield..Quintal.",
"Gross.Income..Rs.", "Total.Expenditure..Rs.", "Net.Income..Rs.",
"Area..acres..1", "Cotton.1", "Pigeon.pea.1", "Soyabean.1", "Sorghum.1",
"Other.1", "Total.yield..Quintal..1", "Gross.Income..Rs..1",
"Total.Expenditure..Rs..1", "Net.Income..Rs..1"), row.names = c(NA,
6L), class = "data.frame"), structure(list(ID = c(1, 2, 3, 4,
5, 6), Area..acres. = c(2, 2, 2, 3, 2, 1), Cotton = c(NaN, 3,
2, NaN, NaN, 4), Pigeon.pea = c(NaN, NaN, 0.5, 0.5, 1.5, 1),
Soyabean = c(3.66, NaN, NaN, 3, 1, NaN), Sorghum = c(2, NaN,
NaN, 1, 2.5, NaN), Other = c(22, NaN, NaN, 0.17, NaN, NaN
), Total.yield..Quintal. = c(12.3, 6, 5, 14.3, 10, 5), Gross.Income..Rs. = c(6030,
6420, 5562, 8183.33, 7780, 11800), Total.Expenditure..Rs. = c(3192,
4080, 3350, 20530, 3240, 5130), Net.Income..Rs. = c(2838,
2340, 2212, 5653.33, 4540, 6670), Area..acres..1 = c(2, 1,
2, 8, 1, 5), Cotton.1 = c(2, 4, 2.5, 3, 5.8, 5), Pigeon.pea.1 = c(3,
NaN, 0.5, 0.7, NaN, 0.25), Soyabean.1 = c(1, NaN, NaN, NaN,
NaN, NaN), Sorghum.1 = c(NaN, NaN, NaN, 3.7, NaN, 2), Other.1 = c(NaN,
NaN, NaN, NaN, NaN, NaN), Total.yield..Quintal..1 = c(0,
4, 6, 28, 5.8, 23), Gross.Income..Rs..1 = c(8675, 9760, 6677.5,
7417.7, 13050, 10860), Total.Expenditure..Rs..1 = c(7700,
6750, 5425, 4112.5, 6300, 4870), Net.Income..Rs..1 = c(975,
3010, 1252.5, 3305.7, 4750, 5990)), .Names = c("ID", "Area..acres.",
"Cotton", "Pigeon.pea", "Soyabean", "Sorghum", "Other", "Total.yield..Quintal.",
"Gross.Income..Rs.", "Total.Expenditure..Rs.", "Net.Income..Rs.",
"Area..acres..1", "Cotton.1", "Pigeon.pea.1", "Soyabean.1", "Sorghum.1",
"Other.1", "Total.yield..Quintal..1", "Gross.Income..Rs..1",
"Total.Expenditure..Rs..1", "Net.Income..Rs..1"), row.names = c(NA,
6L), class = "data.frame"))
Related
I used a 3DUnet with resblock to segment a CT image with input torch size of [1, 1, 96, 176, 176], but it throws the following error:
RuntimeError: Sizes of tensors must match except in dimension 2. Got 55 and 54 (The offending index is 0)
Hence I traced back, I found the error comes from
outputs = self.decoder_stage2(torch.cat([short_range6, long_range3], dim=1)) + short_range6
The short_range6 has torch.Size([1, 64, 24, 55, 40]) while the long_range3 has torch.Size([1, 128, 24, 54, 40]). I think this is because something not being a power of 2, but cannot find where to modify.
Below is the complete structure of the network, really thanks for any help!
class ResUNet(nn.Module):
def __init__(self, in_channel=1, out_channel=2 ,training=True):
super().__init__()
self.training = training
self.dorp_rate = 0.2
self.encoder_stage1 = nn.Sequential(
nn.Conv3d(in_channel, 16, 3, 1, padding=1),
nn.PReLU(16),
nn.Conv3d(16, 16, 3, 1, padding=1),
nn.PReLU(16),
)
self.encoder_stage2 = nn.Sequential(
nn.Conv3d(32, 32, 3, 1, padding=1),
nn.PReLU(32),
nn.Conv3d(32, 32, 3, 1, padding=1),
nn.PReLU(32),
nn.Conv3d(32, 32, 3, 1, padding=1),
nn.PReLU(32),
)
self.encoder_stage3 = nn.Sequential(
nn.Conv3d(64, 64, 3, 1, padding=1),
nn.PReLU(64),
nn.Conv3d(64, 64, 3, 1, padding=2, dilation=2),
nn.PReLU(64),
nn.Conv3d(64, 64, 3, 1, padding=4, dilation=4),
nn.PReLU(64),
)
self.encoder_stage4 = nn.Sequential(
nn.Conv3d(128, 128, 3, 1, padding=3, dilation=3),
nn.PReLU(128),
nn.Conv3d(128, 128, 3, 1, padding=4, dilation=4),
nn.PReLU(128),
nn.Conv3d(128, 128, 3, 1, padding=5, dilation=5),
nn.PReLU(128),
)
self.decoder_stage1 = nn.Sequential(
nn.Conv3d(128, 256, 3, 1, padding=1),
nn.PReLU(256),
nn.Conv3d(256, 256, 3, 1, padding=1),
nn.PReLU(256),
nn.Conv3d(256, 256, 3, 1, padding=1),
nn.PReLU(256),
)
self.decoder_stage2 = nn.Sequential(
nn.Conv3d(128 + 64, 128, 3, 1, padding=1),
nn.PReLU(128),
nn.Conv3d(128, 128, 3, 1, padding=1),
nn.PReLU(128),
nn.Conv3d(128, 128, 3, 1, padding=1),
nn.PReLU(128),
)
self.decoder_stage3 = nn.Sequential(
nn.Conv3d(64 + 32, 64, 3, 1, padding=1),
nn.PReLU(64),
nn.Conv3d(64, 64, 3, 1, padding=1),
nn.PReLU(64),
nn.Conv3d(64, 64, 3, 1, padding=1),
nn.PReLU(64),
)
self.decoder_stage4 = nn.Sequential(
nn.Conv3d(32 + 16, 32, 3, 1, padding=1),
nn.PReLU(32),
nn.Conv3d(32, 32, 3, 1, padding=1),
nn.PReLU(32),
)
self.down_conv1 = nn.Sequential(
nn.Conv3d(16, 32, 2, 2),
nn.PReLU(32)
)
self.down_conv2 = nn.Sequential(
nn.Conv3d(32, 64, 2, 2),
nn.PReLU(64)
)
self.down_conv3 = nn.Sequential(
nn.Conv3d(64, 128, 2, 2),
nn.PReLU(128)
)
self.down_conv4 = nn.Sequential(
nn.Conv3d(128, 256, 3, 1, padding=1),
nn.PReLU(256)
)
self.up_conv2 = nn.Sequential(
nn.ConvTranspose3d(256, 128, 2, 2),
nn.PReLU(128)
)
self.up_conv3 = nn.Sequential(
nn.ConvTranspose3d(128, 64, 2, 2),
nn.PReLU(64)
)
self.up_conv4 = nn.Sequential(
nn.ConvTranspose3d(64, 32, 2, 2),
nn.PReLU(32)
)
# 256*256
self.map4 = nn.Sequential(
nn.Conv3d(32, out_channel, 1, 1),
nn.Upsample(scale_factor=(1, 1, 1), mode='trilinear', align_corners=False),
nn.Softmax(dim=1)
)
# 128*128
self.map3 = nn.Sequential(
nn.Conv3d(64, out_channel, 1, 1),
nn.Upsample(scale_factor=(2, 2, 2), mode='trilinear', align_corners=False),
nn.Softmax(dim=1)
)
# 64*64
self.map2 = nn.Sequential(
nn.Conv3d(128, out_channel, 1, 1),
nn.Upsample(scale_factor=(4, 4, 4), mode='trilinear', align_corners=False),
nn.Softmax(dim=1)
)
# 32*32
self.map1 = nn.Sequential(
nn.Conv3d(256, out_channel, 1, 1),
nn.Upsample(scale_factor=(8, 8, 8), mode='trilinear', align_corners=False),
nn.Softmax(dim=1)
)
def forward(self, inputs):
long_range1 = self.encoder_stage1(inputs) + inputs
short_range1 = self.down_conv1(long_range1)
long_range2 = self.encoder_stage2(short_range1) + short_range1
long_range2 = F.dropout(long_range2, self.dorp_rate, self.training)
short_range2 = self.down_conv2(long_range2)
long_range3 = self.encoder_stage3(short_range2) + short_range2
long_range3 = F.dropout(long_range3, self.dorp_rate, self.training)
short_range3 = self.down_conv3(long_range3)
long_range4 = self.encoder_stage4(short_range3) + short_range3
long_range4 = F.dropout(long_range4, self.dorp_rate, self.training)
short_range4 = self.down_conv4(long_range4)
outputs = self.decoder_stage1(long_range4) + short_range4
outputs = F.dropout(outputs, self.dorp_rate, self.training)
output1 = self.map1(outputs)
short_range6 = self.up_conv2(outputs)
outputs = self.decoder_stage2(torch.cat([short_range6, long_range3], dim=1)) + short_range6
outputs = F.dropout(outputs, self.dorp_rate, self.training)
output2 = self.map2(outputs)
short_range7 = self.up_conv3(outputs)
outputs = self.decoder_stage3(torch.cat([short_range7, long_range2], dim=1)) + short_range7
outputs = F.dropout(outputs, self.dorp_rate, self.training)
output3 = self.map3(outputs)
short_range8 = self.up_conv4(outputs)
outputs = self.decoder_stage4(torch.cat([short_range8, long_range1], dim=1)) + short_range8
output4 = self.map4(outputs)
if self.training is True:
return output1, output2, output3, output4
else:
return output4```
You can pad your image's dimensions to be multiple of 32's. By doing this, you won't have to change the 3DUnet's parameters.
I will provide you a simple code to show you the way.
# I assume that you named your input image as img
padding1_mult = math.floor(img.shape[3] / 32) + 1
padding2_mult = math.floor(img.shape[4] / 32) + 1
pad1 = (32 * padding1_mult) - img.shape[3]
pad2 = (32 * padding2_mult) - img.shape[4]
padding = nn.ReplicationPad2d((0, pad2, pad1, 0, 0 ,0))
img = padding(img)
After this operation, your image shape must be torch.Size([1, 1, 96, 192, 192])
I am dealing with the post-procession of CSV logs arranged in the multi-column format in the following order: the first column corresponds to the line number (ID), the second one contains its population (POP, the number of the samples fell into this ID) and the third column (dG) represent some inherent value of this ID (which is always negative):
ID, POP, dG
1, 7, -9.6000
2, 3, -8.7700
3, 6, -8.6200
4, 4, -8.2700
5, 6, -8.0800
6, 10, -8.0100
7, 9, -7.9700
8, 8, -7.8400
9, 16, -7.8100
10, 2, -7.7000
11, 1, -7.5600
12, 2, -7.5200
13, 9, -7.5100
14, 1, -7.5000
15, 2, -7.4200
16, 1, -7.3300
17, 1, -7.1700
18, 4, -7.1300
19, 3, -6.9200
20, 1, -6.9200
21, 2, -6.9100
22, 2, -6.8500
23, 10, -6.6900
24, 2, -6.6800
25, 1, -6.6600
26, 20, -6.6500
27, 1, -6.6500
28, 5, -6.5700
29, 3, -6.5500
30, 2, -6.4600
31, 2, -6.4500
32, 1, -6.3000
33, 7, -6.2900
34, 1, -6.2100
35, 1, -6.2000
36, 3, -6.1800
37, 1, -6.1700
38, 4, -6.1300
39, 1, -6.1000
40, 2, -6.0600
41, 3, -6.0600
42, 8, -6.0200
43, 2, -6.0100
44, 1, -6.0100
45, 1, -5.9800
46, 2, -5.9700
47, 1, -5.9300
48, 6, -5.8800
49, 4, -5.8300
50, 4, -5.8000
51, 2, -5.7800
52, 3, -5.7200
53, 1, -5.6600
54, 1, -5.6500
55, 4, -5.6400
56, 2, -5.6300
57, 1, -5.5700
58, 1, -5.5600
59, 1, -5.5200
60, 1, -5.5000
61, 3, -5.4200
62, 4, -5.3600
63, 1, -5.3100
64, 5, -5.2500
65, 5, -5.1600
66, 1, -5.1100
67, 1, -5.0300
68, 1, -4.9700
69, 1, -4.7700
70, 2, -4.6600
In order to reduce the number of the lines I filtered this CSV with the aim to search for the line with the highest number in the second column (POP), using the following AWK expression:
# search CSV for the line with the highest POP and save all lines before it, while keeping minimal number of the lines (3) in the case if this line is found at the beginning of CSV.
awk -v min_lines=3 -F ", " 'a < $2 {for(idx=0; idx < i; idx++) {print arr[idx]} print $0; a=int($2); i=0; printed=NR} a > $2 && NR > 1 {arr[i]=$0; i++}END{if(printed <= min_lines) {for(idx = 0; idx <= min_lines - printed; idx++){print arr[idx]}}}' input.csv > output.csv
thus obtaining the following reduced output CSV, which still has many lines since the search string (with highest POP) is located on 26th line:
ID, POP, dG
1, 7, -9.6000
2, 3, -8.7700
3, 6, -8.6200
4, 4, -8.2700
5, 6, -8.0800
6, 10, -8.0100
7, 9, -7.9700
8, 8, -7.8400
9, 16, -7.8100
10, 2, -7.7000
11, 1, -7.5600
12, 2, -7.5200
13, 9, -7.5100
14, 1, -7.5000
15, 2, -7.4200
16, 1, -7.3300
17, 1, -7.1700
18, 4, -7.1300
19, 3, -6.9200
20, 1, -6.9200
21, 2, -6.9100
22, 2, -6.8500
23, 10, -6.6900
24, 2, -6.6800
25, 1, -6.6600
26, 20, -6.6500
How it would be possible to further customize my filter via modifying my AWK expression (or pipe it to something else) in order to consider additionally only the lines with small difference in the negative value of the third column, dG compared to the first line (which has the value most negative)? For example to consider only the lines different no more then 20% in terms of dG compared to the first line, while keeping all rest conditions the same:
ID, POP, dG
1, 7, -9.6000
2, 3, -8.7700
3, 6, -8.6200
4, 4, -8.2700
5, 6, -8.0800
6, 10, -8.0100
7, 9, -7.9700
8, 8, -7.8400
9, 16, -7.8100
10, 2, -7.7000
Both tasks can be done in a single awk:
awk -F ', ' 'NR==1 {next} FNR==NR {if (max < $2) {max=$2; n=FNR}; if (FNR==2) dg = $3 * .8; next} $3+0 == $3 && (FNR == n+1 || $3 > dg) {exit} 1' file file
ID, POP, dG
1, 7, -9.6000
2, 3, -8.7700
3, 6, -8.6200
4, 4, -8.2700
5, 6, -8.0800
6, 10, -8.0100
7, 9, -7.9700
8, 8, -7.8400
9, 16, -7.8100
10, 2, -7.7000
To make it more readable:
awk -F ', ' '
NR == 1 {
next
}
FNR == NR {
if (max < $2) {
max = $2
n = FNR
}
if (FNR == 2)
dg = $3 * .8
next
}
$3 + 0 == $3 && (FNR == n+1 || $3 > dg) {
exit
}
1' file file
reproducible code
Hello, I used the following code in markdown
<pre><span style="color:blue">Text = ' Sooo SAD I will miss you here in San Diego!!!'</span>, <span style="color:blue">Selected Text='Sooo SAD'</span>, <span style="color:blue">Sentiment = 'negative'</span></pre>
<pre>tokens =</pre>
<pre>input_ids = [0, 2430, 98, 3036, 5074, 939, 40, 2649, 47, 259, 11, 15610, 1597, 2977, 16506, 2, 1, 1...1]</pre>
<pre>attention_masks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0]</pre>
<pre>start_tokens = [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>end_tokens = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>Edit Text = ' Sooo SAD I will miss you here in San Diego!!!' (len=46), Edit Seletected Text='Sooo SAD' (len=8)</pre>
<pre>char = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0] (len=46, num_1=9)</pre>
<pre>offset = [(0, 3), (3, 5), (5, 9), (9, 11), (11, 16), (16, 21), (21, 25), (25, 30), (30, 33), (33, 37), (37, 41), (41, 43), (43, 46)]</pre>
undesired effect
and generate the following effect
But the too wide line space makes the effect is kind of ugly. Do you know how to redue the line space?
Tried method
I tried this method
<pre style='display:inline'>tokens =</pre> <br>
<pre>input_ids = [0, 2430, 98, 3036, 5074, 939, 40, 2649, 47, 259, 11, 15610, 1597, 2977, 16506, 2, 1, 1...1]</pre>
But it only works for one line, if I want to apply to other lines such as this
<pre style='display:inline'>tokens =</pre> <br>
<pre style='display:inline'>input_ids = [0, 2430, 98, 3036, 5074, 939, 40, 2649, 47, 259, 11, 15610, 1597, 2977, 16506, 2, 1, 1...1]</pre> <br>
<pre>attention_masks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0]</pre>
it would cover part of line content
Question
How to reduce the line space? Thank you
You could use css display and line-height properties on the pre elements and adjust the line-height you want.
pre {
display: inline;
line-height: 0.8em;
}
<pre><span style="color:blue">Text = ' Sooo SAD I will miss you here in San Diego!!!'</span>, <span style="color:blue">Selected Text='Sooo SAD'</span>, <span style="color:blue">Sentiment = 'negative'</span></pre>
<pre>tokens =</pre>
<pre>input_ids = [0, 2430, 98, 3036, 5074, 939, 40, 2649, 47, 259, 11, 15610, 1597, 2977, 16506, 2, 1, 1...1]</pre>
<pre>attention_masks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0]</pre>
<pre>start_tokens = [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>end_tokens = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>Edit Text = ' Sooo SAD I will miss you here in San Diego!!!' (len=46), Edit Seletected Text='Sooo SAD' (len=8)</pre>
<pre>char = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0] (len=46, num_1=9)</pre>
<pre>offset = [(0, 3), (3, 5), (5, 9), (9, 11), (11, 16), (16, 21), (21, 25), (25, 30), (30, 33), (33, 37), (37, 41), (41, 43), (43, 46)]</pre>
Or reset the default margin.
You can use margin: 0 (or any other value) for pre in CSS:
pre {
margin: 0;
}
<pre><span style="color:blue">Text = ' Sooo SAD I will miss you here in San Diego!!!'</span>, <span style="color:blue">Selected Text='Sooo SAD'</span>, <span style="color:blue">Sentiment = 'negative'</span></pre>
<pre>tokens =</pre>
<pre>input_ids = [0, 2430, 98, 3036, 5074, 939, 40, 2649, 47, 259, 11, 15610, 1597, 2977, 16506, 2, 1, 1...1]</pre>
<pre>attention_masks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0]</pre>
<pre>start_tokens = [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>end_tokens = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...0]</pre>
<pre>Edit Text = ' Sooo SAD I will miss you here in San Diego!!!' (len=46), Edit Seletected Text='Sooo SAD' (len=8)</pre>
<pre>char = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0...0] (len=46, num_1=9)</pre>
<pre>offset = [(0, 3), (3, 5), (5, 9), (9, 11), (11, 16), (16, 21), (21, 25), (25, 30), (30, 33), (33, 37), (37, 41), (41, 43), (43, 46)]</pre>
Im trying to fill a HighCharts Heatmap with data returned from an SQL Query.
What i have in the JS file is
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("php/all-counties-sales-data-box.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'chart-box-combined',
type: 'heatmap',
marginTop: 40,
marginBottom: 80,
plotBorderWidth: 1
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
},
yAxis: {
categories: ['Lucozade', 'Rockstar', 'Sprite', 'Monster', '7Up', 'Fanta', 'Coke'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 280
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
series: [{
name: 'Sales per Shell',
borderWidth: 1,
data:
[[0, 0, 10], [0, 1, 19], [0, 2, 8], [0, 3, 24], [0, 4, 67], [0, 5, 67], [0, 6, 67],
[1, 0, 92], [1, 1, 58], [1, 2, 78], [1, 3, 117], [1, 4, 48], [1, 5, 48], [1, 6, 48],
[2, 0, 35], [2, 1, 15], [2, 2, 123], [2, 3, 64], [2, 4, 52],
[3, 0, 72], [3, 1, 132], [3, 2, 114], [3, 3, 19], [3, 4, 16],
[4, 0, 38], [4, 1, 5], [4, 2, 8], [4, 3, 117], [4, 4, 115],
[5, 0, 88], [5, 1, 32], [5, 2, 12], [5, 3, 6], [5, 4, 120],
[6, 0, 13], [6, 1, 44], [6, 2, 88], [6, 3, 98], [6, 4, 96],
[7, 0, 31], [7, 1, 1], [7, 2, 82], [7, 3, 32], [7, 4, 30],
[8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84],
[9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91],
[10, 0, 47],
[11, 0, 47],
],
dataLabels: {
enabled: true,
color: '#000000'
}
}]
});
});
});
});
And what im trying to fill it with is data from the query
$sth = mysql_query("Select SUM(Profit) as profitSum From FactSales GROUP BY ShellType, SaleMonth");
$rows1 = array();
$rows1['profit'] = 'profitSum';
while($rr = mysql_fetch_assoc($sth)) {
$rows1['series'][] = $rr['profitSum'];
}
$result = array();
array_push($result,$rows1);
What do i actually need to change for the "series" data to be filled with the data returned from the sql query?
Heres the JSON response as requested
[{"profit":"profitSum","data":[1329230,1796743,1789417,1327813,1457103,1198845,1859826,1770589,1555410,1310369,2183499,1212897,6424306,6426002,6345153,6167415,6969392,5974880,6407699,6278843,6622002,5962102,5198177,5386392,72991,2321397,1751565,2029890,642041,1314314,1322492,1557859,1647784,1831767,1347480,1739353,1742597,1636006,1728247,1709689,1206645,1383206,1119153,1378317,1527356,1937898,1485322,1404498,1868629,1635265,1860456,1293870,1485349,2031389,1834402,1291372,1838382,1616009,781641,1421830,1763592,1279535,1123468,2024766,975863,1461843,1318585,1137336,1111721,1407705,2349652,1260858,1144070,1219659,1378615,1354139,2015115,1408858,2650864,1810850,1380157,1844909,2055306,1913532,1701963]}]
I am trying to create a dot chart(bubble chart) using gRaphael. But their documentation is not so clear on how to add hover effects when the user hovers on the dots.
Could any one pls suggest me some examples or give some help tips on the same.
Thanx in advance.
you have to use aDotChart.hoverDot() for registering a "dot hover listener". The following is the source code of example http://cancerbero.vacau.com/gwt/graphael4gwtGallery/?test=dot1 that do what you mention. It is Java code not javascript! but i think it can help you to make an idea of the javascript code:
double[] xs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
double[] ys = {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
double[] data = {294, 300, 204, 255, 348, 383, 334, 217, 114, 33, 44, 26, 41, 39,
52, 17, 13, 2, 0, 2, 5, 6, 64, 153, 294, 313, 195, 280, 365, 392, 340, 184,
87, 35, 43, 55, 53, 79, 49, 19, 6, 1, 0, 1, 1, 10, 50, 181, 246, 246, 220,
249, 355, 373, 332, 233, 85, 54, 28, 33, 45, 72, 54, 28, 5, 5, 0, 1, 2, 3,
58, 167, 206, 245, 194, 207, 334, 290, 261, 160, 61, 28, 11, 26, 33, 46, 36,
5, 6, 0, 0, 0, 0, 0, 0, 9, 9, 10, 7, 10, 14, 3, 3, 7, 0, 3, 4, 4, 6, 28, 24,
3, 5, 0, 0, 0, 0, 0, 0, 4, 3, 4, 4, 3, 4, 13, 10, 7, 2, 3, 6, 1, 9, 33, 32, 6,
2, 1, 3, 0, 0, 4, 40, 128, 212, 263, 202, 248, 307, 306, 284, 222, 79, 39, 26,
33, 40, 61, 54, 17, 3, 0, 0, 0, 3, 7, 70, 199};
String[] axisy = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
String[] axisx = {"12am", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12pm", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
DotOpts opts = new DotOpts();
opts.setSymbol("o");
opts.setMax(10);
opts.setHeat(true);
opts.setAxis("0 0 1 1");
opts.setAxisxlabels(axisx);
opts.setAxisylabels(axisy);
final DotChart c1 = getGPaper().dotchart(10, 10, 620, 260, xs, ys, data, opts);
c1.hoverDot(new DotHoverListener() {
#Override
public void hoverOut(DotContext ctx) {
if(tag!=null)
tag.remove();
}
#Override
public void hoverIn(DotContext ctx) {
tag = (GShape) getGPaper().tag(ctx.getX(), ctx.getY(), ctx.getValue()+"", 0, ctx.getR()+2).
insertBefore(ctx).show();
}
});
Thanks for your reply cancerbero.
Here is my java script solution,
dotChart.hover(function(){//onmouseover
dotChart.covers = r.set();
dotChart.covers.push(r.tag(this.x, this.y, this.value , 0, 10).insertBefore(this));
}, function(){//onmouseout
if(dotChart.covers!=null){
dotChart.covers.remove();
}
});
This has worked fine :)