Skip to content

Instantly share code, notes, and snippets.

View klintan's full-sized avatar

Andreas Klintberg klintan

View GitHub Profile
'use strict';
/* Google Calendar API Module */
angular.module('myApp.calendar', []).
value('resp', {
nullMethod: function() {
return 'value';
},
handleClientLoad: function() {
@klintan
klintan / keras_regression.py
Created August 18, 2016 11:20
A simple model for a linear regression problem in Keras.
import numpy as np
import pandas as pd
from math import sqrt
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from sklearn.feature_selection import VarianceThreshold
from sklearn.preprocessing import StandardScaler
#data preparation
import pandas as pd
import numpy as np
from os import listdir
from os.path import isfile, join
#training file folder (All your csv data files)
file_path = 'CAX_Train'
import pandas as pd
import numpy as np
from math import sqrt
from sklearn.metrics import mean_squared_error
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import StandardScaler
@klintan
klintan / effecient_nested_for.py
Created November 6, 2016 20:47
A more efficent nested for loop in python. It is similar to a pairwise comparison testing, but it applies a function to the two array items instead of comparing them.
import pprint
import collections
H1 = [1, 2, 3, 4, 5]
H2 = [1, 2, 3, 4, 5]
all_dist = []
#http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python?noredirect=1&lq=1
class AutoVivification(dict):
"""Implementation of perl's autovivification feature."""
@klintan
klintan / load_sem3d_data.ipynb
Last active January 31, 2018 07:28
Load Semantic3D data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@klintan
klintan / initialization.py
Created September 7, 2018 21:58
Truthfinder 1
max_iteration_count = 10
it = 0
error = 99
tol = 0.001
# intialize source trustworthiness structure
source_trustworthiness = {k: -np.log(1 - 0.9) for k in data['source'].unique()}
@klintan
klintan / iteration.py
Created September 7, 2018 22:29
Truthfinder 2
while error > tol and it < max_iteration_count:
source_trustworthiness_old = copy.deepcopy(source_trustworthiness)
# 1. Compute fact confidence score
data = compute_confidence(data, objects, source_trustworthiness, attribute_key)
# 2. Compute source trustworthiness score
source_trustworthiness = compute_source_trust(data, source_trustworthiness)
# Check convergence of the process
@klintan
klintan / compute_confidence.py
Created September 7, 2018 22:37
Truthfinder 3
def compute_confidence(df, objects, source_trust, attribute_key):
# compute claims confidence score
all_objects_data = pd.DataFrame()
for obj in objects:
data = df[df['object'] == obj]
# Sub-step 1. compute from source trust
data, confidence = compute_confidence_score(data, source_trust, attribute_key)
def compute_confidence_score(data, source_trust, attribute_key):
'''
compute the confidence score using the sources trust worthiness, sum the scores for all sources
for a specific claim.
'''
# loop through each source for a book
for idx, claim in data.iterrows():
# get all sources for a specific claim
sources = get_sources_for_claim(data, claim, attribute_key)
# sum the trust score for all the sources for a specific claim