Beispiel #1
0
def run():
    limit = 10
    collection = generate_collections()
    fuzzy = Fuzzy(collection)
    print(fuzzy)
    while True:
        search = input("> ")
        if not search:
            return
        start_time = time.time()
        result = fuzzy.search(search)
        has_more = len(result) - limit
        if has_more == 1:
            limit += 1
        print("\"%s\" [%s of %s results (%.6f seconds)]" % (
            search,
            min(limit, len(result)),
            len(result),
            time.time() - start_time
        ))
        result = result[:limit]
        for text in result:
            print("%s[%8.2f] %s" % (
                " " * 2,
                text[0],
                format_text(text[1], text[2])
            ))
        if has_more > 1:
            print(" " * 2 + "...")
Beispiel #2
0
def getCalculation():
   maximumImplicant = Fuzzy.getDefuzyfikasi()
   denomi = Fuzzy.getDenoNomi()
   data = {'rules' : Fuzzy.listOfUsedRule,'insideTempMember':Fuzzy.getInsideTemp(),
      'outsideTempMember':Fuzzy.getOutsideTemp(),'peopleMember':Fuzzy.getPeople(),
      "detail":Fuzzy.getLinguisticValue(),"maximum-Implicant":maximumImplicant,"defuzifikasi":denomi}
   return jsonify(data),200
def algo_fuzzy(links, channels):
    """
    @param links
    @param channels
    """
    # a_link is the link. NOT USED IN ALGO_FUZZY

    #::TODO:: english
    # INFORMACOES DISPONIVEIS:
    # - taxa ocupacao canal n pelo US
    # - taxa ocupacao canal n pelo US
    # - canais livres
    # - BER
    #

    channel_pu_presence = []
    channel_su_presence = []
    for ch in channels:
        pu_occ = globs.p_up_occ_count[ch]
        pu_total = globs.p_up_occ_count[ch] + globs.p_up_idle_count[ch]

        channel_pu_presence.append(100.0 * pu_occ / float(pu_total) if pu_total > 0 else 0)

        su_occ = globs.p_channels_count[ch]
        su_total = globs.p_total_iterations
        channel_su_presence.append(100.0 * su_occ / float(su_total) if su_total > 0 else 0)

    rewards = Fuzzy.full_process(channel_pu_presence, channel_su_presence)

    # map {ch1: reward, ch2: reward}
    valid_reward = {}
    for i in channels:
        valid_reward[i] = rewards.pop(0)

    # get higher rewards
    ret = {}
    for l in links:
        if valid_reward:
            # Search highest reward
            v_cur = -1
            k_cur = -1
            for k, v in valid_reward.iteritems():
                if v > v_cur:
                    k_cur = k
                    v_cur = v

            # remove item from valid_rewards
            if k_cur > -1:
                ret[l] = k_cur
                del valid_reward[k_cur]

    return ret
Beispiel #4
0
 def __init__(self, params, yaw = Fuzzy(mf_types, f_ssets)):
     '''Initialize some variables'''
     
     Controller.__init__(self,params)
     self.heading_angle = 0
     self.yaw = yaw
Beispiel #5
0
from fuzzy import Fuzzy

a = Fuzzy(0.7)
b = Fuzzy(0.4)

if not a:
    print('ERROR : in line 7 a should be true')

if b:
    print('ERROR : in line 10 b should be false')

Fuzzy.set_truth_threshold(3)
if Fuzzy.TRUTH_TRESHOLD > 1.0:
    print('ERROR : thrut treshold set above 1')
Fuzzy.set_truth_threshold(0.3)
if not b:
    print('ERROR : in line 10 b should be true')

c = Fuzzy(23)
if c > 1.0:
    print('ERROR : thrut value set above 1')

if -a != 0.3:
    print('ERROR: negation is incorrect ({})'.format(-a))

if (a | b) != 0.7:
    print('ERROR: alternative is incorrect ({})'.format(a | b))

if a & b != 0.4:
    print('ERROR: conjunction is incorrect ({})'.format(a & b))
	def start(self, quandoTermina):
		if self.pb:
			self.pb.show()
		i = 0
		while (i<len(self.listaDeArquivos)):
			arquivo = self.listaDeArquivos[i]
			label = str(str(arquivo).split('/')[-1])

			im3 = Image.open(str(arquivo))

			# Filtro 1 { Protan }
			if self.pb:
				self.pb.setLabel('[1/6] Aplicando filtro Protan em ' + str(label))
			filtro1 = FiltroDeImagem(debug=False)
			filtro1.carregarImg(str(arquivo))
			filtro1.callBackPogresso(self.percentagem)
			im1 = filtro1.filtrarProtan(equalizar = self.equalizar, lms = self.lms)

			# Filtro 2 { Deutan }
			if self.pb:
				self.pb.setLabel('[2/6] Aplicando filtro Deutan em ' + str(label))
			filtro2 = FiltroDeImagem(debug=False)
			filtro2.carregarImg(str(arquivo))
			filtro2.callBackPogresso(self.percentagem)
			im2 = filtro2.filtrarDeutan(equalizar = self.equalizar, lms = self.lms)

			# Fuzzy 1
			fuz1 = Fuzzy(False,self.p,self.de,self.da,self.n)
			if self.pb:
				self.pb.setLabel('[3/6] Aplicando filtro Fuzzy 1 em ' + str(label))
			fuz1.callBackProgresso(self.percentagem)
			im1 = fuz1.multiplicaProtan(im1)

			# Fuzzy 2
			#fuz2 = Fuzzy(False,self.p,self.de,self.da,self.n)
			if self.pb:
				self.pb.setLabel('[4/6] Aplicando filtro Fuzzy 2 em ' + str(label))
			fuz1.callBackProgresso(self.percentagem)
			im2 = fuz1.multiplicaDeutan(im2)


			if self.pb:
				self.pb.setLabel('[5/6] Aplicando filtro Fuzzy 3 em ' + str(label))
			fuz1.callBackProgresso(self.percentagem)
			im3 = fuz1.multiplicaNormal(im3)

			# Soma da matrizes
			if self.pb:
				self.pb.setLabel('[6/6] Aplicando soma de matrizes em ' + str(label))
			fuz1.callBackProgresso(self.percentagem)
			im4 = Image.open(str(arquivo))
			im4 = fuz1.soma(im1, im2, im3, im4)

			im4.save("default_output/" + str(i) + ".bmp", "BMP")

			self.resultado.append((label, str(arquivo), "default_output/" + str(i) + ".bmp"))

			i = i + 1


		#quandoTermina(self.resultado)
		#self.pb.hide()
		return self.resultado
Beispiel #7
0
from rupiah import Rupiah
from fuzzy import Fuzzy

masaKerja = int(input("Masukkan lama masa kerja (tahun): "))
produkTerjual = int(input("Masukkan banyak barang terjual (unit): "))
fuzz = Fuzzy(masaKerja, produkTerjual)
bonus = Rupiah(fuzz.hitungBonus())
nilai_z = Rupiah(fuzz.nilai_z)
print("> Masa Kerja:", "{} Tahun".format(masaKerja),
      "| {}".format(fuzz.displayMasaKerja()))
print("> Produk Terjual:", "{} Unit".format(produkTerjual),
      "| {}".format(fuzz.displayProdukTerjual()))
print("> Bonus Penjualan:", fuzz.displayBonus())
print("----------------------------------")
print(">> Total Bonus: {}".format(bonus.konversi()), "<<")
print("----------------------------------")
    def initialize(self, article):

        similarity_array = []
        # similarity_array.append(article)
        test = self.articleSummerization(article, 1)  # in one line

        # for i in summerizedSentence:
        # 	test=str(i)
        print('-------Summerized Title-------')
        print(test)

        sitesContainingArticle, scrapId = self.googleSearch(article)

        print('sites_length_after_google search', len(sitesContainingArticle))

        for index, url in enumerate(sitesContainingArticle):
            print('URL ', url, scrapId[index], '\n')

            raw_html = self.simple_get(url)  #full page site content
            try:
                soup = BeautifulSoup(
                    raw_html, 'html.parser')  #proper formattinh raw_html
                # print('hua idhar')
                # print(soup)

            except Exception as e:
                print(e)
                return 0, []

            _ = [s.extract() for s in soup('script')]

            soup_article = soup.find_all('div', {"class": scrapId[index]})

            # print(soup_article)

            article_string = ''
            for data in soup_article:
                # print(data)
                article_string += data.text
                # article_string += data.text
            # print(article_string)
            if not article_string == '':
                # print('aaya\n')
                similarity_array.append(
                    self.articleSummerization(article_string, 5))

            else:
                print('nahi aaya\n')
                pass

        # for c in similarity_array:
        # 	print('\n\n\n',c)

        mylsa = LSA()
        wmdinit = WordMoverDistance()

        length = len(similarity_array)
        # print(length)

        if length == 0:
            return 0, sitesContainingArticle
        else:
            count = 0
            score_array = []

            while (count < length):
                print('\n\n', similarity_array[count])
                lsa_similarity = mylsa.start([article + ' ' + article] +
                                             similarity_array, count + 1)
                wmdinit.data_accept(similarity_array[count], article)
                wmddistance = wmdinit.model()

                print('wordmover distance is', wmddistance)

                fuzzy = Fuzzy(lsa_similarity, wmddistance)
                score = fuzzy.get_score_data()
                # score = score/10
                print('final score ', score)

                score_array.append(score)
                count = count + 1

            score_array = sorted(score_array, key=lambda x: x, reverse=True)

            return min(100,
                       np.around(sum(score_array[:2]), decimals=2) *
                       100), sitesContainingArticle


# wmdinit=wordmover.WordMoverDistance(titles[count],titles[0])
# wmddistance=wmdinit.model()
Beispiel #9
0
def getAcTemp():
   data = request.get_json()
   Fuzzy.valueIinitialization(data['insideTemp'],data['outsideTemp'],data['people'])
   bestTemp = Fuzzy.inferensi()
   return jsonify({'OptimalTemperature': bestTemp}),200