header += f"{i:^4}"
	print(header)

	# printing row by row
	index = 0
	for i in set1.keys():
		string = f'{i}| '+'  '.join(map(str,map(float,product[index])))
		print('_'*len(string))
		print(string)
		index += 1
	print('-'*40+'\n')

if __name__ == "__main__":
	clear()
	set1 = get_set()
	print_set(set1)
	set2 = get_set()
	print_set(set2)

	product = fuzz_product(set1, set2)
	
	print_product(set1,set2,product)
	print( "*" * 30)

"""
Example Input
2
a 0.4
b 0.6
3
c 0.3
Example #2
0
    a = get_set("A")
    a = sort_Fuzzy_set(a, A)
    neg_a = fuzzy_negation(a, A)

    # b and c are from universe Y
    Y = get_universal_set("Universal Y")
    b = get_set("B")
    b = sort_Fuzzy_set(b, Y)

    c = get_set("C")
    c = sort_Fuzzy_set(c, Y)

    while True:
        clear()
        print("A")
        print_set(a)
        print("Not A")
        print_set(neg_a)
        print("B")
        print_set(b)
        print("C")
        print_set(c)

        n = input("Press any key or q to exit: \n")
        if n == 'q' or n == 'Q':
            break
        else:
            first = fuzz_product(a, b)
            print_product(a, b, first, 'A', 'B')

            second = fuzz_product(neg_a, c)
else:
    clear = lambda: os.system('clear')


def lambda_cutset(set1, l):
    new = defaultdict(float)
    for i, v in set1.items():
        if v >= l:
            new[i] = v
    return new


while True:
    clear()
    set1 = get_set()
    print_set(set1)
    lambda_value = float(input("Enter lambda value: "))
    print("New Lambda Cut Set: \n")
    print_set(lambda_cutset(set1, lambda_value))
    input()
"""
Example Input
5
2
a 0.2
b 0.5
c 0.9
d 0.25
e 0.35
0.3
"""
Example #4
0
            fs[i] = round(1 - 2 * (1 - v)**2, 2)
    return fs


if __name__ == "__main__":
    clear()
    print("Fuzzy Rule Base System")

    # define a set alpha
    alpha = get_set("Alpha")
    flag = True

    while flag:
        clear()
        print("Alpha:")
        print_set(alpha)

        while flag:
            print("1. Very α")
            print("2. Very Very α")
            print("3. Plus α")
            print("4. Slightly α")
            print("5. Minus α")
            print("6. Intensify")
            print("7. Not alpha")
            print("8. Quit")
            n = int(input("Enter Choice: "))
            print('-' * 30)

            if n == 1:
                print("Very Alpha")
Example #5
0
def ask_query(query):
	# sets dictionary contain many fuzzy sets used in dictionary
	sets = {}

	# split string and check words not in keyword
	for q in query.split():
		if q .lower() not in ['and','or','not','very','intensely','plus','minus','slightly']:
			print(f"Define set: {q}")
			sets[q] = get_set(q)
	clear()
	# small = OrderedDict({1:1, 2:0.8, 3:0.6, 4:0.4, 5:0.2})
	# large = OrderedDict({1:0.2, 2:0.4, 3:0.6, 4:0.8, 5:1})

	# seperate the string based on 'or' occurance 
	or_seperated = query.split('or')

	# all values are set to 0 so that we can combine (using max operator) different or result 
	or_set = OrderedDict({1: 0, 2: 0, 3: 0, 4: 0, 5: 0})

	# iterate on each component seperated in 'or' split
	for q_or in or_seperated:
		print('*'*50)
		print("OR Clause: ",q_or)

		# seperate each of the or query on 'and' occurance
		and_seperated = q_or.strip().split('and')

		# all values are set to 1 so that we can combine different and result 
		and_set = OrderedDict({1: 1, 2: 1, 3: 1, 4: 1, 5: 1})

		# iterate on each of the and seperated query
		for q_and in and_seperated:
			print("\tAND Clause: ",q_and.strip())
			
			# spliting or clause further by 'and' values
			words = q_and.split()

			# checking for not prefix in clause
			if words[0] == 'not':
				not_prefix = True
				words.pop(0)
			else:
				not_prefix = False

			if len(words) == 3: 
					if words[0] == 'very' and words[1] == 'very':
						temp =  very_very_alpha( sets[words[2]] )
			elif len(words) == 2:
					if words[0] == 'very':
						temp = very_alpha( sets[words[1]] )
					elif words[0] == 'plus':
						temp = plus_alpha( sets[words[1]] )
					elif words[0] == 'slightly' or words[0] == 'slight':
						temp = Slightly_alpha( sets[words[1]] )
					elif words[0] == 'minus':
						temp = minus_alpha( sets[words[1]] )
					elif words[0] == 'intensify':
						temp = intensify( sets[words[1]] )
			elif len(words) == 1:
					temp = sets[words[0]]

			# if not is present in brgining than obtaing negation
			if not_prefix:
				temp = not_alpha(temp) 

			for i,v in temp.items():
				and_set[i] = min(and_set[i], v)
			print("\nResult of this AND clause: ")
			print_set(and_set)

		for i,v in and_set.items():
			or_set[i] = max(or_set[i], v)
		print('*'*50)

	print("\nFinal result: ")
	print_set(or_set)
Example #6
0
    print("2. Calculate B_prime = A_prime x R\n")
    # a is from universe A
    A = get_universal_set("Universal A")
    # getting all elements of universe A even with zero membership
    a = sort_Fuzzy_set(get_set("A"), A)
    a_prime = sort_Fuzzy_set(get_set("A_Prime"), A)
    neg_a = fuzzy_negation(a, A)

    # b from universe Y
    Y = get_universal_set("Universal Y")
    b = sort_Fuzzy_set(get_set("B"), Y)

    while True:
        clear()
        print("A:")
        print_set(a)
        print("Not A:")
        print_set(neg_a)
        print("A_Prime:")
        print_set(a_prime)
        print("B:")
        print_set(b)

        # get A x B
        first = fuzz_product(a, b)
        # get not A x Y
        second = fuzz_product(neg_a, Y)

        # R = (A x B) U (not A x Y) = first x second
        print("\nR = (A x B) U (not A x Y)\n")
        R = fuzzy_relation_union(first, second)