def update_with_reinforcement(feature_ranks): initial_weights = get_actual_weights() from copy import deepcopy backup = deepcopy(initial_weights) pmf1 = calculate_pmf(np.array(initial_weights)) print "mass fx 1 ", pmf1 feature_ranks = np.array(feature_ranks) idx = np.argmax(feature_ranks) val = np.max(np.array(feature_ranks, np.float)) initial_weights[idx] += val initial_weights[idx] /= 2.0 pmf_updated = calculate_pmf(initial_weights) print "mass fx after reinforcement ", pmf_updated if np.sqrt(2) * np.linalg.norm(pmf_updated - pmf1) > 0.02: print "outlier detected, reverting back learning" initial_weights = backup price = initial_weights[0] area = initial_weights[1] bedrooms = initial_weights[2] crime = initial_weights[3] InitialWeights.objects.all().delete() ca = InitialWeights(1, price, area, bedrooms, crime) ca.save()
import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypp.settings") from startpp.models import InitialWeights import xml.etree.ElementTree as ET price = 4.621621622 area = 4.081081081 bedrooms = 3.837837838 crime = 4.567567568 #InitialWeights.objects.all().delete() ca = InitialWeights(1, price, area, bedrooms, crime) ca.save()