Exemple #1
0
def apple_ml():
    text = request.args.get('news_text')
    model = request.args.get('model')

    # condintional checks
    result = prediction(text, model, 'Apple')
    return result
Exemple #2
0
def value():
    parser = reqparse.RequestParser()
    parser.add_argument('Country', type=str)
    parser.add_argument('Variety', type=str)
    parser.add_argument('Winery', type=str)
    args = parser.parse_args()
    country = args.get('Country')
    variety = args.get('Variety')
    winery = args.get('Winery')
    price = prediction(country, variety, winery)
    recomm = recommendation(country, variety, winery)
    return jsonify([price, recomm]), 200
Exemple #3
0
def upload_image():
    if 'file' not in request.files:
        flash('No file part')
        return redirect(request.url)
    file = request.files['file']
    if file.filename == '':
        flash('No image selected for uploading')
        return redirect(request.url)
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        pred = prediction(filename)
        flash('The prediction is ' + pred)
        return render_template('upload.html', filename=filename)
    else:
        flash('Allowed image types are -> png, jpg, jpeg, gif')
        return redirect(request.url)
def index():
    filename = 'nopic.jpg'
    if request.method == 'POST':
        image = request.files['image']
        if image and allowed_file(image.filename):
            name, ext = os.path.splitext(image.filename)
            filename = f'meme_{name}{ext}'
            image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            image_model = request.form.get('image_model')
            text_model = request.form.get('text_model')
            pred = prediction(filename, image_model, text_model)[0]
            print(f"prediction is {pred}")
            flash('Image successfully uploaded and displayed below')
            return render_template("index.html",
                                   pred=pred,
                                   is_post=True,
                                   filename=filename)
        else:
            flash('Allowed image types are -> png, jpg, jpeg, gif')
            return redirect(request.url)
    else:
        return render_template("index.html",
                               is_post=False,
                               filename='nopic.jpg')
Exemple #5
0
def run(parameterContainer):
    # Open the source shapefile.
    shapefile = osgeo.ogr.Open(parameterContainer.targetFileLocation, 1)
    time = parameterContainer.timeStep
    layer = shapefile.GetLayer(0)
    spatialReference = layer.GetSpatialRef()

    driver = osgeo.ogr.GetDriverByName("ESRI Shapefile")

    controlProgramA = getControlProgram(parameterContainer.categories['A'])
    controlProgramB = getControlProgram(parameterContainer.categories['B'])
    controlProgramC = getControlProgram(parameterContainer.categories['C'])
    controlProgramD = getControlProgram(parameterContainer.categories['D'])
    controlProgramE = getControlProgram(parameterContainer.categories['E'])
    controlProgramF = getControlProgram(parameterContainer.categories['F'])

    print parameterContainer.categories['A']
    print parameterContainer.categories['B']
    print parameterContainer.categories['C']
    print parameterContainer.categories['D']
    print parameterContainer.categories['E']
    print parameterContainer.categories['F']

    print controlProgramA
    print controlProgramB
    print controlProgramC
    print controlProgramD
    print controlProgramE
    print controlProgramF

    for t in range(time):
        fieldDef = osgeo.ogr.FieldDefn("no_4_"+str(t), osgeo.ogr.OFTReal)
        fieldDef.SetWidth(5)
        layer.CreateField(fieldDef)
        fieldDef = osgeo.ogr.FieldDefn("li_4_"+str(t), osgeo.ogr.OFTReal)
        fieldDef.SetWidth(5)
        layer.CreateField(fieldDef)
        fieldDef = osgeo.ogr.FieldDefn("mo_4_"+str(t), osgeo.ogr.OFTReal)
        fieldDef.SetWidth(5)
        layer.CreateField(fieldDef)
        fieldDef = osgeo.ogr.FieldDefn("he_4_"+str(t), osgeo.ogr.OFTReal)
        fieldDef.SetWidth(5)
        layer.CreateField(fieldDef)
        fieldDef = osgeo.ogr.FieldDefn("STH_4_"+str(t), osgeo.ogr.OFTReal)
        fieldDef.SetWidth(5)
        layer.CreateField(fieldDef)


    for i in range(layer.GetFeatureCount()):
        feature=layer.GetFeature(i)
        layer.SetFeature(feature)

        feature.SetField("STH_m4", randint(0,100))
        #now estimate the intensity at t=0

        if feature.GetField("CATEGORY") == "A":


            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramA,controlProgramA,controlProgramA,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)




        elif feature.GetField("CATEGORY") == "B":


            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramB,controlProgramB,controlProgramB,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)




        elif feature.GetField("CATEGORY") == "C":


            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramC,controlProgramC,controlProgramC,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)



        elif feature.GetField("CATEGORY") == "D":

            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramD,controlProgramD,controlProgramD,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)




        elif feature.GetField("CATEGORY") == "E":


            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramE,controlProgramE,controlProgramE,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)




        elif feature.GetField("CATEGORY") == "F":

            for t in range(time):
                if t==0:
                    STH_m4=feature.GetField("STH_m4")
                    cs1=model4no(float(STH_m4))
                    cs2=model4light(float(STH_m4))
                    cs3=model4moderate(float(STH_m4))
                    cs4=model4high(float(STH_m4))
                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)
                    cs=np.array([cs1,cs2,cs3,cs4])


                    #end of the loop with t

            value=prediction(time,cs,controlProgramF,controlProgramF,controlProgramF,breakpoint1,breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:

                    cs1=value[t][0]
                    cs2=value[t][1]
                    cs3=value[t][2]
                    cs4=value[t][3]

                    feature.SetField("no_4_"+str(t), cs1)
                    feature.SetField("li_4_"+str(t), cs2)
                    feature.SetField("mo_4_"+str(t), cs3)
                    feature.SetField("he_4_"+str(t), cs4)
                    feature.SetField("STH_4_"+str(t), cs2+cs3+cs4)


        layer.SetFeature(feature)
        feature.Destroy()
    # All done.
    shapefile.Destroy()
Exemple #6
0
    W = np.identity(6)  # 6*6, set to be identity matrix
    mu = np.zeros(
        (4, 4, u.shape[1]))  # 4*4*1106 for 0027.npz, 4*4*500 for 0042.npz
    sigma = np.zeros(
        (6, 6, u.shape[1]))  # 6*6*1106 for 0027.npz, 6*6*500 for 0042.npz
    T_i2w = np.zeros(
        (4, 4, u.shape[1]))  # 4*4*1106 for 0027.npz, 4*4*500 for 0042.npz
    T_i2w[:, :, 0] = np.linalg.inv(
        copy.deepcopy(mu_t_t)
    )  # 4*4*1106 for 0027.npz, 4*4*500 for 0042.npz, pose from imu to world
    mu[:, :, 0] = copy.deepcopy(mu_t_t)
    sigma[:, :, 0] = copy.deepcopy(sigma_t_t)
    for t in range(1, u.shape[1]):
        u_t = u[:, t]  # 6*1
        tau_t = tau[t - 1]  # 1
        mu_tp1_t, sigma_tp1_t = prediction(u_t, tau_t, mu_t_t, sigma_t_t, W)
        mu[:, :, t] = copy.deepcopy(mu_tp1_t)
        sigma[:, :, t] = copy.deepcopy(sigma_tp1_t)
        T_i2w[:, :, t] = np.linalg.inv(copy.deepcopy(mu_tp1_t))  # pose
        mu_t_t = copy.deepcopy(mu_tp1_t)
        sigma_t_t = copy.deepcopy(sigma_tp1_t)

# (b) Landmark Mapping via EKF Update
    time = features.shape[2]  # time
    m = features.shape[1]  # the # of landmark
    temp1 = np.array([-1, -1, -1,
                      -1])  # to determine whether the feature is observed
    sigma_t_j = np.identity(3)  # 3*3
    V = np.identity(4)  # 4*4
    D = np.row_stack((np.identity(3), np.zeros(
        (1, 3))))  # dilation matrix   4*3
def run(parameterContainer):
    # Open the source shapefile.
    shapefile = osgeo.ogr.Open(parameterContainer.targetFileLocation, 1)
    time = parameterContainer.timeStep
    layer = shapefile.GetLayer(0)

    driver = osgeo.ogr.GetDriverByName("ESRI Shapefile")

    #MH I am not sure about the following lines if they are needed since they need to be there before running the model?
    #Also the total prevalences are created randomly further down but they also need to be given beforehand, I guess?
    #define a new field called CATEGORY for user to define
    #fieldDef = osgeo.ogr.FieldDefn("CATEGORY", osgeo.ogr.OFTString)
    #fieldDef.SetWidth(10)
    #targetLayer.CreateField(fieldDef)

    #
    #this is the input of model 3
    #fieldDef = osgeo.ogr.FieldDefn("HW", osgeo.ogr.OFTString) #total prevalence of hookworm in model 3
    #fieldDef.SetWidth(5)
    #targetLayer.CreateField(fieldDef)

    #fieldDef = osgeo.ogr.FieldDefn("TT", osgeo.ogr.OFTString) #total prevalence of hookworm in model 3
    #fieldDef.SetWidth(5)
    #targetLayer.CreateField(fieldDef)

    #fieldDef = osgeo.ogr.FieldDefn("AL", osgeo.ogr.OFTString) #total prevalence of hookworm in model 3
    #fieldDef.SetWidth(5)
    #targetLayer.CreateField(fieldDef)

    words = ['HWNoyear', 'HWLiyear', 'HWModyear', 'HWHiyear', 'HWyear','TTNoyear','TTLiyear','TTMoyear','TTHiyear','TTyear','ALNoyear','ALLiyear','ALMoyear','ALHiyear','ALyear']
    for i in words:
        for t in range(time):
            fieldDef = osgeo.ogr.FieldDefn(i+str(t), osgeo.ogr.OFTReal)
            #fieldDef.SetWidth(5)
            layer.CreateField(fieldDef)


    for i in range(layer.GetFeatureCount()):
        feature=layer.GetFeature(i)
        layer.SetFeature(feature)

        #this generates randome integer value from 0 to 100 for simulation. #MH: Do we need this or should this be given by the user?
        
	#feature.SetField("HW", randint(0,100))
        #feature.SetField("TT", randint(0,100))
        #feature.SetField("AL", randint(0,100))
	#feature.SetField("STH", feature.GetField("STH")*100)

#<<<<<<< HEAD
	feature.SetField("HW", feature.GetField("HW")*1)
	feature.SetField("Tt", feature.GetField("Tt")*1)
	feature.SetField("Al", feature.GetField("Al")*1)
#=======
#	feature.SetField("HW", feature.GetField("HW")*100)
#	feature.SetField("TT", feature.GetField("TT")*100)
#	feature.SetField("AL", feature.GetField("AL")*100)
#>>>>>>> 533be90ebbafee6ae561cd32f60004fe6367577f


        #now estimate the intensity at t=0
        if feature.GetField("CATEGORY") == "A":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)


        elif feature.GetField("CATEGORY") == "B":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)




        elif feature.GetField("CATEGORY") == "C":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)


        elif feature.GetField("CATEGORY") == "D":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)


        elif feature.GetField("CATEGORY") == "E":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)



        elif feature.GetField("CATEGORY") == "F":
            for t in range(time):
                if t==0:
                    HW=feature.GetField("HW")
                    TT=feature.GetField("TT")
                    AL=feature.GetField("AL")
                    #define condition state for Hookworm
                    cs1_HW=model3_no_HW(float(HW))
                    cs2_HW=model3_light_HW(float(HW))
                    cs3_HW=model3_moderate_HW(float(HW))
                    cs4_HW=model3_high_HW(float(HW))
                    #define condition state for T.trichiura
                    cs1_Tt=model3_no_Tt(float(TT))
                    cs2_Tt=model3_light_Tt(float(TT))
                    cs3_Tt=model3_moderate_Tt(float(TT))
                    cs4_Tt=model3_high_Tt(float(TT))
                    #define condition state for A.Alumbricoin
                    cs1_Al=model3_no_Al(float(AL))
                    cs2_Al=model3_light_Al(float(AL))
                    cs3_Al=model3_moderate_Al(float(AL))
                    cs4_Al=model3_high_Al(float(AL))
                    #for anySTH
                    anySTH=model3_anySTH(float(HW),float(TT),float(AL))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    cs_HW=np.array([cs1_HW,cs2_HW,cs3_HW,cs4_HW])
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    cs_Tt=np.array([cs1_Tt,cs2_Tt,cs3_Tt,cs4_Tt])
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)
                    #define conditionstate for compute with numpy package
                    cs_Al=np.array([cs1_Al,cs2_Al,cs3_Al,cs4_Al])
                    #end of the loop with t


            value_HW=prediction(time,cs_HW,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Tt=prediction(time,cs_Tt,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)
            value_Al=prediction(time,cs_Al,mtp3.mtp_cp1,mtp3.mtp_cp1,mtp3.mtp_cp1,breakpoint1,breakpoint2)


            for t in (range(time)):
                if t > 0:
                    cs1_HW=value_HW[t][0]
                    cs2_HW=value_HW[t][1]
                    cs3_HW=value_HW[t][2]
                    cs4_HW=value_HW[t][3]
                    cs1_Tt=value_Tt[t][0]
                    cs2_Tt=value_Tt[t][1]
                    cs3_Tt=value_Tt[t][2]
                    cs4_Tt=value_Tt[t][3]
                    cs1_Al=value_Al[t][0]
                    cs2_Al=value_Al[t][1]
                    cs3_Al=value_Al[t][2]
                    cs4_Al=value_Al[t][3]
                    #for anySTH
                    anySTH=model3_anySTH((cs2_HW+cs3_HW+cs4_HW),(cs2_Tt+cs3_Tt+cs4_Tt),(cs2_Al+cs3_Al+cs4_Al))
                    #assign value of cs to each field in the shapefile
                    #for hookworm
                    feature.SetField("HWNoyear"+str(t), cs1_HW)
                    feature.SetField("HWLiyear"+str(t), cs2_HW)
                    feature.SetField("HWModyear"+str(t), cs3_HW)
                    feature.SetField("HWHiyear"+str(t), cs4_HW)
                    feature.SetField("HWyear"+str(t), cs2_HW+cs3_HW+cs4_HW)
                    #for T.trichiura
                    feature.SetField("TTNoyear"+str(t), cs1_Tt)
                    feature.SetField("TTLiyear"+str(t), cs2_Tt)
                    feature.SetField("TTMoyear"+str(t), cs3_Tt)
                    feature.SetField("TTHiyear"+str(t), cs4_Tt)
                    feature.SetField("TTyear"+str(t), cs2_Tt+cs3_Tt+cs4_Tt)
                    feature.SetField("ALNoyear"+str(t), cs1_Al)
                    feature.SetField("ALLiyear"+str(t), cs2_Al)
                    feature.SetField("ALMoyear"+str(t), cs3_Al)
                    feature.SetField("ALHiyear"+str(t), cs4_Al)
                    feature.SetField("ALyear"+str(t), cs2_Al+cs3_Al+cs4_Al)
                    #for anySTH
                    feature.SetField("STHyear"+str(t), anySTH)

        layer.SetFeature(feature)
        feature.Destroy()
    # All done.
    shapefile.Destroy()
def run(parameterContainer):
    # Open the source shapefile.
    shapefile = osgeo.ogr.Open(parameterContainer.targetFileLocation, 1)
    time = parameterContainer.timeStep
    layer = shapefile.GetLayer(0)
    spatialReference = layer.GetSpatialRef()

    driver = osgeo.ogr.GetDriverByName("ESRI Shapefile")

    controlProgramA = getControlProgram(parameterContainer.categories['A'])
    controlProgramB = getControlProgram(parameterContainer.categories['B'])
    controlProgramC = getControlProgram(parameterContainer.categories['C'])
    controlProgramD = getControlProgram(parameterContainer.categories['D'])
    controlProgramE = getControlProgram(parameterContainer.categories['E'])
    controlProgramF = getControlProgram(parameterContainer.categories['F'])

    print parameterContainer.categories['A']
    print parameterContainer.categories['B']
    print parameterContainer.categories['C']
    print parameterContainer.categories['D']
    print parameterContainer.categories['E']
    print parameterContainer.categories['F']

    print controlProgramA
    print controlProgramB
    print controlProgramC
    print controlProgramD
    print controlProgramE
    print controlProgramF

    words = ['STHyear', 'noyear', 'lightyear', 'moderyear', 'highyear']
    for i in words:
        for t in range(time):
            fieldDef = osgeo.ogr.FieldDefn(i + str(t), osgeo.ogr.OFTReal)
            #fieldDef.SetWidth(5)
            layer.CreateField(fieldDef)

    for i in range(layer.GetFeatureCount()):
        feature = layer.GetFeature(i)
        layer.SetFeature(feature)

        #feature.SetField("STH", randint(0,100))
        #<<<<<<< HEAD
        feature.SetField("STH", feature.GetField("STH") * 1)
        #=======
        #	feature.SetField("STH", feature.GetField("STH")*100)
        #>>>>>>> 533be90ebbafee6ae561cd32f60004fe6367577f
        #now estimate the intensity at t=0

        if feature.GetField("CATEGORY") == "A":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(STH)
                    cs2 = model4light(STH)
                    cs3 = model4moderate(STH)
                    cs4 = model4high(STH)
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramA, controlProgramA,
                               controlProgramA, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        elif feature.GetField("CATEGORY") == "B":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(float(STH))
                    cs2 = model4light(float(STH))
                    cs3 = model4moderate(float(STH))
                    cs4 = model4high(float(STH))
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramB, controlProgramB,
                               controlProgramB, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        elif feature.GetField("CATEGORY") == "C":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(float(STH))
                    cs2 = model4light(float(STH))
                    cs3 = model4moderate(float(STH))
                    cs4 = model4high(float(STH))
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramC, controlProgramC,
                               controlProgramC, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        elif feature.GetField("CATEGORY") == "D":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(float(STH))
                    cs2 = model4light(float(STH))
                    cs3 = model4moderate(float(STH))
                    cs4 = model4high(float(STH))
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramD, controlProgramD,
                               controlProgramD, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        elif feature.GetField("CATEGORY") == "E":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(float(STH))
                    cs2 = model4light(float(STH))
                    cs3 = model4moderate(float(STH))
                    cs4 = model4high(float(STH))
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramE, controlProgramE,
                               controlProgramE, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        elif feature.GetField("CATEGORY") == "F":

            for t in range(time):
                if t == 0:
                    STH = feature.GetField("STH")
                    cs1 = model4no(float(STH))
                    cs2 = model4light(float(STH))
                    cs3 = model4moderate(float(STH))
                    cs4 = model4high(float(STH))
                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)
                    cs = np.array([cs1, cs2, cs3, cs4])

                    #end of the loop with t

            value = prediction(time, cs, controlProgramF, controlProgramF,
                               controlProgramF, breakpoint1, breakpoint2)
            #value=prediction(time,cs,mtp4.mtp_cp1,mtp4.mtp_cp1,mtp4.mtp_cp1,breakpoint1,breakpoint2)

            for t in (range(time)):
                if t > 0:

                    cs1 = value[t][0]
                    cs2 = value[t][1]
                    cs3 = value[t][2]
                    cs4 = value[t][3]

                    feature.SetField("noyear" + str(t), cs1)
                    feature.SetField("lightyear" + str(t), cs2)
                    feature.SetField("moderyear" + str(t), cs3)
                    feature.SetField("highyear" + str(t), cs4)
                    feature.SetField("STHyear" + str(t), cs2 + cs3 + cs4)

        layer.SetFeature(feature)
        feature.Destroy()
    # All done.
    shapefile.Destroy()
Exemple #9
0
def main():

    try:
        # Read account id and private from environment variables
        #account_id = os.environ['EINSTEIN_VISION_ACCOUNT_ID']
        #private_key = os.environ['EINSTEIN_VISION_PRIVATE_KEY'].decode('string_escape')

        account_id = '*****@*****.**'
        private_key = """
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEApndK94LOWGJATet94opTPR4kjv0j66LrhsQtzyG+Ji6pVrJa
Nv6HEVpbE4Iy1cZJ4IyyeQ0yUMNDcJ4E0HZVT514ckNhJWIS0pO9lCrFsWNabc+7
U2q7nL4/7iS5QGvbFU37E1l7Vwtx2Ic0/Xm7czSHngALs9j0IWE6CGbaJfKosJKZ
CCsVIF6hnRV5/mjDWhav8m6gEeqqMPhZ6in74sPTEd/r5xXJ7hQu1lbtb2IyMNN6
K0o3gGPSiREvPvkh8KPWOtqzuMH+LHXvb/TPMCDV10q2/5b05NJ9sEnVQ9Rh54R/
EibKaBvNLBAmVm3IzW4sIFjE4bn8OIG11xz2CQIDAQABAoIBAQCjOO0k6/lv6Eat
IG76pi8gCmJGYifKcKEIL2vLYYaU4cPg4lha/A9sEHClHFDEE/10VADbePkQ/6Us
04Rc8uqLehgT0cV7ZkKWf46vrZDSclzEt58yF8GF23XMB+4tIJRcu22od2Dc5Lfo
XAq1T5thRuyDHABdhCk8YZ0Jh+/2q/L+k9utFZuHkHfBfKrzzpDktFu1vh4qK2xi
ZCu+3/P72oZ5OUKz/kheDP2NTKJiIjt3HPxXuIBXDDlarVb+8YA05KIYOvSaSH0b
r1Odm4CRJbJkkCkXp+5GPxuJRI5Iz4kXfJO4nQEPYDelTFW0c9e1Rwn4adJUrs7s
+juOarRRAoGBAPBWvVnDm9Ito7urQhWXinOGfQHIfujltWmtzV6Pq8F+MDLt9yfc
TWdenVx1N951U3l26bNtB7tjnJKFaYefX+Ox+N1eAVGdoAm6SqsN/hsoIIUI5FzR
C0QSEDLTYEfk/pJrqQ7DBgtWkNc9OMyGvOzguckMLfE2HobVzpSg+y63AoGBALFQ
OoXPOSEEbyUKXUc9CEQ+mcIjZUlILxtUA2Pgbh9BglOWmKzqQUS6b6cK0rrX8Aoy
pyMiDxPRYudzUYixJC+jeJKqmeC9FA/OXmPmHkswyVdAQ1X91+rVu7xmcv7jSCeD
nGr7Yp226fRlq6kJzPPKi19mYM34spD0U9WxEEE/AoGBAOmzfrY9llR/GrqPYlg6
nl+NxBqqynVPgOM9JPkxfVNOkDHF4dJ5zy6X+y5/sQ75SW1QKxnVCHK3/vUfE6nU
WNrBIXyoP2IMgyVSZ+8DUTc5Ar46Ek0K3QiZA/VYQ0RFsSHR3HdFPqhhyb/ygTuo
PSedsiqEVFw8QtzcJN+z1evrAoGABflN/3Qb2KDtnbHbsqq7vJDfXUsT/oQQEjui
YZsOGr96RJauTiUWTdp6KIaU0vazf6R1PRnIqEJFssaP2KsfLPu09DwLMycrpdyu
EW+PVbkvD2F640rKG39X8+D/vtapd6tXecM+b1HaUAGc5vUNkqkgSPaKDGZ0na2d
pXVxtsECgYBi/XuDRPviQuZE7nWGRhKOSKmQZ2qy/6zBaUGU1m/ArUACmU6NuI2t
KeF7J38BAtTCrhpp5whWW7Uooe8FxvhWNe+CkxdNoNoz5GyFUAl4IKfb/HX5nUkL
Xpd2APOZoLNf2gJZCycDmratthie+Ex9YULGSxYFgAlg3Ev5tQz20g==
-----END RSA PRIVATE KEY-----
"""

        # Set expiry time
        expiry = int(time.time()) + (15 * 60)

        # Generate an assertion using RSA private key
        assertion = jwt_helper.generate_assertion(account_id, private_key,
                                                  expiry)

        # Obtain oauth token
        token = token_generator.generate_token(assertion)
        response = token.json()

        # If there is no token print the response
        if 'access_token' not in response:
            raise ValueError(
                "Access token generation failed. Received reply: \"{}\"".
                format(response))
        else:
            # Collect the access token from response
            access_token = response['access_token']

        # Upload the dataset to einstein.ai
        DS = dataset(access_token=access_token)
        #path = 'https://raw.githubusercontent.com/kaul-vineet/socialstudio-ml/master/data/intent_tagging.csv'
        #response = DS.create_intent_dataset(path)
        #print(json.dumps(response, indent=4, sort_keys=True))

        # Train the model on einstein.ai []
        id = '1127772'
        #DS = dataset(access_token=access_token)
        response = DS.train_dataset(id)
        #if('available' in response):
        #    print(json.dumps(response, indent=4, sort_keys=True))
        #else:
        #    print('Response status ok?: ' + str(response.ok))
        #    print(json.dumps(response.text, indent=4, sort_keys=True))

        # Check the model training status on einstein.ai []
        id = 'YRVFEBIDWGX4I6EBKDOFU5KRQM'
        #response = DS.get_train_status(id)
        #print(json.dumps(response, indent=4, sort_keys=True))
        #data = json.loads(json.dumps(response))
        #print ('************ THE MODEL TRAINING IS IN PROGRESS ************')
        #while data['status'] != 'SUCCEEDED':
        #    print ('THE MODEL STATUS IS :' + data['status'])
        #    time.sleep(30)
        #else:
        #    print ('THE MODEL STATUS IS :' + data['status'] + ' WITH LEARNING RATE OF ' + str(data['learningRate']))

        # Check the predictions on einstein.ai []
        model_id = 'YRVFEBIDWGX4I6EBKDOFU5KRQM'
        document = 'hey guys, im a black trans creative named wondy!! i make art, unfortunately my account was suspended and i lost my 3.5k following and clientele :( please retweet this post so i can get my product back out there as this is my income!! any support is phenomenal'
        predict = prediction(access_token=access_token)
        response = predict.predict_social_tag(document, model_id)
        probabilities = response['probabilities']
        max_prob = 0
        max_tag = ''
        for x in probabilities:
            if max_prob < x['probability'] * 100:
                max_prob = x['probability'] * 100
                max_tag = str(x['label'])
        print('There is ' + str(max_prob) + ' probability that this is ' +
              max_tag + ' post.')

    except Exception as e:
        traceback.print_exc()
# Preprocessing data
split_datapoint = 5000
smoothing_window_size = 1000

pp_data = PreProc(df)
pp_data.splitdata(split_datapoint)
pp_data.normalize_smooth(smoothing_window_size, EMA=0.0, gamma=0.1)

# =============================================================================
# Define and apply LSTM
# =============================================================================

# Define hyperparameters
D = 1                           # Dimensionality of the data. Since our data is 1-D this would be 1
num_unrollings = 50             # Number of time steps you look into the future.
batch_size = 500                # Number of samples in a batch
num_nodes = [200, 200, 150]     # Number of hidden nodes in each layer of the deep LSTM stack we're using
n_layers = len(num_nodes)       # number of layers
dropout = 0.2                   # Dropout amount

# Run LSTM
x_axis_seq, predictions_over_time = LSTM(pp_data, D, num_unrollings, batch_size, num_nodes, n_layers, dropout)

# =============================================================================
# Visualisation of the results
# =============================================================================

# Visualisation
best_prediction_epoch = 28      # Replace this with the epoch that you got the best results when running the plotting code
prediction(df, pp_data, x_axis_seq, predictions_over_time, best_prediction_epoch)
)
pic = plt.imread("xception_model_colormap.png")
st.sidebar.image(pic, caption="Model classes", use_column_width=True)
st.set_option('deprecation.showfileUploaderEncoding', False)
img_file = st.file_uploader("Upload the input image : ",
                            type=['jpg', 'jpeg', 'png'])

if img_file is not None:
    img = plt.imread(img_file, 0)
    st.image(img, caption="Input Image", use_column_width=True)

    # # instantiating the semantic segmentation class
    # segment_image = semantic_segmentation()

    # # loading the model deeplabv3+ trained on pascal voc dataset.
    # segment_image.load_pascalvoc_model(DATA_URL)

    # # performing the segmentation on the input image
    # segment_image.segmentAsPascalvoc(img_file, output_image_name = "output_images/out.jpg")
    # out = plt.imread("output_images/out.jpg", 0)

    # # performing the segmentation on the input image with overlay
    # segment_image.segmentAsPascalvoc(img_file, output_image_name = "output_images/out_overlay.jpg", overlay = True)
    # out_overlay = plt.imread("output_images/out_overlay.jpg")

    out, out_overlay = prediction(img_file)

    col1, col2 = st.beta_columns(2)
    col1.image(out, caption="Segmented Image", use_column_width=True)
    col2.image(out_overlay, caption="Overlay", use_column_width=True)
Exemple #12
0
        is_reuse=False,
        with_loss=False,
        test_input=True)

#==========================
#Start training
#==========================
if opt.training:
    training(opt, m_trainer, losses, losses_eval, data_dict, data_dict_eval,
             output, output_eval, global_step, coord_pair, incr_global_step)

#==========================
#Start evaluation
#==========================
elif opt.evaluation:
    evaluate(opt, evaluate_name, m_trainer, losses_eval, data_dict_eval,
             output_eval, global_step, coord_pair)

#==========================
#Start Prediction
#==========================
elif opt.prediction:
    prediction(opt, m_trainer, data_dict_dom, output_dom)

#==========================
#Start training cycle GAN
#==========================
elif opt.cycleGAN:
    cycleGAN_training(opt, m_trainer, gen_loss, disc_loss, gen_loss_bw,
                      disc_loss_bw)