The aim of this project is to get the least number of outputs to get all the possible logic gates for n inputs. This repository contains the code for activation functions, the code for the generation of orders, the code used to compute the OR operation, and some of the results.
-
Here contains the code used to generate all possible orders. Using Queue, in each step, generate a dictionary that contains all the possible elements for next step based on the current item.
-
There are two main functions for the generation of orders.
-
- Next Possible item generation
-
- Take the current list order as input eg.[a, b, ab, c, d]
-
- Take the first item in the input list first (ie. a), as it is the one with the smallest concentration, combine it with the element after it in the order of the input list in order(b, ab, c, d).
-
- If the combined item has existed in the current list(ab is in the list), combine with the next item(c) until there is an item that is not in the list, add that the combined item into a list that would contain all possible item. This item would be the one with least concentration starting with the first item(a). If all the combined item have already existed, move to the second element in the current list.
-
- After combining the previous item, delete the item combined with the first item(d) and all elements after it in the current list.(a,b,ab,c)
-
- Then move to the next item(b) and repeat the same thing(bc) until there is no more item to add.
-
- All the item added to the list will be compared with each other in the next function.
-
- Filter states
-
- After getting the previous list, if the items in it do not contain same letter, then we do not know which have higher concentration, therefore all of them can be the possible next item, and will be in the dictionary move with key 1. eg: 1: [ab, ce]
-
- if they contains same letter, then the function deletes the letter appears in both of them, then compare the rest using the current order, then delete the one with higher order. Eg.[abe, acd], then check in current list does ‘be’or ‘cd’come first.
-
- After comparing all items, the items left will be added into set in the dictionary with key 1.
-
- Then the items in the dictionary with both key 0 and 1 will be added to the current list separately.
-
- Generate by branches
-
- To make the process of generation shorter, we can generate only one branch of orders, use different label to map the orders to get all the possible index order.
-
- Generation of one branch of order takes (T/n), T is the time needed to generate all the orders, n is the number of inputs. Eg: start the Queue with [‘a’], then all the order in this branch will start with ‘a’.
- Code
- Here contains the code used to do the OR operation.
-
- Turn logic gate into int number
-
- Use bitwise_or instead of logical_or
-
- Use numpy.array operation instead of ‘for loop’
-
- Split the data into chunks to avoid running out of memory
-
- Run the program in several branches in parallel to save time
- code of the generation of bar chart
- 3 inputs 1 output logic result
- 4 inputs 1 output logic result
- 4 inputs 2 outputs int result
- 4 inputs 3 outputs int result
- 5 inputs 1 output logic result
The blue bars on the graph below are the results with our approach.