#gpiozero library
Hack DUT
Wednesday, February 12, 2025
Thursday, January 30, 2025
fuzzy search
Below are from answers get from Deepseek
### **How Fuzzy Search Works**
Fuzzy search is designed to find strings that approximately match a given query, even if the query contains typos, misspellings, or incomplete words. The key idea is to rank potential matches based on how closely they align with the query.
#### Key Concepts:
1. **Subsequence Matching**:
- Fuzzy search looks for whether the characters in the query appear in the target string **in the same order**, but not necessarily consecutively.
- For example, the query `"leaders"` matches `"leadership skills"` because the letters `l`, `e`, `a`, `d`, `e`, `r`, `s` appear in order within the target string.
2. **Scoring**:
- Matches are ranked based on how closely they align with the query. Factors like:
- **Proximity of characters**: Characters that appear closer together in the target string are preferred.
- **Completeness**: Matches that include more of the query characters are ranked higher.
3. **Efficiency**:
- Fuzzy search algorithms are optimized to quickly filter and rank potential matches, even in large datasets.
---
### **How FuzzyFinder Implements Fuzzy Search**
FuzzyFinder uses a simple yet effective approach to implement fuzzy search. Here’s a high-level overview of how it works:
#### Algorithm Steps:
1. **Preprocessing**:
- Convert both the query and the target strings to lowercase (to make the search case-insensitive).
2. **Subsequence Matching**:
- For each target string, check if the characters in the query appear in the same order within the target string.
- Example:
- Query: `"leaders"`
- Target: `"leadership skills"`
- Check if `l`, `e`, `a`, `d`, `e`, `r`, `s` appear in order in `"leadership skills"`.
3. **Scoring**:
- Assign a score to each match based on:
- **Character proximity**: Characters that appear closer together in the target string are preferred.
- **Match completeness**: Matches that include more of the query characters are ranked higher.
4. **Ranking**:
- Sort the matches based on their scores and return the results.
---
### **Example Implementation of Fuzzy Search**
If you wanted to implement a simple version of fuzzy search yourself, here’s how you could do it in Python:
#### Code:
```python
def fuzzy_search(query, choices):
query = query.lower()
matches = []
for choice in choices:
choice_lower = choice.lower()
i = 0 # Index for query
j = 0 # Index for choice
score = 0
# Check if query characters appear in order in the choice
while i < len(query) and j < len(choice_lower):
if query[i] == choice_lower[j]:
i += 1
score += 1 # Increase score for each matching character
j += 1
# If all query characters were found in order, add to matches
if i == len(query):
matches.append((choice, score))
# Sort matches by score (higher scores first)
matches.sort(key=lambda x: x[1], reverse=True)
return [match[0] for match in matches]
# Example usage
terms = [
"team leaders",
"project leaders",
"leadership skills",
"manager",
"ceo",
"director",
"lead developer",
"head of department",
"lead engineer",
"leadership training"
]
query = "leaders"
matches = fuzzy_search(query, terms)
print("Fuzzy matches for 'leaders':", matches)
```
#### Output:
```
Fuzzy matches for 'leaders': ['team leaders', 'project leaders', 'leadership skills', 'leadership training']
```
---
### **Why FuzzyFinder is Efficient**
FuzzyFinder is optimized for performance. It avoids complex calculations (like Levenshtein distance) and instead focuses on **subsequence matching** and **scoring**, which makes it fast and suitable for real-time applications.
---
### **Comparison with Other Algorithms**
1. **Levenshtein Distance**:
- Measures the number of edits (insertions, deletions, substitutions) required to transform one string into another.
- More accurate but computationally expensive for large datasets.
2. **FuzzyWuzzy**:
- Uses Levenshtein distance and provides similarity scores.
- Slower than FuzzyFinder but more precise.
3. **Regular Expressions**:
- Can be used for pattern matching but doesn’t handle typos or approximate matches.
---
### **When to Use FuzzyFinder**
- When you need **fast, approximate matching** for large datasets.
- When you want a lightweight solution without heavy dependencies.
- When you don’t need the precision of Levenshtein distance.
---
### **Conclusion**
FuzzyFinder’s algorithm is not overly complicated—it relies on **subsequence matching** and **scoring** to efficiently find approximate matches. If you’re curious, you can even implement a basic version yourself (as shown above) to understand how it works under the hood.
If you’d like to dive deeper into the implementation or explore more advanced fuzzy search techniques, let me know! 😊
Sunday, April 28, 2024
C Programming
Header Files and Includes
Preprocessing Macros
Thursday, February 8, 2024
SVN Quick Reference
this is a short summary for my reference based on the great official tutorial at:
Basic Work Cycle (red-bean.com)
Check out a working copy from a repository
Update Your Working Copy
Make Your Changes
Changing the Repository Without a Working Copy
Review Your Changes
Fix Your Mistakes
Resolve Any Conflicts
Commit Your Changes
Examining History
%svn diff --summarize -r42:41 #just pirnt the filenames that has changes between 2 commits
Checkout a Specific Version of files
Sometimes You Just Need to Clean Up
Saturday, January 13, 2024
PCIe Study Notes
Chapter 1: Background
Nice References
PCI
PCI-X
Chapter 2: PCIe Architecture Overview
Transaction Layer
Data Link Lyaer
Physical Layer
Electriclal Part
Chapter 3: Configuration Overview
Enumeration
PCIe Devices: 32 devices per bus; PCIe point-to-point link means that device will always be Device 0. Deach Device must implement Function 0.
PCIe Functions: Functions do not need to be implemented sequenctially. SW must check every one of the 8 functions to decide which are present.
Errors should not normally be reported during enumeration.(the enumeration sw could fail since it's typically writtent o execute before the OS or other error handling SW is available.
Device not present: SW get Vendor ID of FFFFh, reserved for "device not present"
#TODO: enumeration started after 100ms+link training after reset, how to do it in DV simulation?
#TODO: what will enum sw do if there is no EP attached to a pci-pci bridge? #multi-root system: what if rc assign start bus number 64 to rc, but later find that the total buses are more then 265-64? is this an error? It is important to remember that each port on a switch is aBridge, and thus has its own configuration space with a Type 1 Header. In reality, each port (each P2P Bridge) has its own Type 1 Header and performs the same two checks on TLPs when they are seen by that port.
#TODO: enumeration started after 100ms+link training after reset, how to do it in DV simulation?
#TODO: what will enum sw do if there is no EP attached to a pci-pci bridge?
Chapter 4: Address Space & Transaction Routing
Confugration
TLP Routing
Sunday, December 31, 2023
how to build a cpu
Adder
oscillator
Sunday, November 5, 2023
QEMU/KVM virtual machines on linux
I'm running Debian linux 12 on macbook pro.
I find the official Debian Wiki is as always very useful:
and also this Youtube video tutorial for beginners:
QEMU/KVM for absolute beginners by Veronica Explains
install needed packages
%sudo apt install --no-install-recommends qemu-system libvirt-clients libvirt-daemon-system
%sudo apt install virtinst #if you want to create guest os on command line instead of gui
Creating a new guest:
virt-install --virt-type kvm --name bullseye-amd64 \ --location http://deb.debian.org/debian/dists/bullseye/main/installer-amd64/ \ --os-variant debian11 \ --disk size=20 --memory 4000 \ --graphics none \ --console pty,target_type=serial \ --extra-args "console=ttyS0"
Connect to a VM through command line
raspberry pi gpio controls
#gpiozero library https://gpiozero.readthedocs.io/en/stable/#