activeLearningWlinGP1vs2.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #! /usr/bin/python
  2. import numpy
  3. import pickle
  4. import sys
  5. import os
  6. sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),os.pardir))
  7. import helperFunctions
  8. import activeLearningWlinGPprototype
  9. class Classifier(activeLearningWlinGPprototype.ClassifierPrototype):
  10. def __init__(self, sigmaN = 0.00178, loNoise = True, configFile=None):
  11. activeLearningWlinGPprototype.ClassifierPrototype.__init__(self, sigmaN=sigmaN, configFile=configFile)
  12. self.loNoise = helperFunctions.getConfig(configFile, 'activeLearning', 'loNoise', loNoise, 'bool', True)
  13. # x.shape = (number of samples, feat dim)
  14. def calcAlScores(self, x):
  15. loNoise = (self.yUni == -1).any() and self.loNoise
  16. sortedScores = numpy.sort(self.infer(x, loNoise), axis=1)
  17. alScores = numpy.abs(sortedScores[:,-1] - sortedScores[:,-2])
  18. # since we actually want to select min(scores) instead of max(scores), we have to turn the scores around
  19. return numpy.add(numpy.subtract(alScores, numpy.max(alScores))*(-1.0), numpy.finfo(numpy.float32).eps)