Esempio n. 1
0
def createPlant_c3grass_CMF(c3grass):
    """             
    Implements a specific plant setup with C3 values.
    """
    print 'C3 grass'
    et = PMF.ET_ShuttleworthWallace(c3grass.w_leafwidth, c3grass.z_0w,
                                    c3grass.z_0g, c3grass.z_w,
                                    c3grass.r_st_min, c3grass.sigma_b,
                                    c3grass.c_int, c3grass.C_0,
                                    c3grass.factor_p)
    print 'Evapotranspiration: Shuttleworth-Wallace'
    biomass = PMF.Biomass_LUE_CO2_Soltani(c3grass.RUE, c3grass.C_0,
                                          c3grass.factor_b, c3grass.CO2_ring)
    print 'Biomass: Light-use-efficiency concept with CO2 response'
    development = PMF.Development(c3grass.stage, c3grass.R_p, c3grass.R_v,
                                  c3grass.photo_on_off, c3grass.verna_on_off)
    nitrogen = PMF.Nitrogen()
    print 'No nitrogen uptake'
    interception = PMF.Intercept_Evapo(c3grass.w_leafwidth, c3grass.z_0w,
                                       c3grass.z_0g, c3grass.z_w,
                                       c3grass.r_st_min, c3grass.sigma_b,
                                       c3grass.c_int)
    net_radiation = PMF.Net_Radiation(c3grass.albedo_m, c3grass.Cr)
    water = PMF.Waterstress_Feddes()
    print 'Waterstress: Feddes'
    layer = PMF.SoilLayer()
    print 'layer'
    return makePlant(PMF.Plant,
                     et=et,
                     biomass=biomass,
                     development=development,
                     nitrogen=nitrogen,
                     interception=interception,
                     net_radiation=net_radiation,
                     water=water,
                     layer=layer,
                     FRDR=c3grass.FRDR,
                     stem_specific_factor=c3grass.stem_specific_factor,
                     stem_growth_max=c3grass.stem_growth_max,
                     max_height=c3grass.max_height,
                     CO2_ring=c3grass.CO2_ring,
                     max_depth=c3grass.max_depth,
                     root_growth=c3grass.root_growth,
                     leaf_specific_weight=c3grass.leaf_specific_weight,
                     tbase=c3grass.tbase,
                     fact_sen=c3grass.fact_sen,
                     shoot_percent=c3grass.shoot_percent,
                     root_percent=c3grass.root_percent,
                     leaf_percent=c3grass.leaf_percent,
                     stem_percent=c3grass.stem_percent,
                     storage_percent=c3grass.storage_percent,
                     plantN=c3grass.plantN,
                     pressure_threshold=c3grass.pressure_threshold)
Esempio n. 2
0
def createPlant_wheat_SWC(**args):
    """             
    Implements a specific plant setup with summer wheat values.
    """
    print 'wheat'
    et = PMF.ET_ShuttleworthWallace(wheat.w_leafwidth, wheat.z_0w, wheat.z_0g,
                                    wheat.z_w, wheat.r_st_min, wheat.sigma_b,
                                    wheat.c_int, wheat.C_0, wheat.factor_p)
    print 'Evapotranspiration: Shuttleworth-Wallace'
    biomass = PMF.Biomass_LUE_CO2_Soltani(wheat.RUE, wheat.C_0, wheat.factor_b,
                                          wheat.CO2_ring)
    print 'Biomass: Light-use-efficiency concept with CO2 response'
    development = PMF.Development(wheat.stage, wheat.R_p, wheat.R_v,
                                  wheat.photo_on_off, wheat.verna_on_off)
    nitrogen = PMF.Nitrogen()
    print 'No nitrogen uptake'
    interception = PMF.Intercept_Evapo(wheat.w_leafwidth, wheat.z_0w,
                                       wheat.z_0g, wheat.z_w, wheat.r_st_min,
                                       wheat.sigma_b, wheat.c_int)
    net_radiation = PMF.Net_Radiation(wheat.albedo_m, wheat.Cr)
    water = PMF.Waterstress_FAO()
    print 'Waterstress: FAO'
    layer = PMF.SoilLayer()
    return makePlant(PMF.Plant,
                     et=et,
                     biomass=biomass,
                     development=development,
                     nitrogen=nitrogen,
                     interception=interception,
                     net_radiation=net_radiation,
                     water=water,
                     layer=layer,
                     FRDR=wheat.FRDR,
                     max_height=wheat.max_height,
                     CO2_ring=wheat.CO2_ring,
                     max_depth=wheat.max_depth,
                     root_growth=wheat.root_growth,
                     leaf_specific_weight=wheat.leaf_specific_weight,
                     tbase=wheat.tbase,
                     fact_sen=wheat.fact_sen,
                     shoot_percent=wheat.shoot_percent,
                     root_percent=wheat.root_percent,
                     leaf_percent=wheat.leaf_percent,
                     stem_percent=wheat.stem_percent,
                     storage_percent=wheat.storage_percent,
                     plantN=wheat.plantN,
                     **args)
Esempio n. 3
0
def createPlant_SWC(**args):
    """             
    Implements a specific plant setup with summer wheat values.
    """
    et = PMF.ET_FAO(kcb_values=wheat.kcb, seasons=wheat.seasons)
    print 'Evapotranspiration: FAO - Penman-Monteith'
    biomass = PMF.Biomass_LUE(wheat.RUE, wheat.k)
    print 'Biomass: Light-use-efficiency concept'
    development = PMF.Development(wheat.stage, wheat.R_p, wheat.R_v,
                                  wheat.photo_on_off, wheat.verna_on_off)
    nitrogen = PMF.Nitrogen()
    print 'No nitrogen uptake'
    interception = PMF.Intercept_Evapo(wheat.w_leafwidth, wheat.z_0w,
                                       wheat.z_0g, wheat.z_w, wheat.r_st_min,
                                       wheat.sigma_b, wheat.c_int)
    net_radiation = PMF.Net_Radiation(wheat.albedo_m, wheat.Cr)
    water = PMF.Waterstress_FAO()
    print 'Waterstress: FAO'
    layer = PMF.SoilLayer()
    return makePlant(PMF.Plant,
                     et=et,
                     biomass=biomass,
                     development=development,
                     nitrogen=nitrogen,
                     interception=interception,
                     net_radiation=net_radiation,
                     water=water,
                     layer=layer,
                     FRDR=wheat.FRDR,
                     stem_specific_factor=wheat.stem_specific_factor,
                     stem_growth_max=wheat.stem_growth_max,
                     max_height=wheat.max_height,
                     CO2_ring=wheat.CO2_ring,
                     max_depth=wheat.max_depth,
                     root_growth=wheat.root_growth,
                     leaf_specific_weight=wheat.leaf_specific_weight,
                     tbase=wheat.tbase,
                     fact_sen=wheat.fact_sen,
                     shoot_percent=wheat.shoot_percent,
                     root_percent=wheat.root_percent,
                     leaf_percent=wheat.leaf_percent,
                     stem_percent=wheat.stem_percent,
                     storage_percent=wheat.storage_percent,
                     plantN=wheat.plantN)
Esempio n. 4
0
def createPlant_SWC_Soltani(**args):
    """             
    Implements a specific plant setup with summer wheat values.
    """
    et = PMF.ET_FAO(kcb_values=wheat.kcb, seasons=wheat.seasons)
    print 'Evapotranspiration: FAO - Penman-Monteith'
    biomass = PMF.Biomass_LUE_CO2_Soltani(wheat.RUE, wheat.k)
    print 'Biomass: Light-use-efficiency concept with CO2 response according to Soltani and Sinclair 2012'
    development = PMF.Development(wheat.stage, wheat.R_p, wheat.R_v)
    nitrogen = PMF.Nitrogen()
    print 'No nitrogen uptake'
    water = PMF.Waterstress_FAO()
    print 'Waterstress: FAO'
    layer = PMF.SoilLayer()
    return makePlant(PMF.Plant,
                     et=et,
                     biomass=biomass,
                     development=development,
                     nitrogen=nitrogen,
                     water=water,
                     layer=layer,
                     **args)
Esempio n. 5
0
def createPlant_fromCoefficiant(CropCoefficiant, **args):
    """
    Implements a specific plant setup with the values from the crop coefficant class.
    """
    et = PMF.ET_FAO(kcb_values=CropCoefficiant.kcb,
                    seasons=CropCoefficiant.seasons)
    print 'Evapotranspiration: FAO - Penman-Monteith'
    biomass = PMF.Biomass_LUE(CropCoefficiant.RUE, CropCoefficiant.k)
    print 'Biomass: Light-use-efficiency concept'
    development = PMF.Development(wheat.stage, wheat.R_p, wheat.R_v)
    nitrogen = PMF.Nitrogen()
    print 'No nitrogen uptake'
    water = PMF.Waterstress_FAO()
    print 'Waterstress: FAO'
    layer = PMF.SoilLayer()
    return makePlant(PMF.Plant,
                     et=et,
                     biomass=biomass,
                     development=development,
                     nitrogen=nitrogen,
                     water=water,
                     layer=layer,
                     **args)
Esempio n. 6
0
        model.compile(optimizer=Adagrad(lr=learning_rate),
                      loss='binary_crossentropy')
    elif learner.lower() == "rmsprop":
        model.compile(optimizer=RMSprop(lr=learning_rate),
                      loss='binary_crossentropy')
    elif learner.lower() == "adam":
        model.compile(optimizer=Adam(lr=learning_rate),
                      loss='binary_crossentropy')
    else:
        model.compile(optimizer=SGD(lr=learning_rate),
                      loss='binary_crossentropy')

    # Load pretrain model
    if PMF_pretrain != '' and NCF_pretrain != '':
        PMF_model = PMF.get_model(train, num_users, num_items,
                                  commonuser + PMFlayers1,
                                  commonitem + PMFlayers1, PMFlayers2)
        PMF_model.load_weights(PMF_pretrain)
        model = load_pretrain_PMF(model, PMF_model, commonuser, PMFlayers1,
                                  PMFlayers2)
        del PMF_model
        NCF_model = NCF.get_model(train, num_users, num_items, commonuser,
                                  commonitem, NCFlayers)
        NCF_model.load_weights(NCF_pretrain)
        model = load_pretrain_NCF(model, NCF_model, commonuser, NCFlayers,
                                  mixing_rate)
        del NCF_model
        print("Load pretrained PMF (%s) and NCF (%s) models done. " %
              (PMF_pretrain, NCF_pretrain))

    # Check Init performance
Esempio n. 7
0
    :type  atmosphere: atmosphere
    :param atmosphere: Interface to meteorological data.
    
    :rtype: plant
    :return: Plant instance
    """
    if isinstance(plant, PMF.Plant):
        plant.set_soil(soil)
        plant.set_atmosphere(atmosphere)
        return plant
        print 'connect'
    else:
        return 'Error: No plant instance'


wheat = PMF.CropCoefficiants_wheat()
c3grass = PMF.CropCoefficiants_c3grass()
c4grass = PMF.CropCoefficiants_c4grass()


def createPlant_wheat_SWC(**args):
    """             
    Implements a specific plant setup with summer wheat values.
    """
    print 'wheat'
    et = PMF.ET_ShuttleworthWallace(wheat.w_leafwidth, wheat.z_0w, wheat.z_0g,
                                    wheat.z_w, wheat.r_st_min, wheat.sigma_b,
                                    wheat.c_int, wheat.C_0, wheat.factor_p)
    print 'Evapotranspiration: Shuttleworth-Wallace'
    biomass = PMF.Biomass_LUE_CO2_Soltani(wheat.RUE, wheat.C_0, wheat.factor_b,
                                          wheat.CO2_ring)
#main.py
#Created by ImKe on 2019/11.
#Copyright © 2019 ImKe. All rights reserved.

from daraloader import load_rating_data, spilt_rating_dat
from PMF import *

if __name__ == "__main__":
    pmf = PMF()
    ratings = load_rating_data(file_path)
    print(len(np.unique(ratings[:, 0])), len(np.unique(ratings[:, 1])), pmf.num_feat)
    train, test = spilt_rating_dat(ratings)
    pmf.fit(train, test)

    plt.plot(range(pmf.maxepoch), pmf.train_rmse, 'b-.', label='Training Data')
    plt.plot(range(pmf.maxepoch), pmf.test_rmse, 'go-', label='Test Data')
    plt.title('The MovieLens Dataset Learning Curve')
    plt.xlabel('Number of Epochs')
    plt.ylabel('RMSE')
    plt.legend()
    plt.grid()
    plt.show()
Esempio n. 9
0
def value():
    ucb = LinUCB()
    ucb.set_articles(article, xa)
    #value1=ucb.value1(xa,article)
    #print(value1)
    #print(value1.index(max(value1)),max(value1))
    global request_id
    request_id = user.user_request(request_tot)
    ucb.update(request_id)
    value1 = list(ucb.value1(xa, article))
    value1 = value1[0]
    #print(value1.index(max(value1)),max(value1))
    print('UCB END and PMF Start')

    PMF.initialize(u, c, l, w, R, pu_n_1, pu_n, pl_n_1, pl_n, pw_n_1, pw_n,
                   pc_n_1, pc_n)
    loss_tmp = PMF.loss(S, R, u, c, l, w, content_requested_history)
    PMF.ploss(S, R, u, c, l, w, user_request_history,
              content_requested_history, pu_n, pl_n, pw_n, pc_n)
    PMF.update(beta1, beta2, u, c, l, w, pu_n, pl_n, pw_n, pc_n, pu_n_1,
               pl_n_1, pw_n_1, pc_n_1)
    print(' PMF Update Success')
    loss_now = PMF.loss(S, R, u, c, l, w, content_requested_history)
    while (loss_now < loss_tmp):
        PMF.ploss(S, R, u, c, l, w, user_request_history,
                  content_requested_history, pu_n, pl_n, pw_n, pc_n)
        PMF.update(beta1, beta2, u, c, l, w, pu_n, pl_n, pw_n, pc_n, pu_n_1,
                   pl_n_1, pw_n_1, pc_n_1)
        #print(PMF.loss(R,u,c,l,w,content_requested_history))
        loss_tmp = loss_now
        loss_now = PMF.loss(S, R, u, c, l, w, content_requested_history)
    value2 = PMF.value2(u, c)
    print('PMF End')
    #print(value1,value2)
    for m in range(len(value1)):
        value = value1[m] + value2[m]
        value_list.append(value)
    #print(value_list)
    print('Value End')
    return (value_list)