protected override void Train(IDataset ds)
{
bool use_junk = PGetb("junk") && !DisableJunk;
int nsamples = ds.nSamples();
if (PExists("%nsamples"))
nsamples += PGeti("%nsamples");
Global.Debugf("info", "Training content classifier");
if (CharClass.IsEmpty)
{
Initialize(CreateClassesFromDataset(ds));
}
if (use_junk/*&& !JunkClass.IsEmpty*/)
{
Intarray nonjunk = new Intarray();
for (int i = 0; i < ds.nSamples(); i++)
if (ds.Cls(i) != jc())
nonjunk.Push(i);
Datasubset nonjunkds = new Datasubset(ds, nonjunk);
CharClass.TrainDense(nonjunkds, PGeti("epochs"));
}
else
{
CharClass.TrainDense(ds, PGeti("epochs"));
}
if (use_junk /*&& !JunkClass.IsEmpty*/)
{
Global.Debugf("info", "Training junk classifier");
Intarray isjunk = new Intarray();
int njunk = 0;
for (int i = 0; i < ds.nSamples(); i++)
{
bool j = (ds.Cls(i) == jc());
isjunk.Push(JunkClass.Classes[Convert.ToInt32(j)]);
if (j) njunk++;
}
if (njunk > 0)
{
MappedDataset junkds = new MappedDataset(ds, isjunk);
JunkClass.TrainDense(junkds, PGeti("epochs"));
}
else
{
Global.Debugf("warn", "you are training a junk class but there are no samples to train on");
JunkClass.DeleteLenet();
}
}
PSet("%nsamples", nsamples);
}