math

compare angle and up in strange behavior

依然范特西╮ 提交于 2021-01-29 15:02:06
问题 i have a func to compare angles.. if the angles si between the range -5/+5deg from the starting heading this should return Color .green otherwise should return .orange. i simplify the project so it can be easy to use in swift Playground. here my fun: func convertToPositiveAngle(_ angle : Angle) -> Angle { var toRet = Angle(degrees: fmod(angle.degrees, 360)) if toRet.degrees < 0 { toRet.degrees += 360.0; } return toRet } let headingStart = 3.0 let currentHeading = 3.0 func centro(startHeading

How to improve integer partitioning with n,m,k

我们两清 提交于 2021-01-29 14:52:41
问题 my program counts the integer partitions of n , which have k distinct partition elements, each is smaller or equal to m . How can i improve the performance? I already cache immediate results. public long q(int n, int m, int k){ return q1(n,m,k,0,0,new HashMap()); } private long q1(int n, int m, int k, int level, int last, Map<String, Long> cache){ if(n <0){ return 0; } if(level+1 ==k){ if(n >m){ return 0; } else { return 1; } } int first = (level == 0) ? 1 : last+1; long total = 0; for(int i

Looking for a specific combination algorithm to solve a problem

余生颓废 提交于 2021-01-29 13:13:07
问题 Let’s say I have a purchase total and I have a csv file full of purchases where some of them make up that total and some don’t. Is there a way to search the csv to find the combination or combinations of purchases that make up that total ? Let’s say the purchase total is 155$ and my csv file has the purchases [5.00$,40.00$,7.25$,$100.00,$10.00]. Is there an algorithm that will tell me the combinations of the purchases that make of the total ? Edit: I am still having trouble with the solution

Figuring out new X and Y based on rotation

怎甘沉沦 提交于 2021-01-29 12:05:09
问题 I'm nuilding a graphical editor where you can select elements, scale them, rotate, resize etc. One thing I've been stuck on is positioning an element after it's rotated. I have the following javascript class that handles resizing: const rotateCoords = (x, y, rotation) => { const rad = (rotation * Math.PI) / 180 return { y: y * Math.cos(rad) - x * Math.sin(rad), x: x * Math.cos(rad) + y * Math.sin(rad), } } export default ( e, ratio, resizeDirection, resizeMouseX, resizeMouseY, zoomScale,

How to generate random positions with distance between them inside the hexagon?

你离开我真会死。 提交于 2021-01-29 08:01:37
问题 I am trying to create N random pairs of points (N = 50) of a given distances, inside a 500 meters hexagon. The distance D created by using (dmax - dmin).*rand(N,1) + dmin , with dmin = 10 and dmax = 100 in Matlab. I understant that the first I have to generate a set of points ([x1 y1]) that have at least distance D from the main hexagon border, then generate the second set of points ([x2 y2]) that have exact distance D from the first set. But sometime I got the problem with the second point

Making Canvas text objects bounce off of each other and be created by an array

主宰稳场 提交于 2021-01-29 07:40:43
问题 I've recently started working on a website and learning HTML/CCS/JS and came across and idea that I'm unsure of how to execute. Basically I want the floating text that currently moves around and bounces off the window borders to bounce off one another as well. I also figured that an array might be good to be able to set how many text objects I want to spawn. Here is my site for reference of how the text bounces around http://gmtrash.ga/ And here Is the JavaScript controlling the text objects

Number of digits after multiplication, dividing

一世执手 提交于 2021-01-29 07:18:16
问题 I have two numbers X and Y , i don't know their values but i know that the maximal number of digits that can contain X is 10 (for example) and for Y is 3 (for example) I need to know the maximal number of digits of Z that equals to X * Y . Same for Z = X / Y 回答1: If X can have at most n digits and Y can have at most m digits, then X < 10 ^ n and Y < 10 ^ m This means that X * Y < 10 ^ n * 10 ^ m = 10 ^ (n + m) In other words, X * Y can have at most n + m digits. With division, we need to take

Why do we use log probability in deep learning?

陌路散爱 提交于 2021-01-29 06:51:36
问题 I got curious while reading the paper 'Sequence to Sequence Learning with Neural Networks'. In fact, not only this paper but also many other papers use log probabilities, is there a reason for that? Please check the attached photo. 回答1: For any given problem we need to optimise the likelihood of parameters. But optimising the product require all data at once and requires huge computation. We know that a sum is a lot easier to optimise as the derivative of a sum is the sum of derivatives. So,

choose a number from a range based on percentage of another number

好久不见. 提交于 2021-01-29 06:00:31
问题 I want to select a number between two numbers depends on the percentage of an input. lets say the range is between 40-60. and input range is between 1-10. if the input value is 10 , the output should be 60. value = 1 , output = 40. value = 5 , output = 50. I am first trying to figure the algorithm, how to begin with so far I have used various different formulas. In general, to scale your variable x into a range [a,b] you can use: normalized = ((b−a)x−min(x))(max(x)−min(x))+a https://stats

How to change support of multivariate integral to [0,1]^k using scipy.integrate.quad?

∥☆過路亽.° 提交于 2021-01-29 05:21:08
问题 The following k-dimension integral has dependent limits (a support dependent on gamma ): from scipy.integrate import nquad import numpy as np def func(*args): gamma = args[-1] var = np.array(args[:-1]) return (1-1/(1+gamma-np.sum(var)))*np.prod(((1+var)**-2)) def range_func(*args): gamma = args[-1] return (0, gamma-sum(args[:-1])) gamma, k = 10, 2 print(nquad(func, [range_func]*k, args=(gamma,) )) The limits are defined inside the function range_func above return (0, gamma-sum(args[:-1])) How