CBC solver Result - Linear relaxation infeasible - coin-or-cbc

I am trying to solve an LP problem with the CBC solver in Linux.
When I try t solve it, the model is determined linearly infeasible but a solution is found, so I don't understand why this is happening.
This is the solver output:
Welcome to the CBC MILP Solver
Version: 2.10.5
Build Date: Oct 15 2020
command line - cbc tt2.lp solve printing csv solu sol.txt (default strategy 1)
Presolve determined that the problem was infeasible with tolerance of 1e-08
Analysis indicates model infeasible or unbounded
Perturbing problem by 0.001% of 6368.0221 - largest nonzero change 9.6555471e-05 ( 8.8302642e-05%) - largest zero change 6.095558e-05
0 Obj 0 Primal inf 1303.3614 (30) Dual inf 6484.7494 (8)
0 Obj 0 Primal inf 1303.3614 (30) Dual inf 1.437715e+13 (28)
36 Obj -16980 Primal inf 105.38866 (21) Dual inf 7.2658581e+12 (14) w.o. free dual inf (13)
58 Obj -16046.434 Primal inf 0.28949488 (2)
Primal infeasible - objective value -16046.434
PrimalInfeasible objective -16046.43383 - 58 iterations time 0.002
Result - Linear relaxation infeasible
Enumerated nodes: 0
Total iterations: 0
Time (CPU seconds): 0.01
Time (Wallclock Seconds): 0.02
Option for printingOptions changed from normal to csv
Total time (CPU seconds): 0.01 (Wallclock seconds): 0.03
I turned off preprocessing to see if it made any changes but it didn't.
Welcome to the CBC MILP Solver
Version: 2.10.5
Build Date: Oct 15 2020
command line - cbc tt2.lp preprocess off passp 0 solve printing csv solu sol.txt (default strategy 1)
Option for preprocess changed from sos to off
passPresolve was changed from 5 to 0
Perturbing problem by 0.001% of 6368.0221 - largest nonzero change 9.6555471e-05 ( 8.8302642e-05%) - largest zero change 6.095558e-05
0 Obj 0 Primal inf 1303.3614 (30) Dual inf 6484.7494 (8)
0 Obj 0 Primal inf 1303.3614 (30) Dual inf 1.437715e+13 (28)
36 Obj -16980 Primal inf 105.38866 (21) Dual inf 7.2658581e+12 (14) w.o. free dual inf (13)
58 Obj -16046.434 Primal inf 0.28949488 (2)
Primal infeasible - objective value -16046.434
PrimalInfeasible objective -16046.43383 - 58 iterations time 0.002
Result - Linear relaxation infeasible
Enumerated nodes: 0
Total iterations: 0
Time (CPU seconds): 0.00
Time (Wallclock Seconds): 0.02
Option for printingOptions changed from normal to csv
Total time (CPU seconds): 0.00 (Wallclock seconds): 0.03
So the problem is that the Linear Relaxation of the LP problem is infeasible, but I don't know what this means or how to solve it.
This is the LP file in case it helps.
Minimize
1.0 cv_1_1 - 1.0 w_1_1 + 2.0 cv_2_1 - 2.0 w_2_1 + 4.0 cv_1_2 - 4.0 w_1_2 + 8.0 cv_2_2 - 8.0 w_2_2 + 9.0 cv_1_3 - 9.0 w_1_3 + 18.0 cv_2_3 - 18.0 w_2_3 + 16.0 cv_1_4 - 16.0 w_1_4 + 32.0 cv_2_4 - 32.0 w_2_4 + 1 dmv_2_1 + 1 dmv_2_2
Subject To
\Manipulated variables: initial value
R0: mv_1_0 = 150
R1: mv_2_0 = 150
\States: initial value
R2: x_1_0 = 0.03534155
R3: x_2_0 = 0.07947994
R4: x_3_0 = -0.00548606
R5: x_4_0 = -0.28400902
\Manipulated variables: change variables
R6: dmv_1_1 - mv_1_1 + mv_1_0 = 0
R7: dmv_1_2 - mv_1_2 + mv_1_1 = 0
R8: dmv_1_3 - mv_1_3 + mv_1_2 = 0
R9: dmv_1_4 - mv_1_4 + mv_1_3 = 0
R10: dmv_2_1 - mv_2_1 + mv_2_0 = 0
R11: dmv_2_2 - mv_2_2 + mv_2_1 = 0
R12: dmv_2_3 - mv_2_3 + mv_2_2 = 0
R13: dmv_2_4 - mv_2_4 + mv_2_3 = 0
\Controlled variables: upper and lower bounds
R14: cv_1_1 >= 45
R15: cv_1_1 <= 65
R16: cv_1_2 >= 45
R17: cv_1_2 <= 65
R18: cv_1_3 >= 45
R19: cv_1_3 <= 65
R20: cv_1_4 >= 45
R21: cv_1_4 <= 65
R22: cv_2_1 >= 5
R23: cv_2_1 <= 11
R24: cv_2_2 >= 5
R25: cv_2_2 <= 11
R26: cv_2_3 >= 5
R27: cv_2_3 <= 11
R28: cv_2_4 >= 5
R29: cv_2_4 <= 11
\Manipulated variables: ratio change allowed
R30: dmv_1_1 <= 1
R31: dmv_1_1 >= -1
R32: dmv_1_2 <= 1
R33: dmv_1_2 >= -1
R34: dmv_1_3 <= 0.0
R35: dmv_1_3 >= -0.0
R36: dmv_1_4 <= 0.0
R37: dmv_1_4 >= -0.0
R38: dmv_2_1 <= 1
R39: dmv_2_1 >= -1
R40: dmv_2_2 <= 1
R41: dmv_2_2 >= -1
R42: dmv_2_3 <= 0.0
R43: dmv_2_3 >= -0.0
R44: dmv_2_4 <= 0.0
R45: dmv_2_4 >= -0.0
\Manipulated variables: upper and lower bounds
R46: mv_1_1 >= 140
R47: mv_1_1 <= 170
R48: mv_1_2 >= 140
R49: mv_1_2 <= 170
R50: mv_1_3 >= 140
R51: mv_1_3 <= 170
R52: mv_1_4 >= 140
R53: mv_1_4 <= 170
R54: mv_2_1 >= 130
R55: mv_2_1 <= 150
R56: mv_2_2 >= 130
R57: mv_2_2 <= 150
R58: mv_2_3 >= 130
R59: mv_2_3 <= 150
R60: mv_2_4 >= 130
R61: mv_2_4 <= 150
\W: reference trajectories for controlled variables
R62: w_1_1 = 10.0
R63: w_1_2 = 40.0
R64: w_1_3 = 90.0
R65: w_1_4 = 160.0
R66: w_2_1 = 20.0
R67: w_2_2 = 80.0
R68: w_2_3 = 180.0
R69: w_2_4 = 320.0
\Model
\X(t+1) - Gx(t) - Hmv(t) = 0
\cv(t) - Cx(t) = 0
R70: x_1_2 - 1.001 x_1_1 + 0.0001777 x_2_1 + 0.02923 x_3_1 + 0.001065 x_4_1 - 5.049e-06 mv_1_1 + 8.92e-06 mv_2_1 = 0
R71: x_2_2 - 0.001961 x_1_1 - 0.9536 x_2_1 - 0.009859 x_3_1 + 0.08002 x_4_1 - 9.27e-06 mv_1_1 + 0.0001443 mv_2_1 = 0
R72: x_3_2 - 0.02647 x_1_1 + 0.006174 x_2_1 - 0.9386 x_3_1 + 0.07591 x_4_1 - 5.375e-05 mv_1_1 + 0.000216 mv_2_1 = 0
R73: x_4_2 + 0.001008 x_1_1 - 0.2273 x_2_1 - 0.04935 x_3_1 - 0.6928 x_4_1 - 0.000377 mv_1_1 + 0.001151 mv_2_1 = 0
R74: cv_1_1 - 1408.0 x_1_1 + 10.67 x_2_1 + 19.4 x_3_1 - 0.6612 x_4_1 = 0
R75: cv_2_1 - 4.282 x_1_1 - 77.07 x_2_1 - 0.1379 x_3_1 + 2.884 x_4_1 = 0
R76: x_1_3 - 1.001 x_1_2 + 0.0001777 x_2_2 + 0.02923 x_3_2 + 0.001065 x_4_2 - 5.049e-06 mv_1_2 + 8.92e-06 mv_2_2 = 0
R77: x_2_3 - 0.001961 x_1_2 - 0.9536 x_2_2 - 0.009859 x_3_2 + 0.08002 x_4_2 - 9.27e-06 mv_1_2 + 0.0001443 mv_2_2 = 0
R78: x_3_3 - 0.02647 x_1_2 + 0.006174 x_2_2 - 0.9386 x_3_2 + 0.07591 x_4_2 - 5.375e-05 mv_1_2 + 0.000216 mv_2_2 = 0
R79: x_4_3 + 0.001008 x_1_2 - 0.2273 x_2_2 - 0.04935 x_3_2 - 0.6928 x_4_2 - 0.000377 mv_1_2 + 0.001151 mv_2_2 = 0
R80: cv_1_2 - 1408.0 x_1_2 + 10.67 x_2_2 + 19.4 x_3_2 - 0.6612 x_4_2 = 0
R81: cv_2_2 - 4.282 x_1_2 - 77.07 x_2_2 - 0.1379 x_3_2 + 2.884 x_4_2 = 0
R82: x_1_4 - 1.001 x_1_3 + 0.0001777 x_2_3 + 0.02923 x_3_3 + 0.001065 x_4_3 - 5.049e-06 mv_1_3 + 8.92e-06 mv_2_3 = 0
R83: x_2_4 - 0.001961 x_1_3 - 0.9536 x_2_3 - 0.009859 x_3_3 + 0.08002 x_4_3 - 9.27e-06 mv_1_3 + 0.0001443 mv_2_3 = 0
R84: x_3_4 - 0.02647 x_1_3 + 0.006174 x_2_3 - 0.9386 x_3_3 + 0.07591 x_4_3 - 5.375e-05 mv_1_3 + 0.000216 mv_2_3 = 0
R85: x_4_4 + 0.001008 x_1_3 - 0.2273 x_2_3 - 0.04935 x_3_3 - 0.6928 x_4_3 - 0.000377 mv_1_3 + 0.001151 mv_2_3 = 0
R86: cv_1_3 - 1408.0 x_1_3 + 10.67 x_2_3 + 19.4 x_3_3 - 0.6612 x_4_3 = 0
R87: cv_2_3 - 4.282 x_1_3 - 77.07 x_2_3 - 0.1379 x_3_3 + 2.884 x_4_3 = 0
R88: x_1_5 - 1.001 x_1_4 + 0.0001777 x_2_4 + 0.02923 x_3_4 + 0.001065 x_4_4 - 5.049e-06 mv_1_4 + 8.92e-06 mv_2_4 = 0
R89: x_2_5 - 0.001961 x_1_4 - 0.9536 x_2_4 - 0.009859 x_3_4 + 0.08002 x_4_4 - 9.27e-06 mv_1_4 + 0.0001443 mv_2_4 = 0
R90: x_3_5 - 0.02647 x_1_4 + 0.006174 x_2_4 - 0.9386 x_3_4 + 0.07591 x_4_4 - 5.375e-05 mv_1_4 + 0.000216 mv_2_4 = 0
R91: x_4_5 + 0.001008 x_1_4 - 0.2273 x_2_4 - 0.04935 x_3_4 - 0.6928 x_4_4 - 0.000377 mv_1_4 + 0.001151 mv_2_4 = 0
R92: cv_1_4 - 1408.0 x_1_4 + 10.67 x_2_4 + 19.4 x_3_4 - 0.6612 x_4_4 = 0
R93: cv_2_4 - 4.282 x_1_4 - 77.07 x_2_4 - 0.1379 x_3_4 + 2.884 x_4_4 = 0
Bounds
\States: upper and lower bounds
x_1_1 free
x_1_2 free
x_1_3 free
x_1_4 free
x_1_5 free
x_2_1 free
x_2_2 free
x_2_3 free
x_2_4 free
x_2_5 free
x_3_1 free
x_3_2 free
x_3_3 free
x_3_4 free
x_3_5 free
x_4_1 free
x_4_2 free
x_4_3 free
x_4_4 free
x_4_5 free
End

Disclaimer: I somewhat despise those txt-based serialization-formats and this means, that i'm not an expert because i don't use them often.
My guess:
Variables are by default non-negative
Lower-bound: 0.0
Upper-bound: positive infinity
This is a very common design-decision in various solvers and in regards to the LP-file i guess it might be true too (?).
(A quick glimpse through Gurobi, CPLEX, FICO commercial solvers make me think all of those apply this logic -> CoinOR Clp/Cbc probably does the same)
A:
Let's take some other solver and run your file:
infeasible
says: R4: x_3_0 = -0.00548606 is not okay (there might be other source of infeasibility)
B:
Your lp-file contains:
Bounds
\States: upper and lower bounds
x_1_1 free
...
Free variables are [-infinity, +infinity] variables -> not non-negative
Seeing those explicitly here somewhat indicates a potential default as we guess above
C:
x_3_0 does not appear in free-vars
x_3_0 is probably in [0, +infinity)
Obviously incompatible with R4: x_3_0 = -0.00548606
And it's such a simple deduction, that presolving recognizes that

I meet the same error info, and I solve this problem just by increasing the var bound. For example, (0, 1000) -> (0, 10000).

Related

Plot secondary x_axis in ggplot

Dear All seniors and members,
Hope you are doing great. I have data set, which I like to plot the secondary x-axis in ggplot. I could not make it to work for the last 4 hours. below is my dataset.
Pathway ES NES p_value q_value Group
1 HALLMARK_HYPOXIA 0.49 2.25 0.000 0.000 Top
2 HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION 0.44 2.00 0.000 0.000 Top
3 HALLMARK_UV_RESPONSE_DN 0.45 1.98 0.000 0.000 Top
4 HALLMARK_TGF_BETA_SIGNALING 0.48 1.77 0.003 0.004 Top
5 HALLMARK_HEDGEHOG_SIGNALING 0.52 1.76 0.003 0.003 Top
6 HALLMARK_ESTROGEN_RESPONSE_EARLY 0.38 1.73 0.000 0.004 Top
7 HALLMARK_KRAS_SIGNALING_DN 0.37 1.69 0.000 0.005 Top
8 HALLMARK_INTERFERON_ALPHA_RESPONSE 0.37 1.54 0.009 0.021 Top
9 HALLMARK_TNFA_SIGNALING_VIA_NFKB 0.32 1.45 0.005 0.048 Top
10 HALLMARK_NOTCH_SIGNALING 0.42 1.42 0.070 0.059 Top
11 HALLMARK_COAGULATION 0.32 1.39 0.031 0.067 Top
12 HALLMARK_MITOTIC_SPINDLE 0.30 1.37 0.025 0.078 Top
13 HALLMARK_ANGIOGENESIS 0.40 1.37 0.088 0.074 Top
14 HALLMARK_WNT_BETA_CATENIN_SIGNALING 0.35 1.23 0.173 0.216 Top
15 HALLMARK_OXIDATIVE_PHOSPHORYLATION -0.65 -3.43 0.000 0.000 Bottom
16 HALLMARK_MYC_TARGETS_V1 -0.49 -2.56 0.000 0.000 Bottom
17 HALLMARK_E2F_TARGETS -0.45 -2.37 0.000 0.000 Bottom
18 HALLMARK_DNA_REPAIR -0.46 -2.33 0.000 0.000 Bottom
19 HALLMARK_ADIPOGENESIS -0.42 -2.26 0.000 0.000 Bottom
20 HALLMARK_FATTY_ACID_METABOLISM -0.41 -2.06 0.000 0.000 Bottom
21 HALLMARK_PEROXISOME -0.43 -2.01 0.000 0.000 Bottom
22 HALLMARK_MYC_TARGETS_V2 -0.43 -1.84 0.003 0.001 Bottom
23 HALLMARK_CHOLESTEROL_HOMEOSTASIS -0.42 -1.83 0.003 0.001 Bottom
24 HALLMARK_ALLOGRAFT_REJECTION -0.34 -1.78 0.000 0.003 Bottom
25 HALLMARK_MTORC1_SIGNALING -0.32 -1.67 0.000 0.004 Bottom
26 HALLMARK_P53_PATHWAY -0.29 -1.52 0.000 0.015 Bottom
27 HALLMARK_UV_RESPONSE_UP -0.28 -1.41 0.013 0.036 Bottom
28 HALLMARK_REACTIVE_OXYGEN_SPECIES_PATHWAY -0.35 -1.39 0.057 0.040 Bottom
29 HALLMARK_HEME_METABOLISM -0.26 -1.34 0.014 0.061 Bottom
30 HALLMARK_G2M_CHECKPOINT -0.23 -1.20 0.080 0.172 Bottom
I like to plot like the following plot (plot # 1)
Here is my current codes chunks.
ggplot(data, aes(reorder(Pathway, NES), NES, fill= Group)) +
theme_classic() + geom_col() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, size = 8),
axis.title = element_text(face = "bold", size = 12),
axis.text = element_text(face = "bold", size = 8), plot.title = element_text(hjust = 0.5)) + labs(x="Pathway", y="Normalized Enrichment Score",
title="2Gy_5f vs. 0Gy") + coord_flip()
This code produces the following plot (plot # 2)
So I would like to generate the plot where I have secondary x-axis with q_value (same like the first bar plot I have attached). Any help is greatly appreciated. Note: I used coord_flip so it turn angle of x-axis.
Kind Regards,
synat
[1]: https://i.stack.imgur.com/dBFIS.jpg
[2]: https://i.stack.imgur.com/yDbC5.jpg
Maybe you don't need a secondary axis per se to get the plot style you seek.
library(tidyverse)
ggplot(data, aes(x = NES, y = reorder(Pathway, NES), fill= Group)) +
theme_classic() +
geom_col() +
geom_text(aes(x = 2.5, y = reorder(Pathway, NES), label = q_value), hjust = 0) +
annotate("text", x = 2.5, y = length(data$Pathway) + 1, hjust = 0, fontface = "bold", label = "q_value" ) +
coord_cartesian(xlim = c(NA, 3),
ylim = c(NA, length(data$Pathway) + 1),
clip = "off") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, size = 8),
axis.title = element_text(face = "bold", size = 12),
axis.text = element_text(face = "bold", size = 8),
plot.title = element_text(hjust = 0.5)) +
labs(x="Pathway", y="Normalized Enrichment Score",
title="2Gy_5f vs. 0Gy")
And for future reference you can read in data in the format you pasted like so:
data <- read_table(
"
Pathway ES NES p_value q_value Group
HALLMARK_HYPOXIA 0.49 2.25 0.000 0.000 Top
HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION 0.44 2.00 0.000 0.000 Top
HALLMARK_UV_RESPONSE_DN 0.45 1.98 0.000 0.000 Top
HALLMARK_TGF_BETA_SIGNALING 0.48 1.77 0.003 0.004 Top
HALLMARK_HEDGEHOG_SIGNALING 0.52 1.76 0.003 0.003 Top
HALLMARK_ESTROGEN_RESPONSE_EARLY 0.38 1.73 0.000 0.004 Top
HALLMARK_KRAS_SIGNALING_DN 0.37 1.69 0.000 0.005 Top
HALLMARK_INTERFERON_ALPHA_RESPONSE 0.37 1.54 0.009 0.021 Top
HALLMARK_TNFA_SIGNALING_VIA_NFKB 0.32 1.45 0.005 0.048 Top
HALLMARK_NOTCH_SIGNALING 0.42 1.42 0.070 0.059 Top
HALLMARK_COAGULATION 0.32 1.39 0.031 0.067 Top
HALLMARK_MITOTIC_SPINDLE 0.30 1.37 0.025 0.078 Top
HALLMARK_ANGIOGENESIS 0.40 1.37 0.088 0.074 Top
HALLMARK_WNT_BETA_CATENIN_SIGNALING 0.35 1.23 0.173 0.216 Top
HALLMARK_OXIDATIVE_PHOSPHORYLATION -0.65 -3.43 0.000 0.000 Bottom
HALLMARK_MYC_TARGETS_V1 -0.49 -2.56 0.000 0.000 Bottom
HALLMARK_E2F_TARGETS -0.45 -2.37 0.000 0.000 Bottom
HALLMARK_DNA_REPAIR -0.46 -2.33 0.000 0.000 Bottom
HALLMARK_ADIPOGENESIS -0.42 -2.26 0.000 0.000 Bottom
HALLMARK_FATTY_ACID_METABOLISM -0.41 -2.06 0.000 0.000 Bottom
HALLMARK_PEROXISOME -0.43 -2.01 0.000 0.000 Bottom
HALLMARK_MYC_TARGETS_V2 -0.43 -1.84 0.003 0.001 Bottom
HALLMARK_CHOLESTEROL_HOMEOSTASIS -0.42 -1.83 0.003 0.001 Bottom
HALLMARK_ALLOGRAFT_REJECTION -0.34 -1.78 0.000 0.003 Bottom
HALLMARK_MTORC1_SIGNALING -0.32 -1.67 0.000 0.004 Bottom
HALLMARK_P53_PATHWAY -0.29 -1.52 0.000 0.015 Bottom
HALLMARK_UV_RESPONSE_UP -0.28 -1.41 0.013 0.036 Bottom
HALLMARK_REACTIVE_OXYGEN_SPECIES_PATHWAY -0.35 -1.39 0.057 0.040 Bottom
HALLMARK_HEME_METABOLISM -0.26 -1.34 0.014 0.061 Bottom
HALLMARK_G2M_CHECKPOINT -0.23 -1.20 0.080 0.172 Bottom")
Created on 2021-11-23 by the reprex package (v2.0.1)

create multi-indexed dataframe

I do not know how to create a multi-indexed df (that has unequal number of 2nd-indices). here is a sample:
data = [{'caterpillar': [('Сatérpillar',
{'fuzz': 0.82,
'levenshtein': 0.98,
'jaro_winkler': 0.9192,
'hamming': 0.98}),
('caterpiⅼⅼaʀ',
{'fuzz': 0.73,
'levenshtein': 0.97,
'jaro_winkler': 0.9114,
'hamming': 0.97}),
('cÂteԻpillÂr',
{'fuzz': 0.73,
'levenshtein': 0.97,
'jaro_winkler': 0.881,
'hamming': 0.97})]},
{'elementis': [('elEmENtis',
{'fuzz': 1.0, 'levenshtein': 1.0, 'jaro_winkler': 1.0, 'hamming': 1.0}),
('ÊlemĚntis',
{'fuzz': 0.78,
'levenshtein': 0.98,
'jaro_winkler': 0.863,
'hamming': 0.98}),
('еlÈmÈntis',
{'fuzz': 0.67,
'levenshtein': 0.97,
'jaro_winkler': 0.8333,
'hamming': 0.97})]},
{'gibson': [('giBᏚon',
{'fuzz': 0.83,
'levenshtein': 0.99,
'jaro_winkler': 0.9319,
'hamming': 0.99}),
('ɡibsoN',
{'fuzz': 0.83,
'levenshtein': 0.99,
'jaro_winkler': 0.9206,
'hamming': 0.99}),
('giЬႽon',
{'fuzz': 0.67,
'levenshtein': 0.98,
'jaro_winkler': 0.84,
'hamming': 0.98}),
('glbsՕn',
{'fuzz': 0.67,
'levenshtein': 0.98,
'jaro_winkler': 0.8333,
'hamming': 0.98})]}]
I want a df like this (note: 'Other Name' has differing number of values for each 'Orig Name':
Orig Name| Other Name| fuzz| levenstein| Jaro-Winkler| Hamming
------------------------------------------------------------------------
caterpillar Сatérpillar 0.82 0.98. 0.9192 0.98
caterpiⅼⅼaʀ 0.73 0.97 0.9114 0.97
cÂteԻpillÂr 0.73 0.97 0.881 0.97
gibson giBᏚon 0.83. 0.99 0.9319 0.99
ɡibsoN 0.83 0.99. 0.9206 0.99
giЬႽon 0.67. 0.98 0.84 0.98
glbsՕn 0.67. 0.98. 0.8333 0.98
elementis .........
--------------------------------------------------------------------------
I tried :
orig_name_list = [x for d in data for x, v in d.items()]
value_list = [v for d in data for x, v in d.items()]
other_names = [tup[0] for tup_list in value_list for tup in tup_list]
algos = ['fuzz', 'levenshtein', 'jaro_winkler', 'hamming']
Not sure how to proceed from there. Suggestions are appreciated.
Let's try concat:
pd.concat([pd.DataFrame([x[1]]).assign(OrigName=k, OtherName=x[0])
for df in data for k,d in df.items() for x in d])
Output:
fuzz levenshtein jaro_winkler hamming OrigName OtherName
0 0.82 0.98 0.9192 0.98 caterpillar Сatérpillar
0 0.73 0.97 0.9114 0.97 caterpillar caterpiⅼⅼaʀ
0 0.73 0.97 0.8810 0.97 caterpillar cÂteԻpillÂr
0 1.00 1.00 1.0000 1.00 elementis elEmENtis
0 0.78 0.98 0.8630 0.98 elementis ÊlemĚntis
0 0.67 0.97 0.8333 0.97 elementis еlÈmÈntis
0 0.83 0.99 0.9319 0.99 gibson giBᏚon
0 0.83 0.99 0.9206 0.99 gibson ɡibsoN
0 0.67 0.98 0.8400 0.98 gibson giЬႽon
0 0.67 0.98 0.8333 0.98 gibson glbsՕn
One way to do this is to reformat your data for json record consumption via the pd.json_normalize function. Your json is currently not formatted correctly to be stored into a dataframe easily:
new_data = []
for entry in data:
new_entry = {}
for name, matches in entry.items():
new_entry["name"] = name
new_entry["matches"] = []
for match in matches:
match[1]["match"] = match[0]
new_entry["matches"].append(match[1])
new_data.append(new_entry)
df = pd.json_normalize(new_data, "matches", ["name"]).set_index(["name", "match"])
print(df)
fuzz levenshtein jaro_winkler hamming
name match
caterpillar Сatérpillar 0.82 0.98 0.9192 0.98
caterpiⅼⅼaʀ 0.73 0.97 0.9114 0.97
cÂteԻpillÂr 0.73 0.97 0.8810 0.97
elementis elEmENtis 1.00 1.00 1.0000 1.00
ÊlemĚntis 0.78 0.98 0.8630 0.98
еlÈmÈntis 0.67 0.97 0.8333 0.97
gibson giBᏚon 0.83 0.99 0.9319 0.99
ɡibsoN 0.83 0.99 0.9206 0.99
giЬႽon 0.67 0.98 0.8400 0.98
glbsՕn 0.67 0.98 0.8333 0.98

Why are the limits of the histogram data autodetected as [nan, nan] instead of discarding NaNs?

The following code generates an error
print(g['resp'])
par = {'hist': True, 'kde': False, 'fit': scipy.stats.norm, 'bins': 'auto'}
sns.distplot(g['resp'], color='blue', **par)
31 23.0
32 28.0
33 29.0
34 31.0
35 32.0
36 35.0
37 35.0
38 36.0
39 37.0
40 38.0
41 38.0
42 38.0
43 41.0
44 42.0
45 42.0
46 42.0
47 42.0
48 46.0
49 48.0
50 49.0
51 50.0
52 52.0
53 55.0
54 56.0
55 60.0
56 60.0
57 100.0
58 NaN
59 NaN
60 NaN
61 NaN
Name: resp, dtype: float64
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-23-42944bf1e405> in <module>
1 print(g['resp'])
2 par = {'hist': True, 'kde': False, 'fit': scipy.stats.norm, 'bins': 'auto'}
----> 3 sns.distplot(g['resp'], color='blue', **par)
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py in distplot(a, bins, hist, kde, rug, fit, hist_kws, kde_kws, rug_kws, fit_kws, color, vertical, norm_hist, axlabel, label, ax)
223 hist_color = hist_kws.pop("color", color)
224 ax.hist(a, bins, orientation=orientation,
--> 225 color=hist_color, **hist_kws)
226 if hist_color != color:
227 hist_kws["color"] = hist_color
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1808 "the Matplotlib list!)" % (label_namer, func.__name__),
1809 RuntimeWarning, stacklevel=2)
-> 1810 return func(ax, *args, **kwargs)
1811
1812 inner.__doc__ = _add_data_doc(inner.__doc__,
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, **kwargs)
6589 # this will automatically overwrite bins,
6590 # so that each histogram uses the same bins
-> 6591 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
6592 m = m.astype(float) # causes problems later if it's an int
6593 if mlast is None:
C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\histograms.py in histogram(a, bins, range, normed, weights, density)
708 a, weights = _ravel_and_check_weights(a, weights)
709
--> 710 bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
711
712 # Histogram is an integer or a float array depending on the weights.
C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\histograms.py in _get_bin_edges(a, bins, range, weights)
331 "bins is not supported for weighted data")
332
--> 333 first_edge, last_edge = _get_outer_edges(a, range)
334
335 # truncate the range if needed
C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\histograms.py in _get_outer_edges(a, range)
259 if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
260 raise ValueError(
--> 261 "autodetected range of [{}, {}] is not finite".format(first_edge, last_edge))
262
263 # expand empty range to avoid divide by zero
ValueError: autodetected range of [nan, nan] is not finite
It looks like the NaN values are causing trouble - how to discard them?
I think not, so possible solution is Series.dropna for remove missing values:
sns.distplot(g['resp'].dropna(), color='blue', **par)

NSString sizeWithAttributes Crash on iOS 12

I recently encountered a strange Crash when using a lyrics component. Language is Objective-C. This stupid crash has been bothering me for many days...
Here's the code:
CGFloat charWidth = [character.character sizeWithAttributes:#{NSFontAttributeName:displayFont}].width;
and my crash log stack:
0 CoreText 0x0000000234f09938 __ZNK12TSplicedFont23GetOpticalSizeComponentEd + 148
1 CoreText 0x0000000234e7ffcc __ZL28DerivedOpticalFontDescriptorPK18__CTFontDescriptorPK9TBaseFontd + 120
2 CoreText 0x0000000234e88008 __ZN12TFontCascade26InitCascadeFallbackAtIndexElRj + 252
3 CoreText 0x0000000234e87a70 __ZNK12TFontCascade14CreateFallbackEPK8__CTFontPK10__CFString13CTEmojiPolicy + 728
4 CoreText 0x0000000234e54e40 __ZN13TGlyphEncoder21AppendUnmappedCharRunEjR6TCFRefIP5CTRunEPK8__CTFontR7CFRangeS8_R10TGlyphListI18TDeletedGlyphIndexESD_RK12TFontCascadeNS_15ClusterMatchingEb + 704
5 CoreText 0x0000000234e54900 __ZN13TGlyphEncoder28RunUnicodeEncoderRecursivelyEjO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexESC_PK12TFontCascadeNS_15ClusterMatchingEb + 1900
6 CoreText 0x0000000234e54114 __ZN13TGlyphEncoder17RunUnicodeEncoderEO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexEPK12TFontCascade + 128
7 CoreText 0x0000000234e53c30 __ZN13TGlyphEncoder11EncodeCharsE7CFRangeRK11TAttributesNS_9FallbacksE + 1240
8 CoreText 0x0000000234e6acb0 __ZN21TTypesetterAttrString10InitializeEPK20__CFAttributedString + 304
9 CoreText 0x0000000234e6ab6c __ZN21TTypesetterAttrStringC2EPK20__CFAttributedStringPK14__CFDictionary + 200
10 CoreText 0x0000000234e58070 CTLineCreateWithAttributedString + 60
11 UIFoundation 0x000000023b72be2c -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:context:forceClipping:styledTextOptions:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 1344
12 UIFoundation 0x000000023b7aae38 ___NSStringDrawingEngine + 3104
13 UIFoundation 0x000000023b72eb04 -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] + 160
14 UIFoundation 0x000000023b7307dc -[NSString(NSStringDrawing) sizeWithAttributes:] + 120
I have fix this issue. this method must called in main thread – JethroYe

Crash in CFNetwork on iOS 11

Facing the following crash recently on iOS11. Any known crash in iOS11 ?
Thread 13 crashed:
# 1 0x0000000185e5da70 in TubeManager::_onqueue_newTubeReady(Tube*, CFStreamError) + 992 (CFNetwork + 0x00000000000d6a70) 0x0000000000000000
# 2 0x0000000185e5da70 in TubeManager::_onqueue_newTubeReady(Tube*, CFStreamError) + 992 (CFNetwork + 0x00000000000d6a70) 0x0000000000000000
# 3 0x0000000185e5d438 in invocation function for block in TubeManager::requestNewTube(BaseAwaitingTube*, void (Tube*) block_pointer) + 28 (CFNetwork + 0x00000000000d6438) 0x000000016fe2e5e0
# 4 0x0000000185e8e2f4 in Tube::_onqueue_invokeCB(CFStreamError) + 160 (CFNetwork + 0x00000000001072f4) 0x000000016fe2e600
# 5 0x0000000185e8d04c in Tube::_onqueue_errorHandler(CFStreamError) + 148 (CFNetwork + 0x000000000010604c) 0x000000016fe2e630
# 6 0x0000000185e8e978 in Tube::connectionEstablished(CFStreamError) + 408 (CFNetwork + 0x0000000000107978) 0x000000016fe2e660
# 7 0x0000000185182a4c in _dispatch_call_block_and_release + 16 (libdispatch.dylib + 0x0000000000001a4c) 0x000000016fe2e6a0
# 8 0x0000000185182a0c in _dispatch_client_callout + 8 (libdispatch.dylib + 0x0000000000001a0c) 0x000000016fe2e6c0
# 9 0x000000018518c964 in _dispatch_queue_serial_drain$VARIANT$mp + 520 (libdispatch.dylib + 0x000000000000b964) 0x000000016fe2e6e0
# 10 0x000000018518d2f4 in _dispatch_queue_invoke$VARIANT$mp + 332 (libdispatch.dylib + 0x000000000000c2f4) 0x000000016fe2e780
# 11 0x000000018518c81c in _dispatch_queue_serial_drain$VARIANT$mp + 192 (libdispatch.dylib + 0x000000000000b81c) 0x000000016fe2e810
# 12 0x000000018518d2f4 in _dispatch_queue_invoke$VARIANT$mp + 332 (libdispatch.dylib + 0x000000000000c2f4) 0x000000016fe2e8b0
# 13 0x000000018518dd18 in _dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 396 (libdispatch.dylib + 0x000000000000cd18) 0x000000016fe2e940
# 14 0x0000000185196034 in _dispatch_workloop_worker_thread$VARIANT$mp + 636 (libdispatch.dylib + 0x0000000000015034) 0x000000016fe2e9c0
# 15 0x000000018542af14 in _pthread_wqthread + 924 (libsystem_pthread.dylib + 0x0000000000000f14) 0x000000016fe2ea40
# 16 0x000000018542ab64 in pthread_workqueue_addthreads_np + 120 (libsystem_pthread.dylib + 0x0000000000000b64) 0x000000016fe2eae0