algorithm

Why is KNN slow with custom metric?

£可爱£侵袭症+ 提交于 2021-02-08 08:20:01
问题 I work with data set consists about 200k objects. Every object has 4 features. I classifies them by K nearest neighbors (KNN) with euclidean metric. Process is finished during about 20 seconds. Lately I've got a reason to use custom metric. Probably it will make better results. I've implemented custom metric and KNN has become to work more than one hour. I didn't wait for finishing of it. I assumed that a reason of this issue is my metric. I replace my code by return 1 . KNN still worked more

Generating square wave in AVR Assembly without PWM

北慕城南 提交于 2021-02-08 08:06:11
问题 I'm using an ATmega328. The thing is that I want to generate a square wave of a given frequency and of a given amplitude. PWM can't be used because I was given a board that has already been soldered, so the wave has to be put at the output of an R2R resistor ladder that is connected to the B port of the processor. So, basically, the idea is that I have to put the pins of port B in 0 and VOLUME (VOLUME is a number that goes from 1 to 255) periodically, with a given frequency and a duty cycle

CodeWars/ Merged String Checker

大兔子大兔子 提交于 2021-02-08 07:57:18
问题 The challenge is next: At a job interview, you are challenged to write an algorithm to check if a given string, s, can be formed from two other strings, part1 and part2. The restriction is that the characters in part1 and part2 are in the same order as in s. The interviewer gives you the following example and tells you to figure out the rest from the given test cases. What am I doing wrong? Why it fails anyway? I wrote 2 different scripts, and both aren't working for some test cases function

Find element in a sorted array

倾然丶 夕夏残阳落幕 提交于 2021-02-08 07:52:44
问题 Given a sorted array A and an element x , I need to find an algorithm that returns the index of x in A or -1 if x is not in A . the time complexity of the algorithm should be Θ(logd) when d is the number of elements that appears before x in A , or if x is not in A , d is the number of elements that were before x if he was in A . Binary search is not good enough because its best case is O(1). I thought of starting from the beginning of the array, and start checking the indexes that are powers

sorting numbers with mix of switch and rotate in python

旧巷老猫 提交于 2021-02-08 06:48:52
问题 Justification first :) Switch: Switch the marbles in positions 0 and 1. Rotate: Move the marble in position 0 to position N - 1, and move all other marbles one space to the left (one index lower). If there is a list of number (1,3,0,2) switch - rotate - switch will sort the numbers 3,1,0,2 - 1,0,2,3 - 0,1,2,3 But if we have (3,1,0,2), it never ends with switch - rotate - switch - rotate ... method. Is there a better way to use both switch and rotate to efficiently get the sorted result? 回答1:

Heapq module implementation

风格不统一 提交于 2021-02-08 06:18:09
问题 I was reading the heapq module source because I reviewed a question on CodeReview and I cannot understand something. In the wikipedia article about heap it says: sift-up: move a node up in the tree, as long as needed; used to restore heap condition after insertion. Called "sift" because node moves up the tree until it reaches the correct level, as in a sieve. sift-down: move a node down in the tree, similar to sift-up; used to restore heap condition after deletion or replacement. But the code

Explanation of normalized edit distance formula

牧云@^-^@ 提交于 2021-02-08 06:14:41
问题 Based on this paper: IEEE TRANSACTIONS ON PAITERN ANALYSIS : Computation of Normalized Edit Distance and Applications In this paper Normalized Edit Distance as followed: Given two strings X and Y over a finite alphabet, the normalized edit distance between X and Y, d( X , Y ) is defined as the minimum of W( P ) / L ( P )w, here P is an editing path between X and Y , W ( P ) is the sum of the weights of the elementary edit operations of P, and L(P) is the number of these operations (length of

Explanation of normalized edit distance formula

时光毁灭记忆、已成空白 提交于 2021-02-08 06:11:22
问题 Based on this paper: IEEE TRANSACTIONS ON PAITERN ANALYSIS : Computation of Normalized Edit Distance and Applications In this paper Normalized Edit Distance as followed: Given two strings X and Y over a finite alphabet, the normalized edit distance between X and Y, d( X , Y ) is defined as the minimum of W( P ) / L ( P )w, here P is an editing path between X and Y , W ( P ) is the sum of the weights of the elementary edit operations of P, and L(P) is the number of these operations (length of

Explanation of normalized edit distance formula

末鹿安然 提交于 2021-02-08 06:07:25
问题 Based on this paper: IEEE TRANSACTIONS ON PAITERN ANALYSIS : Computation of Normalized Edit Distance and Applications In this paper Normalized Edit Distance as followed: Given two strings X and Y over a finite alphabet, the normalized edit distance between X and Y, d( X , Y ) is defined as the minimum of W( P ) / L ( P )w, here P is an editing path between X and Y , W ( P ) is the sum of the weights of the elementary edit operations of P, and L(P) is the number of these operations (length of

A*(Star) Prolog

筅森魡賤 提交于 2021-02-08 05:57:38
问题 I have an A*(Star) Algorithm in prolog, and I need receive a list of destinations instead a single destination, and it should past for every element of the list and then back to the start. NOTE: It can pass in the same place twice. I tried it, but Swi-prolog returns false everytime, can I get any help? The code above receive a single destination, and it works, but as I said I need a list of destinations, and pass through them all. Example: astar(1,[2,2,4,6,8,9,10,13,15],C,P). /*area(Number