Skip to content
Snippets Groups Projects
Commit 486a0f91 authored by Jacques Fize's avatar Jacques Fize
Browse files

DEBUG Acc@k

parent 04d402c0
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 20 deletions
.gitattributes 100644 → 100755
File mode changed from 100644 to 100755
.gitignore 100644 → 100755
File mode changed from 100644 to 100755
README.md 100644 → 100755
File mode changed from 100644 to 100755
...@@ -73,21 +73,41 @@ def get_new_ids(cooc_data,id_first_value): ...@@ -73,21 +73,41 @@ def get_new_ids(cooc_data,id_first_value):
topo_id[id_]=interlink topo_id[id_]=interlink
return topo_id return topo_id
def accuracy_at_k(y_true, y_pred): def lat_accuracy(LAT_TOL =1/180.):
""" def accuracy_at_k_lat(y_true, y_pred):
Metrics use to measure the accuracy of the coordinate prediction. But in comparison to the normal accuracy metrics, we add a tolerance threshold due to the (quasi) impossible """
task for neural network to obtain the exact coordinate. Metrics use to measure the accuracy of the coordinate prediction. But in comparison to the normal accuracy metrics, we add a tolerance threshold due to the (quasi) impossible
task for neural network to obtain the exact coordinate.
Parameters
---------- Parameters
y_true : tf.Tensor ----------
truth data y_true : tf.Tensor
y_pred : tf.Tensor truth data
predicted output y_pred : tf.Tensor
""" predicted output
diff = tf.abs(y_true - y_pred) """
fit = tf.where(tf.less(diff,ACCURACY_TOLERANCE)) diff = tf.abs(y_true - y_pred)
return K.size(fit[:,0])/K.size(y_pred),K.size(fit[:,1])/K.size(y_pred) fit = tf.dtypes.cast(tf.less(diff,LAT_TOL),tf.int64)
return tf.reduce_sum(fit)/tf.size(y_pred,out_type=tf.dtypes.int64)
return accuracy_at_k_lat
def lon_accuracy(LON_TOL=1/360.):
def accuracy_at_k_lon(y_true, y_pred):
"""
Metrics use to measure the accuracy of the coordinate prediction. But in comparison to the normal accuracy metrics, we add a tolerance threshold due to the (quasi) impossible
task for neural network to obtain the exact coordinate.
Parameters
----------
y_true : tf.Tensor
truth data
y_pred : tf.Tensor
predicted output
"""
diff = tf.abs(y_true - y_pred)
fit = tf.dtypes.cast(tf.less(diff,LON_TOL),tf.int64)
return tf.reduce_sum(fit)/tf.size(y_pred,out_type=tf.dtypes.int64)
return accuracy_at_k_lon
# LOGGING CONF # LOGGING CONF
logging.basicConfig( logging.basicConfig(
...@@ -98,7 +118,7 @@ logging.basicConfig( ...@@ -98,7 +118,7 @@ logging.basicConfig(
chrono = Chronometer() chrono = Chronometer()
args = ConfigurationReader("./parser_config/toponym_combination_embedding.json")\ args = ConfigurationReader("./parser_config/toponym_combination_embedding.json")\
.parse_args()#("-n 4 -t 0.002 -e 20 -a -w -i data/geonamesData/FR.txt data/geonamesData/hierarchy.txt".split()) .parse_args("-n 4 -t 0.002 -e 20 -i data/geonamesData/FR.txt data/geonamesData/hierarchy.txt".split())
# Initialisee CONSTANTS # Initialisee CONSTANTS
GEONAME_FN = args.geoname_input GEONAME_FN = args.geoname_input
...@@ -108,6 +128,7 @@ ACCURACY_TOLERANCE = args.tolerance_value ...@@ -108,6 +128,7 @@ ACCURACY_TOLERANCE = args.tolerance_value
EPOCHS = args.epochs EPOCHS = args.epochs
ITER_ADJACENCY = args.adjacency_iteration ITER_ADJACENCY = args.adjacency_iteration
COOC_SAMPLING_NUMBER = 3 COOC_SAMPLING_NUMBER = 3
WORDVEC_ITER = 50
# check for output dir # check for output dir
if not os.path.exists("outputs/"): if not os.path.exists("outputs/"):
...@@ -296,7 +317,7 @@ index.save("outputs/"+name+"_index") ...@@ -296,7 +317,7 @@ index.save("outputs/"+name+"_index")
# NGRAM EMBDEDDING # NGRAM EMBDEDDING
logging.info("Generating N-GRAM Embedding...") logging.info("Generating N-GRAM Embedding...")
embedding_weights = index.get_embedding_layer(geoname2encodedname.values(),dim= embedding_dim,iter=50) embedding_weights = index.get_embedding_layer(geoname2encodedname.values(),dim= embedding_dim,iter=WORDVEC_ITER)
logging.info("Embedding generated !") logging.info("Embedding generated !")
# DEEP MODEL # DEEP MODEL
...@@ -326,7 +347,7 @@ output_lat = Dense(1,activation="sigmoid",name="Output_LAT")(x2) ...@@ -326,7 +347,7 @@ output_lat = Dense(1,activation="sigmoid",name="Output_LAT")(x2)
model = Model(inputs = [input_1,input_2], outputs = [output_lon,output_lat])#input_3 model = Model(inputs = [input_1,input_2], outputs = [output_lon,output_lat])#input_3
model.compile(loss=['mean_squared_error','mean_squared_error'], optimizer='adam',metrics=[accuracy_at_k]) model.compile(loss=['mean_squared_error','mean_squared_error'], optimizer='adam',metrics={"Output_LON":lon_accuracy(),"Output_LAT":lat_accuracy()})
history = model.fit(x=[X_1_train,X_2_train], history = model.fit(x=[X_1_train,X_2_train],
y=[y_lon_train,y_lat_train], y=[y_lon_train,y_lat_train],
verbose=True, batch_size=100, verbose=True, batch_size=100,
......
documentation/imgs/first_approach.png

131 B | W: | H:

documentation/imgs/first_approach.png

291 KiB | W: | H:

documentation/imgs/first_approach.png
documentation/imgs/first_approach.png
documentation/imgs/first_approach.png
documentation/imgs/first_approach.png
  • 2-up
  • Swipe
  • Onion skin
documentation/imgs/second_approach.png

131 B | W: | H:

documentation/imgs/second_approach.png

447 KiB | W: | H:

documentation/imgs/second_approach.png
documentation/imgs/second_approach.png
documentation/imgs/second_approach.png
documentation/imgs/second_approach.png
  • 2-up
  • Swipe
  • Onion skin
documentation/imgs/third_approach.png

130 B | W: | H:

documentation/imgs/third_approach.png

30.4 KiB | W: | H:

documentation/imgs/third_approach.png
documentation/imgs/third_approach.png
documentation/imgs/third_approach.png
documentation/imgs/third_approach.png
  • 2-up
  • Swipe
  • Onion skin
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
helpers.py 100644 → 100755
File mode changed from 100644 to 100755
models.py 100644 → 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
pyroutelib3 #pyroutelib3
node2vec node2vec
osrm #osrm
geopandas geopandas
pandas pandas
numpy numpy
...@@ -18,3 +18,4 @@ sqlitedict ...@@ -18,3 +18,4 @@ sqlitedict
nltk nltk
folium folium
flask flask
numba
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment