text:
from numpy import array
def case14():
	ppc = {"version": '2'}
	ppc["baseMVA"] = 100.0
	ppc["bus"] = array([
		[1.0,    3.0, 0.0,      0.0,      0.0,    0.0,    1.0, 1.06,     0.0,      0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[2.0,    2.0, 21.7,     12.7,     0.0,    0.0,    1.0, 1.045,    -4.98,    0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[3.0,    2.0, 94.2,     19.0,     0.0,    0.0,    1.0, 1.01,     -12.72,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[4.0,    1.0, 47.8,     -3.9,     0.0,    0.0,    1.0, 1.019,    -10.33,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[5.0,    1.0, 7.6,      1.6,      0.0,    0.0,    1.0, 1.02,     -8.78,    0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[6.0,    2.0, 11.2,     7.5,      0.0,    0.0,    1.0, 1.07,     -14.22,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[7.0,    1.0, 0.0,      0.0,      0.0,    0.0,    1.0, 1.062,    -13.37,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[8.0,    2.0, 0.0,      0.0,      0.0,    0.0,    1.0, 1.09,     -13.36,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[9.0,    1.0, 29.5,     16.6,     0.0,    19.0,   1.0, 1.056,    -14.94,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[10.0,   1.0, 9.0,      5.8,      0.0,    0.0,    1.0, 1.051,    -15.1,    0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[11.0,   1.0, 3.5,      1.8,      0.0,    0.0,    1.0, 1.057,    -14.79,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[12.0,   1.0, 6.1,      1.6,      0.0,    0.0,    1.0, 1.055,    -15.07,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[13.0,   1.0, 13.5,     5.8,      0.0,    0.0,    1.0, 1.05,     -15.16,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ],
		[14.0,   1.0, 14.9,     5.0,      0.0,    0.0,    1.0, 1.036,    -16.04,   0.0,      1.0, 1.06,     0.94,     0.6, 10   ]
	])
	ppc["gen"] = array([
		[1.0,    232.4,    -16.9,    10.0,     0.0,      1.06,     100.0,  1.0, 332.4,    0.0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99.72,    132.96    ],
		[2.0,    40.0,     42.4,     50.0,     -40.0,    1.045,    100.0,  1.0, 140.0,    0.0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42.0,     56.0      ],
		[3.0,    0.0,      23.4,     40.0,     0.0,      1.01,     100.0,  1.0, 100.0,    0.0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30.0,     40.0      ],
		[6.0,    0.0,      12.2,     24.0,     -6.0,     1.07,     100.0,  1.0, 100.0,    0.0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30.0,     40.0      ],
		[8.0,    0.0,      17.4,     24.0,     -6.0,     1.09,     100.0,  1.0, 100.0,    0.0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30.0,     40.0      ]
	])
	ppc["branch"] = array([
		[1.0,    2.0,    0.01938,       0.05917,       0.0528,        9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[1.0,    5.0,    0.05403,       0.22304,       0.0492,        9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[2.0,    3.0,    0.04699,       0.19797,       0.0438,        9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[2.0,    4.0,    0.05811,       0.17632,       0.034,         9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[2.0,    5.0,    0.05695,       0.17388,       0.0346,        9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[3.0,    4.0,    0.06701,       0.17103,       0.0128,        9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[4.0,    5.0,    0.01335,       0.04211,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[4.0,    7.0,    0.0,           0.20912,       0.0,           9900.0, 0.0,0.0,0.978,  0.0,1.0,-360.0, 360.0,  0.1     ],
		[4.0,    9.0,    0.0,           0.55618,       0.0,           9900.0, 0.0,0.0,0.969,  0.0,1.0,-360.0, 360.0,  0.1     ],
		[5.0,    6.0,    0.0,           0.25202,       0.0,           9900.0, 0.0,0.0,0.932,  0.0,1.0,-360.0, 360.0,  0.1     ],
		[6.0,    11.0,   0.09498,       0.1989,        0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[6.0,    12.0,   0.12291,       0.25581,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[6.0,    13.0,   0.06615,       0.13027,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[7.0,    8.0,    0.0,           0.17615,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[7.0,    9.0,    0.0,           0.11001,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[9.0,    10.0,   0.03181,       0.0845,        0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[9.0,    14.0,   0.12711,       0.27038,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[10.0,   11.0,   0.08205,       0.19207,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[12.0,   13.0,   0.22092,       0.19988,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ],
		[13.0,   14.0,   0.17093,       0.34802,       0.0,           9900.0, 0.0,0.0,0.0,    0.0,1.0,-360.0, 360.0,  0.1     ]
	])
	ppc["gencost"] = array([
		[2.0, 0.0, 0.0, 3.0, 0.0430293,20.0,   0.0,    24.0,   12.0    ],
		[2.0, 0.0, 0.0, 3.0, 0.25,20.0,   0.0,    24.0,   12.0    ],
		[2.0, 0.0, 0.0, 3.0, 0.01,40.0,   0.0,    48.0,   24.0    ],
		[2.0, 0.0, 0.0, 3.0, 0.01,40.0,   0.0,    48.0,   24.0    ],
		[2.0, 0.0, 0.0, 3.0, 0.01,40.0,   0.0,    48.0,   24.0    ]
	])
	ppc["contingency"] = array([
		{'gen': [0], 'branch': [], 'p': 0.001} ,
		{'gen': [1], 'branch': [], 'p': 0.001} ,
		{'gen': [2], 'branch': [], 'p': 0.001} ,
		{'gen': [3], 'branch': [], 'p': 0.001} ,
		{'gen': [4], 'branch': [], 'p': 0.001} ,
		{'gen': [], 'branch': [0], 'p': 0.001} ,
		{'gen': [], 'branch': [1], 'p': 0.001} ,
		{'gen': [], 'branch': [2], 'p': 0.001} ,
		{'gen': [], 'branch': [3], 'p': 0.001} ,
		{'gen': [], 'branch': [4], 'p': 0.001} ,
		{'gen': [], 'branch': [5], 'p': 0.001} ,
		{'gen': [], 'branch': [6], 'p': 0.001} ,
		{'gen': [], 'branch': [7], 'p': 0.001} ,
		{'gen': [], 'branch': [8], 'p': 0.001} ,
		{'gen': [], 'branch': [9], 'p': 0.001} ,
		{'gen': [], 'branch': [10], 'p': 0.001} ,
		{'gen': [], 'branch': [11], 'p': 0.001} ,
		{'gen': [], 'branch': [12], 'p': 0.001} ,
		{'gen': [], 'branch': [13], 'p': 0.001} ,
		{'gen': [], 'branch': [14], 'p': 0.001} ,
		{'gen': [], 'branch': [15], 'p': 0.001} ,
		{'gen': [], 'branch': [16], 'p': 0.001} ,
		{'gen': [], 'branch': [17], 'p': 0.001} ,
		{'gen': [], 'branch': [18], 'p': 0.001} ,
		{'gen': [], 'branch': [19], 'p': 0.001} ,
		{'gen': [0, 1], 'branch': [], 'p': 1e-05} ,
		{'gen': [0, 2], 'branch': [], 'p': 1e-05} ,
		{'gen': [0, 3], 'branch': [], 'p': 1e-05} ,
		{'gen': [0, 4], 'branch': [], 'p': 1e-05} ,
		{'gen': [1, 2], 'branch': [], 'p': 1e-05} ,
		{'gen': [1, 3], 'branch': [], 'p': 1e-05} ,
		{'gen': [1, 4], 'branch': [], 'p': 1e-05} ,
		{'gen': [2, 3], 'branch': [], 'p': 1e-05} ,
		{'gen': [2, 4], 'branch': [], 'p': 1e-05} ,
		{'gen': [3, 4], 'branch': [], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 1], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 2], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 3], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 4], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 5], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [0, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 2], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 3], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 4], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 5], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [1, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 3], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 4], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 5], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [2, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 4], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 5], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [3, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 5], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [4, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 6], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [5, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 7], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [6, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 8], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [7, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 9], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [8, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 10], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [9, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 11], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [10, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 12], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [11, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 13], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [12, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 14], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [13, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [14, 15], 'p': 1e-05} ,
		{'gen': [], 'branch': [14, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [14, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [14, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [14, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [15, 16], 'p': 1e-05} ,
		{'gen': [], 'branch': [15, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [15, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [15, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [16, 17], 'p': 1e-05} ,
		{'gen': [], 'branch': [16, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [16, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [17, 18], 'p': 1e-05} ,
		{'gen': [], 'branch': [17, 19], 'p': 1e-05} ,
		{'gen': [], 'branch': [18, 19], 'p': 1e-05} ,
		{'gen': [0], 'branch': [0], 'p': 1e-05} ,
		{'gen': [0], 'branch': [1], 'p': 1e-05} ,
		{'gen': [0], 'branch': [2], 'p': 1e-05} ,
		{'gen': [0], 'branch': [3], 'p': 1e-05} ,
		{'gen': [0], 'branch': [4], 'p': 1e-05} ,
		{'gen': [0], 'branch': [5], 'p': 1e-05} ,
		{'gen': [0], 'branch': [6], 'p': 1e-05} ,
		{'gen': [0], 'branch': [7], 'p': 1e-05} ,
		{'gen': [0], 'branch': [8], 'p': 1e-05} ,
		{'gen': [0], 'branch': [9], 'p': 1e-05} ,
		{'gen': [0], 'branch': [10], 'p': 1e-05} ,
		{'gen': [0], 'branch': [11], 'p': 1e-05} ,
		{'gen': [0], 'branch': [12], 'p': 1e-05} ,
		{'gen': [0], 'branch': [13], 'p': 1e-05} ,
		{'gen': [0], 'branch': [14], 'p': 1e-05} ,
		{'gen': [0], 'branch': [15], 'p': 1e-05} ,
		{'gen': [0], 'branch': [16], 'p': 1e-05} ,
		{'gen': [0], 'branch': [17], 'p': 1e-05} ,
		{'gen': [0], 'branch': [18], 'p': 1e-05} ,
		{'gen': [0], 'branch': [19], 'p': 1e-05} ,
		{'gen': [1], 'branch': [0], 'p': 1e-05} ,
		{'gen': [1], 'branch': [1], 'p': 1e-05} ,
		{'gen': [1], 'branch': [2], 'p': 1e-05} ,
		{'gen': [1], 'branch': [3], 'p': 1e-05} ,
		{'gen': [1], 'branch': [4], 'p': 1e-05} ,
		{'gen': [1], 'branch': [5], 'p': 1e-05} ,
		{'gen': [1], 'branch': [6], 'p': 1e-05} ,
		{'gen': [1], 'branch': [7], 'p': 1e-05} ,
		{'gen': [1], 'branch': [8], 'p': 1e-05} ,
		{'gen': [1], 'branch': [9], 'p': 1e-05} ,
		{'gen': [1], 'branch': [10], 'p': 1e-05} ,
		{'gen': [1], 'branch': [11], 'p': 1e-05} ,
		{'gen': [1], 'branch': [12], 'p': 1e-05} ,
		{'gen': [1], 'branch': [13], 'p': 1e-05} ,
		{'gen': [1], 'branch': [14], 'p': 1e-05} ,
		{'gen': [1], 'branch': [15], 'p': 1e-05} ,
		{'gen': [1], 'branch': [16], 'p': 1e-05} ,
		{'gen': [1], 'branch': [17], 'p': 1e-05} ,
		{'gen': [1], 'branch': [18], 'p': 1e-05} ,
		{'gen': [1], 'branch': [19], 'p': 1e-05} ,
		{'gen': [2], 'branch': [0], 'p': 1e-05} ,
		{'gen': [2], 'branch': [1], 'p': 1e-05} ,
		{'gen': [2], 'branch': [2], 'p': 1e-05} ,
		{'gen': [2], 'branch': [3], 'p': 1e-05} ,
		{'gen': [2], 'branch': [4], 'p': 1e-05} ,
		{'gen': [2], 'branch': [5], 'p': 1e-05} ,
		{'gen': [2], 'branch': [6], 'p': 1e-05} ,
		{'gen': [2], 'branch': [7], 'p': 1e-05} ,
		{'gen': [2], 'branch': [8], 'p': 1e-05} ,
		{'gen': [2], 'branch': [9], 'p': 1e-05} ,
		{'gen': [2], 'branch': [10], 'p': 1e-05} ,
		{'gen': [2], 'branch': [11], 'p': 1e-05} ,
		{'gen': [2], 'branch': [12], 'p': 1e-05} ,
		{'gen': [2], 'branch': [13], 'p': 1e-05} ,
		{'gen': [2], 'branch': [14], 'p': 1e-05} ,
		{'gen': [2], 'branch': [15], 'p': 1e-05} ,
		{'gen': [2], 'branch': [16], 'p': 1e-05} ,
		{'gen': [2], 'branch': [17], 'p': 1e-05} ,
		{'gen': [2], 'branch': [18], 'p': 1e-05} ,
		{'gen': [2], 'branch': [19], 'p': 1e-05} ,
		{'gen': [3], 'branch': [0], 'p': 1e-05} ,
		{'gen': [3], 'branch': [1], 'p': 1e-05} ,
		{'gen': [3], 'branch': [2], 'p': 1e-05} ,
		{'gen': [3], 'branch': [3], 'p': 1e-05} ,
		{'gen': [3], 'branch': [4], 'p': 1e-05} ,
		{'gen': [3], 'branch': [5], 'p': 1e-05} ,
		{'gen': [3], 'branch': [6], 'p': 1e-05} ,
		{'gen': [3], 'branch': [7], 'p': 1e-05} ,
		{'gen': [3], 'branch': [8], 'p': 1e-05} ,
		{'gen': [3], 'branch': [9], 'p': 1e-05} ,
		{'gen': [3], 'branch': [10], 'p': 1e-05} ,
		{'gen': [3], 'branch': [11], 'p': 1e-05} ,
		{'gen': [3], 'branch': [12], 'p': 1e-05} ,
		{'gen': [3], 'branch': [13], 'p': 1e-05} ,
		{'gen': [3], 'branch': [14], 'p': 1e-05} ,
		{'gen': [3], 'branch': [15], 'p': 1e-05} ,
		{'gen': [3], 'branch': [16], 'p': 1e-05} ,
		{'gen': [3], 'branch': [17], 'p': 1e-05} ,
		{'gen': [3], 'branch': [18], 'p': 1e-05} ,
		{'gen': [3], 'branch': [19], 'p': 1e-05} ,
		{'gen': [4], 'branch': [0], 'p': 1e-05} ,
		{'gen': [4], 'branch': [1], 'p': 1e-05} ,
		{'gen': [4], 'branch': [2], 'p': 1e-05} ,
		{'gen': [4], 'branch': [3], 'p': 1e-05} ,
		{'gen': [4], 'branch': [4], 'p': 1e-05} ,
		{'gen': [4], 'branch': [5], 'p': 1e-05} ,
		{'gen': [4], 'branch': [6], 'p': 1e-05} ,
		{'gen': [4], 'branch': [7], 'p': 1e-05} ,
		{'gen': [4], 'branch': [8], 'p': 1e-05} ,
		{'gen': [4], 'branch': [9], 'p': 1e-05} ,
		{'gen': [4], 'branch': [10], 'p': 1e-05} ,
		{'gen': [4], 'branch': [11], 'p': 1e-05} ,
		{'gen': [4], 'branch': [12], 'p': 1e-05} ,
		{'gen': [4], 'branch': [13], 'p': 1e-05} ,
		{'gen': [4], 'branch': [14], 'p': 1e-05} ,
		{'gen': [4], 'branch': [15], 'p': 1e-05} ,
		{'gen': [4], 'branch': [16], 'p': 1e-05} ,
		{'gen': [4], 'branch': [17], 'p': 1e-05} ,
		{'gen': [4], 'branch': [18], 'p': 1e-05} ,
		{'gen': [4], 'branch': [19], 'p': 1e-05}
	])
	return ppc

max_stars_repo_name: thanever/SOC

max_issues_repo_name: thanever/SOC

max_forks_repo_name: thanever/SOC

reason: from numpy


text:
import os

import tensorflow as tf
from scipy.ndimage.filters import maximum_filter
from sklearn import linear_model
from tensorpack import dataflow
from tensorpack.dataflow.base import RNGDataFlow

import map_utils as mu
from angle_utils import *
from map_utils import decode_image

try:
    import ipdb as pdb
except Exception:
    import pdb

num_directions = 4

def raw_images_to_array(images):
    """
    Decode and normalize multiple images from tfrecord data
    :param images: list of images encoded as a png in a string
    :return: a numpy array of size (N, 56, 56, channels), normalized for training
    """
    image_list = []
    for image_str in images:
        image = decode_image(image_str, (56, 56))
        image = scale_observation(np.atleast_3d(image.astype(np.float32)))
        image = remove_depth_noise(image)
        image_list.append(image)

    return np.stack(image_list, axis=0)

def scale_observation(x):
    """
    Normalizes observation input, either an rgb image or a depth image
    :param x: observation input as numpy array, either an rgb image or a depth image
    :return: numpy array, a normalized observation
    """
    if x.ndim == 2 or x.shape[2] == 1:  # Depth
        return x  # Depth is not scaled.
    else:  # RGB
        return x * (2.0 / 255.0) - 1.0

def bounding_box(img):
    """
    Bounding box of non-zeros in an array (inclusive). Used with 2D maps
    :param img: numpy array
    :return: inclusive bounding box indices: top_row, bottom_row, leftmost_column, rightmost_column
    """
    # helper function to
    rows = np.any(img, axis=1)
    cols = np.any(img, axis=0)
    rmin, rmax = np.where(rows)[0][[0, -1]]
    cmin, cmax = np.where(cols)[0][[0, -1]]

    return rmin, rmax, cmin, cmax

class BatchDataWithPad(dataflow.BatchData):
    """
    Stacks datapoints into batches. Selected elements can be padded to the same size in each batch.
    """

    def __init__(self, ds, batch_size, remainder=False, use_list=False, padded_indices=()):
        """
        :param ds: input dataflow. Same as BatchData
        :param batch_size: mini batch size. Same as BatchData
        :param remainder: if data is not enough to form a full batch, it makes a smaller batch when true.
        Same as BatchData.
        :param use_list: if True, components will contain a list of datapoints instead of creating a new numpy array.
        Same as BatchData.
        :param padded_indices: list of filed indices for which all elements will be padded with zeros to mach
        the largest in the batch. Each batch may produce a different size datapoint.
        """
        super(BatchDataWithPad, self).__init__(ds, batch_size, remainder, use_list)
        self.padded_indices = padded_indices

    def get_data(self):
        """
        Yields:  Batched data by stacking each component on an extra 0th dimension.
        """
        holder = []
        for data in self.ds.get_data():
            holder.append(data)
            if len(holder) == self.batch_size:
                yield BatchDataWithPad._aggregate_batch(holder, self.use_list, self.padded_indices)
                del holder[:]
        if self.remainder and len(holder) > 0:
            yield BatchDataWithPad._aggregate_batch(holder, self.use_list, self.padded_indices)

    @staticmethod
    def _aggregate_batch(data_holder, use_list=False, padded_indices=()):
        """
        Re-implement the parent function with the option to pad selected fields to the largest in the batch.
        """
        assert not use_list  # cannot match shape if they must be treated as lists
        size = len(data_holder[0])
        result = []
        for k in range(size):
            dt = data_holder[0][k]
            if type(dt) in [int, bool]:
                tp = 'int32'
            elif type(dt) == float:
                tp = 'float32'
            else:
                try:
                    tp = dt.dtype
                except AttributeError:
                    raise TypeError("Unsupported type to batch: {}".format(type(dt)))
            try:
                if k in padded_indices:
                    # pad this field
                    shapes = np.array([x[k].shape for x in data_holder], 'i')  # assumes ndim are the same for all
                    assert shapes.shape[1] == 3  # only supports 3D arrays for now, e.g. images (height, width, ch)
                    matching_shape = shapes.max(axis=0).tolist()
                    new_data = np.zeros([shapes.shape[0]] + matching_shape, dtype=tp)
                    for i in range(len(data_holder)):
                        shape = data_holder[i][k].shape
                        new_data[i, :shape[0], :shape[1], :shape[2]] = data_holder[i][k]
                    result.append(new_data)
                else:
                    # no need to pad this field, simply create batch
                    result.append(np.asarray([x[k] for x in data_holder], dtype=tp))
            except Exception as e:
                # exception handling. same as in parent class
                print(e.message)
                pdb.set_trace()
                dataflow.logger.exception("Cannot batch data. Perhaps they are of inconsistent shape?")
                if isinstance(dt, np.ndarray):
                    s = dataflow.pprint.pformat([x[k].shape for x in data_holder])
                    dataflow.logger.error("Shape of all arrays to be batched: " + s)
                try:
                    # open an ipython shell if possible
                    import IPython as IP;
                    IP.embed()  # noqa
                except ImportError:
                    pass
        return result

def camera_angles(width):
    """
    Generate `width' (typically 56) angles for each column of a camera image.
    """
    focal_len = width / (2.0 * np.tan(np.deg2rad(60.0) / 2.0))
    dist = np.arange(width) + 0.5 - width / 2.0
    angles = np.arctan2(dist, focal_len)
    return angles

def distances_from_depth_image(depth):
    """
    Given a depth image, perform a simulated laser scan to get the distances.
    There's some heuristic processing.
    :param depth: (height, width)
    :return: distances of each column of depth image
    """
    invalid_val = 255
    depth_to_grid = 3.9
    height, width = depth.shape

    focal_len = width / (2.0 * np.tan(np.deg2rad(60.0) / 2.0))
    dist = np.arange(width) + 0.5 - width / 2.0

    percentile = 80
    dists = np.array([])
    for i in range(height):
        col = np.copy(depth[:, i])

        # Invalid indices
        inv_indices = np.where(col == invalid_val)[0]
        if len(inv_indices) > 0:
            inv_last = inv_indices[-1]
            inv_bool = inv_last == col.shape[0] - 1  # Bottom of image is 255

            if not inv_bool:
                ys = col[inv_last + 1:inv_last + 9]
                diffs = np.abs(np.diff(ys))
                inv_bool = np.sum(np.greater(diffs, 4).astype(np.int32))
                inv_bool = ys[0] >= 100 and inv_bool >= 2  # Roughly detect a window

            if inv_bool:
                d = 0
                dists = np.append(dists, d)
                continue

        # Process remaining values
        indices = np.where((col < invalid_val) & (col > 0))[0]
        d = 0
        if len(indices):
            d = depth_to_grid * np.percentile(col[indices], percentile)
        dists = np.append(dists, d)

    dists_ths = np.max(dists) * 0.2
    dists[dists < dists_ths] = 0.
    dists = np.sqrt(np.square(dists * dist / focal_len) + np.square(dists))
    return dists

def filter_points_from_depth_image(depth):
    """
    Given a depth image, there are 4 angles to rotate its filter so that the resulting edges align
    with the map. Compute the angles and relative coordinates of the points.
    :param depth: (H, W) image
    :return angles (4,)
    points on wall (4, 56, 2)
    """
    # Compute a RANSAC regression for points on the depth image to give the direction of one edge
    height, width = depth.shape
    dists = distances_from_depth_image(depth)

    assert len(dists) == width
    _camera_angles = camera_angles(width)
    px = np.multiply(dists, np.sin(_camera_angles))
    py = np.multiply(dists, np.cos(_camera_angles))

    ransac = linear_model.RANSACRegressor(residual_threshold=5.)
    eps = .1
    px = px[dists > eps]  # Need to filter out the zero values
    py = py[dists > eps]
    if len(px) > 1:
        ransac.fit(px.reshape(-1, 1), py.reshape(-1, 1))
        y = ransac.predict([[1], [2]])
        angle = normalize_rad(np.arctan(y[1][0] - y[0][0]))
    else:
        angle = 0

    # Produce outputs
    rotated_angles = rotation_rads(angle)
    rotated_angles = np.asarray(np.sort(rotated_angles))

    points_wall = list()
    for angle in rotated_angles:
        angles = [normalize_rad(a + angle + np.pi / 2.) for a in _camera_angles]
        angles_sin = np.sin(angles)
        angles_cos = np.cos(angles)

        px = np.expand_dims(np.multiply(dists, angles_sin), axis=-1)
        py = -np.expand_dims(np.multiply(dists, angles_cos), axis=-1)
        ps = np.concatenate([px, py], axis=-1)
        points_wall.append(ps)

    points_wall = np.asarray(points_wall)
    return rotated_angles, points_wall

def remove_depth_noise(depth):
    """
    Remove noise in depth image using a simple maximum filter.
    :param depth: (K, size, size, 1)
    """
    output = maximum_filter(depth, footprint=np.ones((3, 3, 1)))
    return output

class House3DFilterData(RNGDataFlow):
    """
    Process tfrecords data of House3D trajectories. Produces a dataflow with the following fields:
    true state, global map, observations
    """

    def __init__(self, files, mapmode, obsmode, trajlen, num_particles, init_particles_distr,
                 init_particles_cov, seed=None):
        """
        :param files: list of data file names. assumed to be tfrecords files
        :param mapmode: string, map type. Possible values: wall / wall-door / wall-roomtype / wall-door-roomtype
        :param obsmode: string, observation type. Possible values: rgb / depth / rgb-depth. Vrf is not yet supported
        :param trajlen: int, length of trajectories
        :param seed: int or None. Random seed will be fixed if not None.
        """
        self.files = files
        self.mapmode = mapmode
        self.obsmode = obsmode
        self.trajlen = trajlen
        self.seed = seed
        self.num_particles = num_particles
        self.init_particles_distr = init_particles_distr
        self.init_particles_cov = init_particles_cov

        # Count total number of trajectories
        count = 0
        for f in self.files:
            if not os.path.isfile(f):
                raise ValueError('Failed to find file: ' + f)
            record_iterator = tf.python_io.tf_record_iterator(f)
            for _ in record_iterator:
                count += 1
        self.count = count

    def size(self):
        return self.count

    def reset_state(self):
        """ Reset state. Fix numpy random seed if needed."""
        super(House3DFilterData, self).reset_state()
        np.random.seed(self.seed)

    def get_data(self):
        """
        Yields datapoints, all numpy arrays, with the following fields.
        :return true states: (trajlen, 3). Second dimension corresponds to x, y, theta coordinates.
        :return global map: (n, m, ch). shape is different for each map. number of channels depend on the mapmode setting
        :return observations: (trajlen, 56, 56, ch) number of channels depend on the obsmode setting
        """
        for file in self.files:
            gen = tf.python_io.tf_record_iterator(file)
            for data_i, string_record in enumerate(gen):
                result = tf.train.Example.FromString(string_record)
                features = result.features.feature

                # Process maps
                map_wall = self.process_wall_map(features['map_wall'].bytes_list.value[0])
                map_door = self.process_door_map(features['map_door'].bytes_list.value[0])
                map_empty = self.process_empty_map(features['map_roomtype'].bytes_list.value[0])

                # Has been rescaled to 0..1 range. After transform, 1s represent walls.
                # Zero padding will produce the equivalent of empty space
                # map_rooms = self.process_roomtype_map(features['map_roomtype'].bytes_list.value[0])
                global_map_list = [map_wall, map_door]
                global_map = np.concatenate(global_map_list, axis=-1)

                if self.init_particles_distr == 'tracking':
                    map_roomid = None
                elif self.init_particles_distr == 'all-room':
                    map_roomid = map_empty
                else:
                    map_roomid = self.process_roomid_map(features['map_roomid'].bytes_list.value[0])

                map_margin = mu.identify_margin(global_map[:, :, :1])
                map_roomtype = self.process_roomtype_map(features['map_roomtype'].bytes_list.value[0])
                special_map_list = [map_empty, map_margin, map_roomtype]
                special_map = np.concatenate(special_map_list, axis=-1).astype(np.float32)

                # Process true states
                true_states = features['states'].bytes_list.value[0]
                true_states = np.frombuffer(true_states, np.float32).reshape((-1, 3))
                true_states = np.concatenate([true_states[:, :2], normalize_rad(true_states[:, 2:])], axis=-1)

                # Process odometry
                odometry = features['odometry'].bytes_list.value[0]
                odometry = np.frombuffer(odometry, np.float32).reshape((-1, 3))

                # Trajectory may be longer than what we use for training
                data_trajlen = true_states.shape[0]
                assert data_trajlen >= self.trajlen
                true_states = true_states[:self.trajlen]
                odometry = odometry[:self.trajlen]

                # Process observations
                assert self.obsmode == 'depth'
                observation = raw_images_to_array(list(features['depth'].bytes_list.value)[:self.trajlen])

                # generate particle states
                init_particles = self.random_particles(
                    true_states[0], self.init_particles_distr,
                    self.init_particles_cov, self.num_particles,
                    roomidmap=map_roomid, seed=23
                )

                filter_angles = list()
                points = list()
                for i in range(self.trajlen):
                    depth_i = np.squeeze(observation[i], axis=-1)
                    angles_i, points_i = filter_points_from_depth_image(depth_i)
                    filter_angles.append(angles_i)
                    points.append(points_i)

                filter_angles = np.asarray(filter_angles)
                points = np.asarray(points)

                yield (true_states, init_particles, global_map, special_map, observation, odometry,
                       filter_angles, points, (True))

    def process_wall_map(self, map_feature):
        wall_map = np.atleast_3d(decode_image(map_feature))
        wall_map = np.transpose(wall_map, axes=[1, 0, 2])
        wall_map = wall_map.astype(np.float32) * (1.0 / 255.0)
        return wall_map

    def process_door_map(self, map_feature):
        wall_map = np.atleast_3d(decode_image(map_feature))
        wall_map = np.transpose(wall_map, axes=[1, 0, 2])
        wall_map = wall_map.astype(np.float32) * (1.0 / 255.0)
        return wall_map

    def process_empty_map(self, map_feature):
        # In the returned empty map, 1 represents empty space
        empty_map = np.atleast_3d(decode_image(map_feature))
        ones, zeros = np.ones_like(empty_map), np.zeros_like(empty_map)
        empty_map = np.where(np.greater(empty_map, 1), ones, zeros)
        empty_map = np.transpose(empty_map, axes=[1, 0, 2])
        return empty_map

    def process_roomid_map(self, roomidmap_feature):
        # this is not transposed, unlike other maps
        roomidmap = np.atleast_3d(decode_image(roomidmap_feature))
        return roomidmap

    def process_roomtype_map(self, map_feature):
        output = np.atleast_3d(decode_image(map_feature))
        # transpose and invert
        output = np.transpose(output, axes=[1, 0, 2])
        return output

    @staticmethod
    def random_particles(state, distr, particles_cov, num_particles, roomidmap, seed=None):
        """
        Generate a random set of particles
        :param state: true state, numpy array of x,y,theta coordinates
        :param distr: string, type of distribution. Possible values: tracking / one-room.
        For 'identity', simply return k true states as particles.
        For 'tracking' the distribution is a Gaussian centered near the true state.
        For 'one-room' the distribution is uniform over states in the room defined by the true state.
        For 'two-room' the distribution is over states in the same room as the true state as well as another room.
        For 'all-room' the distribution is over all rooms in the given map.
        :param particles_cov: numpy array of shape (3,3), defines the covariance matrix if distr == 'tracking'
        :param num_particles: number of particles
        :param roomidmap: numpy array, map of room ids. Values define a unique room id for each pixel of the map.
        :param seed: int or None. If not None, the random seed will be fixed for generating the particle.
        The random state is restored to its original value.
        :return: numpy array of particles (num_particles, 3)
        """
        assert distr in ['identity', 'tracking', 'localization', 'global',
                         'one-room', 'two-room', 'all-room']

        particles = np.zeros((num_particles, 3), np.float32)
        if distr == 'identity':
            state = np.expand_dims(state, axis=0)
            particles = np.tile(state, [num_particles, 1])
        elif distr == 'tracking':
            if seed is not None:
                random_state = np.random.get_state()
                np.random.seed(seed)

            # Sample offset from the Gaussian
            center = np.random.multivariate_normal(mean=state, cov=particles_cov)

            # Restore random seed
            if seed is not None:
                np.random.set_state(random_state)

            # Sample particles from the Gaussian, centered around the offset
            particles = np.random.multivariate_normal(mean=center, cov=particles_cov, size=num_particles)
        elif distr == 'one-room' or distr == 'localization':
            # Mask the room the initial state is in
            masked_map = (roomidmap == roomidmap[int(np.rint(state[0])), int(np.rint(state[1]))])

            # Get bounding box for more efficient sampling
            rmin, rmax, cmin, cmax = bounding_box(masked_map)

            # Rejection sampling inside bounding box
            sample_i = 0
            while sample_i < num_particles:
                particle = np.random.uniform(low=(rmin, cmin, 0.0), high=(rmax, cmax, 2.0 * np.pi), size=(3,), )
                # Reject if mask is zero
                if not masked_map[int(np.rint(particle[0])), int(np.rint(particle[1]))]:
                    continue
                particles[sample_i] = particle
                sample_i += 1
        elif distr == 'two-room':
            rooms = np.unique(roomidmap)
            room_1 = roomidmap[int(np.rint(state[0])), int(np.rint(state[1]))]
            rooms_invalid = np.logical_or(rooms == 0, rooms == room_1)
            rooms_remain = np.delete(rooms, np.where(rooms_invalid), axis=0)
            room_2 = np.random.choice(rooms_remain) if len(rooms_remain) else room_1
            masked_map = np.logical_or(roomidmap == room_1, roomidmap == room_2)

            rmin, rmax, cmin, cmax = bounding_box(masked_map)

            sample_i = 0
            while sample_i < num_particles:
                particle = np.random.uniform(low=(rmin, cmin, 0.0), high=(rmax, cmax, 2.0 * np.pi), size=(3,), )
                if not masked_map[int(np.rint(particle[0])), int(np.rint(particle[1]))]:
                    continue
                particles[sample_i] = particle
                sample_i += 1
        elif distr == 'all-room' or distr == 'global':
            ys, xs = np.where(roomidmap[:, :, 0] > 0)
            indices = np.arange(len(xs))
            np.random.shuffle(indices)
            indices = indices[:num_particles]

            xs = np.expand_dims(np.take(xs, indices).astype(np.float32), axis=-1)
            ys = np.expand_dims(np.take(ys, indices).astype(np.float32), axis=-1)
            angles = np.random.uniform(low=0, high=2 * np.pi, size=(num_particles, 1))
            particles = np.concatenate([xs, ys, angles], axis=-1)
        else:
            raise ValueError

        return particles

def get_dataflow(files, params):
    """
    Build a tensorflow Dataset from appropriate tfrecords files.
    :param files: list a file paths corresponding to appropriate tfrecords data
    :param params: parsed arguments
    :param is_training: bool, true for training.
    :return: (nextdata, num_samples).
    nextdata: list of tensorflow ops that produce the next input with the following elements:
    true_states, global_map, init_particles, observations, odometries, is_first_step.
    See House3DTrajData.get_data for definitions.
    """
    mapmode = params.mapmode
    obsmode = params.obsmode
    batchsize = params.batchsize
    trajlen = params.trajlen
    num_particles = params.num_particles

    # build initial covariance matrix of particles, in pixels and radians
    particle_std = params.init_particles_std.copy()
    particle_std[0] = particle_std[0] / params.map_pixel_in_meters  # convert meters to pixels
    particle_std2 = np.square(particle_std)  # variance
    init_particles_cov = np.diag(particle_std2[(0, 0, 1),])

    df = House3DFilterData(
        files, mapmode, obsmode, trajlen, num_particles,
        params.init_particles_distr, init_particles_cov,
        seed=params.seed
    )

    df = dataflow.FixedSizeData(df, size=df.size(), keep_state=False)

    df = BatchDataWithPad(df, batchsize, padded_indices=(2, 3))

    num_samples = df.size()

    df.reset_state()

    # # test dataflow
    # df = dataflow.TestDataSpeed(dataflow.PrintData(df), 100)
    # df.start()

    types = [tf.float32, tf.float32, tf.float32, tf.float32, tf.float32, tf.float32, tf.float32, tf.float32, tf.bool]
    sizes = [(batchsize, trajlen, 3),  # True states
             (batchsize, num_particles, 3),  # Initial particles
             (batchsize, None, None, 2),  # Global map: wall, door
             (batchsize, None, None, 3),  # Special maps: empty space map, wall margin map, room type map
             (batchsize, trajlen, 56, 56, 1),  # Depth images, 1 channel
             (batchsize, trajlen, 3),  # Odometry
             (batchsize, trajlen, num_directions),  # Rotation angles
             (batchsize, trajlen, num_directions, 56, 2),  # Points on each wall filter for each direction
             (batchsize,), ]  # is_first_step,

    # turn it into a tf dataset
    def tuplegen():
        for dp in df.get_data():
            yield tuple(dp)

    dataset = tf.data.Dataset.from_generator(tuplegen, tuple(types), tuple(sizes))
    iterator = dataset.make_one_shot_iterator()
    nextdata = iterator.get_next()

    return nextdata, num_samples

ext: py

max_stars_repo_name: suxuann/mgpf

max_issues_repo_name: suxuann/mgpf

max_forks_repo_name: suxuann/mgpf

reason: from scipy


text:
import json

import matplotlib.pyplot as plt
import numpy as np

from zerogercrnn.lib.preprocess import write_json, read_jsons, read_json, extract_jsons_info, JsonExtractor

FILE_TRAINING = 'data/programs_training.json'
FILE_TRAINING_PROCESSED = 'data/ast/file_train.json'
FILE_STAT_TREE_HEIGHTS = 'data/ast/stat_tree_heights.json'
FILE_STAT_PROGRAM_LENGTHS = 'data/ast/stat_program_lengths.json'

PY_FILE_TRAINING_PROCESSED = 'data/pyast/file_train.json'

# region Utils

def draw_plot(x, y, x_label=None, y_label=None):
    plt.plot(x, y)
    if x_label is not None:
        plt.xlabel(x_label)
    if y_label is not None:
        plt.ylabel(y_label)
    plt.show()

def get_percentile_plot(stat):
    """Get x and y for plot describing percentile of stat < x for each x.

    :param stat: array of int values
    """
    stat = sorted(stat)
    x = []
    y = []
    for i in range(len(stat)):
        if (i == len(stat) - 1) or (stat[i] != stat[i + 1]):
            x.append(stat[i])
            y.append(float(i + 1) / len(stat))

    return x, y

def plot_percentile_from_file(file, x_label, y_label):
    stat = list(read_jsons(file))[0]
    x, y = get_percentile_plot(stat)
    draw_plot(x, y, x_label=x_label, y_label=y_label)

# endregion

# region TreeHeight
def print_tree_heights_stats(tree_heights):
    print('Min height of the tree: {}'.format(min(tree_heights)))
    print('Max height of the tree: {}'.format(max(tree_heights)))
    print('Average height of the trees: {}'.format(float(sum(tree_heights)) / len(tree_heights)))

def print_tree_heights_stats_from_file(tree_heights_file):
    print_tree_heights_stats(list(read_jsons(tree_heights_file))[0])

def tree_heights_distribution(tree_heights_file):
    plot_percentile_from_file(tree_heights_file, x_label='Tree height', y_label='Percent of data')

class JsonTreeHeightExtractor(JsonExtractor):

    def __init__(self):
        self.buffer = {}

    def extract(self, raw_json):
        return self._calc_height(raw_json)

    def _calc_height(self, raw_json):
        to_calc = []
        for node in raw_json:
            if node == 0:
                break

            if 'children' in node:
                to_calc.append(node)
            else:
                self.buffer[int(node['id'])] = 1

        for node in reversed(to_calc):
            id = int(node['id'])
            self.buffer[id] = 0
            for children in node['children']:
                self.buffer[id] = max(self.buffer[id], self.buffer[int(children)] + 1)

        return self.buffer[0]

def calc_tree_heights(heights_file):
    tree_heights = []

    extractor = JsonTreeHeightExtractor()
    for current_height in extract_jsons_info(extractor, FILE_TRAINING):
        tree_heights.append(current_height)

    if heights_file is not None:
        write_json(heights_file, tree_heights)
    print_tree_heights_stats(tree_heights=tree_heights)

# endregion

# region ProgramLen

def plot_program_len_percentiles(lengths_file):
    plot_percentile_from_file(lengths_file, x_label='Program lengths', y_label='Percentile')

class JsonProgramLenExtractor(JsonExtractor):

    def extract(self, raw_json):
        return len(raw_json) - 1

def calc_programs_len(lengths_file):
    extractor = JsonProgramLenExtractor()

    program_lengths = list(extract_jsons_info(extractor, FILE_TRAINING))
    if lengths_file is not None:
        write_json(lengths_file, program_lengths)

# endregion

class JsonProgramDepthStatExtractor(JsonExtractor):

    def extract(self, raw_json):
        depths_prob = np.zeros(50)
        for node in raw_json:
            depths_prob[min(node['d'], 49)] += 1

        return depths_prob

def extract_depths_histogram(file_train):
    extractor = JsonProgramDepthStatExtractor()

    depths_prob = np.zeros(50)
    for info in extract_jsons_info(extractor, file_train):
        depths_prob = depths_prob + info

    res = [x for x in depths_prob]
    with open('eval_local/node_depths.json', 'w') as f:
        f.write(json.dumps(res))

def draw_histogram(file):
    values = read_json(file)
    all = np.sum(values)
    values /= all

    plt.plot(values)
    # n, bins, patches = plt.hist(values, 100, density=True, facecolor='g', alpha=0.75)

    plt.xlabel('Smarts')
    plt.ylabel('Probability')
    plt.show()

class EasyNonTerminalsExtractor(JsonExtractor):

    def __init__(self):
        super().__init__()
        self.parents_table = {}

    def extract(self, raw_json):
        for i in range(len(raw_json) - 1):
            node = raw_json[i]
            if 'children' in node:
                parent_type = node['type']
                children = node['children']
                for position in range(len(children)):
                    child_type = raw_json[int(children[position])]['type']

                    if child_type not in self.parents_table:
                        self.parents_table[child_type] = []

                    self.parents_table[child_type].append(parent_type + '_' + str(position))

def get_easy_non_terminals(file, lim=None):
    extractor = EasyNonTerminalsExtractor()
    for info in extract_jsons_info(extractor, file, lim=lim):
        print(info)

class NonTerminalsStatExtractor(JsonExtractor):
    def __init__(self):
        super().__init__()
        self.stat = {}

    def extract(self, raw_json):
        for i in range(len(raw_json) - 1):
            t = raw_json[i]['type']
            if t not in self.stat:
                self.stat[t] = 0

            self.stat[t] += 1

        return True

def visualize_nt_stat(file):
    stat = read_json(file)
    labels = []
    values = []
    sum = 0
    for k in sorted(stat.keys()):
        labels.append(k)
        values.append(stat[k])
        sum += stat[k]

    x = np.arange(len(values))
    y = np.array(values) / sum * 100

    plt.xticks(x, labels, rotation=30, horizontalalignment='right', fontsize=5)
    plt.grid(True)

    plt.plot(x, y)
    plt.show()

class UNKNTExtractor(JsonExtractor):

    def extract(self, raw_json):
        unk_count = 0
        for node in raw_json:
            if node['N'] == 321:
                unk_count += 1
        return len(raw_json), unk_count

def get_unk_nt_percentage(file_eval):  # unk percentage: 8.86e-7
    extractor = UNKNTExtractor()
    total_count = 0
    unk_count = 0
    for (c_t, c_u) in extract_jsons_info(extractor, file_eval):
        total_count += c_t
        unk_count += c_u

    print(float(unk_count) / total_count)

def get_non_terminals_statistic(file, lim=None):
    extractor = NonTerminalsStatExtractor()
    list(extract_jsons_info(extractor, file, lim=lim))

    with open('data/ast/stat_nt_occurrences.json', mode='w') as f:
        f.write(json.dumps(extractor.stat))

def run_main():
    # get_unk_nt_percentage('data/pyast/file_eval.json')
    # extract_depths_histogram(PY_FILE_TRAINING_PROCESSED)
    # extract_depths_histogram(FILE_TRAINING_PROCESSED)
    draw_histogram('eval_local/node_depths.json')

    # get_easy_non_terminals(file='data/programs_eval_10000.json', lim=100)
    # get_non_terminals_statistic(file='data/programs_eval_10000.json', lim=10000)
    # visualize_nt_stat(file='data/ast/stat_nt_occurrences.json')

    # calc_programs_len(FILE_STAT_PROGRAM_LENGTHS)
    # plot_program_len_percentiles(FILE_STAT_PROGRAM_LENGTHS)

    # calc_tree_heights(heights_file=FILE_STAT_TREE_HEIGHTS)
    # print_tree_heights_stats_from_file(tree_heights_file=FILE_STAT_TREE_HEIGHTS)
    # tree_heights_distribution(tree_heights_file=FILE_STAT_TREE_HEIGHTS)

if __name__ == '__main__':
    run_main()

max_stars_repo_name: zerogerc/rnn-autocomplete

max_issues_repo_name: ZeRoGerc/rnn-autocomplete

max_forks_repo_name: ZeRoGerc/rnn-autocomplete

reason: import numpy


text:
import argparse
import json
import numpy as np

# preprocess the data into jsonl format for training and evaluation of models
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-input_trec', type=str)
    parser.add_argument('-input_qrels', type=str, default=None)
    parser.add_argument('-input_queries', type=str)
    parser.add_argument('-input_qids', type=str)
    parser.add_argument('-input_docs', type=str)
    parser.add_argument('-input_docids', type=str)
    parser.add_argument('-documents', type=int, default=0)
    parser.add_argument('-queries', type=int, default=0)
    parser.add_argument('-output', type=str)
    args = parser.parse_args()

    # for indexing documents/queries
    if args.documents > 0 or args.queries > 0:
        with open(args.input_docs) as f_in, open(args.output, "w") as f_out:
            cnt = 0
            for line in f_in:
                line = line.strip().split('\t')
                if args.documents > 0:
                    if len(line) != 4:
                        cnt += 1
                        print(f"Skipped: {line}, insg: {cnt}")
                    else:
                        id = line[0]
                        content = line[3]
                else:
                    if len(line) != 2:
                        cnt += 1
                        print(f"Skipped: {line}, insg: {cnt}")
                    else:
                        id = line[0]
                        content = line[1]

                f_out.write(json.dumps({'doc_id': id, 'doc': content}) + '\n')
    # for training/dev data
    else:
        qs = {}
        # generate dev data for ranker with embeddings
        if args.input_queries.split('.')[-1] == 'npy':
            queries = np.load(args.input_queries)
            qids = np.load(args.input_qids)
            for idx, _ in enumerate(queries):
                qs[str(qids[idx])] = queries[idx]

        elif args.input_queries.split('.')[-1] == 'json' or args.input_queries.split('.')[-1] == 'jsonl':
            with open(args.input_queries, 'r') as r:
                for line in r:
                    line = json.loads(line)
                    qs[line['query_id']] = line['query']
        else:
            with open(args.input_queries, 'r') as r:
                for line in r:
                    line = line.strip().split('\t')
                    qs[line[0]] = line[1]

        ds = {}
        # generate dev data for ranker with embeddings
        if args.input_docs.split('.')[-1] == 'npy':
            docs = np.load(args.input_docs)
            docids = np.load(args.input_docids)
            for idx, _ in enumerate(docids):
                ds[str(docids[idx])] = docs[idx]

        elif args.input_queries.split('.')[-1] == 'json' or args.input_queries.split('.')[-1] == 'jsonl':
            with open(args.input_docs, 'r') as r:
                for line in r:
                    line = json.loads(line)
                    ds[line['paper_id']] = ' '.join([line['title'], line['abstract']]).replace('\n', ' ').replace('\t', ' ').strip()
        else:
            with open(args.input_docs, 'r') as r:
                for line in r:
                    line = line.strip().split('\t')
                    if len(line) > 2:
                        ds[line[0]] = line[-2] + ' ' + line[-1]
                    else:
                        ds[line[0]] = line[1]

        if args.input_qrels is not None:
            qpls = {}
            with open(args.input_qrels, 'r') as r:
                for line in r:
                    line = line.strip().split()
                    if line[0] not in qpls:
                        qpls[line[0]] = {}
                    qpls[line[0]][line[2]] = int(line[3])

        f = open(args.output, 'w')
        with open(args.input_trec, 'r') as r:
            for line in r:
                line = line.strip().split()
                if line[0] not in qs or line[2] not in ds:
                    continue
                if args.input_qrels is not None:
                    if line[0] in qpls and line[2] in qpls[line[0]]:
                        label = qpls[line[0]][line[2]]
                        # print("if true with label: ", label)
                    else:
                        label = 0
                    f.write(json.dumps({'query': qs[line[0]], 'doc': ds[line[2]], 'label': label, 'query_id': line[0], 'doc_id': line[2], 'retrieval_score': float(line[4])}) + '\n')
                else:
                    f.write(json.dumps({'query': qs[line[0]], 'doc': ds[line[2]], 'query_id': line[0], 'doc_id': line[2], 'retrieval_score': float(line[4])}) + '\n')
        f.close()

if __name__ == "__main__":
    main()

max_stars_repo_name: real-tesco/Multi-Step-Reasoning

max_issues_repo_name: real-tesco/Multi-Step-Reasoning

max_forks_repo_name: real-tesco/Multi-Step-Reasoning


text:
import numpy as np

import rl_sandbox.constants as c

from rl_sandbox.envs.wrappers.wrapper import Wrapper

class AbsorbingStateWrapper(Wrapper):
    def __init__(self, env, create_absorbing_state, max_episode_length):
        super().__init__(env)
        self._done = False
        self._obs = None
        self._max_episode_length = max_episode_length
        self._create_absorbing_state = create_absorbing_state
        self._prev_info = None

    def _get_obs(self):
        if self._done:
            # Return absorbing state which is [0, ..., 0, 1]
            return np.eye(self._obs.size + 1)[-1]

        return np.concatenate((self._obs.reshape(-1), [0]), axis=0)

    def reset(self):
        self._curr_timestep = 0
        self._obs = self._env.reset()
        self._done = False
        return self._get_obs()

    def step(self, action):
        self._curr_timestep += 1
        if self._create_absorbing_state and self._done:
            return self._get_obs(), 0., True, {**self._prev_info, c.ABSORBING_STATE: True, c.DONE: False}

        self._obs, reward, done, info = self._env.step(action)
        self._prev_info = info
        info[c.ABSORBING_STATE] = False
        info[c.DONE] = done
        if self._create_absorbing_state and self._curr_timestep < self._max_episode_length and done:
            self._done = True
            done = False  # otherwise env will reset without getting next absorbing state
        return self._get_obs(), reward, done, info

    def render(self, **kwargs):
        self._env.render(**kwargs)

    def seed(self, seed):
        self._env.seed(seed)

def check_absorbing(config):
    for wrapper in config[c.ENV_SETTING][c.ENV_WRAPPERS]:
        if wrapper[c.WRAPPER] == AbsorbingStateWrapper:
            return True
    return False


text:
import numpy as np

def bestFirstPolicy(q_table, state, agent):
	# take a table of dimension observation_space x action_space and int(state)
	# each cell of it contains a value that give an idea of how good doing an action is from a state
	# this function take a state and return the best action possible

	tab = q_table[state]
	tab = tab.transpose()
	res = tab[agent]
	res = np.argmax(res)
	return res

def randomPolicy(env):
	# return a random possible action from the environment
	return env.action_space.sample()

def randomMovingPolicy(env):
	action = env.action_space.sample()
	if action>=4:
		action = action-4
	return action

def randomShootingPolicy(env):
	action = env.action_space.sample()
	if action <4:
		action = action+4
	return action


text:
import pandas as pd
import numpy as np
import graphviz

def entropy(counts):
    s = sum(counts)
    counts = counts / s
    return -np.sum(counts * np.log2(counts + 1e-100))

def gini(counts):
    s = sum(counts)
    counts = counts / s
    return 1 - np.sum(counts * counts)

def mean_err_rate(counts):
    counts = counts / sum(counts)
    return 1 - max(counts)

class AbstractSplit:
    """Split the examples in a tree node according to a criterion.
    """
    def __init__(self, attr):
        self.attr = attr

    def __call__(self, x):
        """Return the subtree corresponding to x."""
        raise NotImplementedError

    def build_subtrees(self, df, subtree_kwargs):
        """Recuisively build the subtrees."""
        raise NotImplementedError

    def iter_subtrees(self):
        """Return an iterator over subtrees."""
        raise NotImplementedError

    def add_to_graphviz(self, dot):
        """Add the split to the graphviz vizluzation."""
        raise NotImplementedError

    def __str__(self):
        return f"{self.__class__.__name__}: {self.attr}"

class CategoricalMultivalueSplit(AbstractSplit):
    def build_subtrees(self, df, subtree_kwargs):
        self.subtrees = {}
        for group_name, group_df in df.groupby(self.attr):
            child = Tree(group_df, **subtree_kwargs)
            self.subtrees[group_name] = child

    def __call__(self, x):
        # Return the subtree for the given example
        attr = self.attr
        assert(attr in x)
        if x[attr] in self.subtrees:
            return self.subtrees[x[attr]]

        return None

    def iter_subtrees(self):
        return self.subtrees.values()

    def add_to_graphviz(self, dot, parent, print_info):
        for split_name, child in self.subtrees.items():
            child.add_to_graphviz(dot, print_info)
            dot.edge(f'{id(parent)}', f'{id(child)}',
                     label=f'{split_name}')

def get_categorical_split_and_purity(df, parent_purity, purity_fun, attr,
                                     normalize_by_split_entropy=False):
    """Return a multivariate split and its purity.
    Args:
        df: a dataframe
        parent_purity: purity of the parent node
        purity_fun: function to compute the purity
        attr: attribute over whihc to split the dataframe
        normalize_by_split_entropy: if True, divide the purity gain by the split
            entropy (to compute https://en.wikipedia.org/wiki/Information_gain_ratio)

    Returns:
        pair of (split, purity_gain)
    """
    split = CategoricalMultivalueSplit(attr)
    # Compute the purity after the split
    # parent purity - weighted sum of children purity

    children_purity = 0
    for group_name, group_df in df.groupby(attr):
        children_purity += purity_fun(group_df['target'].value_counts()) * len(group_df)

    children_purity /= len(df)
    purity_gain = parent_purity - children_purity

    if normalize_by_split_entropy:
        purity_gain /= entropy(df[attr].value_counts())

    return split, purity_gain

def get_split(df, criterion='infogain', nattrs=None):
    # Implement termination criteria:
    # 1. Node is pure
    target_value_counts = df['target'].value_counts()
    if len(target_value_counts) == 1:
        return None
    # 2. No split is possible
    #    First get alist of attributes that can be split
    possible_splits = [c for c in df.columns if c != 'target' and len(df[c].value_counts()) > 1]
    if nattrs is not None:
        np.random.shuffle(possible_splits)
        possible_splits = possible_splits[:nattrs]

    #    Terminate early if none are possivle
    if not possible_splits:
        return None

    # Get the base purity measure and the purity function
    if criterion in ['infogain', 'infogain_ratio']:
        purity_fun = entropy
    elif criterion in ['mean_err_rate']:
        purity_fun = mean_err_rate
    elif criterion in ['gini']:
        purity_fun = gini
    else:
        raise Exception("Unknown criterion: " + criterion)
    base_purity = purity_fun(target_value_counts)

    best_purity_gain = -1
    best_split = None

    # Random Forest support
    # Randomize the split by restricting the number of attributes

    for attr in possible_splits:
        if np.issubdtype(df[attr].dtype, np.number):
            # Handling of numerical attributes will be defined later, in a manner
            # similar to categorical ones
            split_sel_fun = get_numrical_split_and_purity
        else:
            split_sel_fun = get_categorical_split_and_purity

        split, purity_gain = split_sel_fun(df, base_purity, purity_fun, attr,
                                            normalize_by_split_entropy=criterion.endswith('ratio'))

        if purity_gain > best_purity_gain:
            best_purity_gain = purity_gain
            best_split = split
    return best_split

class Tree:
    def __init__(self, df, **kwargs):
        super().__init__()
        # Assert that threre are no missing values,
        # TODO: remove this for bonus problem #XXX
        assert not df.isnull().values.any()

        # We need to let subrees know about all targets to properly color nodes
        if 'all_targets' not in kwargs:
            kwargs['all_targets'] = sorted(df['target'].unique())
        # Save keyword arguments to build subtrees
        kwargs_orig = dict(kwargs)

        # Get kwargs we know about, remaning ones are for splitting
        self.all_targets = kwargs.pop('all_targets')

        # Save debug info for visualization
        self.counts = df['target'].value_counts()
        self.info = {
            'num_samples': len(df),
            'entropy': entropy(self.counts),
            'gini': gini(self.counts),
        }

        self.split = get_split(df, **kwargs)
        if self.split:
            #print('!!S', self.split)
            self.split.build_subtrees(df, kwargs_orig)

    def get_target_distribution(self, sample):
        # TODO: descend into subtrees and return the leaf target distribution
        if self.split is not None:
            subtree = self.split(sample)
            if subtree is not None:
                return subtree.get_target_distribution(sample)
            else:
                return self.counts / self.info['num_samples']
        else:
            return self.counts / self.info['num_samples']

    def classify(self, sample):
        # TODO: classify the sample by descending into the appropriate subtrees.
        if self.split is not None:
            subtree = self.split(sample)
            if subtree is not None:
                return subtree.classify(sample)
            else:
                return self.counts.idxmax()
        else:
            return self.counts.idxmax()

    def draw(self, print_info=True):
        dot = graphviz.Digraph()
        self.add_to_graphviz(dot, print_info)
        return dot

    def add_to_graphviz(self, dot, print_info):
        freqs = self.counts / self.counts.sum()
        freqs = dict(freqs)
        colors = []
        freqs_info = []
        for i, c in enumerate(self.all_targets):
            freq = freqs.get(c, 0.0)
            if freq > 0:
                colors.append(f"{i%9 + 1};{freq}")
                freqs_info.append(f'{c}:{freq:.2f}')
        colors = ':'.join(colors)
        labels = [' '.join(freqs_info)]
        if print_info:
            for k,v in self.info.items():
                labels.append(f'{k} = {v}')
        if self.split:
            labels.append(f'split by: {self.split.attr}')
        dot.node(f'{id(self)}',
                 label='\n'.join(labels),
                 shape='box',
                 style='striped',
                 fillcolor=colors,
                 colorscheme='set19')
        if self.split:
            self.split.add_to_graphviz(dot, self, print_info)

    def upper_confidenct_interval(self, f, N, z=0.5):
        return (f + ((z ** 2) / (2 * N)) \
                + z * ((f / N - (f ** 2) / N + z ** 2 / (4 * (N ** 2))) ** 0.5))  \
                / (1 + (z ** 2) / N)

    def prune_with_confidence_interval(self):
        if self.split:
            for w in self.split.iter_subtrees():
                w.prune_with_confidence_interval()

        N = self.info['num_samples']
        parent_error = self.counts / np.sum(self.counts)
        parent_error = sorted(list(parent_error), reverse=True)
        parent_error = np.sum(parent_error[1:])
        parent_error = self.upper_confidenct_interval(parent_error, N)
        self.info['confidence_error'] = parent_error

        if self.split:
            children_error = 0
            for w in self.split.iter_subtrees():
                child_error = (w.info['num_samples'] / N) * w.info['confidence_error']
                children_error += child_error

            if children_error > parent_error:
                self.split = None
                self.info['splitted'] = True

class NumericalSplit(AbstractSplit):
    def __init__(self, attr, th):
        super(NumericalSplit, self).__init__(attr)
        self.th = th

    def build_subtrees(self, df, subtree_kwargs):
        self.subtrees = (
            Tree(df[df[self.attr] <= self.th], **subtree_kwargs),
            Tree(df[df[self.attr] > self.th], **subtree_kwargs))

    def __call__(self, x):
        if x[self.attr] <= self.th:
            return self.subtrees[0]
        else:
            return self.subtrees[1]

    def __str__(self):
        return f"NumericalSplit: {self.attr} <= {self.th}"

    def iter_subtrees(self):
        return self.subtrees

    def add_to_graphviz(self, dot, parent, print_info):
        self.subtrees[0].add_to_graphviz(dot, print_info)
        dot.edge(f'{id(parent)}', f'{id(self.subtrees[0])}',
                 label=f'<= {self.th:.2f}')
        self.subtrees[1].add_to_graphviz(dot, print_info)
        dot.edge(f'{id(parent)}', f'{id(self.subtrees[1])}',
                 label=f'> {self.th:.2f}')

def get_numrical_split_and_purity(df, parent_purity, purity_fun, attr,
                                  normalize_by_split_entropy=False):
    """Find best split thereshold and compute the average purity after a split.
    Args:
        df: a dataframe
        parent_purity: purity of the parent node
        purity_fun: function to compute the purity
        attr: attribute over whihc to split the dataframe
        normalize_by_split_entropy: if True, divide the purity gain by the split
            entropy (to compute https://en.wikipedia.org/wiki/Information_gain_ratio)

    Returns:
        pair of (split, purity_gain)
    """
    attr_df = df[[attr, 'target']].sort_values(attr)
    targets = attr_df['target']
    values = attr_df[attr]
    # Start with a split that puts all the samples into the right subtree
    right_counts = targets.value_counts()
    left_counts = right_counts * 0

    best_split = None
    best_purity_gain = -1
    N = len(attr_df)
    for row_i in range(N - 1):
        # Update the counts of targets in the left and right subtree and compute
        # the purity of the slipt for all possible thresholds!
        # Return the best split found.

        # Remember that the attribute may have duplicate values and all samples
        # with the same attribute value must end in the same subtree!

        row_target = targets.iloc[row_i]
        right_counts[row_target] -= 1
        left_counts[row_target] -= 1

        if attr_df.iloc[row_i][0] != attr_df.iloc[row_i + 1][0]:
            children_purity = (row_i + 1) * purity_fun(left_counts) \
                                + (N - row_i - 1) * purity_fun(right_counts)
            children_purity /= N
            purity = parent_purity - children_purity

            if purity > best_purity_gain:
                best_purity_gain = purity
                attr_mean = (attr_df.iloc[row_i][0] + attr_df.iloc[row_i + 1][0]) / 2
                best_split = NumericalSplit(attr, attr_mean)

    if normalize_by_split_entropy:
        best_purity_gain /= entropy(targets.value_counts())
    return best_split, best_purity_gain

max_stars_repo_name: TheFebrin/DataScience

max_issues_repo_name: TheFebrin/DataScience

max_forks_repo_name: TheFebrin/DataScience


text:
import numpy as np
import cv2
import os
from tkinter import filedialog

def get_sources():

    sources = [i for i in os.listdir('_source') if i[-4:] in ['.png', '.bmp', '.jpg']]

    if len(sources) == 0:
        print("There must be at least one image in the '_source' folder.")
    else:
        return sources

def get_target():

    target = filedialog.askopenfilename(initialdir="_target", title="Select A Target", filetypes=[('image files', ('.png', '.bmp', '.jpg'))])

    if len(target) == 0:
        print("Select an image that will be used as a target.")
    else:
        return cv2.cvtColor(cv2.imread(target), cv2.COLOR_BGR2LAB)

def get_mean_and_std(x):
    x_mean, x_std = cv2.meanStdDev(x)
    x_mean = np.hstack(np.around(x_mean,2))
    x_std = np.hstack(np.around(x_std,2))
    return x_mean, x_std

def color_transfer():

    sources = get_sources()

    if sources:

        t = get_target()
        t_mean, t_std = get_mean_and_std(t)

        if len(t) != 0:

            for n in range(len(sources)):
                print("Converting picture " + sources[n] + "...")

                s = cv2.imread('_target/' + sources[n])
                s = cv2.cvtColor(s, cv2.COLOR_BGR2LAB)
                s_mean, s_std = get_mean_and_std(s)

                height, width, channel = s.shape
                for i in range(0,height):
                    for j in range(0,width):
                        for k in range(0,channel):
                            x = s[i,j,k]
                            x = ((x - s_mean[k]) * (t_std[k] / s_std[k])) + t_mean[k]
                            x = round(x)
                            x = 0 if x < 0 else x
                            x = 255 if x > 255 else x
                            s[i,j,k] = x

                s = cv2.cvtColor(s, cv2.COLOR_LAB2BGR)
                cv2.imwrite('_output/' + sources[n], s)

color_transfer()


text:
import cv2, os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from random import choices

from skimage.metrics import structural_similarity as compare_ssim
import imutils

TRAIN_DATA = '../data/train'
TEST_DATA = '../data/test'

train_dirs = os.listdir(TRAIN_DATA)
test_dirs = os.listdir(TEST_DATA)

def get_next_positive_path():
    for locations in train_dirs:
        indv_loc_dir = os.listdir(TRAIN_DATA + "/" + locations)
        day = indv_loc_dir[0]
        night = indv_loc_dir[1]
        day_imgs = os.listdir(TRAIN_DATA + "/" + locations + "/" + day)
        night_imgs = os.listdir(TRAIN_DATA + "/" + locations + "/" + night)
        for dayimg in day_imgs:
            for nightimg in night_imgs:
                daypath = TRAIN_DATA + "/" + locations + "/" + day + "/" + dayimg
                nightpath = TRAIN_DATA + "/" + locations + "/" + night + "/" + nightimg
                yield daypath, nightpath

def get_next_negative_path():
    for locations in train_dirs:
        not_curr = set(train_dirs)-set([locations])
        indv_loc_dir = os.listdir(TRAIN_DATA + "/" + locations)
        day = indv_loc_dir[0]
        day_imgs = os.listdir(TRAIN_DATA + "/" + locations + "/" + day)
        for dayimg in day_imgs:
            daypath = TRAIN_DATA + "/" + locations + "/" + day + "/" + dayimg
            for local in not_curr:
                indv_loc_dir = os.listdir(TRAIN_DATA + "/" + local)
                night = indv_loc_dir[1]
                night_imgs = os.listdir(TRAIN_DATA + "/" + local + "/" + night)
                imgs = choices(night_imgs, k=5)
                for nightimg in imgs:
                    daypath = TRAIN_DATA + "/" + locations + "/" + day + "/" + dayimg
                    nightpath = TRAIN_DATA + "/" + local + "/" + night + "/" + nightimg
                    yield daypath, nightpath

'''pos_counter = 0
for img_paths in get_next_positive_path():
    print(pos_counter, img_paths, 1)
    pos_counter +=1
    img = cv2.imread(img_paths[0])
    img1 = cv2.imread(img_paths[1])
    print(img.shape, img1.shape)'''

'''neg_counter = 0
for img_paths in get_next_negative_path():
    print(neg_counter, img_paths, 0)
    neg_counter +=1'''

'''for dir in test_dirs:
    indv_dir = os.listdir(TEST_DATA + "/" + dir)
    for img in indv_dir:
        print(TEST_DATA + "/" + dir + "/" + img)'''

def similarityMatcher():


text:
import numpy as np
from sds.models.hmm import HiddenMarkovModel as Ours
from ssm.hmm import HMM as Theirs

import warnings

warnings.simplefilter(action='ignore', category=FutureWarning)
np.random.seed(1337)

T = [100, 95]

true_hmm = Theirs(5, 2, observations="gaussian")

true_z, x = [], []
for t in T:
    _z, _x = true_hmm.sample(t)
    true_z.append(_z)
    x.append(_x)

true_ll = true_hmm.log_probability(x)

# true_hmm = HMM(nb_states=5, obs_dim=2)
# true_z, x = true_hmm.sample(horizon=T)
# true_ll = true_hmm.log_probability(x)

our_hmm = Ours(nb_states=5, obs_dim=2)
our_hmm.initialize(x)
our_ll = our_hmm.em(x, nb_iter=1000, tol=0., verbose=True)

their_hmm = Theirs(5, 2, observations="gaussian")
their_ll = their_hmm.fit(x, method="em", num_em_iters=1000, initialize=True)

print("true_ll=", true_ll, "our_ll=", our_ll[-1], "their_ll=", their_ll[-1])

max_stars_repo_name: hanyas/sds

max_issues_repo_name: hanyas/sds

max_forks_repo_name: hanyas/sds


text:
from numpy import nan, array as numpy_array
from pandas import read_csv, merge, DataFrame

bands_df = read_csv("./bands.csv")
df = read_csv("./slider.csv")

def add_band_id(x):
    band_df = bands_df.apply(lambda y: (y[6], y[7]) if
                             (x["price"] >= y["start_price"] and x["price"] <= y["End_price"]
                              and x["Total_cars"] == y['Total_cars'])
                             else None, axis=1)
    band_df = band_df.dropna(axis=0, how='all')
    if band_df.empty:
        band_df = nan
    else:
        band_df = band_df.to_string(index=False)
    return band_df

def get_bands(df):
    df['ticker'] = df.apply(add_band_id, axis=1)
    df['new'] = df.ticker.str.replace("[({':)]", "")
    gh = df['new'].str.split(',', expand=True)
    gh = gh.rename({0: 'band', 1: 'budget'}, axis='columns')
    df = df.drop(['ticker', 'new'], axis=1)
    merged = merge(DataFrame(gh), DataFrame(df),
                   left_index=True, right_index=True)
    merged = numpy_array(merged)
    print(merged)
    return merged

# call the function
# ================-
if __name__ == '__main__':
    print(df)
    get_bands(df)

max_stars_repo_name: manojc/flask-poc

max_issues_repo_name: manojc/flask-poc

max_forks_repo_name: manojc/flask-poc


text:
import numpy as np
from collections import Counter, defaultdict

def minkowski_squared(sample1, sample2, weights = None, P = 2):
    if weights is not None:
        return ((np.fabs(sample1 - sample2) * weights) ** P).sum()
    return (np.fabs(sample1 - sample2) ** P).sum()

def majority_vote(neighbour_labels, _ = None):
    return Counter(neighbour_labels).most_common(1)[0][0]

def weighted_majority_vote(neighbour_labels, neighbour_distances_squared):
    label_votes = defaultdict(int)
    neighbour_distances_squared = 1.0 / (neighbour_distances_squared ** 0.5)
    for i in range(neighbour_labels.shape[0]):
        label_votes[neighbour_labels[i]] += neighbour_distances_squared[i]

    return max(label_votes, key = label_votes.get)

max_stars_repo_name: PBonnema/Applied-AI-Assignments

max_issues_repo_name: PBonnema/Applied-AI-Assignments

max_forks_repo_name: PBonnema/Applied-AI-Assignments


text:
"""
Functions for meteorological variable conversions and functions.

Translated and vectorized from NOAA bulk model and flux processing MATLAB scripts.

Uncomment code at the end of this file and execute '%run flux.py' from the iPython command line to test functions.

Byron Blomquist, CU/CIRES, NOAA/ESRL/PSD3
v1: Oct 2014
"""

def qsat(t,p):
    """
    usage: es = qsat(t,p)
    Returns saturation vapor pressure es (mb) given t(C) and p(mb).

    After Buck, 1981: J.Appl.Meteor., 20, 1527-1532

    Returns ndarray float for any numeric object input.
    """
    from numpy import copy, asarray, exp

    t2 = copy(asarray(t, dtype=float))  # convert to ndarray float
    p2 = copy(asarray(p, dtype=float))
    es = 6.1121 * exp(17.502 * t2 / (240.97 + t2))
    es = es * (1.0007 + p2 * 3.46e-6)
    return es

def qsea(sst,p):
    """
    usage: qs = qsea(sst,p)
    Returns saturation specific humidity (g/kg) at sea surface
    given sst(C) and p(mb) input of any numeric type.

    Returns ndarray float for any numeric object input.
    """
    ex = qsat(sst,p) # returns ex as ndarray float
    es = 0.98 * ex
    qs = 622 * es /(p - 0.378 * es)
    return qs

def qair(t,p,rh):
    """
    usage: qa, em = qair(t,p,rh)
    Returns specific humidity (g/kg) and partial pressure (mb)
    given t(C), p(mb) and rh(%).

    Returns ndarray float for any numeric object input.
    """
    from numpy import copy, asarray

    rh2 = copy(asarray(rh,dtype=float))  # conversion to ndarray float
    rh2 /= 100.0                         # frational rh
    p2 = copy(asarray(p, dtype=float))
    t2 = copy(asarray(t, dtype=float))
    em = rh2 * qsat(t2,p2)
    qa = 621.97 * em / (p2 - 0.378 * em)
    return (qa, em)

def rhcalc(t,p,q):
    """
    usage: rh = rhcalc(t,p,q)
    Returns RH(%) for given t(C), p(mb) and specific humidity, q(kg/kg)

    Returns ndarray float for any numeric object input.
    """
    from numpy import copy, asarray

    q2 = copy(asarray(q, dtype=float))    # conversion to ndarray float
    p2 = copy(asarray(p, dtype=float))
    t2 = copy(asarray(t, dtype=float))
    es = qsat(t2,p2)
    em = p2 * q2 / (0.622 + 0.378 * q2)
    rh = 100.0 * em / es
    return rh

def rhoa(t,p,rh):
    """
    computes moist air density from temperature, pressure and RH

    usage: Ra = rhoa(t,p,rh)

    inputs: t (deg C), p (mb or hPa) and rh

    output: Ra = moist air density in kg/m3

    """
    Md = 0.028964                       # mol wt dry air, kg/mole
    Mv = 0.018016                       # mol wt water, kg/mole
    Tk = t + 273.15                     # deg Kelvin
    Pa = p*100.0                        # Pascals
    Rgas = 8.314                        # in m3 Pa/mol K
    Pv = (rh/100.0)*qsat(t,p)*100.0     # H2O vapor pressure in Pa
    Pd = Pa - Pv                        # pressure dry air
    Ra = (Pd*Md + Pv*Mv)/(Rgas*Tk)      # moist air density
    return Ra

def rhod(t,p):
    """
    computes dry air density from temperature and pressure

    usage: Rd = rhod(t,p)

    inputs: t (deg C), and p (mb or hPa)

    output: Rd = dry air density in kg/m3

    """
    Rd = 287.058        # gas const for dry air in J/kg K
    tk = t+273.15       # deg Kelvin
    Pa = p*100          # Pascals
    Rdry = Pa/(Rd*Tk)   # dry air density, kg/m3
    return Rd

def grv(latitude):
    """
    usage: g = grv(latitude)
    Computes gravity, g [m/sec^2] given latitude in deg.

    Ref??

    Returns ndarray float for any numeric object input.
    """
    from numpy import copy, pi, sin, asarray

    lat = copy(asarray(latitude, dtype=float))    # conversion to ndarray float
    gamma = 9.7803267715
    c1 = 0.0052790414
    c2 = 0.0000232718
    c3 = 0.0000001262
    c4 = 0.0000000007
    phi = lat * pi/180;
    x = sin(phi);
    g = gamma * (1 + c1*x**2 + c2*x**4 + c3*x**6 + c4*x**8)
    return g

def psit_26(z_L):
    """
    usage psi = psit_26(z_L)

    Computes the temperature structure function given z/L.
    """
    from numpy import exp, log, sqrt, arctan, asarray, copy
    from util import find

    zet = copy(asarray(z_L, dtype=float))    # conversion to ndarray float
    dzet = 0.35*zet
    dzet[dzet>50] = 50.           # stable
    psi = -((1 + 0.6667*zet)**1.5 + 0.6667*(zet - 14.28)*exp(-dzet) + 8.525)
    k = find(zet < 0)            # unstable
    x = (1 - 15*zet[k])**0.5
    psik = 2*log((1 + x)/2.)
    x = (1 - 34.15*zet[k])**0.3333
    psic = 1.5*log((1.+x+x**2)/3.) - sqrt(3)*arctan((1 + 2*x)/sqrt(3))
    psic += 4*arctan(1.)/sqrt(3.)
    f = zet[k]**2 / (1. + zet[k]**2.)
    psi[k] = (1-f)*psik + f*psic
    return psi

def psiu_26(z_L):
    """
    usage: psi = psiu_26(z_L)

    Computes velocity structure function given z/L
    """
    from numpy import exp, log, sqrt, arctan, min, asarray, copy
    from util import find

    zet = copy(asarray(z_L, dtype=float))    # conversion to ndarray float
    dzet = 0.35*zet
    dzet[dzet>50] = 50.           # stable
    a = 0.7
    b = 3./4.
    c = 5.
    d = 0.35
    psi = -(a*zet + b*(zet - c/d)*exp(-dzet) + b*c/d)
    k = find(zet < 0)         # unstable
    x = (1 - 15*zet[k])**0.25
    psik = 2.*log((1.+x)/2.) + log((1.+x*x)/2.) - 2.*arctan(x) + 2.*arctan(1.)
    x = (1 - 10.15*zet[k])**0.3333
    psic = 1.5*log((1.+x+x**2)/3.) - sqrt(3.)*arctan((1.+2.*x)/sqrt(3.))
    psic += 4*arctan(1.)/sqrt(3.)
    f = zet[k]**2 / (1.+zet[k]**2)
    psi[k] = (1-f)*psik + f*psic
    return psi

def psiu_40(z_L):
    """
    usage: psi = psiu_40(z_L)

    Computes velocity structure function given z/L
    """
    from numpy import exp, log, sqrt, arctan, min, asarray, copy
    from util import find

    zet = copy(asarray(z_L, dtype=float))    # conversion to ndarray float
    dzet = 0.35*zet
    dzet[dzet>50] = 50.           # stable
    a = 1.
    b = 3./4.
    c = 5.
    d = 0.35
    psi = -(a*zet + b*(zet - c/d)*exp(-dzet) + b*c/d)
    k = find(zet < 0)         # unstable
    x = (1. - 18.*zet[k])**0.25
    psik = 2.*log((1.+x)/2.) + log((1.+x*x)/2.) - 2.*arctan(x) + 2.*arctan(1.)
    x = (1. - 10.*zet[k])**0.3333
    psic = 1.5*log((1.+x+x**2)/3.) - sqrt(3.)*arctan((1.+2.*x)/sqrt(3.))
    psic += 4.*arctan(1.)/sqrt(3.)
    f = zet[k]**2 / (1.+zet[k]**2)
    psi[k] = (1-f)*psik + f*psic
    return psi

def Le_water(t, sal):
    """
    computes latent heat of vaporization for pure water and seawater
    reference:  M. H. Sharqawy, J. H. Lienhard V, and S. M. Zubair, Desalination
                and Water Treatment, 16, 354-380, 2010. (http://web.mit.edu/seawater/)
    validity: 0 < t < 200 C;   0 <sal <240 g/kg

    usage: Le_w, Le_sw = Le_water(t, sal)

    inputs: T in deg C
            sal in ppt

    output: Le_w, Le_sw in J/g (kJ/kg)

    """

    # polynomial constants
    a = [2.5008991412E+06, -2.3691806479E+03, 2.6776439436E-01,
        -8.1027544602E-03, -2.0799346624E-05]

    Le_w = a[0] + a[1]*t + a[2]*t**2 + a[3]*t**3 + a[4]*t**4
    Le_sw = Le_w*(1 - 0.001*sal)
    return (Le_w/1000.0, Le_sw/1000.0)

def uv2spd_dir(u,v):
    """
    converts u, v meteorological wind components to speed/direction
    where u is velocity from N and v is velocity from E (90 deg)

    usage spd, dir = uv2spd_dir(u, v)

    """
    import numpy as np

    spd = np.zeros_like(u)
    dir = np.zeros_like(u)

    spd = np.sqrt(u**2 + v**2)
    dir = np.arctan2(v, u)*180.0/np.pi

    return (spd, dir)

def spd_dir2uv(spd,dir):
    """
    converts wind speed / direction to u, v meteorological wind components
    where u is velocity from N and v is velocity from E (90 deg)

    usage u, v = uv2spd_dir(spd, dir)

    """
    import numpy as np

    dir2 = (np.copy(dir) + 180.0)*np.pi/180.0
    s = np.sin(dir2)
    c = np.cos(dir2)
    v = -spd*s
    u = -spd*c

    return (u, v)

# This code executes if 'run flux.py' is executed from iPython cmd line
# Uncomment lines below to test particular functions
if __name__ == '__main__':
    import numpy as np
    import matplotlib.pyplot as plt

    # TEST MET FUNCTIONS
#     print 'testing qsat(25,1015) = 31.8037'
#     print qsat(25,1015)

#     print 'testing qsea(18,1013) = 12.5615'
#     print qsea(18,1013)

#     print 'testing qair(10,1010,77) = 5.8665'
#     print qair(10,1010,77)

#     print 'testing rhcalc(14,1013,9.7121) = 98'
#     print rhcalc(14,1013,9.7121)

#     print 'testing grv(45) = 9.8062'
#     print grv(45)

    # TEST PSI FUNCTIONS
#     zet = np.arange(1,501,25)
#     psi = psit_26(zet)
#     print 'psit_26: MATLAB result *10^3'
#     print '-0.0044   -0.0870   -0.2156   -0.3799'
#     print '-0.5734   -0.7922   -1.0337   -1.2959'
#     print '-1.5772   -1.8765   -2.1927   -2.5250'
#     print '-2.8726   -3.2349   -3.6113   -4.0013'
#     print '-4.4044   -4.8202   -5.2484   -5.6886'
#     print psi
#     psi = psiu_26(zet)
#     print 'psiu_26: MATLAB result'
#     print '  -4.3926  -28.9153  -46.4143  -63.9143  -81.4143'
#     print ' -98.9143 -116.4143 -133.9143 -151.4143 -168.9143'
#     print '-186.4143 -203.9143 -221.4143 -238.9143 -256.4143'
#     print '-273.9143 -291.4143 -308.9143 -326.4143 -343.9143'
#     print psi
#     psi = psiu_40(zet)
#     print 'psiu_40: MATLAB result'
#     print '  -4.6926  -36.7153  -61.7143  -86.7143 -111.7143'
#     print '-136.7143 -161.7143 -186.7143 -211.7143 -236.7143'
#     print '-261.7143 -286.7143 -311.7143 -336.7143 -361.7143'
#     print '-386.7143 -411.7143 -436.7143 -461.7143 -486.7143'
#     print psi

max_stars_repo_name: noaa-psd/pyCOARE

max_issues_repo_name: noaa-psd/pyCOARE

max_forks_repo_name: noaa-psd/pyCOARE

reason: import numpy,from numpy