def avaliacao(metrica, arq): arquivo = open('arquivo.txt', 'r') #abrir o arquivo subjectscores = open(arq, 'r') #ler arquivo conteudo_texto = arquivo.read() # conteudo_texto1 = subjectscores.read() # a = conteudo_texto.split('\n') # separar por quebra de linha c = a[:-1] #tirar ultimo elemento aa = conteudo_texto1.split('\n') #separar por espaco cc = aa[:-1] arquivo.close() #fechar arquivo subjectscores.close() x = np.array([]) y = np.array([]) l = np.array([]) total_pontos = 0 #plotar grafico for i in xrange(0, len(cc)): w = cc[i].split('\t') #buscar linha q = len(w) #tamanho da linha ww = w[2:q] #tirar primeiro elemento total_pontos = len(ww) + total_pontos b = c[i].split(';') #separar por , psnr = b[metrica] #buscar psnr h = np.asarray(ww[0:13]) #criando vetor com media de mos t = h.astype(np.float) v = np.mean(t) if (psnr !=str('inf')): x = np.insert(x,0,psnr) #guardar y = np.insert(y,0,v) #vetor media mos r = float(psnr) #converter para float p = q-1.0 #tamanho da linha menos o 1 item d = np.zeros(p) #criar vetor de 0s dd = d + r #criar vetor de psnr do tm d mos #plt.plot(dd, ww, 'o', color='r') #plotar psnr x mos out = outlier.outlier(t) #calcular outliers l = np.append(l, out) #vetor com n de outliers por coluna mos razao_outliers = np.sum(l)/total_pontos coeficiente_spearman = spearman.spearman(x,y) #spearman/s = stats.spearmanr(x,y) coeficiente_pearson = pearson.pearson(x,y) #pearson/p = stats.pearsonr(x,y) a, b = regressaoLinear.regressaoLinear(x,y) #regressao linear x, t, y, v = levenbergMarquart.levenberg(x,y) #funcao logistica linear = '(' + str(a) + ')*x + (' + str(b) + ')' logistica = '(' + str(v[0])+ ') * (' + str(0.5) + '-(' + str(v[1]) + ')/(exp(' + str(v[1]) + '*(x-(' + str(v[2])+ '))))) + (' + str(v[3])+ ') * x+(' + str(v[4]) + ')' return razao_outliers, coeficiente_spearman, coeficiente_pearson, logistica, linear
def avaliacao(metrica, arq): arquivo = open('arquivo.txt', 'r') subjectscores = open(arq, 'r') conteudo_texto = arquivo.read() conteudo_texto1 = subjectscores.read() a = conteudo_texto.split('\n') c = a[:-1] aa = conteudo_texto1.split('\n') cc = aa[:-1] arquivo.close() subjectscores.close() x = np.array([]) y = np.array([]) l = np.array([]) total_pontos = 0 for i in xrange(0, len(cc)): w = cc[i].split('\t') #buscar linha q = len(w) #tamanho da linha ww = w[2:q] #tirar primeiro elemento total_pontos = len(ww) + total_pontos b = c[i].split(';') #separar por , psnr = b[metrica] #buscar metrica h = np.asarray(ww[0:13]) #criando vetor com media de mos t = h.astype(np.float) v = np.mean(t) if (psnr !=str('inf')): x = np.insert(x,0,psnr) #guardar y = np.insert(y,0,v) #vetor media mos r = float(psnr) #converter para float p = q-1.0 #tamanho da linha menos o 1 item d = np.zeros(p) #criar vetor de 0s dd = d + r #criar vetor de psnr do tm d mos out = outlier.outlier(t) #calcular outliers l = np.append(l, out) #vetor com n de outliers por coluna mos razao_outliers = np.sum(l)/total_pontos coeficiente_spearman = spearman.spearman(x,y) #spearman/s = stats.spearmanr(x,y) coeficiente_pearson = pearson.pearson(x,y) #pearson/p = stats.pearsonr(x,y) a, b = regressaoLinear.regressaoLinear(x,y) #regressao linear x, t, y, v = levenbergMarquart.levenberg(x,y) #funcao logistica linear = '(' + str(a) + ')*x + (' + str(b) + ')' logistica = '(' + str(v[0])+ ') * (' + str(0.5) + '-(' + str(v[1]) + ')/(exp(' + str(v[1]) + '*(x-(' + str(v[2])+ '))))) + (' + str(v[3])+ ') * x+(' + str(v[4]) + ')' return razao_outliers, coeficiente_spearman, coeficiente_pearson, logistica, linear
if (maxG < g): maxG=g imax=i jmax=j clusNuevo=clus[imax] + clus[jmax] aux = clus[jmax] clus.remove(clus[imax]) clus.remove(aux) clus.append(clusNuevo) return clus datos=outlier(N=150,outliers=0.2) datos=datos[:,range(0,2)] r = ROCK(datos,10) clusters = r.ejecutar(4,0.5) #Los dibujo figure() plt.plot(datos[clusters[0],0],datos[clusters[0],1],'ro') plt.plot(datos[clusters[1],0],datos[clusters[1],1],'bo') plt.plot(datos[clusters[2],0],datos[clusters[2],1],'go') plt.plot(datos[clusters[3],0],datos[clusters[3],1],'yo') plt.show()
def avaliacao(metrica, arq): # abrir arquivo de avaliacoes objetivas (metricas) arquivo = open('metricas.txt', 'r') conteudo_texto = arquivo.read() a = conteudo_texto.split('\n') c = a[:-1] arquivo.close() # abrir aquivo de avaliacoes subjetivas subjectscores = open(arq, 'r') conteudo_texto1 = subjectscores.read() aa = conteudo_texto1.split('\n') cc = aa[:-1] subjectscores.close() # abrir arquivo de avaliacoes objetivas (metricas) arquivo2 = open('jpeginfo.txt', 'r') conteudo_texto2 = arquivo2.read() aaa = conteudo_texto2.split('\n') ccc = aaa[:-1] arquivo2.close() #inicializacao das variaveis x = np.array([]) y = np.array([]) l = np.array([]) total_pontos = 0 ref = '' ab = '' #plot METRICA X DMOS for i in xrange(0, len(cc)): w = aa[i].split('\t') for line in ccc: if w[0] in line: #print line cond = line.split() #print cond[2] if cond[2] == '0': ab = cond[1] #q = len(w) for line in cc: if ab in line: w0 = line w1 = w0.split('\t') ww = w[2:(len(w))] ww1 = w1[2:(len(w))] #print ww1 total_pontos = len(ww) + total_pontos b = c[i].split(';') psnr = b[metrica] h = np.asarray( ww[0:12]) #substituir numeracao por eliminacao de valores nulos h1 = np.asarray(ww1[0:12]) #t = h.astype(np.float) v2 = np.mean(h1.astype(np.float)) v1 = np.mean(h.astype(np.float)) v = v2 - v1 if (psnr != str('inf')): x = np.insert(x, 0, psnr) y = np.insert(y, 0, v1) r = float(psnr) #p = (len(w))-1.0 #outlier out = outlier.outlier(h.astype(np.float)) l = np.append(l, out) razao_outliers = np.sum(l) / total_pontos coeficiente_spearman = spearman.spearman( x, y) #spearman/s = stats.spearmanr(x,y) coeficiente_pearson = pearson.pearson(x, y) #pearson/p = stats.pearsonr(x,y) coeficiente_anova_F, coeficiente_anova_p, relacao_anova = anova.anova(x, y) a, b = regressaoLinear.regressaoLinear(x, y) #regressao linear x, t, y, v = levenbergMarquart.levenberg(x, y) #funcao logistica linear = '(' + str(a) + ')*x + (' + str(b) + ')' logistica = '(' + str(v[0]) + ') * (' + str(0.5) + '-(' + str( v[1]) + ')/(exp(' + str(v[1]) + '*(x-(' + str( v[2]) + '))))) + (' + str(v[3]) + ') * x+(' + str(v[4]) + ')' return razao_outliers, coeficiente_spearman, coeficiente_pearson, coeficiente_anova_F, coeficiente_anova_p, relacao_anova, logistica, linear
import numpy as np import retrieve import outlier import util if __name__ == '__main__': ## initial data retrieval (parts a - f) # parts a-f: retrieve data data = retrieve.retrieve_data('example_data.csv') # part c: filter outliers data = outlier.outlier(data, 3) ## split training and test, remove outliers if new data # part d training = outlier.outlier(data[3::4], 3) test = outlier.outlier(np.delete(data, np.s_[3::4], axis=0), 3) # part f # training = outlier.outlier(data, 3) # test = outlier.outlier(retrieve.retrieve_data('trip_data_2.csv'), 3) # part i # training = outlier.outlier(retrieve.retrieve_data('trip_data_1.csv'), 3) # test = outlier.outlier(retrieve.retrieve_data('trip_data_2.csv'), 3) ## normalize the matrix # part h - don't normalize train 2 (pickup time) bc of the binary modification for count in range(0, 8): if count != 2: training = util.normalize(training, count) test = util.normalize(test, count) ## plot the graphs