def test_knot_candidates(): np.random.seed(10) m = 1000 x = np.random.normal(size=m) p = np.random.normal(size=m) p[np.random.binomial(p=.1, n=1,size=m)==1] = 0. x[np.random.binomial(p=.1, n=1,size=m)==1] = 0. predictor = PredictorDependentData.alloc(x) candidates, candidates_idx = predictor.knot_candidates(p, 5, 10, 0, 0, set()) assert_array_equal(candidates, x[candidates_idx]) assert_equal(len(candidates), len(set(candidates)))
def test_knot_candidates(): np.random.seed(10) m = 1000 x = np.random.normal(size=m) p = np.random.normal(size=m) p[np.random.binomial(p=.1, n=1, size=m) == 1] = 0. x[np.random.binomial(p=.1, n=1, size=m) == 1] = 0. predictor = PredictorDependentData.alloc(x) candidates, candidates_idx = predictor.knot_candidates( p, 5, 10, 0, 0, set()) assert_array_equal(candidates, x[candidates_idx]) assert_equal(len(candidates), len(set(candidates)))
def form_inputs(x, B, p, knot, candidates, y, w): # Formulate the inputs for the fast version m, q = B.shape max_terms = q + 2 workings = [] n_outcomes = w.shape[1] for _ in range(n_outcomes): working = KnotSearchWorkingData.alloc(max_terms) workings.append(working) outcome = MultipleOutcomeDependentData.alloc(y, w, m, n_outcomes, max_terms, 1e-16) for j in range(B.shape[1]): outcome.update_from_array(B[:, j]) predictor = PredictorDependentData.alloc(x) constant = KnotSearchReadOnlyData(predictor, outcome) return KnotSearchData(constant, workings, q)
def form_inputs(x, B, p, knot, candidates, y, w): # Formulate the inputs for the fast version m, q = B.shape max_terms = q + 2 workings = [] n_outcomes = w.shape[1] for _ in range(n_outcomes): working = KnotSearchWorkingData.alloc(max_terms) workings.append(working) outcome = MultipleOutcomeDependentData.alloc( y, w, m, n_outcomes, max_terms, 1e-16) for j in range(B.shape[1]): outcome.update_from_array(B[:, j]) predictor = PredictorDependentData.alloc(x) constant = KnotSearchReadOnlyData(predictor, outcome) return KnotSearchData(constant, workings, q)