public override void TrainDense(IDataset ds) { int nclasses = ds.nClasses(); float miters = PGetf("miters"); int niters = (int)(ds.nSamples() * miters); niters = Math.Max(1000, Math.Min(10000000,niters)); double err = 0.0; Floatarray x = new Floatarray(); Floatarray z = new Floatarray(); Floatarray target = new Floatarray(nclasses); int count = 0; for (int i = 0; i < niters; i++) { int row = i % ds.nSamples(); ds.Output(target, row); ds.Input1d(x, row); TrainOne(z, target, x, PGetf("eta")); err += NarrayUtil.Dist2Squared(z, target); count++; } err /= count; Global.Debugf("info", " {4} n {0} niters={1} eta={2:0.#####} errors={3:0.########}", ds.nSamples(), niters, PGetf("eta"), err, FullName); }
public void InitData(IDataset ds, int nhidden, Intarray newc2i = null, Intarray newi2c = null) { CHECK_ARG(nhidden > 1 && nhidden < 1000000, "nhidden > 1 && nhidden < 1000000"); int ninput = ds.nFeatures(); int noutput = ds.nClasses(); w1.Resize(nhidden, ninput); b1.Resize(nhidden); w2.Resize(noutput, nhidden); b2.Resize(noutput); Intarray indexes = new Intarray(); NarrayUtil.RPermutation(indexes, ds.nSamples()); Floatarray v = new Floatarray(); for (int i = 0; i < w1.Dim(0); i++) { int row = indexes[i]; ds.Input1d(v, row); float normv = (float)NarrayUtil.Norm2(v); v /= normv * normv; NarrayRowUtil.RowPut(w1, i, v); } ClassifierUtil.fill_random(b1, -1e-6f, 1e-6f); ClassifierUtil.fill_random(w2, -1.0f / nhidden, 1.0f / nhidden); ClassifierUtil.fill_random(b2, -1e-6f, 1e-6f); if (newc2i != null) c2i.Copy(newc2i); if (newi2c != null) i2c.Copy(newi2c); }