This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Algoritmo completo modularizado (dividido em pequenas funções para facilitar compreensão). ## | |
library('plyr') | |
library('dplyr') | |
compute_probabilities <- function(df, target_variable_name){ | |
feature_variables_names <- names(df[,!(names(df) %in% target_variable_name)]) | |
rules_probabilities <- as.data.frame(rbind(NULL, NULL)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Algoritmo completo modularizado (dividido em pequenas funções para facilitar compreensão). ## | |
import numpy as np | |
import pandas as pd | |
from dfply import * | |
def compute_probabilities(df, target): | |
prob_table = pd.DataFrame() | |
feature_matrix = df.drop(target, axis=1) | |
feature_variables = feature_matrix.columns.values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Université Paris-Saclay - M2 Data & Knowledge | |
#Web Data Models - Silviu Maniu - Final Project | |
#Anderson Pinheiro de Araújo Chaves | |
def readFileByChunk(file_object): | |
while True: | |
data = file_object.readline() | |
if not data: | |
break | |
#elif data != ' ' and data != '\n' and data != '0' and data != '1': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.StringTokenizer; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.io.IntWritable; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.mapreduce.Mapper; | |
import org.apache.hadoop.mapreduce.Reducer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.StringTokenizer; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.mapreduce.Mapper; | |
import org.apache.hadoop.mapreduce.Reducer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addFact(HashSet<Variable> newfacts) { | |
for(Variable var : newfacts) { | |
this.facts.add(var); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public FactBase forwardChaining(Formalism ruleBase, Formalism factBase) { | |
FactBase updatedFactBase = (FactBase) factBase; | |
FactBase oldFactBase = (FactBase) factBase; | |
HornRuleBase hornRuleBase = (HornRuleBase) ruleBase; | |
do { | |
oldFactBase = updatedFactBase; | |
for (HornRule rule : hornRuleBase.getRules()) { | |
if (this.eval(rule, updatedFactBase)) { | |
updatedFactBase.addFact(rule.getConclusions()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean eval(HornRule rule, FactBase fb) { | |
for (Variable condition : rule.getConditions()) { | |
boolean conditionMatched = false; | |
for (Variable fact : fb.getFact()) { | |
if (condition.equals(fact)) | |
conditionMatched = true; | |
} | |
if (!conditionMatched) | |
return false; | |
} |