public Params RunEpoch(DSet <Example> trainSet, ISGDModel <Params> model, Params curParams) { Params accumulatedParams = trainSet.Fold( (wb, e) => { return(model.Update(wb, e)); }, model.AddParams, curParams); var averagedParams = model.ScaleParams(accumulatedParams, (float)(1.0 / trainSet.NumPartitions)); return(averagedParams); }
public float GetAccuracy(DSet <Example> dataset, ISGDModel <Params> model, Params curParams) { int hits = dataset.Fold((c, ex) => model.Predict(curParams, ex) == ex.Label ? c + 1 : c, (c1, c2) => c1 + c2, 0); return((float)hits / dataset.Count()); }
/// <summary> /// The "prior" of a dataset is simply the number of positive examples divided by the size of the dataset. /// </summary> /// <param name="examples"></param> /// <returns></returns> private static float GetPrior(DSet <Example> examples) { long hits = examples.Fold((c, ex) => ex.Label == 1.0f ? c + 1 : c, (c1, c2) => c1 + c2, 0); return((float)hits / examples.Count()); }