Commit 0672db01 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

KnowledgeExtraction folder moved in root

parent f0092824
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 16 Nov 2013
@author: Panos
'''
from rpy2 import robjects
#The ConfidenceIntervals object
class Intervals:
#Calculate the p (decimal number) confidence intervals for a sample of data
def ConfidIntervals(self,data,p):
data=robjects.FloatVector(data) #The given list changes into float vector in order to be handled by RPy2
alpha=1-p
rsqrt=robjects.r['sqrt'] #Call square root function - R function
rsd=robjects.r['sd'] #Call standard deviation function - R function
rmean=robjects.r['mean'] #Call mean function - R function
t=len(data)
n=rsqrt(t)
b=rsd(data)
rqt=robjects.r['qt'] #Call the cumulative probability distribution function for t distribution
q=rqt((1-(alpha/2)),t-1)
m=rmean(data) #Calculate the sample average value
me=q[0]*(b[0]/n[0]) #Calculate the margin of error
#Calculate the lower and the upper bound
lo=m[0]-me
up=m[0]+me
l=[lo,up]
return l
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 16 Dec 2013
@author: Panos
'''
from rpy2 import robjects
#The Graphs object
class Graphs:
#Graphs that can visualize the data samples
def Plots(self,data, fileName="plotChart.jpg"):
data=robjects.FloatVector(data) #The given list changes into float vector in order to be handled by RPy2
rplot=robjects.r['plot'] #Call plot function - R function
rdev=robjects.r['dev.off'] #Call dev.off - R function
rjpeg=robjects.r['jpeg'] #Call jpeg - R function
output=rjpeg(fileName) #output the plot (jpeg file format) in the given directory
rplot(data, type="o", col="blue") #Graph data sample and define color and type for the data points visualization
rdev
return output
def ScatterPlot(self,data1,data2, fileName="scatterplot.jpg"):
#The given lists change into float vector in order to be handled by RPy2
data1=robjects.FloatVector(data1)
data2=robjects.FloatVector(data2)
rplot=robjects.r['plot']
rdev=robjects.r['dev.off']
rjpeg=robjects.r['jpeg']
output=rjpeg(fileName)
rplot(data1,data2,main='Scatterplot',xlab="data1", ylab='data2',pch=19) #Graph data samples and define type for the data points visualization
rdev
return output
def Histogram(self,data,fileName="histogram.jpg"):
data=robjects.FloatVector(data) #The given list change into float vector in order to be handled by RPy2
rhist=robjects.r['hist'] #Call hist function - R function
rdev=robjects.r['dev.off']
rjpeg=robjects.r['jpeg']
output=rjpeg(fileName)
rhist(data, main='Histogram',col="lightblue") #Create a histogram for the given data sample
rdev
return output
def Barplot(self,data,fileName="barplot.jpg"):
data=robjects.FloatVector(data) #The given list changes into float vector in order to be handled by RPy2
rbarplot=robjects.r['barplot'] #Call barplot - R function
rdev=robjects.r['dev.off']
rjpeg=robjects.r['jpeg']
output=rjpeg(fileName)
rbarplot(data, main='Barplot',border='blue') #Create a bar plot for the given data sample
rdev
return output
def TwoSetPlot(self, data1,data2, fileName="twosetplot.jpg"):
#The given lists change into float vector in order to be handled by RPy2
data1=robjects.FloatVector(data1)
data2=robjects.FloatVector(data2)
rplot=robjects.r['plot'] #Call plot - R function
rdev=robjects.r['dev.off']
rjpeg=robjects.r['jpeg']
rlines=robjects.r['lines'] #Call lines function - R function
rbox=robjects.r['box'] #Call box function - R function
rrange=robjects.r['range'] #Call range - R function
plot_colors= robjects.StrVector(["red", "forestgreen"]) #Define colors to be used in the plot
output=rjpeg(fileName)
rplot(data1, xlab="x", ylab="Total",ylim=rrange(data1,data2)) #Graph the first data sample and set axes' names
rlines(data2) #Graph the second data sample
# Create box around plot
rbox()
# Graph data1 with thicker red dashed line
rlines(data1, type="l", lty=2, lwd=2, col=plot_colors[0])
# Graph data2 with thicker green dotted line
rlines(data2, type="l", lty=3, lwd=2, col=plot_colors[1])
rdev
return output
def Pie(self, data1, fileName="pieChart.jpg"):
data1=robjects.FloatVector(data1) #The given list changes into float vector in order to be handled by RPy2
rpaste=robjects.r['paste'] #Call paste - R function
rround=robjects.r['round'] #Call round - R function
rsum=robjects.r['sum'] #Call sum - R function
rpie=robjects.r['pie'] #Call pie - R function
rdev=robjects.r['dev.off']
colors=robjects.StrVector(["white","grey70","grey90","grey50","grey60","black"]) #Define colors to be used for black&white print
s=rsum(data1)
d_labels=[0]*(len(data1))
i=0
while i<len(data1):
d_labels[i]=((rround((data1[i]/s[0])*100,1))) #Calculate the percentage for each data point, rounded to one decimal place
i+=1
d_labels=rpaste(d_labels,"%",sep="") #Concatenate a "%" car after each value
rjpeg=robjects.r['jpeg']
export=rjpeg(fileName)
rpie(data1,main="Data",col=colors,labels=d_labels,cex=0.8) #Create a pie chart with defined heading and custom colors
rdev
return export
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 14 Nov 2013
@author: Panos
'''
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
MASS= importr('MASS')
#The BasicStatisticalMeasures object
class BasicStatisticalMeasures:
# A variety of statistical measures are calculated in this object
def length(self, data): #Calculate the length of data sample
data=robjects.FloatVector(data) ##The given list changes into float vector in order to be handled by RPy2
rlength = robjects.r['length'] #Call length function-R function
return rlength(data)[0]
def summary(self, data): #Calculate the summary of data sample (output the results in a specific format used in R)
data=robjects.FloatVector(data)
rsummary = robjects.r['summary'] #Call summary - R function
return rsummary(data)
def quantile(self,data): #Calculate the quantiles (0%,25%,50%,75%,100%) of the data sample
data=robjects.FloatVector(data)
rquantile = robjects.r['quantile'] #Call quantile - R function
return rquantile(data)
def frequency(self,data): #Calculate the frequency of a data point in the sample
data=robjects.FloatVector(data)
rtable= robjects.r['table'] #Call table - R function
return rtable(data)
def mean (self, data): #Calculate the mean value of a data sample
data=robjects.FloatVector(data)
rmean = robjects.r['mean'] #Call mean - R function
return rmean(data)[0]
def var (self, data): #Calculate the variance of a data sample
data=robjects.FloatVector(data)
rvar = robjects.r['var'] #Call variance function - R function
return rvar(data)[0]
def sd (self, data): #Calculate the standard deviation of a data sample
data=robjects.FloatVector(data)
rsd = robjects.r['sd'] #Call standard deviation function - R function
return rsd(data)[0]
def range (self, data): #Calculate the range of a data sample
data=robjects.FloatVector(data)
rrange = robjects.r['range'] #Call range function - R function
return rrange(data)[0]
def IQR (self, data): #Calculate the Interquartile range (IQR) of a data sample
data=robjects.FloatVector(data)
rIQR = robjects.r['IQR'] #Call IQR function - R function
return rIQR(data)[0]
def all(self, data): #Print the results of the above measures
data=robjects.FloatVector(data)
print 'The length of the data set is:', self.length(data)[0]
print 'The summary is:', self.summary(data)
print 'The quartiles and percentiles of the data set are:', self.quantile(data)
print 'The frequency of the datapoints are:', self.frequency(data)
print 'The mean value is:', self.mean(data)[0]
print 'The standard deviation is:', self.sd(data)[0]
print 'The variance is:', self.var(data)[0]
print 'The range is:', self.range(data)[0]
print 'The Interquartile Range is:', self.IQR(data)[0]
\ No newline at end of file
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment