text
stringlengths 0
27.6k
| python
int64 0
1
| DeepLearning or NLP
int64 0
1
| Other
int64 0
1
| Machine Learning
int64 0
1
| Mathematics
int64 0
1
| Trash
int64 0
1
|
---|---|---|---|---|---|---|
Say you have n GPS coordinates how could you work out the central GPS point between them?
| 0 | 0 | 0 | 0 | 1 | 0 |
if I do positionVector*worldMatrix the position is transformed into world space.
But what happens if I do it the other way around (worldMatrix*positionVector) in terms of 3d space?
I noticed the result is different to the first one. I already googled about matrix, math they explain a lot but not this one, at least I couldn't find it.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have an application with some probabilities of measured features. I want to select n-best features from vector. I have a vector of real numbers. Vector is normalized, sum of all numbers is 1 (it is probability of some features).
I want to select group of n less than N (assume approx. 8) largest numbers. Numbers has to be close together without gaps and they're also should have large sum (sum of remaining numbers should be several times lower).
Any ideas how to accomplish that?
I tried to use 80% quantile (but it is not sensitive to relative large gaps like [0.2, 0.2, 0.01, 0.01, 0.001, 0.001 ... len ~ 100] ), I tried a some treshold between two successive numbers, but nothing work too good.
I have some partial solution at this moment but I am just wondering if there is some simple solution that I have overlooked.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have the following problem, and am having trouble understanding part of the equation:
Monte Carlo methods to estimate an integral is basically, take a lot of random samples and determined a weighted average. For example, the integral of f(x) can be estimated from N independent random samples xr by
alt text http://www.goftam.com/images/area.gif
for a uniform probability distribution of xr in the range [x1, x2]. Since each
function evaluation f(xr) is independent, it is easy to distribute this work
over a set of processes.
What I don't understand is what f(xr) is supposed to do? Does it feed back into the same equation? Wouldn't that be an infinite loop?
| 0 | 0 | 0 | 0 | 1 | 0 |
How to get the fraction length? If at all possible, without using string operation or loop
should all return length of 3:
5.234
5.23400
5.234000
Any programming language is accepted
[EDIT]
Not a homework, I want to display fractions at its minimum. Example, I defined numeric(18,8) in database. If the user entered only 5.234, the data saved in database is 5.23400000. I just want to display it back as 5.234 only
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm using
worldview_inverse * (projection_inverse * vector)
to transform screen space coordinates into world space coordinates.
I assumed that
(x,y,1,1)
would transform to a point on the far plane, while
(x,y,-1,1)
transforms to a point on the near plane, and connecting the line I can query all objects in the view frustum that intersect the line.
After the transformation I divide the resulting points by their respective .w component.
This works for the far-plane, but the point on the near plane somehow gets transformed to the world space origin.
I think this has to do with the w components of 1 I'm feeding into the inverse projection, because usually it is 1 before projection, not after, and I'm doing the reverse projection. What am I doing wrong?
| 0 | 0 | 0 | 0 | 1 | 0 |
In a "multitouch" environement, any application showed on a surface can be rotated/scaled to the direction of an user. Actual solution is to drawing the application on a FBO, and draw a rotated/scaled rectangle with the texture on it. I don't think it's good for performance, and all graphics cards don't provide FBO.
The idea is to clip the rendering viewport in the direction of user.
Since glViewport cannot be used for that, is another way exist to achieve that ?
(glViewport use (x, y, width, height), and i would like (x, y, width, height, rotation from center?))
PS: rotating the modelview or projection matrix will not help, i would like to "rotate the clipping plan" generated by glViewport. (only part of the all scene).
| 0 | 0 | 0 | 0 | 1 | 0 |
Given is a set S of size n, which is partitioned into classes (s1,..,sk) of sizes n1,..,nk. Naturally, it holds that n = n1+...+nk.
I am interested in finding out the number of ways in which I can combine elements of this partitioning so that each combination contains exactly one element of each class.
Since I can choose n1 elements from s1, n2 elements from s2 and so on, I am looking for the solution to max(n1*..*nk) for arbitrary n1,..nk for which it holds that n1+..+nk=n.
I have the feeling that this is a linear-optimization problem, but it's been too long since I learned this stuff as an undergrad. I hope that somebody remembers how to compute this.
| 0 | 0 | 0 | 0 | 1 | 0 |
With reference to this programming game I am currently building.
Thanks to the answers from this post, I am now able to find the x-y coordinates of all the points of the rectangles (even when rotated), and Collision-Detection with Walls is almost working perfectly now.
Now I need to implement collision detection with the bots themselves (cause obviously, there will be more than one bot in the Arena).
Square-Square Collision Detection (Non-rotated) is not valid in this case because the bots will be turned at an angle (just like I described here).
So what is the best way to implement this form of Rotated Rectangles Collision Detection in WPF?
I guess there must be some math involved, but usually it turns out that there are functions in WPF that "calculate" these maths for you (just like in this case)
| 0 | 0 | 0 | 0 | 1 | 0 |
Might anyone be famiiar with tricks and techniques to coerce the set of valid floating point numbers to be a group under a multiplication based operation?
That is, given any two floating point numbers ("double a,b"), what sequence of operations, including multiply, will turn this into another valid floating point number? (A valid floating point number is anything 1-normalized, excluding NaN, denormals and -0.0).
To put this rough code:
double a = drand();
while ( forever )
{
double b = drand();
a = GROUP_OPERATION(a,b);
//invariant - a is a valid floating point number
}
Just multiply by itself doesn't work, because of NaNs. Ideally this would be a straight-line approach (avoiding "if above X, divide by Y" formulations).
If this can't work for all valid floating point numbers, is there a subset for which such an operation is available?
(The model I'm looking for is akin to integer multiplication in C - no matter what two integers get multiplied together, you always get an integer back).
| 0 | 0 | 0 | 0 | 1 | 0 |
I am working on an app that will need to handle very large numbers.
I checked out a few available LargeNumber classes and have found a few that I am happy with. I have a class for large integers and for large floating point numbers.
Since some of the numbers will be small and some large the question is whether it is worth checking the length of the number and if it is small use a regular C# int or double and if is is large use the other classes I have or if I am already using the Large Integer and Large Float classes I should just stick with them even for smaller numbers.
My consideration is purely performance. Will I save enough time on the math for the smaller numbers that it would be worthwhile to check each number after is is put in.
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm solving problems in Project Euler. Most of the problems solved by
big numbers that exceeds ulong,
Ex : ulong number = 81237146123746237846293567465365862854736263874623654728568263582;
very sensitive decimal numbers with significant digits over 30
Ex : decimal dec =
0,3242342543573894756936576474978265726385428569234753964340653;
arrays that must have index values that exceeds biggest int value.
Ex : bool[] items = new
bool[213192471235494658346583465340673475263842864836];
I found a library called IntX to solve this big numbers. But I wonder how can I solve this problems with basic .NET types ?
Thanks for the replies !
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm looking for articles on tile based games, like the old ultima 6&7, or even puzzle pirates. Specifically:
How they keep track of objects on the map. Objects such as other characters, or trees, or things the character can move.
AI behind the characters. How the game handles character behavior for
characters on the map that are off screen. Especially with very large maps and numerous characters.
| 0 | 1 | 0 | 0 | 0 | 0 |
Binarization is the act of transforming colorful features of of an entity into vectors of numbers, most often binary vectors, to make good examples for classifier algorithms.
If we where to binarize the sentence "The cat ate the dog", we could start by assigning every word an ID (for example cat-1, ate-2, the-3, dog-4) and then simply replace the word by it's ID giving the vector <3,1,2,3,4>.
Given these IDs we could also create a binary vector by giving each word four possible slots, and setting the slot corresponding to a specific word with to one, giving the vector <0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1>. The latter method is, as far as I know, is commonly referred to as the bag-of-words-method.
Now for my question, what is the best binarization method when it comes to describe features for natural language processing in general, and transition-based dependency parsing (with Nivres algorithm) in particular?
In this context, we do not want to encode the whole sentence, but rather the current state of the parse, for example the top word on the stack en the first word in the input queue. Since order is highly relevant, this rules out the bag-of-words-method.
With best, I am referring to the method that makes the data the most intelligible for the classifier, without using up unnecessary memory. For example I don't want a word bigram to use 400 million features for 20000 unique words, if only 2% the bigrams actually exist.
Since the answer is also depending on the particular classifier, I am mostly interested in maximum entropy models (liblinear), support vector machines (libsvm) and perceptrons, but answers that apply to other models are also welcome.
| 0 | 1 | 0 | 1 | 0 | 0 |
My usercase is an iphone application where I do an animation on the scale, rotation and translation of an image.
So, I concat everything and feed it to the transform property, but there is one problem:
Since my images vary in size, it is a problem to position them correctly. I'm used to an inverted y axis coordinate system, so I want my image to positioned exactly at 60 pixels in the y axis.
So, how do I change from the original cartesian y axis to an inverted y axis point of view?
| 0 | 0 | 0 | 0 | 1 | 0 |
How can I make a LaTex macro which replaces each
\and by the word "and"
\or by the word "or"
so that the nouns are not in italics?
| 0 | 0 | 0 | 0 | 1 | 0 |
Does anybody know of something similar to Date.js in Ruby? Something that would be able to return a date object from something like: "two weeks from today". The Remember the Milk webapp incorporates this feature into their system and it is incredibly easy to use.
I would use the Date.js library itself but because it is on the client side it has its limitations. If the user doesn't have javascript enabled the functionality would be lost. This would affect mobile phone users who would, ideally, use our system via text message (sms).
I would love to use a solution that's already out there but if not how hard would it be to port this code into Ruby? I really don't know much about natural language interpretation but it seems like it would take some time.
Thanks.
| 0 | 1 | 0 | 0 | 0 | 0 |
I want to instance a slider constraint, that allows a body to slide between point A and point B.
To instance the constraint, I assign the two bodies to constrain, in this case, one dynamic body constrained to the static world, think sliding door.
The third and fourth parameters are transformations, reference Frame A and reference Frame B.
To create and manipulate Transformations, the library supports Quaternions, Matrices and Euler angles.
The default slider constraint slides the body along the x-axis.
My question is:
How do I set up the two transformations, so that Body B slides along an axis given by its own origin and an additional point in space?
Naively I tried:
frameA.setOrigin(origin_of_point); //since the world itself has origin (0,0,0)
frameA.setRotation(Quaternion(directionToB, 0 rotation));
frameB.setOrigin(0,0,0); //axis goes through origin of object
frameB.setRotation(Quaternion(directionToPoint,0))
However, Quaternions don't seem to work as I expected. My mathematical knowledge of them is not good, so if someone could fill me in on why this doesn't work, I'd be grateful.
What happens is that the body slides along an axis orthogonal to the direction. When I vary the rotational part in the Quaternion constructor, the body is rotated around that sliding direction.
Edit:
The framework is bullet physics.
The two transformations are how the slider joint is attached at each body in respect to each body's local coordinate system.
Edit2
I could also set the transformations' rotational parts through a orthogonal basis, but then I'd have to reliably construct a orthogonal basis from a single vector. I hoped quaternions would prevent this.
Edit3
I'm having some limited success with the following procedure:
btTransform trafoA, trafoB;
trafoA.setIdentity();
trafoB.setIdentity();
vec3 bodyorigin(entA->getTrafo().col_t);
vec3 thisorigin(trafo.col_t);
vec3 dir=bodyorigin-thisorigin;
dir.Normalize();
mat4x4 dg=dgGrammSchmidt(dir);
mat4x4 dg2=dgGrammSchmidt(-dir);
btMatrix3x3 m(
dg.col_x.x, dg.col_y.x, dg.col_z.x,
dg.col_x.y, dg.col_y.y, dg.col_z.y,
dg.col_x.z, dg.col_y.z, dg.col_z.z);
btMatrix3x3 m2(
dg2.col_x.x, dg2.col_y.x, dg2.col_z.x,
dg2.col_x.y, dg2.col_y.y, dg2.col_z.y,
dg2.col_x.z, dg2.col_y.z, dg2.col_z.z);
trafoA.setBasis(m);
trafoB.setBasis(m2);
trafoA.setOrigin(btVector3(trafo.col_t.x,trafo.col_t.y,trafo.col_t.z));
btSliderConstraint* sc=new btSliderConstraint(*game.worldBody, *entA->getBody(), trafoA, trafoB, true);
However, the GramSchmidt always flips some axes of the trafoB matrix and the door appears upside down or right to left.
I was hoping for a more elegant way to solve this.
Edit4
I found a solution, but I'm not sure whether this will cause a singularity in the constraint solver if the top vector aligns with the sliding direction:
btTransform rbat = rba->getCenterOfMassTransform();
btVector3 up(rbat.getBasis()[0][0], rbat.getBasis()[1][0], rbat.getBasis()[2][0]);
btVector3 direction = (rbb->getWorldTransform().getOrigin() - btVector3(trafo.col_t.x, trafo.col_t.y, trafo.col_t.z)).normalize();
btScalar angle = acos(up.dot(direction));
btVector3 axis = up.cross(direction);
trafoA.setRotation(btQuaternion(axis, angle));
trafoB.setRotation(btQuaternion(axis, angle));
trafoA.setOrigin(btVector3(trafo.col_t.x,trafo.col_t.y,trafo.col_t.z));
| 0 | 0 | 0 | 0 | 1 | 0 |
I want to create something similar to a double linked list (but with arrays) that works with lower/upper bounds.
A typical circular array would probably look like:
next = (current + 1) % count;
previous = (current - 1) % count;
But what's the mathematical arithmetic to incorporate lower/upper bounds properly into this ?
0 (lower bound item 1)
1
2 (upper bound item 1)
3 (lower bound item 2)
4 (upper bound item 2)
So that:
-> next on index 2 for item 1 returns 0
-> previous on index 0 for item 1 returns 2
-> next on index 4 for item 2 returns 3
-> previous on index 3 for item 2 returns 4
Thank you !
NOTE: Can't use external libraries.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a table that stores all values..eg x1, x2, x3 which determines fuzzy sets. Degree of membership is assigned to each using mathematical functions for Low, Med, High.
My rule 1 states that if x1 is high AND x2 is medium then probability of output is z.
I then take min{x1,x2} to evaluate the rule. Rule 2 states that if x2 is high OR x3 is medium then output is max{x2,x3}.
Now to defuzzify I take aggregation of rule consequences to find out the output of the 2 rules. I have all degrees of membership defined (0 to 1) for x1 x2 x3 for each rule.
How do I defuzzify?
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm devolping on Compact Framework 2.0 SP1 and when I try to use Math.Sinh it throws me a Not Supported Exception
If I can't use this function, is there any other alternative?
Thanks!
| 0 | 0 | 0 | 0 | 1 | 0 |
I am trying to find words (specifically physical objects) related to a single word. For example:
Tennis: tennis racket, tennis ball, tennis shoe
Snooker: snooker cue, snooker ball, chalk
Chess: chessboard, chess piece
Bookcase: book
I have tried to use WordNet, specifically the meronym semantic relationship; however, this method is not consistent as the results below show:
Tennis: serve, volley, foot-fault, set point, return, advantage
Snooker: nothing
Chess: chess move, checkerboard (whose own meronym relationships shows ‘square’ & 'diagonal')
Bookcase: shelve
Weighting of terms will eventually be required, but that is not really a concern now.
Anyone have any suggestions on how to do this?
Just an update: Ended up using a mixture of both Jeff's and StompChicken's answers.
The quality of information retrieved from Wikipedia is excellent, specifically how (unsurprisingly) there is so much relevant information (in comparison to some corpora where terms such as 'blog' and 'ipod' do not exist).
The range of results from Wikipedia is the best part. The software is able to match terms such as (lists cut for brevity):
golf: [ball, iron, tee, bag, club]
photography: [camera, film, photograph, art, image]
fishing: [fish, net, hook, trap, bait, lure, rod]
The biggest problem is classifying certain words as physical artefacts; default WordNet is not a reliable resource as many terms (such as 'ipod', and even 'trampolining') do not exist in it.
| 0 | 1 | 0 | 0 | 0 | 0 |
Consider a routine that counts by successive divide w/ remainder operations.
Starting with a 64-bit dividend, the routine divides by a constant divisor.
If the remainder is 0, the routine returns.
Otherwise, a new dividend is constructed by multiplying the remainder by 2^32 and adding the integer quotient.
In code:
/// ULong - 64 bit, unsigned
/// UInt - 32 bit, unsigned
const UInt Divisor;
int TrickyCounter( ULong Dividend)
{
int count = 0;
Ulong Quotient;
UInt Remainder;
do {
Quotient = Dividend/Divisor;
Remainder = Dividend%Divisor;
assert((Quotient >> 32) == 0);
count = count + 1;
Dividend = ((ULong)Remainder << 32) + Quotient;
} while (Remainder != 0);
return count;
}
With an arbitrary Divisor, is there a preferably non-iterating method to calculate the necessary Dividend to get the desired count?
For many initial dividends, this seems to quickly hit the "Assert" condition. Would some dividends cause this to loop forever?
If, instead of a count, the routine returns the quotient, can I calculate the Dividend to produce the number I want returned?
Uint TrickyNumber( ULong Dividend, int count)
{
Ulong Quotient = 0;
UInt Remainder;
while (count > 0)
Quotient = Dividend/Divisor;
Remainder = Dividend%Divisor;
assert((Quotient >> 32) == 0);
count = count - 1;
Dividend = ((ULong)Remainder << 32) + Quotient;
}
return (UInt)Quotient;
}
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a little math problem. I would like to have a function with these properties:
for x much bigger than 0: lim f(x) = x
for x much smaller than 0: lim f(x) = 0
and f(0) = 1 (sorry, I had here f(1)=1 which was wrong!)
f(x) should be monotonically increasing
So the function should look somewhat like this:
^
| /
| /
| /
___.-+´
--´-----+------>
|
The best I got so far is x/(1 + e^(-x)) but then I recognized that it drops below 0 and is not monotonically increasing.
A great help for playing around with these function is GraphFunc Online.
Also, it would be helpful if the function is fast to calculate as I need to execute it very often.
EDIT: I am using this in a program to limit values. I have an optimization algorithm, that uses curve fitting with a Levenberg-Marquardt algorithm. But this algorithm does not allow constraints, and optimizes over the full range of real values. So I need a function like this so that I can add an artificial constraint so that the function is bigger than 0. A simple approach would be to use f(x) = x² but then the function is not monotonically increasing and it has two minimas.
The Levenberg-Marquardt approximates derivatives, so I think it would be best when the function is smooth too. But I am not sure if this is absolutely necessary.
| 0 | 0 | 0 | 0 | 1 | 0 |
Stemming is something that's needed in tagging systems. I use delicious, and I don't have time to manage and prune my tags. I'm a bit more careful with my blog, but it isn't perfect. I write software for embedded systems that would be much more functional (helpful to the user) if they included stemming.
For instance:
Parse
Parser
Parsing
Should all mean the same thing to whatever system I'm putting them into.
Ideally there's a BSD licensed stemmer somewhere, but if not, where do I look to learn the common algorithms and techniques for this?
Aside from BSD stemmers, what other open source licensed stemmers are out there?
-Adam
| 0 | 1 | 0 | 0 | 0 | 0 |
Let's take a concrete example and hope I can be clear. Suppose the (ordered) list of months:
January < February < March < ... <
December
(with integers that stand for the months, zero-based), such that
Jan is 0, Feb is 1, ..., Dec is 11.
Now suppose I do not have access to the full names of months, and am given the following list, where months have been shortened to their first letter, and e stands for an empty category, like this:
e, F, e, e, e
If I build a list of "unambiguous months" (f:1, s:8, o:9, n:10, d:11), I can fill the empty categories by by first calculating the first category (using subtraction and mod 12), and then write the rest from there. However, suppose I am given the list
e, A, e, e, J, e
Then I can (intuitively) calculate that although A is ambiguous (could be April or August), in this context it can only be April, since August does not have any Js following it after 2 categories. Once I find this, I can again calculate everything from the start.
My question, finally, is: is there an analytic solution (function, algorithm) for this problem, or is my only hope to use brute force to define each potential relation? For some examples, no disambiguation algorithm/function can work: consider the case where I have a J followed by 11 e's, followed by a J followed by 11 e's ... Since there is a year in between, I cannot disambiguate J into January, June or July.
Answer: I ended up coding Il-Bhima's answer, because for this case in particular, regex's are ok, even at a higher running time O(mn). However, I accepted Ben's answer as the correct answer because it subsumes the others (mentions the regex solution), but also suggests a better way by using the KMP algorithm O(m+n), although this is for larger numbers of the string against to match the pattern. Thanks, everybody.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have the following in a program (part of a much larger function, but this is the relevant testing bit):
int test = 100 + (100 * (9 / 100));
sprintf (buf, "Test: %d
\r", test);
display_to_pc (buf, player);
Basically it amounts to:
x = a + (a * (b / 100))
Where a is a given figure, b is a percentage modifier, and x is the result (the original plus a percentage of the original)... I hope that makes sense.
It gives me:
Test: 100
I thought the math in my head might be wrong, but I've checked several calculators and even the expression evaluator in my IDE, and they all give me the expected result of 109 for the first expression.
Can anyone enlighten me as to what I'm missing here?
Thanks much. :)
| 0 | 0 | 0 | 0 | 1 | 0 |
Isn't it easily possible to construct a PRNG in such a fashion? Why is it not done?
That is, as far as I know we could simply have a PRNG that takes a seed n. When you ask for a random bit, it takes the nth digit of the binary expansion of the computable normal number, and increments n.
My first thought was that perhaps we hadn't found a computable normal number, but we have. The remaining thought is that there is a good reason not to-- either there's some property of PRNGs that I'm not familiar with that such a method would not have, or it would be impractical somehow, or is otherwise outstripped by other methods.
| 0 | 0 | 0 | 0 | 1 | 0 |
I noticed something when I was trying to solve a problem today. The scalar triple product is the same as the determinant or a three by three matrix with three vectors as rows:
A = [a, b, c]
det(A) = (a X b) * c
I came across this in Real Timer Rendering, and I can't really figure out why this is, or if its even useful. It seems sort of related to the short cut method of computing the cross product using a determinate where you write the unit vectors along the top of the matrix, but I always thought that was more of a mnemonic and not actually sound math.
Is there a real relationship here, or is this just some kind of happy coincidence?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm looking for a function that will determine the value of a place given a number and a base. For example,
Given:
Whole Value: 1120
Base: 10
Place: Tens place
Should return: 2
Does anybody know the math for this?
Edit: The function is also expected to pass the whole value numerically, not as a string like "e328fa" or something. Also the return value should be numeric as well, so a FindInPlace(60 (whole value), 16 (base), 2 (place, 1-based index)) should return 3.
| 0 | 0 | 0 | 0 | 1 | 0 |
So I have a function (I'm writing this in a pseudo-functional language, I hope its clear):
dampen (lr : Num, x : Num) = x + lr*(1-x)
And I wish to apply this n times to a value x. I could implement it recursively:
dampenN (0, lr, x) = dampen(lr, x)
dampenN (n, lr, x) = dampenN(n-1, lr, dampen(x))
But there must be a way I can do it mathematically without resorting to an iterative procedure (recursive, or a loop).
Unfortunately my algebra skills are rusty beyond belief, can anyone help?
| 0 | 0 | 0 | 0 | 1 | 0 |
Is there an arbitrary-precision decimal class available for C#? I've seen a couple of arbitrary precision integer classes, but that's not quite the same thing.
| 0 | 0 | 0 | 0 | 1 | 0 |
For reasons I'd rather not go into, I need to filter a set of values to reduce jitter. To that end, I need to be able to average a list of numbers, with the most recent having the greatest effect, and the least recent having the smallest effect. I'm using a sample size of 10, but that could easily change at some point.
Are there any reasonably simple aging algorithms that I can apply here?
| 0 | 0 | 0 | 0 | 1 | 0 |
I am looking to use a natural language parsing library for a simple chat bot. I can get the Parts of Speech tags, but I always wonder. What do you do with the POS. If I know the parts of the speech, what then?
I guess it would help with the responses. But what data structures and architecture could I use.
| 0 | 1 | 0 | 0 | 0 | 0 |
I have two form fields money and years that need to output a number into a third field cv .
Ideally while the first numbers are being entered but I'm OK with it happening after a button is pressed as well
<FORM name="salary">
<input type="number" size=12 name="money">
<input type="number" size=12 name="years">
<input type="number" size=12 name="cv">
</FORM>
The math involved would be the following.
(money * years) - (money * years) x = cv
Where:
x equals 0 if years equals 1
x equals .2 if years equals 2
x equals .45 if years equals 3
x equals .6 if years equals 4
x equals .65 if years equals 5
x equals .75 if years equals 6
| 0 | 0 | 0 | 0 | 1 | 0 |
Given are two sets of three-dimensional points, a source and a destination set. The number of points on each set is arbitrary (may be zero). The task is to assign one or no source point to every destination point, so that the sum of all distances is minimal. If there are more source than destination points, the additional points are to be ignored.
There is a brute-force solution to this problem, but since the number of points may be big, it is not feasible. I heard this problem is easy in 2D with equal set sizes, but sadly these preconditions are not given here.
I'm interested in both approximations and exact solutions.
Edit: Haha, yes, I suppose it does sound like homework. Actually, it's not. I'm writing a program that receives positions of a large number of cars and i'm trying to map them to their respective parking cells. :)
| 0 | 0 | 0 | 0 | 1 | 0 |
I've been slowly working my way through the list of Project Euler problems, and I've come to one that I know how to solve, but it seems like I can't (given the way my solution was written).
I am using Common Lisp to do this with and my script has been running for over 24 hours (well over their one minute goal).
For the sake of conciseness, here's my solution (it's a spoiler, but only if you have one hell of a fast processor):
(defun square? (num)
(if (integerp (sqrt num)) T))
(defun factors (num)
(let ((l '()))
(do ((current 1 (1+ current)))
((> current (/ num current)))
(if (= 0 (mod num current))
(if (= current (/ num current))
(setf l (append l (list current)))
(setf l (append l (list current (/ num current)))))))
(sort l #'< )))
(defun o_2 (n)
(reduce #'+ (mapcar (lambda (x) (* x x)) (factors n))))
(defun sum-divisor-squares (limit)
(loop for i from 1 to limit when (square? (o_2 i)) summing i))
(defun euler-211 ()
(sum-divisor-squares 64000000))
The time required to solve the problem using smaller, more friendly, test arguments seems to grow larger than exponentialy... which is a real problem.
It took:
0.007 seconds to solve for 100
0.107 seconds to solve for 1000
2.020 seconds to solve for 10000
56.61 seconds to solve for 100000
1835.385 seconds to solve for 1000000
24+ hours to solve for 64000000
I'm really trying to figure out which part(s) of the script is causing it to take so long. I've put some thought into memoizing the factors function, but I'm at a loss as to how to actually implement that.
For those that want to take a look at the problem itself, here it be.
Any ideas on how to make this thing go faster would be greatly appreciated.
**sorry if this is a spoiler to anyone, it's not meant to be.... but if you have the computing power to run this in a decent amount of time, more power to you.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a list of words and I want to filter it down so that I only have the nouns from that list of words (Using Java). To do this I am looking for an easy way to query a database of words for their type.
My question is does anybody know of a free, easy word lookup API that would enable me to find the class of a word, not necessarily its semantic definition.
Thanks!
Ben.
EDIT: By class of the word I meant 'part-of-speech' thanks for clearing this up
| 0 | 1 | 0 | 0 | 0 | 0 |
I read about intersection rectangles on:
Algorithm to detect intersection of two rectangles?
But i have trouble to implement it.
If R1 (A,B,C,D) is my rotated rectangle and R2(A',B',C',D') the other rectangle with no rotation.
The formula extracted in from the link above is:
edge = v(n) - v(n-1)
You can get a perpendicular to this by rotating it by 90°. In 2D this is easy as:
rotated.x = -unrotated.y
rotated.y = unrotated.x
// rotated: your rotated edge
// v(n-1) any point from the edge.
// testpoint: the point you want to find out which side it's on.
side = sign (rotated.x * (testpoint.x - v(n-1).x) +
rotated.y * (testpoint.y - v(n-1).y);
My rotated edges will be from R1 with
AB (xB-xA, yB-yA) so rotated x is xB-xA ?
BC (xC-xB, yC-y1)
CD ...
AD ...
Testpoint will be A', B', C', D' from R2
So i have to check the sign of the result from all points of R2 against the 4 edges from R1.
Thats 16 comparisons if intersecting. How do i know if i found a separating edge ?
Thanks
| 0 | 0 | 0 | 0 | 1 | 0 |
I would need some basic vector mathematics constructs in an application. Dot product, cross product. Finding the intersection of lines, that kind of stuff.
I can do this by myself (in fact, have already) but isn't there a "standard" to use so bugs and possible optimizations would not be on me?
Boost does not have it. Their mathematics part is about statistical functions, as far as I was able to see.
Addendum:
Boost 1.37 indeed seems to have this. They also gracefully introduce a number of other solutions at the field, and why they still went and did their own. I like that.
| 0 | 0 | 0 | 0 | 1 | 0 |
I have not marked this question Answered yet.
The current accepted answer got accepted automatically because of the Bounty Time-Limit
With reference to this programming game I am currently building.
As you can see from the above link, I am currently building a game in where user-programmable robots fight autonomously in an arena.
Now, I need a way to detect if a robot has detected another robot in a particular angle (depending on where the turret may be facing):
alt text http://img21.imageshack.us/img21/7839/robotdetectionrg5.jpg
As you can see from the above image, I have drawn a kind of point-of-view of a tank in which I now need to emulate in my game, as to check each point in it to see if another robot is in view.
The bots are just canvases that are constantly translating on the Battle Arena (another canvas).
I know the heading the turret (the way it will be currently facing), and with that, I need to find if there are any bots in its path(and the path should be defined in kind of 'viewpoint' manner, depicted in the image above in the form of the red 'triangle'. I hope the image makes things more clear to what I am trying to convey.
I hope that someone can guide me to what math is involved in achieving this problem.
[UPDATE]
I have tried the calculations that you have told me, but it's not working properly, since as you can see from the image, bot1 shouldn't be able to see Bot2 . Here is an example :
alt text http://img12.imageshack.us/img12/7416/examplebattle2.png
In the above scenario, Bot 1 is checking if he can see Bot 2. Here are the details (according to Waylon Flinn's answer):
angleOfSight = 0.69813170079773179 //in radians (40 degrees)
orientation = 3.3 //Bot1's current heading (191 degrees)
x1 = 518 //Bot1's Center X
y1 = 277 //Bot1's Center Y
x2 = 276 //Bot2's Center X
y2 = 308 //Bot2's Center Y
cx = x2 - x1 = 276 - 518 = -242
cy = y2 - y1 = 308 - 277 = 31
azimuth = Math.Atan2(cy, cx) = 3.0141873380511295
canHit = (azimuth < orientation + angleOfSight/2) && (azimuth > orientation - angleOfSight/2)
= (3.0141873380511295 < 3.3 + 0.349065850398865895) && (3.0141873380511295 > 3.3 - 0.349065850398865895)
= true
According to the above calculations, Bot1 can see Bot2, but as you can see from the image, that is not possible, since they are facing different directions.
What am I doing wrong in the above calculations?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have to following problem to solve. I have to calculate the bidding price from a total price. For example, a client wants to pay 2000$ as a total price, but from this price, there are added costs:
-usage price which is 10% from the bidding price with a minimum of 10$ and a maximum of 50$
-seller price: 2% from bidding price
-added price: 5$ for a bid between 1 and 500
10$ for a bid between 501 and 1000
15$ for a bid between 1001 and 3000
20$ for a bid over 3000$
-storing cost: 100$
from all this, I have to calculate the bidding price for a total of 2000$, for example. I kind of have no clue of how this can be done. Can anyone give me some hints or pieces of answer of what the algorithm should be?
EDIT: ok I got how to calculate the algebra, now where i'm stuck is how to write the algorithm in code or pseudo-code. Anyone got a hint?
| 0 | 0 | 0 | 0 | 1 | 0 |
in another post, MSN gave me a good guide on solving my algebra problem (Calculating bid price from total cost). Now, even though I can calculate it by hand, I'm completely stuck on how to write this in pseudocode or code. Anyone could give me a quick hint? By the way, I want to calculate the bid given the final costs .
usage cost(bid) = PIN(bid*0.10, 10, 50)
seller cost(bid) = bid*.02
added cost(bid) = PIN(ceiling(bid/500)*5, 5, 10) + PIN(ceiling((bid - 1000)/2000)*5, 0, 10)
storing cost(bid) = 100
So the final cost is something like:
final cost(bid) = PIN(bid*.1, 10, 50) + pin(ceiling(bid/500)*5, 5, 20) + PIN(ceiling((bid - 1000)/2000)*10, 0, 20) + bid*.02 + 100 + bid
Solve for a particular value and you're done.
For example, if you want the total cost to be $2000:
2000 = PIN(bid*.1, 10, 50) + pin(ceiling(bid/500)*5, 5, 10) + PIN(ceiling((bid - 1000)/2000)*5, 0, 10) + bid*.02 + 100 + bid.
Bid must be at least > 1500 and < 2000, which works out nicely since we can make those PIN sections constant:
2000 = 50 + 10 + 5 + 100 + bid*1.02
1835 = bid*1.02
bid = 1799.0196078431372549019607843137
| 0 | 0 | 0 | 0 | 1 | 0 |
I need to deliver one and half hour seminar on programming for students at the department of mathematics.
I have chosen python as language.
What should be content of my presentation ?
What are good resources available ?
What is necessity of programming for maths students?
How will knowledge of programming will help them?
Thank you !!!
NOTE: I know here is one post but it doesn't solve my problem.
| 0 | 0 | 0 | 0 | 1 | 0 |
The algorithm I'm using at the moment runs into extremely high numbers very quickly. A step in the algorithm I'm to raises x to the result of the totient function applied to y. The result is that you can run into very large numbers.
Eg. When calculating the multiplicative order of 10 modulo 53:
10^totient(53) == 10^52 == 1 * 10^52
The following algorithm fares a bit better either in terms of avoiding large numbers, but it still fails where 10^mOrder is greater than the capacity of the data type:
mOrder = 1
while 10^mOrder % 53 != 1
if mOrder >= i
mOrder = 0;
break
else
mOrder = mOrder + 1
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm trying to come up with a non brute-force solution to the following problem. Given a matrix of arbitrary size:
[6 0 3 5]
[3 7 1 4]
[1 4 8 2]
[0 2 5 9]
Transform its diagonals to a list of vectors, like so:
(0)
(1, 2)
(3, 4, 5)
(6, 7, 8, 9)
(0, 1, 2)
(3, 4)
(5)
(Working from bottom left to top right in this example)
Is there an elegant way to do this short of iterating up the left column and across the top row?
| 0 | 0 | 0 | 0 | 1 | 0 |
With reference to this programming game I am currently building.
Important: Scroll down to see [Edit]
Some of the methods that a user can call in my game will be methods that will do a Translate Transform to the Robot (just a Canvas basically).
From the move method, I know the heading (angle) at which the Robot will be facing at the time, and I also know the length of pixels that the Robot wants to move.
Now, the problem I am facing is how to translate the canvas (in a timer) to move at its current facing angle?
alt text http://img8.imageshack.us/img8/3606/robottranslatemovementfu3.jpg
There must be some Maths that I am missing here, but I just can't figure out what to work out in each Timer tick.
Here is the method that is invoked, that contains the timer that will tick every 5 milliseconds, animate the movement:
public void Ahead(int pix)
{
eventQueue.Enqueue((TimerDelegate)delegate(DispatcherTimer dt)
{
/* Available Variables:
Translate_Body.X <= Current Robot Location on X-axis
Translate_Body.Y <= Current Robot Location on Y-axis
Bot.Body <= The Canvas that needs to be translated (moved)
To translate the robot, I just basically do this:
Translate_Body.X++; or Translate_Body.YY++; to increment, or -- to decrement ofcourse
Now I need to figure out the logic on when to increment (or decrement, according to the angle I suppose) the Y and X
*/
IsActionRunning = true;
dt.Tick += new EventHandler(delegate(object sender, EventArgs e)
{
lock (threadLocker)
{
//The logic needs to happen in here, with each timer tick.
//so with each timer tick, the robot is moved on pixel according to its angle.
//Then I need to make a condition that will indicate that the robot has arrived at its destination, and thus stop the timer.
}
});
dt.Start();
});
}
[IMPORTANT EDIT]
I have now changed my logic to use the WPF BeginAnimation instead of a ticker to do the animation for me. So now I do not need to calculate the new coordinates on every tick, but I just provide the end coordinates, and the BeginAnimation will translate it over a period of time:
public void Ahead(int pix)
{
eventQueue.Enqueue((TimerDelegate)delegate
{
Animator_Body_X.From = Translate_Body.X;
Animator_Body_X.To = //The end X-coordinate
Translate_Body.BeginAnimation(TranslateTransform.XProperty, Animator_Body_X);
Animator_Body_Y.From = Translate_Body.Y;
Animator_Body_Y.To = //The end Y-coordinate
Translate_Body.BeginAnimation(TranslateTransform.YProperty, Animator_Body_Y);
});
}
So now, given the angle (0-359) the canvas is currently rotated at, starting x and y coordinates (of where the canvas is currently situated) and distance, how do I calculate to end coordinates?
UPDATE: Solution
| 0 | 0 | 0 | 0 | 1 | 0 |
Question
So I've recently came up with some new possible projects that would have to deal with deriving 'meaning' from text submitted and generated by users.
Natural language processing is the field that deals with these kinds of issues, and after some initial research I found the OpenNLP Hub and university collaborations like the attempto project. And stackoverflow has this.
If anyone could link me to some good resources, from reseach papers and introductionary texts to apis, I'd be happier than a 6 year-old kid opening his christmas presents!
Update
Through one of your recommendations I've found opencyc ('the world's largest and most complete general knowledge base and commonsense reasoning engine'). Even more amazing still, there's a project that is a distilled version of opencyc called UMBEL. It features semantic data in rdf/owl/skos n3 syntax.
I've also stumbled upon antlr, a parser generator for 'constructing recognizers, interpreters, compilers, and translators from grammatical descriptions'.
And there's a question on here by me, that lists tons of free and open data.
Thanks stackoverflow community!
| 0 | 1 | 0 | 0 | 0 | 0 |
In box2d physics engine I can set a motor speed for a joint on my wheel in Radians/Second.
What would be an expression I could set the speed to so the final actual "speed" of the wheel would be the same regardless of wheel radius.
Presently, I'm setting the Wheel speed as a constant, wheelSpeed = 20. But this has the effect of making large wheels faster than small ones. I want the radius to be used in figuring the radians/sec for the motor speed so I will get the same effective speed regardless.
So, if it was a small wheel, it would have to turn much more often than a large one.
I think I need to do something like 2 * PI * Radius / 180 * Speed? Or something similar, but I can't figure it out exactly.
I want to based the wheel motor speed (in radians/sec) it so the final "speed" of the wheels is constant regardless of size of the wheel.
| 0 | 0 | 0 | 0 | 1 | 0 |
Why in some countries there is a comma separator and in some dot? Do you know what is the reason of that? It's very annoying to check every time if you should use this or this.
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm writing a BMR function, should I be using a decimal type as my return value for highest percision? (C#)
| 0 | 0 | 0 | 0 | 1 | 0 |
When dealing with double data types is multiplying by the inverse better or worse?
Which way is faster?
Which way uses less memory?
Which way is preferred?
How does MSIL handle this?
SquareInches = MMSquared / 645.16
SquareInches = MMSquared * 0.0015500031000062000124000248000496
NB: 10K users will note that this is a duplicate of this question,
which was deleted because the original
question asker decided to berate
everyone in the 'comments' section of
the question.
This question was reposted because it is a 'good' question.
Please 'uncheck' Community Wiki for your answer, as I'm only posting this as CW so that it's not seen as a 'reputation' grab.
Related Question:
Should I use multiplication or division?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have to display flight paths on google earth and (still I got the exact flight plan path) want to show in a parabola way (markting side). From the taking off to the landing points.
Basically I'm looking for the math formula to calculate latlng point with altitudes to display the parabola path.
I see how to do the parabolic view with the altitude parameter. But there is less easy, how to get points on a path from two cordinates (start; end).
Thank you !
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm trying to parse a string in a self-made language into a sort of tree, e.g.:
# a * b1 b2 -> c * d1 d2 -> e # f1 f2 * g
should result in:
# a
* b1 b2
-> c
* d1 d2
-> e
# f1 f2
* g
#, * and -> are symbols. a, b1, etc. are texts.
Since the moment I know only rpn method to evaluate expressions, and my current solution is as follows. If I allow only a single text token after each symbol I can easily convert expression first into RPN notation (b = b1 b2; d = d1 d2; f = f1 f2) and parse it from here:
a b c -> * d e -> * # f g * #
However, merging text tokens and whatever else comes seems to be problematic. My idea was to create marker tokens (M), so RPN looks like:
a M b2 b1 M c -> * M d2 d1 M e -> * # f2 f1 M g * #
which is also parseable and seems to solve the problem.
That said:
Does anyone have experience with something like that and can say it is or it is not a viable solution for the future?
Are there better methods for parsing expressions with undefined arity of operators?
Can you point me at some good resources?
Note. Yes, I know this example very much resembles Lisp prefix notation and maybe the way to go would be to add some brackets, but I don't have any experience here. However, the source text must not contain any artificial brackets and also I'm not sure what to do about potential infix mixins like # a * b -> [if value1 = value2] c -> d.
Thanks for any help.
EDIT: It seems that what I'm looking for are sources on postfix notation with a variable number of arguments.
| 0 | 1 | 0 | 0 | 0 | 0 |
I am trying to build an NLP system for an assignment, for which I am allowed to use external libraries.
I am using parse trees to break down sentences into their constituent parts down to nouns, verbs, etc.
I am looking for a library or software that would let me identify which lexical form a word is in, and possibly translate it to some other form for me.
Basically, I need something with functions like isPlural, singularize, getInfinitive, etc.
I have considered the Ruby Linguistics package and a simple Porter Stemmer (for infinitives) but neither is very good.
This does not seem like a very hard problem, just very tedious.
Does anyone know of a good package/library/software that could do things like that?
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm trying use the modulo operator (%) on long longs, and it seems to return 0 if the number is above the range of an unsigned int. Is there an operator or function that I should be using instead, or should I roll my own?
-- Update: sorry for the lack of example code before, I was in a hurry, heading out the door --
Here's the code:
long long val = 12345678991245; // always less than LLONG_MAX
int power = 0;
NSMutableArray *powers = [[NSMutableArray alloc] init];
while (pow(10, power) <= val) {
tVal = (val % (lround(pow(10, power + 1)))) / lround(pow(10, power));
[powers addObject:[NSNumber numberWithInt:tVal]];
NSLog(@"Power: %d tVal: %d", power, tVal);
val -= val % lround(pow(10, power + 1));
power++;
}
When you look at the output made by that NSLog statement, though, you see this when the number exceeds UINT_MAX (for the number 1,111,111,111,111):
2009-03-18 20:42:16.471 Numbers[11197:20b] Power: 0 tVal: 1
2009-03-18 20:42:16.472 Numbers[11197:20b] Power: 1 tVal: 1
2009-03-18 20:42:16.473 Numbers[11197:20b] Power: 2 tVal: 1
2009-03-18 20:42:16.476 Numbers[11197:20b] Power: 3 tVal: 1
2009-03-18 20:42:16.476 Numbers[11197:20b] Power: 4 tVal: 1
2009-03-18 20:42:16.477 Numbers[11197:20b] Power: 5 tVal: 1
2009-03-18 20:42:16.477 Numbers[11197:20b] Power: 6 tVal: 1
2009-03-18 20:42:16.477 Numbers[11197:20b] Power: 7 tVal: 1
2009-03-18 20:42:16.477 Numbers[11197:20b] Power: 8 tVal: 1
2009-03-18 20:42:16.478 Numbers[11197:20b] Power: 9 tVal: 0
2009-03-18 20:42:16.478 Numbers[11197:20b] Power: 10 tVal: 0
2009-03-18 20:42:16.479 Numbers[11197:20b] Power: 11 tVal: 0
2009-03-18 20:42:16.479 Numbers[11197:20b] Power: 12 tVal: 0
Everything is kosher until you get up to past UINT_MAX, then it just returns 0.
I'm compiling against the iPhone SDK using Xcode 3.1.2.
Any ideas?
| 0 | 0 | 0 | 0 | 1 | 0 |
edit
So based on the answers so far (thanks for taking your time) I'm getting the sense that I'm probably NOT looking for a Normal Distribution function. Perhaps I'll try to re-describe what I'm looking to do.
Lets say I have an object that returns a number of 0 to 10. And that number controls "speed". However instead of 10 being the top speed, I need 5 to be the top speed, and anything lower or higher would slow down accordingly. (with easing, thus the bell curve)
I hope that's clearer ;/
-original question
These are the times I wish I remembered something from math class.
I'm trying to figure out how to write a function in obj-C where I define the boundries, ex (0 - 10) and then if x = foo y = ? .... where x runs something like 0,1,2,3,4,5,6,7,8,9,10 and y runs 0,1,2,3,4,5,4,3,2,1,0 but only on a curve
Something like the attached image.
I tried googling for Normal Distribution but its way over my head. I was hoping to find some site that lists some useful algorithms like these but wasn't very successful.
So can anyone help me out here ? And if there is some good sites which shows useful mathematical functions, I'd love to check them out.
TIA!!!
-added
I'm not looking for a random number, I'm looking for.. ex: if x=0 y should be 0, if x=5 y should be 5, if x=10 y should be 0.... and all those other not so obvious in between numbers
alt text http://dizy.cc/slider.gif
| 0 | 0 | 0 | 0 | 1 | 0 |
I recently faced a problem of presenting the output of simple genetic algorithm that looks for extremes of 2 argument function f(x1,x2) . I would like to be able to use x1 as x, x2 as y and f as z and to draw points in 3d space that I could rotate. ( I'm currently drawing this on bitmap using color as the 'z axis'.)
Where should I start?
UPDATE:
I found a directory of 3D engines for C# but there are a lot to choose from... Could you advise if any one of them would be best for my problem?
UPDATE 2:
Thanks to Cameron's suggestion a 3D options in WPF seem to be suiting my needs. I will give it a try for sure.
I am reposting his links here:
* WPF 3D Tutorial
* CodeProject: WPF 3D Primer
* CodeProject: WPF 3D : Part 1 of n
| 0 | 0 | 0 | 0 | 1 | 0 |
I had a work for the university which basically said:
"Demonstrates that the non-regular language L={0^n 1^n : n natural} had no infinite regular sublanguages."
I demonstrated this by contradiction. I basically said that there is a language S which is a sublanguage of L and it is a regular language. Since the possible Regular expressions for S are 0*, 1*, (1+0)* and (0o1)*. I check each grammar and demonstrate that none of them are part of the language L.
However, how I could prove that ANY non regular context free language could not contain any regular infinite sublanguages?
I don't want the prove per se, I just want to be pointed in the right direction.
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm working on a 2D game where I'm trying to accelerate an object to a top speed using some basic physics code.
Here's the pseudocode for it:
const float acceleration = 0.02f;
const float friction = 0.8f; // value is always 0.0..1.0
float velocity = 0;
float position = 0;
move()
{
velocity += acceleration;
velocity *= friction;
position += velocity;
}
This is a very simplified approach that doesn't rely on mass or actual friction (the in-code friction is just a generic force acting against movement). It works well as the "velocity *= friction;" part keeps the velocity from going past a certain point. However, it's this top speed and its relationship to the acceleration and friction where I'm a bit lost.
What I'd like to do is set a top speed, and the amount of time it takes to reach it, then use them to derive the acceleration and friction values.
i.e.,
const float max_velocity = 2.0;
const int ticks; = 120; // If my game runs at 60 FPS, I'd like a
// moving object to reach max_velocity in
// exactly 2 seconds.
const float acceleration = ?
const float friction = ?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm writing a Range class at the moment and I'm looking for a good name for the common range [0->1]. If it was a vector of length 1, I would call it a Unit vector. Is there a clear name to give this range/interval? Possibly a Unit Range?
| 0 | 0 | 0 | 0 | 1 | 0 |
Is there a valid math term? I could just name this guy "sumXY", but that is (a) lame, and (b) not scalable, since going up a dimension would require a rename.
While typing I thought of "componentSum", but I'd love to know if there's a real name for it.
| 0 | 0 | 0 | 0 | 1 | 0 |
A couple of days ago, I read a blog entry (http://ayende.com/Blog/archive/2008/09/08/Implementing-generic-natural-language-DSL.aspx) where the author discuss the idea of a generic natural language DSL parser using .NET.
The brilliant part of his idea, in my opinion, is that the text is parsed and matched against classes using the same name as the sentences.
Taking as an example, the following lines:
Create user user1 with email [email protected] and password test
Log user1 in
Take user1 to category t-shirts
Make user1 add item Flower T-Shirt to cart
Take user1 to checkout
Would get converted using a collection of "known" objects, that takes the result of parsing. Some example objects would be (using Java for my example):
public class CreateUser {
private final String user;
private String email;
private String password;
public CreateUser(String user) {
this.user = user;
}
public void withEmail(String email) {
this.email = email;
}
public String andPassword(String password) {
this.password = password;
}
}
So, when processing the first sentence, CreateUser class would be a match (obviously because it's a concatenation of "create user") and, since it takes a parameter on the constructor, the parser would take "user1" as being the user parameter.
After that, the parser would identify that the next part, "with email" also matches a method name, and since that method takes a parameter, it would parse "[email protected]" as being the email parameter.
I think you get the idea by now, right? One quite clear application of that, at least for me, would be to allow application testers create "testing scripts" in natural language and then parse the sentences into classes that uses JUnit to check for app behaviors.
I'd like to hear ideas, tips and opinions on tools or resource that could code such parser using Java. Better yet if we could avoid using complex lexers, or frameworks like ANTLR, which I think maybe would be using a hammer to kill a fly.
More than that, if anyone is up to start an open source project for that, I would definitely be interested.
| 0 | 1 | 0 | 0 | 0 | 0 |
I have a long double constant that I am setting either as const or not-const. It is longer (40 digits) than the precision of a long double on my test workstation (19 digits).
When I print it out, it no longer is displayed at 19 digits of precision, but at 16.
Here is the code I am testing:
#include <iostream>
#include <iomanip>
#include <limits>
#include <cstdio>
int main ()
{
const long double constLog2 = 0.6931471805599453094172321214581765680755;
long double log2 = 0.6931471805599453094172321214581765680755;
std::cout << std::numeric_limits<long double>::digits10 + 1 << std::endl;
std::cout << "const via cout: " << std::setprecision(19) << constLog2 << std::endl;
std::cout << "non-const via cout: " << std::setprecision(19) << log2 << std::endl;
std::fprintf(stdout, "const via printf: %.19Lf
", constLog2);
std::fprintf(stdout, "non-const via printf: %.19Lf
", log2);
return 0;
}
Compile:
$ g++ -Wall precisionTest.cpp
Output:
$ ./a.out
19
const via cout: 0.6931471805599452862
non-const via cout: 0.6931471805599452862
const via printf: 0.6931471805599452862
non-const via printf: 0.6931471805599452862
I would expect 0.6931471805599453094 but instead get 0.6931471805599452862.
Is there a reason that the 19 digits of precision are cut to 16 digits?
Here is my environment:
$ gcc --version
i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
I am seeing the same problem with other versions of gcc, e.g.:
$ gcc --version
g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-10)
I can look into NTL or other libraries but I'm curious what is causing this. Thanks for your insight.
| 0 | 0 | 0 | 0 | 1 | 0 |
Does anyone know how to have vim convert the html entities of math symbols into the math characters?
For example:
≠ becomes ≠
∴ becomes ∴
here is a table with the symbol html entities
http://barzilai.org/math_sym.htm
Updated: Solved, bignose came through with the solution.
using the :digraphs functionality of Vim. with a character encoding of Unicode,
see ':help digraphs' for documentation
I'm Still looking for a monospace Unicode font so it renders completely but with extra spaces it works great.
In order to see math characters UTF-8 has to be the encoding and a font that will display those characters.
I added the following to my vim configuration files.
created custom file: mathdoc.vim in syntax/
" set the encoding to be utf-8, requires gVim or a terminal capable of
" unicode see ':help Unicode' for details
set encoding=utf-8
" requires a font that has characters for the higher uniocode symbols
set guifont=MS\ Gothic
I added this to filetype to set this for my own custom extension .txtmt
au BufNewFile,BufRead *.txtmt setf mathdoc
but you could alternately call this with the file open:
:set ft=mathdoc
digraphs works great as bignose specified below here is how it works
in insert mode:
press control+k followed by:
∴ is S*
≠ is !=
∑ is +Z
≡ is =3
⇐ is <=
⇒ is =>
⇔ is ==
∀ is FA
∃ is TE
∋ is -)
see :digraphs for the complete list
* note if you only see half a screens worth you're character encoding is not unicode, unicode characters cover several screens, type :set encoding=utf-8 to switch to utf-8.
The table in the above link has the numbers for the characters that you'll need to find the keyboard shortcuts, 8756 is ∴ for example
| 0 | 0 | 0 | 0 | 1 | 0 |
I was given three functions:
dx/dt = a(y-x)
dy/dt = x(b-z)-y
dz/dt = xy-cz
All the variables are set by the user. I can do it if its just the basic one-equation problem. But now, i need to make a program using the improved Euler's method. Can the method solve three functions at the same time? Or can I use the Runge-Kutta method?
| 0 | 0 | 0 | 0 | 1 | 0 |
If I have a series of pixels, which range from say -500 to +1000, how would I normalize all the pixels on the same gradient so that they fall between a specific range, say 0 and 255?
| 0 | 0 | 0 | 0 | 1 | 0 |
I am new to Artificial Intelligence. I understand K nearest neighbour algorithm and how to implement it. However, how do you calculate the distance or weight of things that aren't on a scale?
For example, distance of age can be easily calculated, but how do you calculate how near is red to blue? Maybe colours is a bad example because you still can say use the frequency. How about a burger to pizza to fries for example?
I got a feeling there's a clever way to do this.
Thank you in advance for your kind attention.
EDIT: Thank you all for very nice answers. It really helped and I appreciate it. But I am thinking there must be a way out.
Can I do it this way? Let's say I am using my KNN algorithm to do a prediction for a person whether he/she will eat at my restaurant that serves all three of the above food. Of course, there's other factors but to keep it simple, for the field of favourite food, out of 300 people, 150 loves burger, 100 loves pizza, and 50 loves fries. Common sense tells me favourite food affect peoples' decision on whether to eat or not.
So now a person enters his/her favourite food as burger and I am going to predict whether he/she's going to eat at my restaurant. Ignoring other factors, and based on my (training) previous knowledge base, common sense tells me that there's a higher chance the k nearest neighbours' distance for this particular field favourite food is nearer as compared to if he entered pizza or fries.
The only problem with that is that I used probability, and I might be wrong because I don't know and probably can't calculate the actual distance. I also worry about this field putting too much/too little weight on my prediction because the distance probably isn't to scale with other factors (price, time of day, whether the restaurant is full, etc that I can easily quantify) but I guess I might be able to get around it with some parameter tuning.
Oh, everyone put up a great answer, but I can only accept one. In that case, I'll just accept the one with highest votes tomorrow. Thank you all once again.
| 0 | 1 | 0 | 0 | 0 | 0 |
I'm doing some image processing, and I need to find some information on line growing algorithms - not sure if I'm using the right terminology here, so please call me out on this is needs be.
Imagine my input image is simply a circle on a black background. I'd basically like extract the coordinates, so that I may draw this circle elsewhere based on the coordinates.
Note: I am already using edge detection image filters, but I thought it best to explain with a simple example.
Basically what I'm looking to do is detect lines in an image, and store the result in a data type where by I have say a class called Line, and various different Point objects (containing X/Y coordinates).
class Line
{
Point points[];
}
class Point
{
int X, Y;
}
And this is how I'd like to use it...
Line line;
for each pixel in image
{
if pixel should be added to line
{
add pixel coordinates to line;
}
}
I have no idea how to approach this as you can probably establish, so pointers to any subject matter would be greatly appreciated.
| 0 | 0 | 0 | 0 | 1 | 0 |
Imagine I have this list, that is divided by 3
1
2
3
4
5
6
7
8
9
Now, I have 9 items, grouped in 3 sections.
My question is how know in which section is 6 (ie: 6 belong to section 2, 2 to section 1, 9 to section 3)
| 0 | 0 | 0 | 0 | 1 | 0 |
I have an input 3D vector, along with the pitch and yaw of the camera. Can anyone describe or provide a link to a resource that will help me understand and implement the required transformation and matrix mapping?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm trying to come up with a simple and efficient way to create a smooth surface which intersects a number of given "sample" points.
For any X,Y point on the surface, I identify up to 4 sample points in each of the 4 directions (the next higher and lower points on the X, and then the Y axes). Given this point, I want a way to compute a Z value that interpolates between the 4 sample points.
Of course the algorithm, given the X, Y position of any of the 4 sample points, should output the Z value for that point. Note also that there may be less than 4 sample points.
I guess some function of the Z values for the 4 sample points, somehow inversely biased by the distance to the sample point, but I can't figure out how to do this.
Anyone got any ideas about a simple way to do this?
| 0 | 0 | 0 | 0 | 1 | 0 |
Just realized that I am getting errors on simple math if I mixed Integer with floats in iPhone SDK on the Simulator. Two examples:
float testVal1 = 10 + 5/10;
//evaluates to 10 instead of 10.5 unless I use explicit 10.0f..
// Problem Code mixed float int
NSUInteger jvalue = 2312345;
NSInteger testVal2 = (jvalue - 2512345); // evaluates correctly
float testVal3 = (jvalue - 2512345); // fails with some huge bogus value
I thought that in mixed mode expression it will convert to float values. Seems it is all or nothing while using floats, no mixing
What is going wrong here ?
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm sorry if I'm not using the correct mathemathical terms, but I hope you'll understand what I'm trying to accomplish.
My problem:
I'm using linear regression (currently least squares method) on the values from two vectors x and y against the result z. This is to be done in matlab, and I'm using the \-operator to perform the regression. My dataset will contain a few thousand observations (up to about 50000 at max).
The x-values will be in the area of 10-300 (most between 60 and 100) and the y-values in the 1-3 area.
My code looks like this:
X = [ones(size(x,1) x y];
parameters = X\y;
The output "parameters" are then the three factors a0, a1 and a2 which is used in this formula:
a0 * 1 + a1 * xi + a2 * yi = zi
(The i's are supposed to be subscripted)
This works like expected, although I want the two parameters a1 and a2 to ALWAYS be positive values, even when the vector z is negative (this means that the a0 will be negative, of course), since this is what the real model looks like (z is always positively correlated to x and z). Is this possible using the least squares method? I'm also open for other algorithms for linear regression.
| 0 | 0 | 0 | 0 | 1 | 0 |
Attempts 1 & 2:
Note: Removed first attempts to cut down on question size. See community wiki for previous attempts.
Attempt 3:
As per fuzzy-waffle's example, I have implemented the following, which doesn't appear to work correctly. Any ideas what I could be doing wrong?
ImageMatrix ImageMatrix::GetRotatedCopy(VDouble angle)
{
// Copy the specifications of the original.
ImageMatrix &source = *this;
ImageMatrix &target = CreateEmptyCopy();
double centerX = ((double)(source.GetColumnCount()-1)) / 2;
double centerY = ((double)(source.GetRowCount()-1)) / 2;
// Remember: row = y, column = x
for (VUInt32 y = 0; y < source.GetRowCount(); y++)
{
for (VUInt32 x = 0; x < source.GetColumnCount(); x++)
{
double dx = ((double)x) - centerX;
double dy = ((double)y) - centerY;
double newX = cos(angle) * dx - sin(angle) * dy + centerX;
double newY = cos(angle) * dy + sin(angle) * dx + centerY;
int ix = (int)round(newX);
int iy = (int)round(newY);
target[x][y][0] = source[ix][iy][0];
}
}
return target;
}
With this prototype matrix...
1 2 1
0 0 0
-1 -2 -1
... prototype.GetRotatedCopy(0) (which is correct) ...
1 2 1
0 0 0
-1 -2 -1
... prototype.GetRotatedCopy(90) (incorrect) ...
-2 0 0
-2 0 2
0 0 2
... prototype.GetRotatedCopy(180) (incorrect - but sort of logical?) ...
0 -1 -2
1 0 -1
2 1 0
... prototype.GetRotatedCopy(270) (incorrect - why is this the same as 0 rotation?) ...
1 2 1
0 0 0
-1 -2 -1
Solution:
As pointed out by Mark Ransom, I should be using radians, not degrees; I have adjusted my code as follows:
ImageMatrix ImageMatrix::GetRotatedCopy(VDouble degrees)
{
// Copy the specifications of the original.
ImageMatrix &source = *this;
ImageMatrix &target = CreateEmptyCopy();
// Convert degree measurement to radians.
double angle = degrees / 57.3;
// ... rest of code as in attempt #3 ...
Thanks for all your help guys!
1 2 1
0 0 0
-1 -2 -1
1 2 1
0 0 0
-1 -2 -1
-1 0 1
-2 0 2
-1 0 1
-1 -2 -1
0 0 0
1 2 1
1 0 -1
2 0 -2
1 0 -1
| 0 | 0 | 0 | 0 | 1 | 0 |
I have an ASP page where I have 2 variables, strActualRate and strProposed.
The values are:
strActualRate = 33.30
strProposed = 33.3
So when I write the following line to compare:
if strActualRate <> strProposed then
Response.Writr "Both are not equal!"
end if
I am getting the output "Both are not equal", even though both are the same.
I am sure that I need to use some mathematical conversion function to compare.
Can anyone tell me how to solve this ?
Thanks in advance!
| 0 | 0 | 0 | 0 | 1 | 0 |
I just finished implementing a kd-tree for doing fast nearest neighbor searches. I'm interested in playing around with different distance metrics other than the Euclidean distance. My understanding of the kd-tree is that the speedy kd-tree search is not guaranteed to give exact searches if the metric is non-Euclidean, which means that I might need to implement a new data structure and search algorithm if I want to try out new metrics for my search.
I have two questions:
Does using a kd-tree permanently tie me to the Euclidean distance?
If so, what other sorts of algorithms should I try that work for arbitrary metrics? I don't have a ton of time to implement lots of different data structures, but other structures I'm thinking about include cover trees and vp-trees.
| 0 | 0 | 0 | 1 | 1 | 0 |
I'm moving through the atmosphere with Microsoft Virtual Earth 3D and I can descend smoothly, but I don't know the math to ascend smoothly.
I'm descending like this:
for(int curAlt = startAlt; curAlt < endAlt; curAlt--){
//do something
curAlt -= curAlt/150
}
This works by decreasing the size of the jump the closer I get to the earth (lower altitude). I need a solution that would do similar, just in reverse, while still keeping the smaller jumps at the lower altitude.
How can I do this? Or is what I am doing unacceptable and should be done differently (say with logarithms)?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a Point on the surface of the earth which I am converting to a Vector from Earth Center.
I have a True North Heading in degrees describing the path the point will travel on the surface of the earth.
I need to calculate a Vector which is perpendicular to the plane created by the path of this point along the earths surface.
I have tried calculating an arbitrary point along the path using the method described here
and then taking the cross product of the two vectors however it does not seem to be quite accurate enough and seems like more overhead than is necessary.
This is related to my other post ray-polygon-intersection-point-on-the-surface-of-a-sphere.
| 0 | 0 | 0 | 0 | 1 | 0 |
We've gotten a homework assignment in Java, which relates to inheritance. I don't have a problem with the programming in itself, but I'm a bit unsure about some of the math, and would like confirmation/corrections from someone a bit more knowledgable.
The assignment starts with a abstract class, GeometricObject, which is extended into three two-dimensional objects. A rectangle, a circle and a triangle. Those three are then extended into a cuboid for the rectangle, a cylinder and a sphere for the circle, and the triangle into a triangular prism.
Each of these three-dimensional objects are hollow, and has a defined thickness and is made of a special metal, so we are to calculate their weight. And herein lies the problem, since I'm a bit unsure as to how I find the "inner volume" on some of them.
Cuboid: Here I assume that I can just subtract 2 * thickness from the width, height and depth, and then everything looks fine.
Cylinder: Subtract thickness from the radius making up the base, and 2*thickness from the height
Sphere: Subtract thickness from the radius
Prism: This is where I'm a bit stuck. Each object gets passed a baseline, height of the triangle, and the height for the entire prism. How can I use this in order to find the "inner prism" representing the inner volume?
Update: Forgot to mention that when creating the object, we specify the outmost sizes, and the hollow part is inside of this. The other way around is not allowed.
Update again: The triangle is an isosceles triangle.
Update yet again: Mixed up radius and diameter for the circular. Corrected now.
| 0 | 0 | 0 | 0 | 1 | 0 |
First of all this is tough thing to solve, so far I didn't come up with a good example but I hope someone here will figure this out. I hope there is known way to solve these kind of problems, or an obscure algorithm.
Scenario:
In my application I do several requests to the very same webpage
Webpage has dynamic and random content in it such as (datetime, and quote of the day etc. in theory can be anything)
Response of this application has got 2 cases, let's call them "TRUE" and "FALSE". For example sometimes response would return a "True Text" sometimes it would be "False Text".
My application knows 3 samples of "TRUE" case and 3 samples of "FALSE" case, but these are also include random content such as "time" as well.
Challenge
Now when my application gets a new response how can I understand if this response is an example of "TRUE" or "FALSE" case?
What I've tried
Process the first sample of TRUE case line by line and generate an integer array from the value of characters
Do the same thing for second TRUE sample
Do the same thing for third TRUE sample
Analyse the differences between these stored TRUE cases and create a new array with
Now, I know which lines are dynamic (such as datetime), now I create a new final TRUE case array which stores only static lines to a final TRUE case array.
Now when I got a new case, I create a similar array then compare it with previously stored final TRUE case and if does match (except filtered lines) it's a TRUE case if other lines are massively changed (there is a tolerance value) then it's FALSE.
Limitations and weaknesses of this algorithm is pretty obvious. Although I've got some good results in some cases, but it doesn't work as expected all the time.
My current class works like this:
Dim Analyser AS NEW ContentAnalyzer()
Analyser.AddTrueCase(True1Html)
Analyser.AddTrueCase(True2Html)
Analyser.AddTrueCase(True3Html)
'This will return True if the UnknownHtml is similar to TRUE case, otherwise False
Analyser.IsThisTrue(UnknownHtml)
Sorry the title doesn't make much sense, I couldn't find a good way to describe it.
| 0 | 1 | 0 | 0 | 0 | 0 |
Throughout my academic years in computer science I fell in love with many aspects of artificial intelligence. From expert systems, neural networks, to data mining (classification). I wonder, if I was to transform this academic passion professionally, what kind of AI-related jobs are out there?
| 0 | 1 | 0 | 0 | 0 | 0 |
Seeking a method to:
Take whitespace separated tokens in a String; return a suggested Word
ie:
Google Search can take "fonetic wrd nterpreterr",
and atop of the result page it shows "Did you mean: phonetic word interpreter"
A solution in any of the C* languages or Java would be preferred.
Are there any existing Open Libraries which perform such functionality?
Or is there a way to Utilise a Google API to request a suggested word?
| 0 | 1 | 0 | 0 | 0 | 0 |
Before I set about to writing this myself, has anyone seen a ruby implementation of the following behavior?
puts 7.nextprime(); #=> 11
puts 7.previousprime(); #=> 5
puts 7.isprime(); #=> true
Obviously this kind of thing would be ugly for large numbers but for integers never exceeding a few thousand (the common instance for me) a sensible implementation is doable, hence the question.
| 0 | 0 | 0 | 0 | 1 | 0 |
Ok, so here is a problem analogous to my problem (I'll elaborate on the real problem below, but I think this analogy will be easier to understand).
I have a strange two-sided coin that only comes up heads (randomly) 1 in every 1,001 tosses (the remainder being tails). In other words, for every 1,000 tails I see, there will be 1 heads.
I have a peculiar disease where I only notice 1 in every 1,000 tails I see, but I notice every heads, and so it appears to me that the rate of noticing a heads or tails is 0.5. Of course, I'm aware of this disease and its effect so I can compensate for it.
Someone now gives me a new coin, and I noticed that the rate of noticing heads is now 0.6. Given that my disease hasn't changed (I still only notice 1 in every 1,000 tails), how do I calculate the actual ratio of heads to tails that this new coin produces?
Ok, so what is the real problem? Well, I have a bunch of data consisting of input, and outputs which are 1s and 0s. I want to teach a supervised machine learning algorithm to predict the expected output (a float between 0 and 1) given an input. The problem is that the 1s are very rare, and this screws up the internal math because it becomes very susceptible to rounding errors - even with high-precision floating point math.
So, I normalize the data by randomly omitting most of the 0 training samples so that it appears that there is a roughly equal ratio of 1s and 0s. Of course, this means that now the machine learning algorithm's output is no-longer predicting a probability, ie. instead of predicting 0.001 as it should, it would now predict 0.5.
I need a way to convert the output of the machine learning algorithm back to a probability within the original training set.
Author's Note (2015-10-07): I later discovered that this technique is commonly known as "downsampling"
| 0 | 0 | 0 | 1 | 0 | 0 |
Say you want to take CMU's phonetic data set input that looks like this:
ABERRATION AE2 B ER0 EY1 SH AH0 N
ABERRATIONAL AE2 B ER0 EY1 SH AH0 N AH0 L
ABERRATIONS AE2 B ER0 EY1 SH AH0 N Z
ABERT AE1 B ER0 T
ABET AH0 B EH1 T
ABETTED AH0 B EH1 T IH0 D
ABETTING AH0 B EH1 T IH0 NG
ABEX EY1 B EH0 K S
ABEYANCE AH0 B EY1 AH0 N S
(The word is to the left, to the right are a series of phonemes, key here)
And you want to use it as training data for a machine learning system that would take new words and guess how they would be pronounced in English.
It's not so obvious to me at least because there isn't a fixed token size of letters which could possible map to a phoneme. I have a feeling that something to do with a markov chain might be the right way to go.
How would you do this?
| 0 | 0 | 0 | 1 | 0 | 0 |
Do you have any recommendations of books or websites that would teach me mathematical notation. As a developer I work on a wide range of projects from .NET/SQL Server stuff through to Flash games and I often find myself referring to articles on the internet for guidance. Many of the articles contain mathematical formula, and unless they are accompanied by "plain English" explanations I usually struggle to convert the formula into code.
I have a degree in Interactive Multimedia, and so I have had no formal higher math education, however, I don't find math to be too taxing to figure out.
Hopefully by learning this notation I will be able to further my knowledge by actually being able to get stuck into more of it.
Note: please, don't suggest I go back to school, and do a higher math course as, while I know this would be the best bet, it simply isn't an option. Other than that, any and all suggestions are welcome.
Update
Here are a few types of thing that I program most often. I'm not sure what areas of math these cover.
2d and 3d collision detection
Reporting utilities for data collection applications (registration forms, surveys, etc.)
2d and 3d vector math, mainly based around games
Colour manipulation (programmatically fading from one colour to the next, adding and subtracting colours, making colours lighter / darker on the fly)
Hope this helps add a bit of context.
| 0 | 0 | 0 | 0 | 1 | 0 |
Here is the problem:
One sheet contains 10 labels. I want to print many labels, but from an arbitrary starting index. Now, I want to find how many sheets would be required to print the labels that the user desires. For example, let's say I took starting index 52 and I want to print 23 labels. Then how do I find the number of sheets required? Does anyone have a formula to count this?
edit Hello guys, thanks for the answers the problem is solved now.
thank u very much all.
| 0 | 0 | 0 | 0 | 1 | 0 |
Given a series of incoming items, I want to assign each one to a bucket as it comes in. The bucket can either be a new one (one that has never been used before, of which there are an infinite supply) or it can be an existing bucket. If I look at the number of buckets with one item, the number with two, the number with three, etc., I want those bucket counts to follow an exponential distribution. I hope I'm saying that correctly -- if 80% of the buckets have 1 item, then 16% should have two, 3.2% should have three, etc. In general, the number of buckets of size k should be 1/p as many as the number of buckets of size k-1, and the fraction of buckets that are size 1 should be (1-p) to make the math work out right.
If I knew the number of items in advance, it would be easy: I'd know how many buckets of each size, so I can just pile the the items into as many buckets of each size as I needed. Or if I were just generating bucket sizes, it'd be easy even if I didn't know the total in advance: each new bucket has probability (1-p) of being size 1, (1-p)p of being size 2, (1-p)p^2 size 3, (1-p)p^3 size 4, etc.
But I am processing items, so as I get an item in, I need to choose a bucket: either an existing one, or a new one. If I make a new bucket, then I get one more of size 1. But if I choose an existing one of size k, then I get one more bucket of size k+1, and one fewer of size k. So what should the probability of choosing a bucket of size k be (where k can be zero to indicate making a new bucket)? And how does it relate to p?
I am doing this to generate test data where I only know the mean number of items per bucket (1.5, it turns out), don't know the number of items in advance, and think that the exponential distribution of bucket sizes is realistic for my situation. I'm probably making it more complicated than it needs to be, but I was surprised because I thought it would be easy.
And maybe it is, but I'm just missing something. (And I can't figure out how to Google it, either.)
| 0 | 0 | 0 | 0 | 1 | 0 |
It's clear that one shouldn't use floating precision when working with, say, monetary amounts since the variation in precision leads to inaccuracies when doing calculations with that amount.
That said, what are use cases when that is acceptable? And, what are the general principles one should have in mind when deciding?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a bunch of floating point numbers (Java doubles), most of which are very close to 1, and I need to multiply them together as part of a larger calculation. I need to do this a lot.
The problem is that while Java doubles have no problem with a number like:
0.0000000000000000000000000000000001 (1.0E-34)
they can't represent something like:
1.0000000000000000000000000000000001
Consequently of this I lose precision rapidly (the limit seems to be around 1.000000000000001 for Java's doubles).
I've considered just storing the numbers with 1 subtracted, so for example 1.0001 would be stored as 0.0001 - but the problem is that to multiply them together again I have to add 1 and at this point I lose precision.
To address this I could use BigDecimals to perform the calculation (convert to BigDecimal, add 1.0, then multiply), and then convert back to doubles afterwards, but I have serious concerns about the performance implications of this.
Can anyone see a way to do this that avoids using BigDecimal?
Edit for clarity: This is for a large-scale collaborative filter, which employs a gradient descent optimization algorithm. Accuracy is an issue because often the collaborative filter is dealing with very small numbers (such as the probability of a person clicking on an ad for a product, which may be 1 in 1000, or 1 in 10000).
Speed is an issue because the collaborative filter must be trained on tens of millions of data points, if not more.
| 0 | 0 | 0 | 0 | 1 | 0 |
See also: Why is my image rotation algorithm not working?
This question isn't language specific, and is a math problem. I will however use some C++ code to explain what I need as I'm not too hot on math.
Here's how the image is composed:
ImageMatrix image;
image[0][0][0] = 1;
image[0][1][0] = 2;
image[0][2][0] = 1;
image[1][0][0] = 0;
image[1][1][0] = 0;
image[1][2][0] = 0;
image[2][0][0] = -1;
image[2][1][0] = -2;
image[2][2][0] = -1;
Here's the prototype for the function I'm trying to create:
ImageMatrix rotateImage(ImageMatrix image, double angle);
I'd like to rotate only the first two indices (rows and columns) but not the channel.
| 0 | 0 | 0 | 0 | 1 | 0 |
I'm implementing a CSS Sprites setup in my ASP.NET application based on this article..
http://weblogs.asp.net/zowens/archive/2008/03/05/css-sprite-for-asp-net.aspx
In the section "Get the SPRITE already!"... the author says...
"The only real down side to this is that all your images are lined up vertically. I'm not quite sure that this matters, but most other generators have the ability to somehow line the images up vertically and horizontally."
I'm sure this must be a previously solved problem so my question is, "Given a collection of rectangles, can you efficiently lay these out in an optimal way?" (I suppose it depends on my definition of optimal, but being the closest possible to a square as a start. (although this may not actually be the case.)) Also, would you need all the rectangles in advance or could this be done progressively?
| 0 | 0 | 0 | 0 | 1 | 0 |
Suppose I have a sequence of numbers:
{n, n+1, n+2, ... n + m}
Without storing the numbers ahead of time I want to create a function f(), which given the sequence {1,2,3,...m} will spit out the original set in a random (or at least pseudo random) order.
For example assume my sequence is {10, 11, 12, 13, 14, 15, 16, 17}
f(1) could yield 14
f(2) could yield 17
f(3) could yield 13
f(4) could yield 10
f(5) could yield 16
f(6) could yield 15
f(7) could yield 11
f(8) could yield 12
At one point in the past a co-worker showed me a mathematical algorithm that was able to do this, but I have since forgotten almost everything about it other than it existed. I remember that you had to have the sequence in advance, and generate some constants from the sequence which were used in the function. And for those wondering, I have sadly lost contact with that co-worker.
This question's answers looks close to what I want, but I am not sure if the answers allow me to constrain the output to a specific sequence ahead of time.
Edit:
To clarify a little more I don't want to store the original sequence, or the shuffled sequence. I want to generate a function f() from the original sequence.
What is frustrating is that I have seen this, I just cannot remember enough about it to find it again with google.
The Fisher-Yates algorithm is great for permuting or shuffling a deck, but it is not what I am looking for.
| 0 | 0 | 0 | 0 | 1 | 0 |
Using the standard English letters and underscore only, how many characters can be used at a maximum without causing a potential collision in a hashtable/dictionary.
So strings like:
blur
Blur
b
Blur_The_Shades_Slightly_With_A_Tint_Of_Blue
...
| 0 | 0 | 0 | 0 | 1 | 0 |
Say you've got a big table that contains a varchar column.
How would you match rows that contain the word 'preferred' in the varchar col BUT the data is somewhat noisy and contains occasional spelling errors, e.g.:
['$2.10 Cumulative Convertible Preffered Stock, $25 par value',
'5.95% Preferres Stock',
'Class A Preffered',
'Series A Peferred Shares',
'Series A Perferred Shares',
'Series A Prefered Stock',
'Series A Preffered Stock',
'Perfered',
'Preffered C']
The permutations of the word 'preferred' in the spelling errors above appear to exhibit a family resemblance but there's very little that they all have in common. Note that splitting out every word and running levenshtein on every word in every row is going to be prohibitively expensive.
UPDATE:
There are a couple of other examples like this, e.g. with 'restricted':
['Resticted Stock Plan',
'resticted securities',
'Ristricted Common Stock',
'Common stock (restrticted, subject to vesting)',
'Common Stock (Retricted)',
'Restircted Stock Award',
'Restriced Common Stock',]
| 0 | 1 | 0 | 0 | 0 | 0 |
Given a set** S containing duplicate elements, how can one determine the total number all the possible subsets of S, where each subset is unique.
For example, say S = {A, B, B} and let K be the set of all subsets, then K = {{}, {A}, {B}, {A, B}, {B, B}, {A, B, B}} and therefore |K| = 6.
Another example would be if S = {A, A, B, B}, then K = {{}, {A}, {B}, {A, B}, {A, A}, {B, B}, {A, B, B}, {A, A, B}, {A, A, B, B}} and therefor |K| = 9
It is easy to see that if S is a real set, having only unique elements, then |K| = 2^|S|.
What is a formula to calculate this value |K| given a "set" S (with duplicates), without generating all the subsets?
** Not technically a set.
| 0 | 0 | 0 | 0 | 1 | 0 |
With MySQL
a DIV b
is much faster than
FLOOR(a / b).
But I need to round up so I'm using,
CEIL(a / b)
It seems strange that there wouldn't be a ceiling version of DIV, but I can't find it. Is there anything undocumented hidden away somewhere? Or any other non floating point way to do this?
| 0 | 0 | 0 | 0 | 1 | 0 |
I have a Random into a class which aims to generate random sequences in different contexts: this is the result of a porting from Java code.
In the Java version everything works fine since the java.lang.Random class has the method setSeed, which permits the change of the seed value dynamically.
Random rnd = new Random();
...
rnd.nextInt();
...
rnd.setSeed(seedValue);
This generates a consistent result, since each time the seed value is set, the result is random.
Unfortunately in C# the behavior is much different, since the Random class needs the seed to be set at construction:
Random rnd = new Random(seedValue);
...
rnd.Next();
...
So I have to build a new Random instance each time with the given seed, which in some spare cases generates the same value of a previous call.
Is it a way to set the seed of a Random instance in C# dynamically, without losing the consistency of the instance globally?
Thank you very much!
| 0 | 0 | 0 | 0 | 1 | 0 |
I am working on a turn-based-game AI using a neural-network technique known as NEAT. I am attempting to train a network that can move around a two dimensional (X&Y coords) space given a variety of values that are stored in what is effectively a two dimensional array.
I can see two strategies for using the neural network:
For each "cell" in the grid, provide the scores from the different heuristics as inputs to neurons and create a NN that is effectively a very complicated "scoring" system. Move the Non Playing Character (NPC) to the location with the highest score.
Create a compressed value for each heiuristic measure (somehow compressed into as few bits as possible) and provide an input neuron for each of these measures.
I am quite interested in option two because it presents the least amount of calculations required (the runtime of the game is quite long), however I am confused as to what approach I could use to create the "small representation" version of the two-dimensional heiuristic values. I know there are techniques such as Fourier Transformations out there, however I don't know if these will suit my problem. Basically I am looking for a way to convert a 50x50 array of doubles into one or maybe two double values. These two double values can be lossy-compressed, I don't need to be able to get the original values back, I just need a reasonable mechanism for changing the input data into a small footprint.
An alternative to these two possibilities is to somehow encode a "region" based on some distance from the NPC (so you get the actual values for a "close" cell, and an approximation for a "far" cell). I don't know exactly how I would wire this up, but it at least gets rid of the need to evaluate every cell every turn of the game (given I am looking at about 5 million rounds at approximately 1 second per round, any simplification I can come up with would greatly help).
I apologise if this isn't making much sense, it is quite a difficult problem that has stumped me for a while, and I can't think of an easy way to describe it.
Thankyou,
Aidan
EDITED TO ADD (and change title):
Thanks to Chris we've refined what I am looking for. What I am looking for is a way to approximate a line (I can convert the 2D map into a line) in as few parameters as possible. I have used cubic splines for interpolation before, however I need something a lot more feasable for a data-set that varies between 0.0 and 1.0 quite aggressively. What I am realling looking for I suppose is a "hash" of the map.
I know there are techniques such as cubic splines that I can work out some "key-points" from, and these values are a reasonable analogy for what I am looking for. I need a way to take the 2500 values and come up with a small representation of these values that I can use for the neural network. I think the NN can be trained to infer the true meaning of these representations, or at least to determine some correlation between the representation and the real world, so it doesn't necessarily need to be a reversible function, but I don't think many one way functions (such as MD5's, SHA's) are actually going to be very helpful either...
| 0 | 1 | 0 | 0 | 0 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.