Commit 3c662884 authored by Alain Shakour's avatar Alain Shakour

First commit

parents
# OS
.DS_Store
# Python
*.pyc
*.pyo
*.egg-info
# Common IDEs
*.swp
.idea/
.buildpath
.project
.pydevproject
.settings
atlassian-ide-plugin.xml
*.sublime-*
[
{
"pk": 20,
"model": "workflows.category",
"fields": {
"uid": "f24e960b-c428-4d6d-aad7-ca9d446350e3",
"parent": null,
"workflow": null,
"user": null,
"order": 1,
"name": "Context_aware"
}
},
{
"pk": 98,
"model": "workflows.abstractwidget",
"fields": {
"category": 20,
"treeview_image": "",
"name": "Create Integer List",
"is_streaming": false,
"uid": "4fb188b6-554a-4c56-9ff7-5f4f4c63ccce",
"interaction_view": "",
"image": "",
"package": "context_aware",
"static_image": "construction_work .png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"action": "context_aware_create_integers",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
}
},
{
"pk": 248,
"model": "workflows.abstractinput",
"fields": {
"widget": 98,
"name": "Integer List String",
"short_name": "str",
"uid": "fff9496e-a1da-4690-80aa-386a19f9f617",
"default": "3\r\n2\r\n1\r\n4",
"required": false,
"multi": false,
"parameter_type": "textarea",
"variable": "intStr",
"parameter": true,
"order": 1,
"description": "Comma or new-line separated list of integers"
}
},
{
"pk": 253,
"model": "workflows.abstractinput",
"fields": {
"widget": 98,
"name": "Sort list",
"short_name": "bol",
"uid": "64d6d6d8-96bc-4bab-b8ed-f76ae412b820",
"default": "true",
"required": true,
"multi": false,
"parameter_type": "checkbox",
"variable": "sort",
"parameter": true,
"order": 2,
"description": "Should the list be sorted"
}
},
{
"pk": 104,
"model": "workflows.abstractoutput",
"fields": {
"widget": 98,
"name": "Integer List",
"short_name": "lst",
"variable": "intList",
"uid": "8b9584ed-9983-4c02-aa0e-6ee53a6a7bcc",
"order": 1,
"description": "List of integers"
}
},
{
"pk": 101,
"model": "workflows.abstractwidget",
"fields": {
"category": 20,
"treeview_image": "",
"name": "Filter Integers",
"is_streaming": false,
"uid": "daf07e32-aab2-4efe-a025-67422577b502",
"interaction_view": "context_aware_filter_integers",
"image": "",
"package": "context_aware",
"static_image": "construction_work .png",
"post_interact_action": "context_aware_post_filter_integers",
"user": null,
"visualization_view": "",
"action": "context_aware_pre_filter_integers",
"wsdl_method": "",
"wsdl": "",
"interactive": true,
"has_progress_bar": false,
"order": 2,
"description": ""
}
},
{
"pk": 250,
"model": "workflows.abstractinput",
"fields": {
"widget": 101,
"name": "Integer List",
"short_name": "lst",
"uid": "e940c839-a5a6-4774-bc4f-d780bb2265e5",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "intList",
"parameter": false,
"order": 1,
"description": "List of integers"
}
},
{
"pk": 106,
"model": "workflows.abstractoutput",
"fields": {
"widget": 101,
"name": "Filtered Integer List",
"short_name": "lst",
"variable": "intList",
"uid": "1124a526-bed4-4b0a-99ba-738d03fcfa2b",
"order": 1,
"description": "Filtered list of integers"
}
},
{
"pk": 99,
"model": "workflows.abstractwidget",
"fields": {
"category": 20,
"treeview_image": "",
"name": "Sum Integers",
"is_streaming": false,
"uid": "2492e173-b493-427c-89fc-fa9312f4bbff",
"interaction_view": "",
"image": "",
"package": "context_aware",
"static_image": "construction_work .png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"action": "context_aware_sum_integers",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 3,
"description": ""
}
},
{
"pk": 249,
"model": "workflows.abstractinput",
"fields": {
"widget": 99,
"name": "Integer List",
"short_name": "lst",
"uid": "27f05eef-0e71-4baa-98f8-58832a13c836",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "intList",
"parameter": false,
"order": 1,
"description": "List of integers"
}
},
{
"pk": 105,
"model": "workflows.abstractoutput",
"fields": {
"widget": 99,
"name": "Sum",
"short_name": "int",
"variable": "sum",
"uid": "2a7db97e-4584-465f-9d51-7580cfbf2aa3",
"order": 1,
"description": "Sum of integer list"
}
},
{
"pk": 100,
"model": "workflows.abstractwidget",
"fields": {
"category": 20,
"treeview_image": "",
"name": "Display Summation",
"is_streaming": false,
"uid": "64504908-b239-4474-ae03-a50f4ae764dd",
"interaction_view": "",
"image": "",
"package": "context_aware",
"static_image": "construction_work .png",
"post_interact_action": "",
"user": null,
"visualization_view": "context_aware_display_summation",
"action": "context_aware_pre_display_summation",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 4,
"description": ""
}
},
{
"pk": 251,
"model": "workflows.abstractinput",
"fields": {
"widget": 100,
"name": "Integer List",
"short_name": "lst",
"uid": "60d1f18f-c86d-4979-a3e0-0068d7961f41",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "intList",
"parameter": false,
"order": 1,
"description": "List of integers"
}
},
{
"pk": 252,
"model": "workflows.abstractinput",
"fields": {
"widget": 100,
"name": "Sum",
"short_name": "int",
"uid": "2fbc8b0c-b3c9-4c8c-809b-da2d56661025",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "sum",
"parameter": false,
"order": 2,
"description": "Sum (possibly correct) of integer list"
}
}
]
\ No newline at end of file
from django.shortcuts import render
def context_aware_filter_integers(request,input_dict,output_dict,widget):
return render(request, 'interactions/context_aware_filter_integers.html',{'widget':widget,'intList':input_dict['intList']})
\ No newline at end of file
def ca_set_binary_threshold_from_skew(input_dict):
cost_false_pos = input_dict['cost_false_pos']
cost_false_neg = input_dict['cost_false_neg']
ratio_pos_neg = input_dict['ratio_pos_neg']
output_dict = {}
output_dict['bin_thres'] = float(ratio_pos_neg) * (float(cost_false_pos) / float(cost_false_neg))
return output_dict
def ca_estimate_pos_neg_from_prd_fct(input_dict):
import re
output_dict = {}
deploy_data = input_dict['deploy_data']
target_att = input_dict['target_att']
pos_col = input_dict['pos_col']
neg_col = input_dict['neg_col']
with open(deploy_data) as f:
deploy_file = f.read()
pos_arr = re.findall(target_att+"\(.*," +pos_col+"\)\.", deploy_file)
print len(pos_arr)
neg_arr = re.findall(target_att+"\(.*," +neg_col+"\)\.", deploy_file)
print len(neg_arr)
output_dict['ratio_pos_neg'] = len(pos_arr)/float(len(neg_arr))
return output_dict
def ca_apply_binary_threshold(input_dict):
performance = input_dict['score']
thres = input_dict['bin_thres']
n = len(performance['predicted'])
for i in range(n):
if performance['predicted'][i] >= thres:
performance['predicted'][i] = 1
else:
performance['predicted'][i] = 0
output_dict = {}
output_dict['classes'] = performance
return output_dict
def ca_rate_driven_threshold_selection(input_dict):
from collections import Counter
performance = input_dict['score']
list_score = []
labels = ''
n = len(performance['actual'])
for i in range(n):
list_score.append((performance['actual'][i],performance['predicted'][i]))
output_dict = {}
sorted_score = sorted(list_score, key=lambda scr: scr[1],reverse=True)
counter_neg = len([score for score in list_score if score[0] == 0])
counter_pos = len([score for score in list_score if score[0] == 1])
output_dict['bin_thres'] = find_best_roc_weight('rate',sorted_score,counter_pos,counter_neg)
return output_dict
def ca_score_driven_threshold_selection(input_dict):
from collections import Counter
performance = input_dict['score']
method = input_dict['method']
list_score = []
labels = ''
n = len(performance['actual'])
for i in range(n):
list_score.append((performance['actual'][i],performance['predicted'][i]))
output_dict = {}
sorted_score = sorted(list_score, key=lambda scr: scr[1],reverse=True)
counter_neg = len([score for score in list_score if score[0] == 0])
counter_pos = len([score for score in list_score if score[0] == 1])
output_dict['bin_thres'] = find_best_roc_weight(method,sorted_score,counter_pos,counter_neg)
return output_dict
def find_best_roc_weight(method,a_list,a_num_positives,a_num_negatives):
previous = float('inf')
xpos = 0
xneg = a_num_negatives
the_best_value = get_value(method,xpos,xneg,a_num_positives,a_num_negatives)
best = previous
for the_elt in a_list:
the_roc = the_elt
current = the_roc[1]
if current != previous:
possible_best_value = get_value(method,xpos,xneg,a_num_positives,a_num_negatives)
if possible_best_value > the_best_value:
the_best_value = possible_best_value
best = (previous + current) / float(2)
if the_roc[0] == 1:
xpos += 1
else:
xneg -= 1
previous = current;
possible_best_value = get_value(method,xpos,xneg,a_num_positives,a_num_negatives)
if possible_best_value > the_best_value:
the_best_value = possible_best_value
best = (previous + float('-inf')) / float(2)
return best
def get_value(method, TP, TN, P, N):
if method == 'accuracy':
accuracy = ( TP + TN ) / float( N + P )
return accuracy
elif method == 'balanced':
balanced = ( TP / float(P) + TN / float(N)) / 2
return balanced
FN = P - TP
FP = N - TN
recall = TN / float(N)
if TN + FN > 0:
precision = TN / float(TN + FN)
if method == 'precision':
return precision
if precision + recall > 0:
F_measure = 2 * precision * recall / (precision + recall)
else:
F_measure = 0
else:
F_measure = 0
return F_measure
\ No newline at end of file
{
"model": "workflows.category",
"fields": {
"name": "Context Aware",
"parent": null,
"order": 1,
"uid": "43303106-bb42-467f-8ffe-6ac1f5a011e3"
}
}
\ No newline at end of file
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "43303106-bb42-467f-8ffe-6ac1f5a011e3",
"treeview_image": "",
"uid": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"windows_queue": false,
"package": "context_aware",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "",
"static_image": "",
"action": "ca_estimate_pos_neg_from_prd_fct",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,
"order": 1,
"name": "Estimate positive/negative ratio from prd and fct files"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"name": "Positive column",
"short_name": "pos",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "pos_col",
"parameter": true,
"order": 3,
"uid": "5f1582c9-a071-4511-9aa6-c5b8d84c0203"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"name": "Deployment Data",
"short_name": "fil",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "file",
"variable": "deploy_data",
"parameter": false,
"order": 1,
"uid": "8884fd0c-a811-4243-8c42-7d37c5f69fad"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"name": "Target attribute",
"short_name": "tcl",
"default": "class",
"description": "",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "target_att",
"parameter": true,
"order": 2,
"uid": "bcb4a307-a943-48b9-a5e8-570cd5958658"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"name": "Negative column",
"short_name": "neg",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "neg_col",
"parameter": true,
"order": 4,
"uid": "ed7a4303-6ca0-45fd-a039-3b03cafc41c6"
}
},
{
"model": "workflows.abstractoutput",
"fields": {
"widget": "9f8ee88b-aae0-441a-9348-17cd4bcb2d1e",
"name": "Ratio positive/negative",
"short_name": "rpn",
"description": "",
"variable": "ratio_pos_neg",
"order": 1,
"uid": "9e3ebe8f-e748-4eb6-a9ce-c4ebcc0eed7c"
}
}
]
\ No newline at end of file
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "43303106-bb42-467f-8ffe-6ac1f5a011e3",
"treeview_image": "",
"uid": "aa8e12a8-1a98-4699-9b96-ab86a7632533",
"windows_queue": false,
"package": "context_aware",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "",
"static_image": "",
"action": "ca_apply_binary_threshold",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,
"order": 1,
"name": "Apply binary threshold to predict classes"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "aa8e12a8-1a98-4699-9b96-ab86a7632533",
"name": "Binary threshold",
"short_name": "thr",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "bin_thres",
"parameter": false,
"order": 2,
"uid": "c478fa0c-632c-472d-93eb-b0a908186d0a"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "aa8e12a8-1a98-4699-9b96-ab86a7632533",
"name": "Binary score",
"short_name": "scr",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "textarea",
"variable": "score",
"parameter": false,
"order": 1,
"uid": "e9d5add2-1c79-4e28-a601-525830955ffe"
}
},
{
"model": "workflows.abstractoutput",
"fields": {
"widget": "aa8e12a8-1a98-4699-9b96-ab86a7632533",
"name": "Predict classes",
"short_name": "cls",
"description": "",
"variable": "classes",
"order": 1,
"uid": "cdcb906e-4ce1-4a84-8865-2e02a340a053"
}
}
]
\ No newline at end of file
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "43303106-bb42-467f-8ffe-6ac1f5a011e3",
"treeview_image": "",
"uid": "b22c82a2-9c2a-4a7c-bb73-5f74f923fd31",
"windows_queue": false,
"package": "context_aware",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "",
"static_image": "",
"action": "ca_rate_driven_threshold_selection",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,
"order": 1,
"name": "Rate driven threshold selection"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "b22c82a2-9c2a-4a7c-bb73-5f74f923fd31",
"name": "Score",
"short_name": "scr",
"default": "",
"description": "",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "score",
"parameter": false,
"order": 1,
"uid": "aa094f35-43a8-4d00-8a4a-50667c759044"
}
},
{
"model": "workflows.abstractoutput",
"fields": {
"widget": "b22c82a2-9c2a-4a7c-bb73-5f74f923fd31",
"name": "Binary Threshold",
"short_name": "thr",
"description": "",
"variable": "bin_thres",
"order": 1,
"uid": "6e9ba07a-508b-4102-9092-fce15274f9fa"
}
}
]
\ No newline at end of file
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "43303106-bb42-467f-8ffe-6ac1f5a011e3",
"treeview_image": "",
"uid": "f42c4d99-48f8-4db3-b475-070d47450c1b",
"windows_queue": false,
"package": "context_aware",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "",
"static_image": "",
"action": "ca_score_driven_threshold_selection",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,