I'm trying to process a huge text file containing dozens millions lines of text. The text file contains the results of a convnet analysis of several millions of images and looks like this:
CUDNN_HALF=1
net.optimized_memory = 0
mini_batch = 1, batch = 8, time_steps = 1, train = 0
nms_kind: greedynms (1), beta = 0.600000
nms_kind: greedynms (1), beta = 0.600000
nms_kind: greedynms (1), beta = 0.600000
seen 64, trained: 447 K-images (6 Kilo-batches_64)
Enter Image Path: data/obj1/H001683-19-1-5-OCT2 [x=13390,y=52118,w=256,h=256].png: Predicted in 19.894000 milli-seconds.
tumor: 99% (left_x: 2 top_y: 160 width: 67 height: 34)
bcell: 98% (left_x: 6 top_y: 54 width: 32 height: 22)
bcell: 80% (left_x: 51 top_y: 0 width: 30 height: 16)
bcell: 98% (left_x: 52 top_y: 198 width: 28 height: 26)
bcell: 98% (left_x: 150 top_y: 216 width: 35 height: 23)
bcell: 56% (left_x: 150 top_y: 78 width: 45 height: 30)
bcell: 91% (left_x: 187 top_y: 132 width: 31 height: 26)
bcell: 96% (left_x: 219 top_y: 185 width: 20 height: 26)
bcell: 37% (left_x: 222 top_y: -0 width: 24 height: 4)
bcell: 98% (left_x: 241 top_y: 208 width: 15 height: 21)
bcell: 64% (left_x: 248 top_y: 35 width: 8 height: 35)
[... a lot of similar lines...]
Enter Image Path: data/obj1/H001683-19-1-5-OCT2 [x=13390,y=52530,w=256,h=256].png: Predicted in 19.195000 milli-seconds.
bcell: 97% (left_x: 45 top_y: 180 width: 29 height: 24)
bcell: 58% (left_x: 59 top_y: 1 width: 35 height: 22)
tumor: 98% (left_x: 105 top_y: 143 width: 99 height: 44)
tumor: 97% (left_x: 113 top_y: 50 width: 57 height: 40)
bcell: 96% (left_x: 191 top_y: 194 width: 29 height: 27)
bcell: 99% (left_x: 201 top_y: 129 width: 34 height: 22)
Enter Image Path:
Each image is mentioned by the image file name after "Enter Image Path" followed by a list of objects which were identified. I do not know a priori, how many objects (here tumor an bcell) are in each image. Sometimes where are no objects at all, sometimes where are hundreds.
I first tried to read the whole file using
test11<-readLines("result.txt")
picsna<-grep(test11,pattern="Enter Image") # line numbers with the image file name
lle<-length(picsna) # length for the subsequent script
and then to go ahead with my script but it proved to take hours to read the file so I came with the Idea to read the file line by line and execute my code "on the fly" using a while-loop:
require(LaF)
n=1
lle<-0 # number of images (to be used in a subsequent code)
picsna<-c() # vector with the line numbers of each image entry
# read the result-file initially (first bunch of lines do not contain image entries
test11<-get_lines(file="result.txt", line_numbers=n)
# as long as the line exists read the next line and do following:
while(is.na(test11)==FALSE){
test11<-get_lines(file="result.txt", line_numbers=n+1)
# I wanted to know how far my reading progressed but had a feeling, print slowed down the loop
#print(n)
# I found here this solution for printing progress periodically
if(n %% 10000==0) {
cat(paste0("iteration: ", n, "\n"))
}
# look for image entry and save the line number (not the iteration number)
if(grepl(test11,pattern="Enter Image")==TRUE){
picsna<-c(picsna,n+1)
lle<-lle+1} # increase the number of images
n<-n+1
}
# the last line of the file is always incomplete but has to be added to the vector to calculate the number of objects (in a following script not shown here) if the previous image had any.
if(is.na(test11)==TRUE){
picsna<-c(picsna,n)
print("The End")
lle<-lle+1
}
I measured the elapsed time for the first and the second script on a small result file containing about 200 lines. The second script was even a little bit slower (0.04 vs 0.01), which confused me.
I thought about rewriting it in a foreach-%dopar%-loop but could not realize how to implement it with the readLines-function or with my while-loop. My problem is, that I do not know apriori how many lines the file contains. I would really appreciate if somebody could help me to parallelize my script!
Thank you #Bas! I tested your suggestion on a Linux machine: for a file with ~239 million lines it took less than 1 min. By adding >lines.txt I could save the results. Interestingly, my first readLines R script needed "only" 29 min, which was surprisingly fast compared with my first experience (so I might have had some problem with my Windows computer at work which was not related to R).
Related
I cannot find how to insert a line break in long titles inside nodes. For example:
library(DiagrammeR)
mermaid("
graph TB
A[GE Solution]-->C{ }
B[GA Solution]-->C{ }
C{ }-->D[Stir 10 mins at 500 r/min]
D[Stir 10 mins at 500 r/min]-->E[Homogenisation at 10000 r/min]
E[Homogenisation at 10000 r/min]-->F(Stir 10 min 450 r/min Complex coacervation)
")
Note node F is too long. How to I make it into sth like..?
|Stir 10 min 450 r/min|
|Complex coacervation |
Note \n doesn't work.
It appears you can use <br> instead:
mermaid("
graph TB
A[GE Solution]-->C{ }
B[GA Solution]-->C{ }
C{ }-->D[Stir 10 mins at 500 r/min]
D[Stir 10 mins at 500 r/min]-->E[Homogenisation at 10000 r/min]
E[Homogenisation at 10000 r/min]-->F(Stir 10 min 450 r/min <br> Complex coacervation)
")
Another answer that appears to work just fine is to use \n rather than <br>.
When solving a portfolio optimization problem with an additional 1-norm constraint on the portfolio weights, I faced with convergency problems.
Description of the exercise:
For given N assets with T observations of their returns find the value of 1Norm constraint Theta, such that the last period portfolio return (T-th one) is maximized. That is, solve the problem: min_w w'COVw$ s.t. w1+w2+...+wN=1 and |w1|+|w2|+...+|wN|<=Theta and, out of all values of Theta, choose the one with the maximum value of w'r_T, where r_T is the vector of assets returns in the last period and COV is the variance-covariance matrix of asset returns.
Description of the problem:
First I tried the "naive" approach: with a grid of 0.001 for Theta from 1 to 6 I was going to solve the portfolio optimization problem and compute the last period portfolio return for each Theta. The idea was to choose then the value of Theta with the largest corresponding last period return. However, I noticed that for quite a few values of Theta the solnp function did not converge. The problem occured mostly for small values of Theta: from 1 to 3. For larger values no problems with convergency were detected.
The second approach was to use solnp function twice: first as the function to find Theta and second as the inner part of the objective function. However, I could not find reliable estimates in this way: the values I got did not deliver the optimal solution. Apparently, the objective function is not smooth, but gosolnp function does not find the solution.
The code with data (6 assets with 120 return observations) is provided below. Any suggestions are welcome.
> exp_d
[,1] [,2] [,3] [,4] [,5] [,6]
1 1.3724 0.9081 -0.0695 5.7168 1.9642 1.4222
2 0.6095 1.5075 5.3842 2.7154 2.6838 6.3154
3 -2.6779 -0.1359 -0.4374 1.4287 0.0709 -0.7967
4 -3.5365 -4.3572 -2.0112 -3.5898 -2.3460 -4.0970
5 3.1210 3.6608 2.0944 3.1292 2.8965 3.4614
6 2.7364 1.8411 3.2639 2.9678 2.6067 2.3950
7 -1.0001 -0.3782 3.9316 -0.2621 0.0347 4.4635
8 3.9022 6.3784 6.6192 5.0044 3.5568 8.6305
9 -1.6000 -0.9889 -3.1676 1.3025 0.2071 -2.4764
10 -1.3184 0.8741 3.4796 3.0510 -0.7634 -0.5452
11 5.5482 3.3467 13.3256 5.4076 5.1017 7.4921
12 -1.5484 1.3040 -3.9474 -0.9628 -3.0156 -1.6326
13 4.3331 5.2347 3.9846 9.2369 6.7429 7.2603
14 2.3503 -2.2044 0.8600 3.9191 1.2181 -1.9651
15 2.3981 2.2316 0.3990 5.3864 4.3919 5.9674
16 -0.1633 -2.1458 -5.8357 -3.6349 -4.2840 -6.6219
17 10.4346 8.0620 10.2275 7.0560 6.7676 6.6346
18 5.5505 2.6016 2.4506 2.4954 1.8547 3.4755
19 3.2031 2.7804 3.5948 -0.4774 -0.3667 -2.3168
20 -4.7913 -1.7203 -4.1271 -0.6762 -1.1395 -2.7296
21 7.3930 8.6229 9.4570 12.2800 6.1327 7.8254
22 4.2158 10.6845 9.9723 2.9145 6.0000 4.4979
23 7.5326 1.9540 2.5740 2.6065 -0.1128 0.6388
24 -8.5131 -8.3044 -6.8294 -3.6094 -4.1224 -5.4164
25 -0.4048 -0.4017 -0.8867 1.3590 0.1098 0.9017
26 6.1240 5.0517 3.6990 8.7368 5.3867 6.9468
27 5.7317 4.4538 6.1762 3.4108 1.9153 4.4896
28 6.8299 3.1244 1.6621 1.3590 1.4325 2.0067
29 8.6705 11.1936 12.2831 11.1602 13.2781 13.1497
30 0.9055 -0.5953 -0.6462 0.9332 -0.0008 1.2917
31 -0.0340 1.9379 1.4480 6.5262 4.8373 2.6307
32 0.7414 1.1014 0.3820 -0.5791 0.8306 3.1476
33 -5.9533 -3.4602 -4.1597 -1.3835 2.2098 -0.0642
34 -0.0822 2.7549 0.5136 2.2172 1.1145 2.8362
35 -10.2009 -9.3603 -12.8907 -5.7297 -4.1622 -6.1709
36 6.9673 9.4356 6.4064 12.4593 9.3500 7.5052
37 -0.0681 -0.7029 3.8633 3.5471 6.2018 4.9529
38 -0.8885 -0.4641 -0.4544 7.2353 12.5430 6.9497
39 -4.2569 -4.3105 -3.6218 -4.4211 -4.9685 -6.3175
40 -21.7261 -19.3351 -19.8329 -24.1865 -14.0943 -10.3723
41 -16.4096 -9.8425 -12.3366 -14.2535 -10.9314 -7.6677
42 -2.7511 -2.7249 -1.8488 3.3988 0.5515 1.3170
43 6.2347 9.4395 8.4631 7.1735 3.3113 2.9221
44 1.3502 1.2075 4.3779 3.4639 1.8818 1.2221
45 9.0009 11.0661 10.7647 6.8160 8.3348 5.3573
46 -6.0956 -1.7406 -3.4814 -2.3610 -1.7939 -6.6523
47 -3.7611 -2.3132 -2.9578 0.7061 -2.2643 -1.3650
48 -16.9330 -16.6497 -18.9287 -17.8490 -13.1565 -11.8439
49 6.5208 3.7280 2.5406 4.4017 4.2198 5.2644
50 -3.7646 -1.6135 -2.5073 1.1969 -0.8000 -1.6232
51 -13.6823 -14.6721 -19.1619 -12.0325 -11.7394 -17.0858
52 -10.1007 -7.6801 -10.7443 -9.4278 -7.3264 -11.4835
53 0.2234 -2.7838 -2.6023 -2.3616 -2.8339 -6.6002
54 -10.4236 -11.0266 -17.2866 -5.8057 -9.1776 -9.7245
55 9.9121 11.3602 15.4627 4.7170 6.9823 13.5911
56 13.2032 11.6577 17.0900 12.8706 6.7357 12.1756
57 -4.3440 -2.9204 -6.9601 -4.1971 -10.3577 -8.8826
58 -12.8949 -14.0212 -18.2229 -8.8412 -11.1070 -11.3490
59 -9.6709 -8.7006 -13.8440 -11.3932 -15.9343 -20.3630
60 10.1262 7.7295 20.3174 12.8509 16.1956 25.2657
61 -8.5867 -8.9411 -5.7363 -5.1668 -10.1775 -12.2143
62 -1.6114 -1.1797 -3.7504 0.8986 -1.5948 0.0531
63 -26.5722 -30.0521 -33.8286 -28.8671 -28.1493 -35.1131
64 4.2319 9.2071 5.4593 9.5401 3.2588 11.7214
65 -7.7335 -7.2915 -9.3902 -6.1288 -16.6307 -14.5665
66 -13.7987 -16.5088 -22.4192 -11.5667 -18.8221 -20.6686
67 2.4924 3.9264 10.5116 -3.4347 1.9132 6.6353
68 -2.4754 1.9822 1.3833 7.1142 1.7366 0.3507
69 -10.5259 -12.1366 -10.6244 -10.2031 -15.1403 -14.7460
70 -19.3072 -17.1449 -16.0430 -18.1275 -20.1476 -18.5418
71 -17.1387 -24.8400 -17.4741 -19.2184 -25.9531 -25.4360
72 0.9540 6.2481 1.0364 -1.7110 0.0545 8.8476
73 31.9086 36.1125 63.2475 28.1955 48.6209 67.7847
74 48.7266 55.3725 83.5754 31.3211 50.9661 62.5277
75 -2.8054 -4.5841 -12.4737 -1.0366 -6.5149 -5.0087
76 -16.2535 -19.6450 -23.8672 -10.7514 -17.5126 -23.2272
77 -0.2972 -8.2786 -13.2053 -2.7223 -8.9288 -16.3816
78 -5.1581 -4.2529 -11.0631 6.8503 1.0438 -3.5633
79 4.3896 1.3914 7.8950 -0.0120 3.0297 8.7685
80 -17.8468 -18.4137 -20.8881 -14.9493 -16.5816 -17.3738
81 7.0790 6.1577 16.0332 0.9569 9.8608 6.7577
82 45.4453 54.8024 56.5610 33.7390 51.8933 57.4905
83 59.9378 62.1965 73.3394 16.9717 26.7781 41.6260
84 32.9373 23.3035 18.5882 11.3683 15.5089 21.9496
85 -14.1385 -12.7712 -7.2418 -8.8583 -13.0573 -9.2208
86 10.5585 10.1102 8.2144 10.5958 15.7784 18.8615
87 -7.6121 -13.3352 -20.9042 -9.1454 -12.3603 -19.3866
88 -8.4949 -12.4200 -13.8362 -6.1614 -10.5922 -17.7448
89 4.4492 4.6618 6.1086 9.6900 12.2772 12.6924
90 4.7702 4.0567 0.4565 2.1093 1.8286 3.3536
91 21.5203 28.5643 38.3403 9.8669 16.8246 24.1368
92 -0.2935 1.1796 5.3723 -2.3815 -3.1241 -3.8100
93 4.7722 2.0674 -0.0727 -0.0029 -0.1362 -0.6200
94 2.8356 -1.3170 -1.8303 -1.7780 -2.3152 -4.6160
95 -7.3381 -9.8907 -12.0504 -6.4033 -8.5879 -13.5106
96 3.7672 0.0811 -2.3100 2.6280 2.4811 2.8615
97 -18.0226 -21.5042 -24.4760 -8.3110 -11.7051 -23.1790
98 10.9235 9.4125 12.2230 6.0718 4.4464 5.7691
99 -0.9255 -0.5806 -3.5672 -0.2597 -0.1487 -0.1050
100 -0.9250 -1.6380 -4.1937 -0.4115 -2.7080 -7.3690
101 17.4218 15.4433 12.5284 10.2402 5.0137 10.6573
102 4.9409 1.7554 1.5981 0.7507 0.5333 -2.2372
103 -5.5523 -3.3988 -3.0325 -3.0099 -2.8838 -9.3128
104 -3.5225 -4.8589 -5.8780 -0.8581 -1.6838 -12.9875
105 -5.9234 -7.4692 -11.2668 -2.9715 -3.3289 -7.7499
106 6.7174 9.3484 10.2238 8.0311 9.8871 13.0598
107 -2.4801 2.3317 1.7345 3.1370 4.3390 3.9570
108 -1.7502 5.9262 0.8071 6.3821 5.6136 8.0813
109 9.1528 12.9358 12.7537 6.9882 6.3196 17.1148
110 4.2227 8.6796 14.4462 2.5694 2.2001 3.7475
111 5.0917 5.5331 0.5575 4.6757 0.6768 1.1198
112 10.9064 10.8504 6.8068 6.6016 7.9769 6.0328
113 6.6969 10.4475 18.9743 3.0389 5.6087 14.5739
114 5.7713 10.1556 2.2152 2.9835 5.8064 8.6858
115 10.3194 7.6727 22.3771 3.2881 9.5299 12.2406
116 1.9010 6.5601 6.7824 1.9137 2.8060 7.1039
117 0.5096 2.3380 0.8324 2.6378 0.0632 -1.0088
118 -14.3931 -13.9743 -15.4640 -7.1563 -8.3505 -10.2494
119 4.9011 5.5856 8.6767 5.0578 5.1107 6.5508
120 -2.2080 -0.2588 -1.2498 3.6325 2.1402 0.2676
#define equality constraint function
equal <- function(x) c(sum(x))
#define inequality constraint function
in_inequal <- function(x) c(sum(abs(x)))
#define objective function1
obj_f <- function(x) {
int_r <- t(x)%*%V_C_M%*%x
c(as.numeric(int_r))
}
#define objective function2
ex_obj_f <- function(x) {
tteta <- x
port_w <- solnp(rep(1/n,n), fun = obj_f, eqfun=equal, eqB=1,
ineqfun = in_inequal, ineqLB = 0, ineqUB = tteta, control = list(trace=0))
lp_ret <- exp_d[nrow(exp_d),]%*%port_w$pars
-lp_ret
}
#First "naive" attempt
exp_d <- as.matrix(exp_d)
n <- 6
V_C_M <- cov(exp_d)
res <- matrix(0:0, nrow = 5000, ncol = 3)
for (i in 1:5000) {
tteta <- 1 + i*0.001
port_w <- solnp(rep(1/n,n), fun = obj_f, eqfun=equal, eqB=1, ineqfun = in_inequal, ineqLB = 0, ineqUB = tteta, control = list(trace=0))
lp_ret <- exp_d[nrow(exp_d),]%*%port_w$pars
res[i,1] <- tteta
res[i,2] <- lp_ret
res[i,3] <- port_w$convergence
}
#Second Approach (the result really depends on the starting value of the parameter)
tt_op1 <- solnp(pars = 1.5, fun = ex_obj_f, LB = 1, UB = 10, control = list(trace=1))
tt_op2 <- gosolnp(pars = 1.5, fun = ex_obj_f, LB = 1, UB = 10)
P.S. I have read posts with similar problems here, but coud not find a solution to my question.
Your model can be formulated as a pure QP (quadratic programming) problem instead of a difficult nonlinear problem with a nonlinear non-differentiable constraint.
The constraint
sum(i, |x(i)|) <= Theta
can be linearized in different ways. One possible reformulation is
-y(i) <= x(i) <= y(i)
sum(i, y(i)) <= Theta
non-negative (or free) variable y(i)
Now you can solve the model with a QP solver instead of a general purpose NLP solver.
I have a Qt/QML application with a C++ model and a QML visualisation.
At run-time (start-up), I get a warning
QML Item: Binding loop detected for property "xyz"
I see no obvious loop in my QML.
Can I enable more debugging to understand where this loop comes from? Other suggestions?
I usually do this by placing a breakpoint in the Qt code that prints the warning. For that, you need to have a Qt with debug symbols.
Searching for "Binding loop detected" in the Qt sources gives me QQmlAbstractBinding::printBindingLoopError(). Placing a breakpoint there will usually lead to a backtrace that gives a clear picture of the situation.
Update: David Edmundson has developed a little tool that displays a QML-only backtrace on binding loops, see his blog here. Under the hood is does exactly what is described here, only that it is nicely automated and wrapped in a Python script.
Example:
Rectangle {
id: parent
width: child.width + 1
height: child.height + 1
Rectangle {
id: child
anchors.fill: parent
}
}
Backtrace:
1 QQmlAbstractBinding::printBindingLoopError qqmlabstractbinding.cpp 178 0x7ffff6eb36da
2 QQmlBinding::update qqmlbinding.cpp 221 0x7ffff6eb9abe
3 QQmlBinding::update qqmlbinding_p.h 97 0x7ffff6eba354
4 QQmlBinding::expressionChanged qqmlbinding.cpp 260 0x7ffff6eb9e68
5 QQmlJavaScriptExpressionGuard_callback qqmljavascriptexpression.cpp 361 0x7ffff6eb223e
6 QQmlNotifier::emitNotify qqmlnotifier.cpp 94 0x7ffff6e9087a
7 QQmlData::signalEmitted qqmlengine.cpp 763 0x7ffff6e19a45
8 QMetaObject::activate qobject.cpp 3599 0x7ffff683655e
9 QMetaObject::activate qobject.cpp 3578 0x7ffff6836364
10 QQuickItem::widthChanged moc_qquickitem.cpp 1104 0x7ffff7a7ba49
11 QQuickItem::geometryChanged qquickitem.cpp 3533 0x7ffff7a6e9cd
12 QQuickItem::setSize qquickitem.cpp 6389 0x7ffff7a75f35
13 QQuickAnchorsPrivate::setItemSize qquickanchors.cpp 400 0x7ffff7a60d94
14 QQuickAnchorsPrivate::fillChanged qquickanchors.cpp 177 0x7ffff7a5fe0e
15 QQuickAnchorsPrivate::itemGeometryChanged qquickanchors.cpp 441 0x7ffff7a6106f
16 QQuickItem::geometryChanged qquickitem.cpp 3523 0x7ffff7a6e96c
17 QQuickItem::setWidth qquickitem.cpp 6091 0x7ffff7a74c1d
18 QQuickItem::qt_static_metacall moc_qquickitem.cpp 874 0x7ffff7a7b0dc
19 QQuickItem::qt_metacall moc_qquickitem.cpp 946 0x7ffff7a7b4d8
20 QQuickRectangle::qt_metacall moc_qquickrectangle_p.cpp 610 0x7ffff7c189c2
21 QMetaObject::metacall qmetaobject.cpp 296 0x7ffff680118b
22 QQmlPropertyPrivate::writeBinding qqmlproperty.cpp 1512 0x7ffff6e33ec3
23 QQmlBinding::update qqmlbinding.cpp 199 0x7ffff6eb992a
24 QQmlBinding::update qqmlbinding_p.h 97 0x7ffff6eba354
25 QQmlBinding::expressionChanged qqmlbinding.cpp 260 0x7ffff6eb9e68
26 QQmlJavaScriptExpressionGuard_callback qqmljavascriptexpression.cpp 361 0x7ffff6eb223e
27 QQmlNotifier::emitNotify qqmlnotifier.cpp 94 0x7ffff6e9087a
28 QQmlData::signalEmitted qqmlengine.cpp 763 0x7ffff6e19a45
29 QMetaObject::activate qobject.cpp 3599 0x7ffff683655e
30 QMetaObject::activate qobject.cpp 3578 0x7ffff6836364
31 QQuickItem::widthChanged moc_qquickitem.cpp 1104 0x7ffff7a7ba49
32 QQuickItem::geometryChanged qquickitem.cpp 3533 0x7ffff7a6e9cd
33 QQuickItem::setSize qquickitem.cpp 6389 0x7ffff7a75f35
34 QQuickAnchorsPrivate::setItemSize qquickanchors.cpp 400 0x7ffff7a60d94
35 QQuickAnchorsPrivate::fillChanged qquickanchors.cpp 177 0x7ffff7a5fe0e
36 QQuickAnchorsPrivate::update qquickanchors.cpp 431 0x7ffff7a60fc6
37 QQuickAnchorsPrivate::updateOnComplete qquickanchors.cpp 425 0x7ffff7a60f93
38 QQuickItem::componentComplete qquickitem.cpp 4593 0x7ffff7a70944
39 QQmlObjectCreator::finalize qqmlobjectcreator.cpp 1207 0x7ffff6ecab66
40 QQmlComponentPrivate::complete qqmlcomponent.cpp 928 0x7ffff6e38609
41 QQmlComponentPrivate::completeCreate qqmlcomponent.cpp 964 0x7ffff6e386ee
42 QQmlComponent::completeCreate qqmlcomponent.cpp 957 0x7ffff6e386a0
43 QQmlComponent::create qqmlcomponent.cpp 791 0x7ffff6e37edd
44 QQuickView::continueExecute qquickview.cpp 476 0x7ffff7b720d4
45 QQuickViewPrivate::execute qquickview.cpp 124 0x7ffff7b7101f
46 QQuickView::setSource qquickview.cpp 253 0x7ffff7b71426
47 main main.cpp 24 0x4033e4
In the backtrace, one can see that the anchors.fill anchor for the child item is calculated when loading the file (frame 35, 36). That causes the child item's width to change (frame 31), which causes a binding update (frame 25) for a binding on the "width" property (frame 17) on the parent item. That in turn forces a recalculation of the child anchors (frame 14), which changes the child's width (frame 10), which updates a binding (frame 4). That is the same binding that was already being updated in frame 25, hence a binding loop exists. One can see that the this pointer in frame 25 and frame 4 are the same, i.e. the same binding is updated recursively.
Thanks much for the receipt however it did not help me. In case somebody will need it, adding another possible solution. I was getting binding loops in ListView trying to set all items width and list width to item max value:
ListView {
implicitWidth: contentItem.childrenRect.width
delegate: listItem
}
Item {
id: listItem
width: Math.max(internalWidth, listView.implicitWidth)
}
Binding loop error appeared on items count update but not every time - only on some batch binding updates, while the is no actual binding loop. Was able to solve the issue by moving binding expression to Binding QML Type and adding delayed property to it:
Item { // Item causing binding loop
Binding on item_property_causing_loop {
value: <binding_expression>
when: <when_expression> // Optional however could also help
delayed: true // Prevent intermediary values from being assigned
}
}
So in my case it is:
Item { // Item causing binding loop
id: listItem
Binding on width {
value: Math.max(internalWidth, listView.implicitWidth)
when: index >= 0 // Optional however could also help
delayed: true // Prevent intermediary values from being assigned
}
}
I am using font icons (web fonts) generated from Fontello. Downloaded pack includes SVG file.
Example. I generated fontello pack consisting of only 1 icon (mail-1)
It looks as below:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2015 by original authors # fontello.com</metadata>
<defs>
<font id="fontello" horiz-adv-x="1000">
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="mail-1" unicode="" d="m929 11v428q-18-20-39-37-149-114-238-188-28-24-46-38t-48-27-57-13h-2q-26 0-57 13t-48 27-46 38q-88 74-238 188-21 17-39 37v-428q0-8 6-13t12-5h822q7 0 12 5t6 13z m0 586v14t-1 7-1 7-3 5-5 4-8 2h-822q-7 0-12-6t-6-12q0-94 82-159 108-85 224-177 4-2 20-16t25-21 25-18 28-15 24-5h2q11 0 24 5t28 15 25 18 25 21 20 16q116 92 224 177 30 24 56 65t26 73z m71 21v-607q0-37-26-63t-63-27h-822q-36 0-63 27t-26 63v607q0 37 26 63t63 26h822q37 0 63-26t26-63z" horiz-adv-x="1000" />
</font>
</defs>
</svg>
I need to use this icon in CSS as background-image, thanks to similar code:
.icon {
background: url('data:image/svg+xml; ... ');
}
...I read about it on https://css-tricks.com/using-svg/...
But I do not know how can I generate this data:image/svg+xml code from my SVG (Fontello) code. Of course I pasted this SVG code as it is in background: url('data:image/svg+xml;... but it does not work...
help!
I create a svg file with a path from the glyph with the following steps.
First, go to the config.json and locate the character.
It should be something like:
{
"uid": "91d1768d00bc3e6ee51c2fcea9810679",
"css": "my-address",
"code": 57514,
"src": "custom_icons",
"selected": true,
"svg": {
"path": "M994.5 17.7C988.8 11.8 980 10.1 972.5 13.6L11.3 454.7C3.6 458.3-0.9 466.5 0.2 474.9S7.8 490 16.2 491.4L447.3 563.7 496.6 971.1C497.7 979.6 504.1 986.4 512.6 987.9 513.7 988.1 514.8 988.2 515.8 988.2 523.1 988.2 529.9 984.1 533.2 977.4L998 39.8C1001.6 32.4 1000.2 23.6 994.5 17.7Z",
"width": 1000
},
"search": [
"myaddress-icon"
]
}
Copy its path value and insert it into the path of a svg like this one (set the width and height value of the svg as the width value in the config):
<svg width="1000" height="1000" xmlns="http://www.w3.org/2000/svg">
<path d="M994.5 17.7C988.8 11.8 980 10.1 972.5 13.6L11.3 454.7C3.6 458.3-0.9 466.5 0.2 474.9S7.8 490 16.2 491.4L447.3 563.7 496.6 971.1C497.7 979.6 504.1 986.4 512.6 987.9 513.7 988.1 514.8 988.2 515.8 988.2 523.1 988.2 529.9 984.1 533.2 977.4L998 39.8C1001.6 32.4 1000.2 23.6 994.5 17.7Z"/>
</svg>
and save it as a .svg file.
Lastly, you can open it with an image editor (I use inkscape) and adjust the vectorial image to the viewbox.
And you can use it as a background.
Just convert the image <glyph> to a <path>.
Remove all glyph attributes like unicode.
add transform and scale to actually showing the element at a decent size
You can play around with the size of the icon width transform='scale()' on the path element.
I chose to use 200px as its size (approximately)
Then you can just use it inside the url();
.svgback {
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><path transform='scale(0.2) translate(0 200)' d='m929 11v428q-18-20-39-37-149-114-238-188-28-24-46-38t-48-27-57-13h-2q-26 0-57 13t-48 27-46 38q-88 74-238 188-21 17-39 37v-428q0-8 6-13t12-5h822q7 0 12 5t6 13z m0 586v14t-1 7-1 7-3 5-5 4-8 2h-822q-7 0-12-6t-6-12q0-94 82-159 108-85 224-177 4-2 20-16t25-21 25-18 28-15 24-5h2q11 0 24 5t28 15 25 18 25 21 20 16q116 92 224 177 30 24 56 65t26 73z m71 21v-607q0-37-26-63t-63-27h-822q-36 0-63 27t-26 63v607q0 37 26 63t63 26h822q37 0 63-26t26-63z'/></svg>");
width: 200px;
height: 200px;
}
<div class="svgback"></div>
<!-- Image data -->
<!--svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2015 by original authors # fontello.com</metadata>
<path transform='scale(0.2) translate(0 200)' d="m929 11v428q-18-20-39-37-149-114-238-188-28-24-46-38t-48-27-57-13h-2q-26 0-57 13t-48 27-46 38q-88 74-238 188-21 17-39 37v-428q0-8 6-13t12-5h822q7 0 12 5t6 13z m0 586v14t-1 7-1 7-3 5-5 4-8 2h-822q-7 0-12-6t-6-12q0-94 82-159 108-85 224-177 4-2 20-16t25-21 25-18 28-15 24-5h2q11 0 24 5t28 15 25 18 25 21 20 16q116 92 224 177 30 24 56 65t26 73z m71 21v-607q0-37-26-63t-63-27h-822q-36 0-63 27t-26 63v607q0 37 26 63t63 26h822q37 0 63-26t26-63z"
/>
</svg-->
I'm pretty new in statistics:
fisher = function(idxToTest, idxATI){
idxDependent=c()
dependent=c()
p = c()
for(i in c(1:length(idxToTest)))
{
tbl = table(data[[idxToTest[i]]], data[[idxATI]])
rez = fisher.test(tbl, workspace = 20000000000)
if(rez$p.value<0.1){
dependent=c(dependent, TRUE)
if(rez$p.value<0.1){
idxDependent = c(idxDependent, idxToTest[i])
}
}
else{
dependent = c(dependent, FALSE)
}
p = c(p, rez$p.value)
}
}
This is the function I use. It seems to work.
What I understood until now is that I have to pass as first parameter data like:
Men Women
Dieting 10 30
Non-dieting 5 60
My data comes from a CSV:
data = read.csv('***.csv', header = TRUE, sep=',');
My first problem is that I don't know how to converse from:
Loan.Purpose Home.Ownership
lp_value_1 ho_value_2
lp_value_1 ho_value_2
lp_value_2 ho_value_1
lp_value_3 ho_value_2
lp_value_2 ho_value_3
lp_value_4 ho_value_2
lp_value_3 ho_value_3
to:
ho_value_1 ho_value_2 ho_value_3
lp_value1 0 2 0
lp_value2 1 0 1
lp_value3 0 1 1
lp_value4 0 1 0
The second issue is that I don't know what the second parameter should be
POST UPDATE: This is what I get using fisher.test(myTable):
Error in fisher.test(test) : FEXACT error 501.
The hash table key cannot be computed because the largest key
is larger than the largest representable int.
The algorithm cannot proceed.
Reduce the workspace size or use another algorithm.
where myTable is:
MORTGAGE NONE OTHER OWN RENT
car 18 0 0 5 27
credit_card 190 0 2 38 214
debt_consolidation 620 0 2 87 598
educational 5 0 0 3 7
...
Basically, fisher tests only work on smallish data sets because they require alot of memory. But all is good because chi-square tests make minimal additional assumptions and are easier on the computer. Just do:
chisq.test(Loan.Purpose,Home.Ownership)
to get your p-values.
Make sure you read through and understand the help page for chisq.test, especially the examples at the bottom.
http://stat.ethz.ch/R-manual/R-patched/library/stats/html/chisq.test.html
Then look at a mosaicplot to see the quantities like:
mosaicplot(Loan.Purpose,Home.Ownership)
this reference explains how mosaicplots work.
http://alumni.media.mit.edu/~tpminka/courses/36-350.2001/lectures/day12/