Esempio n. 1
0
def jac(train_data, engine, penalty=1e-2):
    w = engine.scorer.parameters
    g = np.zeros_like(w)
    for X, y in train_data:
        jt = engine.run(X)
        jt_cond = engine.observe_target(jt, y)
        fe = loglin.feature_expectations(jt)
        fe_cond = loglin.feature_expectations(jt_cond)
        g += fe_cond - fe
    return g
Esempio n. 2
0
np.round(weights.collapsed()[:10], 3)
cm = loglin.ConditionalModel(models)
w = cm.initial_weights(0)
np.round(np.exp(cm.marg_log_proba(train_data[0][0], w)), 3)
import imp
imp.reload(loglin)
weights = loglin.ModelWeights(num_subtypes)
scorer = loglin.Scorer(models, weights)
engine = loglin.InferenceEngine(scorer)
s, p = engine.run(train_data[0][0])
np.round(s[0], 3)
weights = loglin.ModelWeights(num_subtypes)
scorer = loglin.Scorer(models, weights)
engine = loglin.InferenceEngine(scorer)
junction_tree = engine.run(train_data[0][0])
np.round(loglin.feature_expectations(junction_tree)[:20], 3)
import imp
imp.reload(loglin)
weights = loglin.ModelWeights(num_subtypes)
scorer = loglin.Scorer(models, weights)
engine = loglin.InferenceEngine(scorer)
junction_tree = engine.run(train_data[0][0])
np.round(loglin.feature_expectations(junction_tree)[:20], 3)
weights = loglin.ModelWeights(num_subtypes)
scorer = loglin.Scorer(models, weights)
engine = loglin.InferenceEngine(scorer)
junction_tree = engine.run(train_data[0][0])
np.round(loglin.feature_expectations(junction_tree)[:20], 3)
import imp
imp.reload(loglin)
weights = loglin.ModelWeights(num_subtypes)