Пример #1
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'best_width': float(width),
                                     'best_param': float(param),
                                     'best_scale': float(best_scale),
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))
Пример #2
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))

    if int(features.get_num_vectors()) > 100 and learn == "ML2":
        return HttpResponse(
            json.dumps({
                "status":
                ("Model Selection "
                 "allowed only for less than 100 samples due to computational costs"
                 )
            }))

    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(
            features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(
        json.dumps({
            'status': 'ok',
            'best_width': float(width),
            'best_param': float(param),
            'best_scale': float(best_scale),
            'domain': [np.min(z), np.max(z)],
            'z': z.tolist()
        }))
Пример #3
0
def classify(request):
    try:
        features, labels = get_binary_features(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        kernel = get_kernel(request, features)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        lik = get_likelihood(request)
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    try:
        learn = request.POST["learn"]
    except ValueError as e:
        return HttpResponse(json.dumps({"status": e.message}))
    
    if int(features.get_num_vectors()) > 100 and learn == "ML2":
        return HttpResponse(json.dumps({"status": ("Model Selection " 
            "allowed only for less than 100 samples due to computational costs")}))

    try:
        scale = float(request.POST["scale"])
    except:
        raise ValueError("Scale is not correct")
    try:
        domain = json.loads(request.POST['axis_domain'])
        x, y, z, width, param, best_scale = gaussian_process.classify_gp(features, labels, kernel, domain, lik, learn, scale)
    except Exception as e:
        return HttpResponse(json.dumps({"status": repr(e)}))

    return HttpResponse(json.dumps({ 'status': 'ok',
                                     'best_width': float(width),
                                     'best_param': float(param),
                                     'best_scale': float(best_scale),
                                     'domain': [np.min(z), np.max(z)],
                                     'z': z.tolist() }))