loss_defs.py 506 B

1234567891011121314151617181920
  1. import numpy as np
  2. import mxnet as mx
  3. from mxnet import nd
  4. import snlay as snlay
  5. def mxmod_arr_loss(x, target, mxmodel):
  6. x_np = np.array(x)
  7. x_np = (x_np - 50.0)/20.0
  8. res2 = mxmodel.predict(x_np)
  9. y_t = nd.array(target, ctx=mx.gpu())
  10. err = nd.abs(y_t - res2)/y_t
  11. err2 = 100*nd.mean(err, axis=1).asnumpy()
  12. return err2
  13. def loss_func(x, target, mats, lams):
  14. spec_ac = snlay.calc_spectrum(x, mats, lams)
  15. diff = np.abs(target - spec_ac)/target
  16. return 100*np.amax(diff)